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

zerodb

v0.2.2

Published

Easy to use JSON database for Node.js with encryption.

Downloads

5

Readme

Table of Contents

Install

npm:

npm install zerodb

Yarn:

yarn add zerodb

GitHub:

git clone https://github.com/mazecodes/zerodb.git

Usage

Load a database:

const ZeroDB = require('zerodb');

const db = new ZeroDB('./database.json');

If the database doesn't exist, ZeroDB will create a new one.

Adding defaults:

db.init({
  posts: [],
  user: {},
});

You can also force the database to replace the current state with the initial state:

db.init(
  {
    posts: [],
    user: [],
  },
  { force: true }
);

Save the database:

await db.save();

Set a value:

db.set('user.name', 'John Doe');

You can set multiple values with chaining:

db.set('user.name', 'John Doe')
  .set('user.age', 18)
  .set('user.email', '[email protected]');

Get a value:

db.get('user.name');

You can also provide a fallback value:

db.get('user.admin', false);

Push to an array:

db.push('posts', {
  id: 0,
  title: 'Hello World',
});

You can also push multiple values with chaining:

db.push('posts', {
  id: 0,
  title: 'Hello World 1',
})
  .push('posts', {
    id: 1,
    title: 'Hello World 2',
  })
  .push('posts', {
    id: 2,
    title: 'Hello World 3',
  })
  .push('posts', {
    id: 3,
    title: 'Hello World 4',
  });

ZeroDB will set a new array if the pushing path doesn't exist.

Check if a property exists:

db.has('user.name'); // true

Delete a propery:

db.delete('user.name');
db.has('user.name'); // false

Reset the database to its initial state:

db.reset();

Find all the matches:

db.find('posts', { author: 'John' });

You can also use RegExp:

db.find('posts', { title: /^Hello/ });

Find only the first match:

db.findOne('post', { id: 0 });

Increase the value:

db.increment('user.age'); // Increase by 1
db.increment('user.age', 5); // Increase by 5

Decrease the value:

db.decrement('user.age'); // Decrease by 1
db.decrement('user.age', 5); // Decrease by 5

Update a property based on its last value:

db.update('user.name', name => name.toLowerCase());

Get the current state of the database:

db.getState();

Replace the current state:

db.setState({ foo: 'bar' });

Destory the database:

db.destory();

This will also delete the database file. If you don't want that, you can specify it like this:

db.destroy(false);

Encryption

Using encryption with ZeroDB is pretty simple. All you have to do is:

new ZeroDB('./database.json', {
  encryption: true,
  secret: 's3cr3t',
  iterations: 50_000,
});

iterations is the number of iterations used for key derivation. The encryption key will be derived from secret.

ZeroDB uses PBKDF2 for key derivation with default iterations set to 50,000 and uses AES256 for encryption. It will also use HMAC-SHA256 for signing the state.

Note: The encryption will only happen when the database is being saved.

Contributing

All contributions, issues and feature requests are welcome! Please feel free to check issues page.

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AwesomeFeature)
  3. Commit your changes (git commit -m "Add Awesome Feature")
  4. Push to the branch (git push origin feature/AwesomeFeature)
  5. Open a Pull Request

Author

Maze Peterson:

Show your support

Give a ⭐ if you liked this project!

License

MIT © Maze Peterson