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

sjsondblib

v1.0.4

Published

A simple package that lets you use json as a database.

Downloads

1

Readme

jsondb

A super simple package that allows you to use JSON files (or objects) as a database.

Version GitHub license Generic badge Generic badge Open Source Love svg2

I am fully aware that the code is bad and that there is a lot of better database packages out there, but I still want to share this one.

NOTE: The types are fixed now lol

How to install

Simply run npm install sjsondblib in the project directory.

How to use

  1. Require the package

    You need to require the npm package

    const jsondb = require('sjsondblib')
  2. Create the database object

    const db = new jsondb.database(<object>, '<type: optional>')

    If you want to load from a file, just use const db = new jsondb.database(<file name (string)>)

    If you want to load json from variable, use const db = new jsondb.database(<variable>, 'object')

  3. Create some keys

    These are the field of your database. You can create new ones at any time.

    db.newKey('key name', <key defauld value>)

    The key name always has to be string. The default value can be string or number or boolean. Here is an example of how can it look

    db.newKey('name', '')
    db.newKey('age', 0)
    db.newKey('likes_pancakes', true)
  4. Create a new database line (entry)

    This will add new entry to the database

    db.newEntry('id - optional')

    If you dont specify id, it will be created automatically.

    db.newEntry() // Id: 1
    db.newEntry('custom') // Id: custom
    db.newEntry() // Id: 2
  5. Edit values

    db.setValue('<id>', '<key>', <value>)

    id and key always have to be strings. Value can be anything.

    Lets say you have the user input the values name age and likes_pancakes. Now lets save it to our database.

    db.setValue('1', 'name', name)
    db.setValue('1', 'age', age)
    db.setValue('1', 'likes_pancakes', likes_pancakes)
  6. Get values

    db.getValue('<id>', '<key>')

    Both id and key have to be strings. This function will return th value in its original type.

    Lets say you want to write the values.

    console.log(db.getValues('1', 'name'))
    console.log(db.getValues('1', 'age'))
    console.log(db.getValues('1', 'likes_pancakes'))

    You can also use db.getType('<id>', '<key>') to get the type of the value.

  7. Find values You can find all entries with a specified value.

    db.locate('<key>', <value>)

    This will return an array of all the ids that have the specified value under the specified key.

    Eg. If you want to find the list of people that like pancakes, you can do

    const ids_of_ppl_that_like_pancakes = db.locate('likes_pancakes', true)
  8. Save file

    Saving the json into file is simple.

    db.writeFile('<file - optional>')
    • If you have the database loaded from a file, then the file parameter is optional. If you have an object loaded, you always need to specify file.
  9. You can name the database

    db.setName('<name>')

Better readme comming soon