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

setsuna

v1.0.4

Published

Setsuna is a package designed to make storing both persistent and temporary configuration data easy.

Downloads

7

Readme

Setsuna

Install

npm i setsuna --save

Quick example

const Setsuna = require("setsuna");

var setsuna = new Setsuna();

setsuna.set("property", "value", ({ error }) => {
    if (error) return console.log("ERROR", error);

    setsuna.get("property", ({ data, error }) => {
        if (error) return console.log("ERROR", error);

        console.log(data); // data = "value"
    });
});

Setup

In order to use Setsuna in your project you first need to import it:

const Setsuna = require("setsuna");

Next, declare a variable, and set up the settings that you need, for example:

var setsuna = new Setsuna({
	setting:'parameter' ...
});

Here are all the available settings:

  • dirname : A directory name which will contain all the files Setsuna generates.

    (Default: Setsuna will name the directory <YOUR-PROJECT-NAME>_settings.)

  • dirpath : Location of Setsuna's file directory.

    (Default: Setsuna stores the settings in the current user's home directory.)

  • persistent : Enable\Disable saving Setsuna's data to files.

    (Default: true. Setsuna writes all the data to files.)

Once you set up all your settings, you are ready to work with Setsuna. You have a choice between using Setsuna in syncrhonous and asynchronous modes.

Here is a list of all asynchronous methods:

setsuna.init

setsuna.init({ error } => {
    if (error) return console.log("ERROR", error);
});

In order to work, Setsuna needs to create a working directory and a default settings file. Call setsuna.init at the start of the project in order to prepare Setsuna for work.

Outside of persistent mode setsuna.init creates the default objects for temporary data storage.

setsuna.set

setsuna.set("property", "value", ({ error }) => {
    if (error) return console.log("ERROR", error);
});

To save any data to the default settings file (or to the temporary storage object if you're not running in persistent mode), you need to call setsuna.set. This method creates a property with your data. Specify the property and the value you want it to have.

setsuna.unset

setsuna.unset("property", ({ error }) => {
    if (error) return console.log("ERROR", error);
});

To remove any data from the default settings file/storage object, you need to call setsuna.unset. This method deletes the property you have specified.

setsuna.get

setsuna.get("property", ({ data, error }) => {
    if (error) return console.log("ERROR", error);

    console.log(data);
});

To get the data you saved to Setsuna, you need to call setsuna.get and specify the property name that you used to save said data.

setsuna.writeData

setsuna.writeData({ 
    data: {"your" : "data_to_write"}, 
    force: false,
    spacing: 0,
    filename: "filename.json"
}, ({ error }) => {
    if (error) return console.log("ERROR", error);
});

Setsuna can also write your data to a separate file. Call setsuna.writeData and pass it an object where you specify the filename you want to create with your data. The force option enables you to overwrite the file if it exists when the option is set to true. Additionally, you can specify the spacing option if you want your JSON to be pretty printed. If not in persistent mode, Setsuna will save all the data to a separate object property.

setsuna.readData

setsuna.readData("filename.json", ({ data, error }) => {
    if (error) return console.log("ERROR", error);

    console.log(data);
});

To read your created file/storage object, simply call setsuna.readData and pass it the filename you have previously created.

setsuna.deleteData

setsuna.deleteData("filename.json", ({ error }) => {
    if (error) return console.log("ERROR", error);
});

If you need to remove your created file/storage object, call setsuna.deleteData and pass it the filename you have previously created.

Here is a list of all synchronous methods:

setsuna.init

setsuna.initSync();

Just like the asynchronous method, but no callback.

setsuna.setSync

setsuna.setSync("parameter", "value");

Just like the asynchronous method, but no callback.

setsuna.unsetSync

setsuna.unsetSync("parameter");

Just like the asynchronous method, but no callback.

setsuna.getSync

setsuna.getSync("parameter");

Just like the asynchronous method, but no callback.

setsuna.writeDataSync

setsuna.writeDataSync({ 
    data: {"your" : "data_to_write"}, 
    force: false, 
    spacing: 0,
    filename: "filename.json"
});

Just like the asynchronous method, but no callback.

setsuna.readDataSync

setsuna.readDataSync("filename.json");

Just like the asynchronous method, but no callback.

setsuna.deleteDataSync

setsuna.deleteDataSync("filename.json");

Just like the asynchronous method, but no callback.

And that's pretty much it! Have fun!