lkon
v5.1.5
Published
LKON is type of Object Notation implemented as an open-source library for JS.
Downloads
14
Maintainers
Readme
About project...
LKON Parser was created to deliever brand new configuration language called Language for Konfiguration Object Notation
to your Node.JS project.
Current version of newer stringifier does not support variables and imports yet!
Highlighting
Are you bored and tired of looking at LKON Syntax in the only one color? Well, we have something special for you. Thanks to my friend (yobonez) we now have special VSC addon with highlighter for LKON files. The only thing you have to do is download it in VSC marketplace:
- Name of addon:
LKON Syntax Hightlighting
- GitHub
What's new?
Version 5.1.5: Parser:
- parses numbers including "_" from now;
- parsing variables is now fixed; Stringifier:
- stringifies boolean values properly from now;
LKON Supports these types of data:
- Files -
"./path/to/file"encoding
; - RegExps -
/your_expression_here/flags
; - String -
"string"
; - Date -
"01-01-1970, 0:00:00.000"date
- undefined -
Undefined
; - Boolean -
True
orFalse
; - null -
Null
; - Number - (every kind of notation!)
0x0001
,1
,1e+21
,.1
,-1
, orInfinity
; - NaN -
NaN
; - Numeric Array:
[
@* => value;
];
- Associative Array:
[
@key => value;
];
Remember
- Before you use it, you need to init this using require("lkon")({allowGlobal: true|false, allowRequire: true|false});
- If you set allowGlobal to true, LKON global object will be created.
- If you set allowRequire to true, you will be able to read files with ".lkon" extension using require method, e.g. require("./path/to/file.lkon").
- Variables & Imports can be set before
[
, in aheader
of the file;- Import instruction examples:
- With destructuring:
import "./path/to/file.lkon"utf8 as [ key=>alias; ];
; - Without destructuring:
import "./path/to/file.lkon"utf8 as key;
;
- With destructuring:
- Use instruction examples:
- With destructuring
use [ @hello => "world"; ] as [ hello=>alias ];
- Without destructuring:
use "01-01-1970, 0:00:00.000"date as start;
;
- With destructuring
- Import instruction examples:
- Single-line comments must be followed by
#
; - Multi-line comments must begin and be followed by
'''
(three apostrophes); - Every line/expression of LKON Code must end with
[
, or;
; - Object keys must begin with
@
; *
(asterisk) mean numeric index, if first property of object has a*
key, the object is set to an array;- An assignment mark is
=>
; True
,False
,Undefined
,NaN
andNull
are cases sensitive and must be started by upper case letter;- Every string is multi-line, and template string. To put variables into string, you just need to put your variable into
[]
square brackets, e.g.@string => "Hello, [users.0.username]";
,@string => "Hello, [Main.users.0.username]";
; Main
keyword is a reference to the global variable of the main object of file.
Examples of using
Using this module is very simple:
const lkon = require('lkon')();
lkon.parse(
`
use "v3.0.0" as version;
use [
@privateKey => "./private.key"bin;
@publicKey => "./public.key"bin;
] as keys;
import "./database.lkon"utf8 as [
host => dbHost;
port => dbPort;
];
[
@version => version;
@admin => [
@username => "root";
@password => "Q@wertyuiop";
];
@keys => keys;
@greeting => "Hello, [Main.admin.username]! The server is running on [dbHost]:[dbPort], its version is [version]."
@database => [
@host => dbHost;
@port => dbPort;
@username => Main.admin.username;
@password => Main.admin.password;
];
@localhostDirectory => "./views";
@maxPasswordLength => 128;
@passwordRegex => /[^a-zA-Z0-9\!@#$%\^&\*\(\)\{\}\[\];"'\/\\\.,]/g;
];
`
)
/* Expecting:
{
version: "v2.0.0",
admin: {
username: "root",
password: "Q@wertyuiop"
},
keys: {
public: <Buffer A7 B2 C7 ...>,
private: <Buffer C3 A1 B8 ...>
},
greeting: "Hello, root! The server is running on 127.0.0.1:80, its version is v2.0.0.",
database: {
host: "127.0.0.1",
port: 80,
username: "root",
password: "Q@wertyuiop"
},
localhostDirectory: "./views",
maxPasswordLength: 128,
passwordRegex: /[^a-zA-Z0-9\!@#$%\^&\*\(\)\{\}\[\];"'\/\\\.,]/g
}
*/
lkon.stringify(
[
{
username: "JohnDoe",
age: 24,
email: "[email protected]",
password: "password",
favRegexp: /[abc]+/
},
{
username: "FooBar",
age: 20,
email: "[email protected]",
password: "password",
favRegexp: /[def]+/
},
{
username: "CatSamson",
age: 21,
email: "[email protected]",
password: "password",
favRegexp: /[ghi]+/
}
],
null,
'\t'
)
/*Expecting:
[
@* => [
@username => "JohnDoe";
@age => 24;
@email => "[email protected]";
@password => "password";
@favRegexp => /[abc]+/;
];
@* => [
@username => "FooBar";
@age => 20;
@email => "[email protected]";
@password => "password";
@favRegexp => /[def]+/;
];
@* => [
@username => "CatSamson";
@age => 21;
@email => "[email protected]";
@password => "password";
@favRegexp => /[ghi]+/;
];
];
*/