Skip to content

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

License

Notifications You must be signed in to change notification settings

evanlucas/map-util

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published