0.1.3 • Published 12 months ago

json-configuration-parser v0.1.3

Weekly downloads
-
License
ISC
Repository
-
Last release
12 months ago

json-configuration-parser

Utility to load JSON configuration file like .env files with a TS file to type values. (no depth)

Examples

Given the following JSON file

{
  "hello": "world"
}

We can load the configuration file in process.env with the identifiers as the key to find them, and a TS file will be created dynamically to type the configuration.

const { configJsonSync } = require('json-configuration-parser');

configJsonSync();

console.log(process.env.hello); // "world"

or

We can take back the object (configuration) and use it as we want (a TS file will not be emitted then)

const { configJsonSync } = require('json-configuration-parser');

const configuration = configJsonSync(true);

You can also find your configuration elsewhere than the root of the project directory (relative to package.json) givin a path

const { configJsonSync } = require('json-configuration-parser');

configJsonSync('path-to-my-json-file');

console.log(process.env.hello); // "world"

And there is two version of the function to load JSON files, sync or async

const { configJson } = require('json-configuration-parser');

(async () => {
  await configJson();
  
  console.log(process.env.hello); // "world"
})();
0.1.3

12 months ago

0.1.2

12 months ago

0.1.1

12 months ago

0.1.0

12 months ago