Pretty self-explanatory
(Character: Tohru from Miss Kobayashi’s Dragon Maid)
A better way to load your configuration files
I needed a module to save me from having to write the same snippets of code in every project that required a config.
There already existed many modules that drastically reduced the amount of code I would have to write.
But I often still found myself in very simmilar situations: Like writing snippets to generate default configs.
Not to mention anyting to do with directories.
So that’s why I made this neat little module. I hope you are able to get a simmilar amount of value from it as I
import * as mlc from "@aery/mlc";
const file: mlc.ConfigFile = await mlc.file("raw.txt") // Defaults to RawFormat format by default
.read();
file.content;
import * as mlc from "@aery/mlc";
const file: mlc.ConfigFile = await mlc.file("config.json") /* Associates json files with
JSONFormat format by default */
.defaults({
ip: "127.0.0.1",
port: 1337
}) // What content should default to when reading
.read({ write_if_defaulted: true }); // Write if content was defaulted in any way after reading
file.content;
import * as mlc from "@aery/mlc";
const file: mlc.ConfigFile = mlc.file("foo.txt"); // Defaults to RawFormat format by default
file.content = "bar";
file.write();
import * as mlc from "@aery/mlc";
const directory: mlc.ConfigDirectory = await mlc.directory("recipies", new mlc.formats.JSONFormat())
.defaults({
"water.json": {
steps: [ "Pour water" ]
},
"cereal.json": {
steps: [
"Pour cereal FIRST",
"THEN pour milk"
]
}
}) // What the ConfigDirectory's ConfigFiles' content should default to when reading
.read();
const contents: object = directory.contents();
contents["water.json"];
contents["cereal.json"];
npm install --only=dev
npm run-script compile
npm install --only=dev
npm run-script test