1.0.7 • Published 7 years ago

dankjson v1.0.7

Weekly downloads
1
License
ISC
Repository
-
Last release
7 years ago

Cover photo

Dank JSON

  • Simplifies JSON reading & writing
  • Configuration reading into singleton object with configuration defaults

Reading

ParameterOptionalTypeDescription
filefalseStringPath to the file to be read

This example reads and logs the contents of fruits.json

const dj = require("dankjson");

dj("fruits.json").then(object => console.log(object));

Writing

ParameterOptionalTypeDescription
filefalseStringPath to the file to be read
objectfalseObjectJSON object to be writen to file
tabSizetrueNumberIndentation tab size

This example writes the colors object to colors.json with 4 space indentation

const dj = require("dankjson");

let colors = {
    red: {
        r: 255,
        g: 0,
        b: 0
    },
    blue: {
        r: 0,
        g: 0,
        b: 255
    }
}

dj("colors.json", colors, 4);

Reading to config

ParameterOptionalTypeDescription
filesfalseArrayPaths to the files to be read into config
defaultstrueArrayJSON objects to be writen to file if it does not exist
tabSizetrueNumberIndentation tab size

This example reads config.json into config and logs it. If the config does not exists it writes the default with 4 space indentation

const dj = require("dankjson");

let configDefault {
    ip: "",
    port: 80,
    messages: [
        "Hello, world.",
        "Bye, world."
    ]
}

dj(["config.json"], [configDefault], 4).then(config => console.log(config));

Getting config

This example gets and logs the config

const dj = require("dankjson");

dj().then(config => console.log(config));
1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago