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 🙏

© 2024 – Pkg Stats / Ryan Hefner

bolt-json-db

v2.1.1

Published

⚡️ Persistence JSON without active save.

Downloads

12

Readme

bolt-json-db npm david-dm

⚡️ Persistence JSON without active save.

Usage

npm i bolt-json-db
const BoltJsonDb = require('bolt-json-db');

const json = BoltJsonDb('./data/db.json', {
    YourAttrs: 'YourValue'
});

// Use json just like a js Object
// and the json will save to `./data/db.json` auto.

want Faster And Safer

You can use jsonschema at 3nd argument.

const json = BoltJsonDb('./data/db.json', {
    YourAttrs: 'YourValue'
}, {
    title: 'Example Schema',
    type: 'object',
    properties: {
        YourAttrs: {
            type: 'string'
        }
    }
});

Guide

It should be noted that properties in data are only reactive if they existed when the instance was created.

That means if you add a new property, like:

const db1 = BoltJsonDb('./data/db1.json', { a: 0 });
const db2 = BoltJsonDb('./data/db2.json', { a: 0 });
const db3 = BoltJsonDb('./data/db3.json', { a: 0 });

db1.a = 1; // right
db1.b = 1; // wrong, because can't listen setter of db1.b

db2.a = {
    b: 2
}; // right
db2.a.b = 3; // right
db2.a.c = 3; // wrong, because can't listen setter of db2.a.c

db3.a = [];
db3.a.push(1); // right
db3.a.push({
    b: 3
}); // right
db3.a[1].b = 4; // right
db3.a[1].c = 4; // wrong, because can't listen setter of db3.a[1].c
db3.a[0] = 2; //right
db3.a[2] = 2; // wrong, because can't listen setter of db3.a[2]

// But result maybe right when auto save is going, not recommend.

// When use jsonschema
const db4 = BoltJsonDb('./data/db3.json', {
    a: 0,
    b: 1
}, {
    title: 'Example Schema',
    type: 'object',
    properties: {
        a: {
            type: 'string'
        },
        c: {
            type: 'string'
        }
    }
});

db4.a = 1;  // wrong, but db4.a === '1' at result file, because type is string at Schema
db4.b = 2;  // wrong, because not at Schema
db4.c = 3;  // wrong, because can't listen setter of db4.c
db4.a = db4;    // wrong, but db4.a === '[object Object]' at result file, because type is string at Schema

you’ll need to set some initial value.

Next

  • [ ] Schema support Circular
    • https://github.com/fastify/fast-json-stringify
    • https://github.com/WebReflection/circular-json
  • [ ] throw Error when type is mismatching at Schema