setsuna

1.0.4 • Public • Published

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!

Package Sidebar

Install

npm i setsuna

Weekly Downloads

2

Version

1.0.4

License

ISC

Unpacked Size

14.6 kB

Total Files

5

Last publish

Collaborators

  • ghostsos
  • atomic-addison