JSONotebook

extends Nodebook

"JSONotebook" is a customized class used for JSON (JavaScript Object Notation) files.

Usage

Setup

const Nodebook = require('nodejs-notebook');

const config = new Nodebook.JSONotebook('config');

note(key, value)

Properly notes a key and a value into JSON data. Can also replace existing values.

key: Represents the key to fetch the value. Can be anything.

value: The value that key is tied to. Can be anything.

config.note('name', 'Alex');
// Sets "name" to "Alex"

config.note('name', 'Alexander');
// Name isn't "Alex" anymore, it is "Alexander"

push(key, newkey)

Pushes a value into an array.

key: The key that represents the array.

The value tied to the key must be an existing array or it will not work

newkey: The value to push into the array. Can be anything.

config.push('favorite_colors', 'blue');
// Adds "blue" to array "favorite_colors"

fetch(key)

Fetches a value based on the key.

key: The key that represents the value you want to get.

const myname = config.fetch('name');
console.log(myname);
// logs "Alexander"

erase(key)

Erases an existing value from the JSON file.

key: The key that represents the value you want erased.

config.erase('hate_letters');
// Array "hate_letters" does not exist anymore

config.erase('middlename');
// String "middlename" does not exist anymore

toYML()

Converts the JSON data to YML data.

let yml = config.toYML();
console.log(yml.toString());
// logs the JSON data as YML data

Last updated