1.1.5 • Published 5 years ago
mtlc v1.1.5
(Character: Tohru from Miss Kobayashi's Dragon Maid)
A simple, functional, and flexible way to load your configuration files
Features
- Simple, configs loaded with 2 lines of code
- Functional, read with or without defaults and write both files and directories
- Flexible, create support for formats of your needs
- TypeScript, built in type definitions
- JSDocs, together with TypeScript's type definitions for helpful IntelliSense
- Promises
Documentation
Examples
Reading a raw text file
import * as mtlc from "mtlc";
const file: mtlc.ConfigFile = await mtlc.file("raw.txt") // Defaults to RawFormat format by default
.read();
console.log(file.content);
Contents of raw.txt
Reading a JSON file
import * as mtlc from "mtlc";
const file: mtlc.ConfigFile = await mtlcfile("config.json") // Associates json files with JSONFormat format by default
.def({
ip: "127.0.0.1",
port: 1337
}) // What content should default to when reading
.read({ write_if_defaulted: true }); // Write if content is defaulted in any way after reading
console.log(file.content);
{ ip: "127.0.0.1", port: 1337 } | Contents of config.json
Writing a raw text file
import * as mtlc from "mtlc";
const file: mtlc.ConfigFile = mtlc.file("foo.txt"); // Defaults to RawFormat format by default
file.content = "bar";
file.write();
Reading a directory
import * as mtlc from "mtlc";
const directory: mtlc.ConfigDirectory = await mtlc.directory("recipies", new mtlc.formats.JSONFormat())
.def({
"water.json": {
steps: [ "Pour water" ]
},
"cereal.json": {
steps: [
"Pour cereal FIRST",
"THEN pour milk"
]
}
}) // What the directory's files' content should default to when reading
.read();
const contents: any = directory.contents();
console.log(contents["water.json"]);
console.log(contents["cereal.json"]);
{ steps: [ "Pour water" ] } | Contents of water.json
{ steps: [ "Pour cereal FIRST", "THEN pour milk" ] } | Contents of cereal.json
(Remaining files' contents from recipies)
Compiling
npm install --only=dev
npm run-script compile
Testing
npm install --only=dev
npm run-script test