1.0.7 • Published 7 years ago
dankjson v1.0.7
Dank JSON
- Simplifies JSON reading & writing
- Configuration reading into singleton object with configuration defaults
Reading
Parameter | Optional | Type | Description |
---|---|---|---|
file | false | String | Path 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
Parameter | Optional | Type | Description |
---|---|---|---|
file | false | String | Path to the file to be read |
object | false | Object | JSON object to be writen to file |
tabSize | true | Number | Indentation 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
Parameter | Optional | Type | Description |
---|---|---|---|
files | false | Array | Paths to the files to be read into config |
defaults | true | Array | JSON objects to be writen to file if it does not exist |
tabSize | true | Number | Indentation 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));