1.0.4 • Published 7 months ago

lightweight-config-parser v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

MIT license

Lightweight Config Parser

Lightweight configuration parser and API for the .conf files.

Install

Install with npm:

$  npm  install  --save  lightweight-config-parser

Install with yarn:

$  yarn  add  lightweight-config-parser

Usage

  • To use the Configuration class in a TypeScript file -
import { Configuration } from 'lightweight-config-parser';

const config = new Configuration('/path/to/config.conf');
  • To use the Configuration class in a JavaScript file -
const Configuration = require('lightweight-config-parser').Configuration;

const config = new Configuration('/path/to/config.conf');

API

Config Values: Environmental vs. Static

Our configuration system can have both environmental and static values for a given path.

Use the isEnvironmental parameter to specify the desired value type:

  • true: Fetch the environmental value.
  • false (default): Fetch the static value. If only an environmental value exists, it will be returned.

Config file example

server {
	port = 8080
	port = ${?PORT_ENV_VARIABLE}
	bind = ${?BIND_ENV_VARIABLE}
	bind = "test_bind"
}

Fetching values

config.get('server.port', true); // Gets environmental value
config.get('server.port'); // Gets static value, or environmental if no static exists

Checking values existence

config.has('server.bind', true); // Checks if environmental value exists
config.has('server.bind'); // Checks if static value exists
1.0.2

8 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.1

1 year ago

1.0.0

1 year ago