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

json-store-factory

v0.0.1

Published

Function that returns a store that can save/load sync/async data into a specified JSON file.

Readme

json-store-factory

Function that returns a store that can save/load sync/async data into a specified JSON file.

No dependencies at all.

Why

To have this repeated pattern of code uploaded as an external module.

Installation

$ npm i -s json-store-factory

Explanation

This tool gives you an interface to load/save/get/set/delete data of a json file, in a sync or async way.

Usage

Basic operations

  1. create store
  2. save store
  3. load store
  4. get store data
  5. set store data
  6. delete store

1. Create a store:

const jsonStoreFactory = require("json-store-factory");
const store = jsonStoreFactory("./store.json", { beautify: true });

2. Save new data:

Synchronously:

store.saveSync({ title: "My title", info: { author: "someone" } });

Asynchronously:

await store.save({ title: "My title", info: { author: "someone" }  });

3. Load data:

Synchronously:

const data = store.loadSync();

Asynchronously:

const data = await store.load();

4. Get data:

Pass a selector (array of property names) indicating what you want to get from the store. You can pass a default value too.

Synchronously:

const item = store.getSync(["info", "author"], "Optional default value"); // returns: "someone"

Asynchronously:

const item = await store.get(["info", "author"], "Optional default value");

5. Set data:

Pass a selector (array of property names) indicating what you want to set from the store, and the value for it. The resultant data is returned.

Synchronously:

store.setSync(["title"], "My new title");

Asynchronously:

await store.set(["title"], "My new title");

6. Delete store:

Synchronously:

store.deleteSync();

Asynchronously:

await store.delete();

You can also delete specific parts of the store by providing selectors:

Synchronously:

const store = store.deleteSync("title");

Asynchronously:

const store = await store.delete(["title"]);

API

The module is a simple function that takes 3 arguments:

  • store:String: path to the store.
  • settings:Object: settings for the store. Currently, only beautify:Boolean is allowed (which defaults to true).
  • extensions:Object: extensions for the store instance. Properties and methods that will be added to the store (which defaults to {}).

The signatures of the methods of the store can be guessed by the Usage section of this document.

Synchronous operations can throw errors due to filesystem operations or JSON transformations.

Internal API

Due to how very useful are the internal methods of the API, they are also available through the function the module is:

  • getter: this function...
    • ...receives:
      • data:Object: data to be altered.
      • selector:Array|String: selector of the data we want to get.
      • defaultValue:any: the value returned when it is not found.
  • setter: this function...
    • ...receives:
      • data:Object: data to be altered.
      • selector:Array|String: selector of the data we want to set.
      • value:any: the value we want to assign to the provided selection.
      • force:Boolean: whether or not we want to force the creation of intermediate objects. Defaults to false.
  • deleter: this function...
    • ...receives:
      • data:Object: data to be altered.
      • selector:Array|String: selector of the data we want to delete.

They all return the resulted data.

Note: This internal API is available for browser environments too.

Here you have an example of how to use it:

require("json-store-factory").getter({ some: { data: "text" }}, ["some", "data"]) === "text"; // returns true

Tests

To run tests, place the cmd in the json-store-factory project and run:

$ npm run test

As it does not hace external dependencies, it should work.

License

This project is released under WTFPL or What The Fuck Public License, which means do what you want, basically.

Issues

Please, address your issues here.