nkv
v2.3.2
Published
A simple parser for Nested Key Value (nkv) structures.
Downloads
9
Maintainers
Readme
NKV — Nested Key Value
With this package you can parse nested key value structures like this one:
#
# First part
#
key1: Value 1
key2: Value 2 # This one is very important!
key3: Value 3
key4: Value 4
#
# Second one
#
key5:
key6: Value 6
into JavaScript objects:
{
[
{
key: "key1",
value: "Value 1",
children: [
{
key: "key2",
value: "Value 2",
children: null
},
{
key: "key3",
value: "Value 3",
children: [
{
key: "key4",
value: "Value 4",
children: null
}
]
}
]
},
{
key: "key5",
value: null,
children: [
{
key: "key6",
value: "Value 6",
children: null
}
]
}
]
}
Usage
Just use parse()
or parseFile()
functions.
They return an array of root-level NKVItem
elements.
const nkv = require('nkv');
let toParse = `
key1:
key2: Value 2
`;
let result = nkv.parse(toParse);
console.log(result);