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

jsonbases

v2.0.2

Published

Local database with json.

Downloads

43

Readme

Jsonbases - local Json database or NPM package to manage JSON-based dataset in Node.js. It provides functions to create, read, update, and delete records in a JSON file, following a specified data format.

Installation

npm install jsonbases

Get started

import jsonbases from 'jsonbases';

// Define user data format giving types, optionally specify required and unique values.
const format = {
    types: {
        name: 'string',
        age: 'number',
    },
    requireds: ['name', 'age'],
    uniques: ['name'],
};

// Create user table named "users".
const users = jsonbases('users', format);

//Optionally specify the path, by default it's './jsonbases'
const usersTemp = jsonbases('users-temp', format, './path/to/your/database');
  • createItem() Creates a new item with properties initialized to null based on the defined data format.
// Create a new item with default values
const newItem = users.createItem(); // returns object
// ex: { name: null, age: null, _id: 'ad5sad132' }
  • createItem(number) Creates multiple items with properties initialized to null based on the defined data format.
// Create a list of items with default values
const itemList = users.createItem(100); // returns list
// ex: [{ name: null, age: null, _id: 'ad5sad132' },...]
  • add(item) Adds a new item into the database if it conforms to the specified data format.
// Add a new item to the database
newItem.name = 'John';
newItem.age = 25;
const added = users.add(newItem); // returns boolean
  • find(item) Finds and returns an item from the database based on provided criteria. Input should contain only unique values.
// Find an item by unique values
const foundItem = users.find({ name: 'John' }); // returns object
  • findAll(item) Finds and returns an array of items from the database based on provided criteria.
// Find all items matching certain criteria
const allItems = users.findAll({ age: 25 }); // returns list
  • update(item) Updates an existing item in the database with the provided data, including original _id.
// Update an existing item
newItem.age = 26;
const updated = users.update(newItem); // returns boolean
  • remove(item) Removes an item from the database based on provided criteria. Input should contain only unique values.
// Remove an item by unique values
const removed = users.remove({ name: 'John' }); // returns boolean
  • removeAll(item) Removes all items from the database that matches provided criteria. Input can be any data.
// Remove all items matching certain criteria
const removedAll = users.removeAll({ age: 26 }); // returns boolean
  • addFromList(list) Adds all items in a list to the database if it conforms to the specified data format.
// Add list of items to the database
const addedFromList = users.addFromList(itemList); // returns boolean
  • updateFromList(list) Updates multiple items in database as provided list, including original _id.
// Update multiple items
const updatedFromList = users.updateFromList(itemList); // returns boolean
  • removeFromList(list) Removes multiple items from the database based on provided list of criteria. Input should contain only unique values.
// Remove multiple items
const removedFromList = users.removeFromList([{ name: 'John' }, { name: 'Maria' }]); // returns boolean
  • getAll() Returns an array containing all items in the database.
// Get all items in the database
const allData = users.getAll(); // returns list
  • reset() Resets the entire table, removing all items.
// Reset the database (remove all items)
users.reset();

Features

  • Saves your time - no need to learn, install, create connections, sign up for other databases.

  • Easy to use - simple intuitive functions to manage with your tables.

  • Fast to work - simplicity of this tool makes your work more faster.

  • List control - manipulate large amount of data faster.