0.2.0 • Published 9 years ago
sonparser v0.2.0
node-sonparser
Safe parser of JSON and CSON for config parsing like ConfigParser of python.
For more information, view the documentation.
Installation
npm install sonparser --save
Quick Example
Javascript
var sonparser = require("sonparser");
var result;
var ExampleTsConfParser = sonparser.hasProperties([
["compilerOptions", sonparser.hasProperties([
["target", sonparser.string],
["module", sonparser.string],
["noImplicitAny", sonparser.boolean.option(false)],
["preserveConstEnums", sonparser.boolean.option(false)],
])],
["exclude", sonparser.array(sonparser.string).option([])],
]);
result = ExampleTsConfParser.parse({
"compilerOptions": {
"target": "es5",
"module": "commonjs"
},
"exclude": [
"node_modules",
"build"
]
});
result = ExampleTsConfParser.parse({
"compilerOptions": {
"target": 5,
"module": "commonjs"
}
}); // throw Error!
Typescript
/// <reference path="node_modules/sonparser/lib-typings/sonparser.d.ts" />
import * as sonparser from "sonparser";
let result: TsConfig;
interface CompilerOptions {
target: string;
module: string;
noImplicitAny: boolean;
preserveConstEnums: boolean;
}
interface TsConfig {
compilerOptions: CompilerOptions;
exclude: string[];
}
const ExampleTsConfParser = sonparser.hasProperties<TsConfig>([
["compilerOptions", sonparser.hasProperties<CompilerOptions>([
["target", sonparser.string],
["module", sonparser.string],
["noImplicitAny", sonparser.boolean.option(false)],
["preserveConstEnums", sonparser.boolean.option(false)],
])],
["exclude", sonparser.array(sonparser.string).option([])],
]);
result = ExampleTsConfParser.parse({
compilerOptions: {
target: "es5",
module: "commonjs"
},
exclude: [
"node_modules",
"build"
]
});
result = ExampleTsConfParser.parse({
compilerOptions: {
target: 5,
module: "commonjs"
}
}); // throw Error!
License
0.2.0
9 years ago
0.1.3
10 years ago
0.1.2
10 years ago
0.1.1
10 years ago
0.1.0
10 years ago
0.0.17
10 years ago
0.0.16
10 years ago
0.0.15
10 years ago
0.0.14
10 years ago
0.0.13
10 years ago
0.0.12
10 years ago
0.0.11
10 years ago
0.0.10
10 years ago
0.0.9
10 years ago
0.0.8
10 years ago
0.0.7
10 years ago
0.0.6
10 years ago
0.0.5
10 years ago
0.0.4
10 years ago
0.0.3
10 years ago
0.0.2
10 years ago
0.0.1
10 years ago