UNPKG

wj-config

Version:

Javascript configuration module for NodeJS and browser frameworks such as React that works like ASP.net configuration where data sources are specified (usually JSON files) and environment variables can contribute/overwrite values by following a naming con

20 lines (19 loc) 531 B
import { DataSource } from "./DataSource.js"; export class JsonDataSource extends DataSource { _json; _jsonParser; _reviver; constructor(json, jsonParser, reviver) { super('JSON Data'); this._json = json; this._jsonParser = jsonParser ?? JSON; this._reviver = reviver; } async getObject() { let json = this._json; if (typeof json === 'function') { json = await json(); } return this._jsonParser.parse(json, this._reviver); } }