JSPM

super-array

1.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q23797F
  • License MIT

JavaScript Array enhanced with O(1) access for properties by unique key

Package Exports

  • super-array

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (super-array) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

super-array

Travis npm npm Coveralls node GitHub stars GitHub forks license David

Just like a normal JavaScript Array but enhanced with constant O(1) access time for properties by unique key!

Install

$ npm install --save super-array

Usage

const SuperArray = require('super-array');

const myArray = new SuperArray([
  {id: 'ab1', name: 'John'},
  {id: 'ab2', name: 'Peter'},
]);

myArray.get('ab1') // {id: 'ab1', name: 'John'}
myArray.get('ab2') // {id: 'ab2', name: 'Peter'}

or you can use a custom identifier function: (please note that the identifier has to be unique)

const SuperArray = require('super-array');

const myArray = new SuperArray([
  {id: 'ab1', name: 'John'},
  {id: 'ab2', name: 'Peter'},
], function(item) { return item.name });

myArray.get('John') // {id: 'ab1', name: 'John'}
myArray.get('Peter') // {id: 'ab2', name: 'Peter'}

API

SuperArray(arr, identifyFn)

arr (optional):
  • Type: <Array>
  • Default: []
identifyFn (optional):
  • Type: <Function(item):identifier>
  • Default: function(item) { return item.id }

Returns SuperArray instance.

License

MIT © Patrik Toma