Resource-parser
Parse a JSON resource file or object using .env
file and process.env
.
This module allows you to refer to environment variables or keys in the object itself.
References are searched for in all strings of the object. A string can contain one or more references.
Install
npm i --save resource-parser
Load resource
When resource loaded, it will be parser from .env
and process.env
data
Default usage
const resourceParser = ; /* Resource can be a relative/absolute path, or an object If resource is a relative path or an object with "imports" key, you must provide a dirpath as second argument*/const config = ;
Express usage
const resourceParser = ;const express = ; // ... const app = ; /* will add "config" key to "req" object Config data is parsed during app loading and will be cloned for each request*/app;
config.json
Load resource with import resources
const resourceParser = ; const config = ;
config.json
parameters.json
Load resource with extra data
const resourceParser = ; const config = key: 'value';
API
Express middleware
resourceParser.middleware(config: object, dirpath?: string, refs?: object): function
resourceParser.middleware(config: string, dirpath?: string, refs?: object): function
resourceParser.middleware(config: string, refs?: object): function
Parse from file or object
resourceParser.parse(config: object, dirpath?: string, refs?: object): object
resourceParser.parse(config: string, dirpath?: string, refs?: object): object
resourceParser.parse(config: string, refs?: object): object
Parse object
using refs
resourceParser.parseObject(obj: object, refs: object, isArray?: boolean): object
Parse string value
using refs
resourceParser.parseString(value: string, refs: object): string
Test if value
contains one or more references
resourceParser.containReferences(value: string): boolean
Extract references from value
resourceParser.getReferences(value: string): Array<string>