New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

sortable-map

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sortable-map

Dictionary data structure with flexible sort capabilities

latest
Source
npmnpm
Version
0.0.17
Version published
Maintainers
1
Created
Source

sortable-map

npm version Build Status Coverage Status Dependency Status devDependencies Status

Dictionary data structure with flexible sort capabilities

Installation

npm i -S sortable-map

Usage

  • import SortableMap from 'sortable-map';
  • const SortableMap = require('sortable-map');

Example

const map = new SortableMap();

const key = 'foo'       // Key must be a string literal
const value = 'bar;     // Value can be anything

map.add(key, value);

map.has('foo');         // true
map.find('foo');        // 'bar'
map.findAll();          // [{ key: 'foo', value: 'bar' }]
map.isEmpty();          // false
map.count();            // 1
may.keys();             // [ 'foo' ]
may.values();           // [ 'bar' ]

map.has('baz');         // false
map.find('baz');        // undefined

map.delete('foo');      // 'bar'
map.count()             // 0

map.add('foo', 'bar');
map.add('ham', 'egg');
map.clear();
map.count();            // 0

Sorting

By default findAll() returns the map sorted by key ascending. If your values are objects, pass a property name (findAll('sortOrder)) for finer sorting:

map.add('abc', { sortOrder: 20 });
map.add('xyz', { sortOrder: 0 });
map.add('nop', { sortOrder: 10 });

map.findAll();              // [{key: 'abc', value: { sortOrder: 20 }, ...];
map.findAll('sortOrder');   // [{key: 'xyz', value: { sortOrder: 0 }, ...];

Iterators

const map = new SortableMap();
map.add('foo', 'bar');

forEach(cb)

map.forEach(entry => {
    entry.key;      // 'foo'
    entry.value;    // 'bar'
));

forEachKey(cb)

map.forEachKey(key => {
    key;             // 'foo'
));

forEachValue(cb)

map.forEachValue(value => {
    value;           // 'bar'
));

Keywords

javascript

FAQs

Package last updated on 13 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts