3.2.2 • Published 6 years ago
hackee v3.2.2
hackee
Module to build node.js configuration using files, environment variables and command line arguments
require("hackee")
Motivation: I'd like to not use relative path to require configuration
Examples:
const assert = require('assert') const hackee = require('hackee') process.env['a'] = 'one' // argv: --a=one process.env['b#c'] = '2' // argv: --b#c=2 process.env['d#e[0]'] = 'true' // argv: --d#e[0]=true const config = hackee({ a: undefined, b: { c: undefined }, d: { e: [undefined] } })
import * as assert from 'assert' import * as hackee from 'hackee' process.env['a'] = 'one' // argv: --a=one process.env['b#c'] = '2' // argv: --b#c=2 process.env['d#e[0]'] = 'true' // argv: --d#e[0]=true interface Config extends hackee.Hackee { a: string; b: { c: number; }; d: { e: boolean[]; }; f: { g: number; }; h: { i: boolean[]; }; } const config = hackee<Config>({ a: undefined, b: { c: undefined }, d: { e: [undefined] } })
test:
assert(config.a === 'one') assert(config.b.c === 2) assert(config.d.e[0] === true) assert(hackee.a === 'one') assert(hackee.b.c === 2) assert(hackee.d.e[0] === true) assert(config.set('f.g', 3) === 3) assert(config.get('f.g') === 3) assert(hackee.f.g === 3) assert(config.setIndexOf('h.i', 0, false) === false) assert(config.getIndexOf('h.i', 0) === false) assert(hackee.h.i[0] === false) assert(hackee.set('f.g', 4) === 4) assert(hackee.get('f.g') === 4) assert(config.f.g === 4) assert(hackee.setIndexOf('h.i', 0, true) === true) assert(hackee.getIndexOf('h.i', 0) === true) assert(config.h.i[0] === true) assert(config.a === hackee.a) assert.deepStrictEqual(config.b, hackee.b) assert.deepStrictEqual(config.d, hackee.d) assert.deepStrictEqual(config.f, hackee.f) assert.deepStrictEqual(config.h, hackee.h)