An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# Immutable Sorted Map
[![Build Status](https://travis-ci.org/rongierlach/immutable-sorted-map.svg?branch=master)](https://travis-ci.org/rongierlach/immutable-sorted-map) [![Coverage Status](https://coveralls.io/repos/github/rongierlach/immutable-sorted-map/badge.svg?branch=master)](https://coveralls.io/github/rongierlach/immutable-sorted-map?branch=master) [![Dependency Status](https://david-dm.org/rongierlach/range-life.svg)](https://david-dm.org/rongierlach/immutable-sorted-map) [![devDependency Status](https://david-dm.org/rongierlach/immutable-sorted-map/dev-status.svg)](https://david-dm.org/rongierlach/immutable-sorted-map#info=devDependencies) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](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)