immutable-sorted-map

v0.3.0
SortedMap implemented in Immutable.js
immutable immutablejs sorted map keys

Immutable Sorted Map

Build Status Coverage Status Dependency Status devDependency Status JavaScript Style Guide Commitizen friendly

Ever wish Immutable.js Maps would insert new items sorted by key?
Issue #88 inspired me to extend Immutable's Map to do just this.

Installation

Using npm:
$ npm install immutable-sorted-map
Using yarn:
$ yarn install immutable-sorted-map

Usage

import SortedMap from 'immutable-sorted-map'

const myData = {
  '0.01': 'hundredth',
  '0.001': 'thousandth',
  '0.1': 'tenth'
}

const compareKeys = (currKey, nextKey) => {
  const currNum = Number(currKey)
  const nextNum = Number(nextKey)
  if (currNum < nextNum) return -1
  if (currNum > nextNum) return 1
  return 0
}

const myImmutableData = new SortedMap(myData, compareKeys)

myImmutableData.toJS()
/* {
  '0.001': 'thousandth',
  '0.01': 'hundredth',
  '0.1': 'tenth'
} */

Api

See the documentation for Immutable's Map

npm i immutable-sorted-map

Metadata

  • GPL-3.0
  • Whatever
  • https://github.com/rongierlach
  • released 5/22/2017

Downloads

Maintainers