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

the-lopster

v0.1.9

Published

A small library for manipulating json files and using them to save data.

Downloads

243

Readme

The-Lopster

A small library for manipulating json files and using them to save data.

ES6

import DB from "the-lopster";

CommonJS

const DB = require("the-lopster").default;

new DB

let db = new DB.DB(src, value);
  • src - is the path to your JSON file. (A mandatory parameter, but the file does not have to exist, but if it exists, it should contain {} as a minimum)

  • value - this is a preset, the value of which will be set in the file, but if the file already contains the data, the preference will be given to the data entered in this parameter (optional parameter)

That is, if in the file:

{
  "age": 25
}

And in the code:

const db = new DB.DB("path/to/file.js", {age: 20});

Then the file will be overwritten:

{
  "age": 20
}

DB.data

This is a field in which the values from the file are stored, through it you can get the values of the file and also change them, but it is not recommended to change them.

DB.set

Through this method, you can change the value of the file. Use exactly this method to change data.

const db = new DB.DB("path/to/file.json", {age: 20});

db.set(callback);

callback - This is a function:

db.set(function () {
	this.age = 25;
})

Or:

db.set((data) => {
	data.age = 25;
})

DB.watch

This function enables synchronization with the file in the group will automatically change this.data if there were any variables in the file. Calling again will disable sync.

:)

Any data changes are automatically written to the file. If the watch function is enabled, when changing the file, the variables from the file will be automatically pulled up.

DB.use

If you need to use other data storage methods, you can use extensions based on the DB.Extension class. At the moment, there is support for such files as JSON (default), INI, YAML, TOML, XML.

To use the extension there is a function .use

Example:

import DB from "the-lopster";

DB.use(DB.XML);

DB.Extension

This is an extension class that accepts three parameters ext, parse, stringify.

  • ext - file extension with a dot at the beginning.
  • parse - a function that takes string and returns an Object
  • stringify - a function that takes Object and returns an string
import DB from "the-lopster";

function parse(value: string): Object {
}

function stringify(value: Object): string {
}

let EXT = new DB.Extension(".ext", parse, stringify);

Using:

DB.use(EXT);

DB.Sherbet

This is a slightly truncated analogue of DB.DB, it does not save data by itself, for this you need to call method DB.Sherbet.save. Also, when closed due to the combination of CTRL+C, when method DB.Sherbet.watch works, data will be saved. It reads data when an instance is created and when the program is closed, and all the rest of the time the data is stored in the RAM, which is why it is called Sherbet. Everything else works as in DB.DB.