JavaScript/Typescript Configuration Parser and API for the Pure Config Specification
See the Pure Config Specification for how to write .pure config files
Install the library using NPM and include it in your code
- To use the
Configuration
class in a TypeScript file -
import { Configuration } from "pure-config";
const config = new Configuration("/path/to/config.pure");
- To use the
Configuration
class in a JavaScript file -
const Configuration = require('pure-config').Configuration;
const config = new Configuration('/path/to/config.pure');
You can get and set any value, as well as ask for specific types
config.get('server.port'); // Returns the type that the parser found in the .pure file
config.has('server.bind'); // Returns a boolean of whether that value exists or not
config.set('server.port', 8080); // Sets whatever type you give it
config.put('server.port', 80);
config.getString('log.level'); // Returns a string
// Paths must start with a Drive Letter (i.e. 'C:'), dot(s) (i.e. '.' or '..'), tilde '~', or root ('\' or '/')
config.getPath('server.log'); // Returns the string representation of the path
config.getQuantity('bandwidth') // Returns an object: { magnitude: [number], unit: [string] }
config.getInt('my-number') // Returns round number, or rounds floating points, or tries to coerce other types
config.getDouble('pi') // Returns a number, or tries to coerce other types
config.getBoolean('isAdmin') // Returns a boolean, or tries to coerce other types
This implementation of the Pure Specification does not currently support the optional Schema mechanism, so data types are determined implicitly