New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

indexify

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

indexify

A simple collection that will automatically update multiple indexes.

  • 0.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

README

Sometimes you want to keep track of a collection of objects, but have that collection indexed by different properties. This is where indexify might be useful:

indexify = require('indexify');

var persons = indexify([
  { key: 'id',  extract: function(obj) { return obj.id; }, unique: true },
  { key: 'age', extract: function(obj) { return obj.age; }, unique: false }
]);

persons.add({ 
  id: '09707', age: 37
});
persons.add({ 
  id: '08227', age: 37
});

persons.by.age(37);     // two persons (an array)
persons.by.id('09707'); // one person (an object)

That's basically it. The only other thing you're currently able to do is remove objects from the collection:

persons.remove({ 
  id: '09707', age: 37
});

Changes

0.3

  • Add the ability to search for multiple values: posts.by.tags('pet', 'house').

0.2

  • If the extract function returns an array, then the index will be updated based on the individual elements in the array.

FAQs

Package last updated on 16 Mar 2015

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc