https://github.com/phaalonso/config-typing
An Javascript library created with the objective of loading config from JSON files with type checking, defaults and the ability to update the configuration file
https://github.com/phaalonso/config-typing
config-load js library ts
Last synced: about 1 year ago
JSON representation
An Javascript library created with the objective of loading config from JSON files with type checking, defaults and the ability to update the configuration file
- Host: GitHub
- URL: https://github.com/phaalonso/config-typing
- Owner: phaalonso
- License: mit
- Created: 2021-08-09T03:30:00.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-08-18T01:00:29.000Z (almost 5 years ago)
- Last Synced: 2025-04-18T21:17:54.733Z (about 1 year ago)
- Topics: config-load, js, library, ts
- Language: TypeScript
- Homepage:
- Size: 66.4 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Config validator
[Npm package](https://www.npmjs.com/package/config-validation)
A library created with the objective to facilitate creating configurating configuration that are stored in JSON files. It's uses a schema defined by the user, that the loaded json file needs to have otherside the loading of the file will fail as an "Config error".
## Important
In the moment this library is in pre-release, so be careful when to use it. There can be lots of bugs or some problems that needs to be fixed.
## Reasong
An alternative of [Convict](https://www.npmjs.com/package/convict) written in Typescript, the primary reason of this library is the need of dynamically updating the configuration file in some of my projects (yeah, it has it's owns risk but I need to do it :/ and take care of all possible errors)
## How to use
Setup an configuration file anywhere in your machine (be certain that the application can read the file), and use it's path in configurator
Example:
```ts
import { configurator } from "config-validation";
import path from 'path';
const Configurator = configurator({
databaseUrl: {
description: 'Database url',
type: 'string',
required: true,
},
insert_invertal: {
description: 'Bach insert interval used for buffer cleaning',
type: 'number',
required: true,
},
server: {
port: {
description: 'The server port',
type: 'number',
default: 3333,
}
}
});
// Load configs from the file config.json
Configurator.load(path.join(__dirname, 'config.json'));
console.log(Configurator.get('databaseUrl'));
// Update the config value
Configurator.set('databaseUrl', 'Another url')
console.log(Configurator.get('databaseUrl'));
// Write the config changes to the file
Configurator.updateConfigFile();
```
## Todo
- [X] Ability to the user add new types
- [X] Method that permit changing an config
- [X] Updating the configuration file
- [X] Sub-configs
- [ ] Fix set and get to work with Sub-configs
- [ ] Implementing unit test's
## Inspiration
- [Convict](https://www.npmjs.com/package/convict)