@f/index

1.0.4 • Public • Published

index

Build status Git tag NPM version Code style

Generate a keyed map from a list

Installation

$ npm install @f/index

Usage

Use it to figure out what was created/removed from lists, or to test membership, etc.., e.g.

var index = require('@f/index')
var reduce = require('@f/reduce')

function removedItems (cur, prev) {
  var map = index(getKey, cur)
  return reduce(function (removed, item) {
    if (!map[getKey(item)]) removed.push(item)
    return removed
  }, [], prev)
}

API

index(keyFn?, itemFn?, list)

  • keyFn - Optional. Defaults to identity. A function that takes an item of list and returns a key appropriate for use in an object map.
  • itemFn - Optional. If two arguments are passed, list is the second argument. Transforms the value in the indexed map.
  • list - The list of things you want to index

Returns: An indexed map of the items in list to their corresponding key as returned by fn(item).

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.4
    12
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.4
    12
  • 1.0.2
    0
  • 1.0.1
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i @f/index

Weekly Downloads

12

Version

1.0.4

License

MIT

Last publish

Collaborators

  • f