0.3.0
Loads config files.
Repository
Current version released
3 years ago
Dependencies
std
load_config_files
Loads config files.
Supports joining with common config files, also further up in the directory structure.
Filetypes supported:
- .toml
- .json
- .yml
- .yaml
- .js
- .mjs
- .ts
Usage
Set up a directory for example like example-config, in your current working directory:
example-config/
βββ dev/
βΒ Β βββ common.js
βΒ Β βββ myapp1.toml
βΒ Β βββ myapp2.toml
βββ prod/
βββ common.json
βββ myapp1.json
βββ myapp2.json
// example.ts
import {
Config,
CONFIG_FORMATTERS,
ConfigFormatter,
loadConfig,
LoadConfigOptions,
} from "https://deno.land/x/load_config_files/mod.ts";
const options: LoadConfigOptions = { verbose: false };
const [formatterId, configRootPath, ...segments] = Deno.args;
const configRootUrl = new URL(configRootPath, "file:" + Deno.cwd());
const config: Config = await loadConfig(configRootUrl, segments, options);
const formatter: ConfigFormatter = CONFIG_FORMATTERS[formatterId];
const output: string = await formatter(config);
console.log(output);
Running the above program:
deno run \
--allow-read \
--allow-net=deno.land \
https://deno.land/x/load_config_files/example.ts \
shell example-config dev myapp2
β¦would output:
COLOR='purple'
CUSTOMER_URLS='{"CustomerA":"https://dev.example.com/customers/CustomerA.json","CustomerB":"https://dev.example.com/customers/CustomerB.json","CustomerC":"https://dev.example.com/customers/CustomerC.json","CustomerD":"https://dev.example.com/customers/CustomerD.json","CustomerE":"https://dev.example.com/customers/CustomerE.json"}'
APP_ID='myapp2'
More examples
For all possible combinations, including different output formats, see example-config/EXAMPLE_ALL_COMBINATIONS.md.