2.1.1 • Published 8 years ago

map-util v2.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

map-util

Build Status Coverage Status

Simple set of utilities that make getting the previous or next value in a map easier.

Install

$ npm install [--save] map-util

Usage

'use strict'

const utils = require('map-util')
const nextVal = utils.nextVal
const prevVal = utils.prevVal

const map = new Map()
map.set('1', '1')
map.set('2', '2')

nextVal('1', map) // => '2'
nextVal('2', map) // => null
// If we want to wrap around:
nextVal('2', map, true) // => '1'

prevVal('2', map) // => '1'
prevVal('1', map) // => null
// If we want to wrap around:
prevVal('1', map, true) // => '2'

// or to get first and last
utils.first(map)    // => ['1', '1']
utils.firstKey(map) // => '1'
utils.firstVal(map) // => '1'

utils.last(map)     // => ['2', '2']
utils.lastKey(map)  // => '2'
utils.lastVal(map)  // => '2'

// Replace the key with another key, but keep the value
utils.replace('2', '10', map)
console.log(map.get('10'))
// => '2'

Test

$ npm test

Author

Evan Lucas

License

MIT (See LICENSE for more info)

2.1.1

8 years ago

2.1.0

8 years ago

2.0.0

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago