https://github.com/youfoundron/immutable-sorted-map
SortedMap implemented for Immutable.js
https://github.com/youfoundron/immutable-sorted-map
Last synced: 3 months ago
JSON representation
SortedMap implemented for Immutable.js
- Host: GitHub
- URL: https://github.com/youfoundron/immutable-sorted-map
- Owner: youfoundron
- Created: 2017-05-10T17:09:56.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2022-12-06T20:18:21.000Z (over 3 years ago)
- Last Synced: 2025-02-22T04:34:48.781Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 534 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Immutable Sorted Map
[](https://travis-ci.org/rongierlach/immutable-sorted-map) [](https://coveralls.io/github/rongierlach/immutable-sorted-map?branch=master) [](https://david-dm.org/rongierlach/immutable-sorted-map) [](https://david-dm.org/rongierlach/immutable-sorted-map#info=devDependencies) [](https://standardjs.com) [](http://commitizen.github.io/cz-cli/)
Ever wish Immutable.js Maps would insert new items sorted by key?
Issue [#88](https://github.com/facebook/immutable-js/issues/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
```javaScript
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](https://facebook.github.io/immutable-js/docs/#/Map)