npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

object-index-service

v0.0.8

Published

Easy indexing and retrieval of objects by property (or properties)

Readme

ObjectIndexService

Angular 6 Javascript Service for indexing objects by a property or collection of properties.

Best deployed in low-infrastructure environments using low-powered mobile devices. We most often use this on tablets to navigate nested entities that we pull from APIs in flat collections, especially if they have to be accessed in multiple ways.

e.g. the collections: SalesOrders, SalesPerson, BusinessUnit, where SalesOrders has foreign keys to SalesPerson and BusinessUnit. If we create catalogs for each collection, we can create indices for SalesOrders by SalesOrderId, SalesPersonId, and BusinessUnitId. We can also index SalesPerson and BusinessUnit by their IDs. Then, given a specific SalesOrder, I can retrieve the BusinessUnit and the SalesPerson without having to loop through the arrays. And given a specific SalesPerson, I can retrieve all the orders without looping through that array.

Installation

> npm install --save object-index-service

In your module, include it with:

// Import the service
import { ObjectIndexService } from "object-index-service";

// Add it to the providers array for the module
@NgModule({
  ...
  providers: [ObjectIndexService, ...]
  ...
})

Then import the service and either of the classes you need in the component or service where you are going to use them

// Import what you need
import { ObjectIndexService, Catalog } from "object-index-service";

Structure and Classes

ObjectIndexService: standard angular service that should be declared in your module and manages Catalogs and keeps them loaded between controllers

Catalog: This keeps track of a collection of objects that share the same interface (for example, Dogs) and the indices that are built on the shared properties.

IndexDefinition: Defines the properties used for each index and whether the index is a collection or a single item

Usage

Create a Catalog (a collection of objects with the same interface)

let dogCat = objectIndexService.createCatalog("Dog");
// For Dog objects:
//  class Dog {
//    dogId: number;
//    name: string;
//    breed: string;
//    isAGoodBoy: boolean;
//    age: number;
//  }

Define Indices for the object being catalogued

// index name, array of properties to index, isCollection
let breedIndex = new IndexDefinition("byBreed", ["breed"], true);

// also isCollection == true (because there are a lot of Fidos)
let nameIndex = new IndexDefinition("byNameAndIsGood", ["name","isAGoodBoy"], true);

// isCollection == false because the id is unique
let idIndex = new IndexDefinition("byId", ["dogId"], false );

Add the indices to the catalog

dogCat.addIndex(breedIndex).addIndex(nameIndex).addIndex(idIndex);
// alternatively:
// objectIndexService.addIndex("Dog",breedIndex).addIndex("Dog",nameIndex)
//    .addIndex("Dog",idIndex)

Add the entities, then access them by index

dogCat.addAll(dogs);
// alternatively:
// objectIndexService.addAll("Dog",dogs)

let schnauzers = objectIndexService.get("Dog","byBreed",{breed: "schnauzer"});
let dog1 = objectIndexService.get("Dog","byId",{dogId: 1});
let goodFidos = objectIndexService.get("Dog","byNameAndIsGood", {name:"Fido",isAGoodBoy:true});

Notes

If an index is defined as isCollection: false adding a new object with the same indexed properties as a previous object will cause the first object no longer to be referenced in the index.

You can add the objects before defining the indices, but you will get a little more performance if you add the indices first.

You can add indices and objects at any time and in any order.

When you CHANGE an object's properties, it's always best if you use the service's update function so that changes to an indexed property will properly ensure reindexing.

let myDog = objectIndexService.get("Dog","byId",{dogId:1});
// myDog == { dogId: 1, name: "Mr. Snuffles", breed: "Lhasa Apso", age: 2, isAGoodBoy: true};

// undefined properties in the update object are not changed in the reference object
updateDog: { isAGoodBoy: false };

objectIndexService.update("Dog", myDog, updateDog);
// alternately: 
// dogCat.update(myDog, updateDog);