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

@mdaemon/items-model

v3.0.1

Published

A basic items manipulation model

Readme

Dynamic JSON Badge Static Badge TypeScript install size Dynamic JSON Badge Node.js CI

@mdaemon/items-model, A basic items Map model library with TypeScript support

Includes MDaemon's Emitter library as a dependency

[ @mdaemon/items-model on npm ]

The "items-model" provides basic methods for manipulating an array of objects based on a constructor

Install

  $ npm install @mdaemon/items-model --save  

Node CommonJS

const ItemsModel = require("@mdaemon/items-model/dist/items-model.cjs");

Node Modules (TypeScript/ES6)

import ItemsModel, { IItemsModelConfig, ItemObject } from "@mdaemon/items-model/dist/items-model.mjs";
// or
import ItemsModel from "@mdaemon/items-model/dist/items-model.mjs";  

Web

    <script type="text/javascript" src="/path_to_modules/dist/items-model.umd.js"></script>
<!-- necessary for versions < 2.0.0 -->
    <script type="text/javascript">window.ItemsModel = window["items-model"];</script>

ItemsModel

import ItemsModel, { ItemObject } from "@mdaemon/items-model";

// TypeScript class extending ItemObject interface
class Car implements ItemObject {
  id: number = 0;
  make: string = "";
  model: string = "";
  color: string = "";
  [key: string]: any; // Allow additional properties

  constructor(config?: any) {
    if (config) {
      Object.assign(this, config);
    }
  }
}

class Cars extends ItemsModel {
  constructor() {
    super({
      itemConstructor: Car,
      itemName: "Car"
    });
  }
}

// Alternative: Function-based constructor (still supported)
// If you do not include an id attribute, a numbered id will be assigned
function CarLegacy(config?: any) {
  this.id = 0;
  this.make = "";
  this.model = "";
  this.color = "";

  if (config) {
    Object.assign(this, config);
  }
}

function CarsLegacy() { 
  Object.assign(this, new ItemsModel({
    itemConstructor: CarLegacy,
    itemName: "Car"
  }));
}
    
const carsModel = new Cars();

// returns the name set for the model items
carsModel.getName(); // "Car";

// empties the internal items Map
carsModel.clear(); 
  
// adds a new Car to the items Map with only the config object
carsModel.add({ make: "Honda", model: "Element", color: "gray" });
// emits "added-Car" and "indexed-Car"

// gets the internal items Map
carsModel.getAll(); // [Car]

// gets all the ids from the items Map
carsModel.getAllIds();

// gets a copy of the internal items Map, so that manipulation of the items in the array do not impact the internal array
carsModel.getCopies(); // [Car]

// gets a copy of the requested item by id, so that manipulation of the item does not impact the internal item
carsModel.getCopy(0); // Car
carsModel.getCopy(1); // null

// gets an item from the internal items Map based on the id
carsModel.getById(0); // Car
carsModel.getById(1); // null

// gets the index of a given item in the internal array
carsModel.getIndex(0); // 0
carsModel.getIndex(1); // -1

// gets the first item from the internal items Map based on an attribute/value combination
carsModel.getByAttribute("make", "Honda"); // Car
carsModel.getByAttribute("model", "Odyssey"); // null

carsModel.getFirstByAttribute("make", "Honda"); // Car -- this is an alias for getByAttribute

// gets all the items from the internal array based on an attribute/value combination
carsModel.getAllByAttribute("make", "Honda"); // [Car]
carsModel.getAllByAttribute("model", "Odyssey"); // []

// sets the values passed in an object based on the id
// returns success true or false
carsModel.setAttributes(0, { model: "Odyssey", color: "blue" }); // true
carsModel.setAttributes(1, { model: "Odyssey" }); // false

// sets the values for all matching items
// returns an array of objects that use the id and success true or false
carsModel.setAttributesByAttr("model", "Odyssey", { color: "gray" }); // [{ 0: true }]

// inserts or updates the passed items after the parent id
// returns success true or false
carsModel.insert(0, [{ make: "Toyota", model: "Camry", color: "tan" }]); // true
carsModel.insert(2, [{ make: "Toyota", model: "Carolla", color: "red" }]); // false because a parent of id 2
//emits "inserted-Car"

// upsert is an alias for insert
carsModel.upsert(1, [{ id: 0, model: "Element" }]); // true

// similar to set attributes, except the full object is expected (including the id)
// returns success true or false
carsModel.update({ id: 1, make: "Toyota", model: "Camry", color: "brown" }); // true
// emits "updated-Car"

// removes the item from the internal items Map based on the id
// returns success true or false
carsModel.remove(1); // true
carsModel.remove(2); // false
// emits "removed-Car"

v3.0.0

Breaking change: The library is now written in TypeScript with full type definitions.

v2.0.0

Breaking change: Instead of window["items-model"], window.ItemsModel must be used for umd builds.

See @mdaemon/emitter for how to details on the event emitter

License

Published under the LGPL-2.1 license.

Published by MDaemon Technologies, Ltd. Simple Secure Email https://www.mdaemon.com