0.3.0 • Published 7 years ago

immutable-sorted-map v0.3.0

Weekly downloads
1
License
GPL-3.0
Repository
github
Last release
7 years ago

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

0.3.0

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.1

7 years ago