selene-fmt
v1.0.0
Published
Selene Data Format v1.0 — parser, validator, and converter
Maintainers
Readme
selene-fmt
JavaScript implementation of the Selene Data Format v1.0 — a compact, human-readable serialization format for configuration files and data interchange.
Install
npm install selene-fmtFormat overview
__sel_v1__
users [
{ name: "Rick" age: 43 }
{ name: "Sam" age: 56 }
]
products [
{ name: "Laptop" price: 999.99 }
{ name: "Mouse" price: 19.5 }
]key: valueeverywhere — no exceptions{ }delimits records,[ ]delimits blocks- Strings must be double-quoted
- Unquoted tokens: numbers,
true,false,nullonly #comments- Duplicate keys within a record are an error
API
const selene = require("selene-fmt");
// Parse
const data = selene.loads(text);
// Serialize
const text = selene.dumps(data);
const text = selene.dumps(data, { indent: 2 });
// Validate — throws SeleneError on failure
selene.validate(text);
// Convert
const json = selene.toJSON(text, { indent: 2 });
const sel = selene.fromJSON(jsonText);Example
const selene = require("selene-fmt");
const src = `
__sel_v1__
users [
{ name: "Rick" age: 43 }
{ name: "Sam" age: 56 }
]
`;
const data = selene.loads(src);
// { users: [ { name: 'Rick', age: 43 }, { name: 'Sam', age: 56 } ] }
console.log(selene.toJSON(src, { indent: 2 }));Error handling
All errors throw selene.SeleneError with a descriptive message including the line number:
try {
selene.loads(badInput);
} catch (e) {
if (e instanceof selene.SeleneError) {
console.error(e.message); // Line 4: duplicate key "name" in record
}
}CLI
selene validate myfile.sel
selene to-json myfile.sel --indent=2
selene from-json myfile.json --indent=4License
SOCL
