Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hugojosefson/load-config-files
Loads config files.
https://github.com/hugojosefson/load-config-files
common config deno file javascript json toml typescript yaml yml
Last synced: 5 days ago
JSON representation
Loads config files.
- Host: GitHub
- URL: https://github.com/hugojosefson/load-config-files
- Owner: hugojosefson
- Created: 2022-03-26T15:12:23.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-05-16T15:09:38.000Z (over 2 years ago)
- Last Synced: 2024-12-15T06:45:51.744Z (19 days ago)
- Topics: common, config, deno, file, javascript, json, toml, typescript, yaml, yml
- Language: TypeScript
- Homepage: https://deno.land/x/load_config_files
- Size: 26.4 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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](https://deno.land/x/load_config_files/example-config), in your
current working directory:```
example-config/
├── dev/
│ ├── common.js
│ ├── myapp1.toml
│ └── myapp2.toml
└── prod/
├── common.json
├── myapp1.json
└── myapp2.json
``````typescript
// example.tsimport {
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:
```sh
deno run \
--allow-read \
--allow-net=deno.land \
https://deno.land/x/load_config_files/example.ts \
shell example-config dev myapp2
```...would output:
```sh
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](https://deno.land/x/load_config_files/example-config/EXAMPLE_ALL_COMBINATIONS.md).