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 🙏

© 2025 – Pkg Stats / Ryan Hefner

localstorage-orm

v1.1.0

Published

Interact with localStorage as we would with an ORM.

Downloads

9

Readme

localstorage-orm

GitHub Actions Workflow Status GitHub package.json dynamic Codecov

Interact with localStorage as we would with an ORM.

Setup

import { Model, Schema } from "localstorage-orm";

// Define the schema
interface Person extends Schema {
    name: string;
    age: number;
}

// Use the schema to define the model
const personModel = new Model<Person>("person");

Creating records

// Create a new instance of the model with build
const person = personModel.build();

person.name = "John Doe";
person.age = 24;

// Persist the instance
person.save();

// Or use the create method to instantly persist a data
const janeDoe = personModel.create({
    name: "Jane Doe",
    age: 24,
});

Fetching records

// Get all records of the model
const allRecords = personModel.list();

// Get a filtered list
const personAged24 = personModel.find({
    age: 24,
});

// Get a single record
const johnDoe = personModel.findOne({
    name: "John Doe",
});

// Get a single record by ID
const johnDoeAgain = personModel.findById(johnDoe.id);
const johnDoeAgainAndAgain = personModel.get(johnDoe.id);

Updating Records

// Updating a single instance
johnDoe.name = "Johnny Doe";
johnDoe.save();

for (let person of personAged24) {
    // What's funnier than 24?
    person.age = 25;
}

// Updating multiple records
personAged24.save();

Deleting records

// Delete a single instance
johnDoe.delete();

// Deletes a list of instance
personAged24.delete();

Reference and populatiom

// Schema declarations
interface Contact extends Schema {
    phone: number;
    email: string;
}
// Allow string for ID and schema for population
interface Employee extends Schema {
    name: string;
    contact: string | Contact;
}
// Array of references
interface Company extends Schema {
    name: string;
    employees: string[] | Employee[];
    contact: string | Contact;
}

const contactModel = new Model<Contact>("contact");

// Declare reference in modelSettings
// modelName - to reference which model to get the data from
// property - field in interface that references that model
const employeeModel = new Model<Employee>("employee", {
    references: [
        {
            modelName: "contact",
            property: "contact",
        },
    ],
});
// If one to many, add isArray property
const companyModel = new Model<Company>("company", {
    references: [
        {
            modelName: "employee",
            property: "employees",
            isArray: true,
        },
        {
            modelName: "contact",
            property: "contact",
        },
    ],
});

const company = ...
// Will convert {string} id into an instance of Contact
company.populate("contact");
// Will convert {string[]} ids into an array of Employees
company.populate("employees");
// Only populate the reference in the first index
company.populate("employees", 0);

Model Settings

const personModelWithSettings = new Model<Person>("person", {
    timestamps: true;
    softDelete: true;
    references: Reference[]
});
  • timestamps: boolean - if true, adds an autogenerated createdAt and updatedAt property to the schema
  • softDelete: boolean - if true, adds an isDeleted flag to the schema, which is set to true instead of deleting the data
  • references: Reference[] - list of references for the model
    • property: string - property of schema that references the target model
    • modelName: string - name of the target model
    • isArray: boolean - indicates that the property is an array

TODO

  • findAndUpdate
  • findOneAndUpdate
  • findAndDelete
  • findOneAndDelete
  • joins
  • population
  • indexing
  • unique

Brief history (of why I made this)

  1. Created a to do app to study Vue and added localStorage as persistence option
  2. Thought "Hey! I can reuse this" and uploaded as seperate repo (localStorage-crud) to github
  3. Published my first package and thought about this project