{"_id":"@amazebot/config","_rev":"2-c3fcb9d179cafad671f5b95ca8d52c1a","name":"@amazebot/config","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.0":{"name":"@amazebot/config","version":"0.1.0","description":"Centralised app configuration loaded from ENV, CLI and/or JSON.","homepage":"https://github.com/Amazebot/util/tree/master/packages/config","repository":{"type":"git","url":"git@github.com:Amazebot/util.git"},"author":{"name":"Tim Kinnane","email":"tim.kinnane@amazebot.chat"},"license":"MIT","engines":{"node":"> 8.0.0","npm":"> 5.0.0"},"main":"lib/index.js","types":"lib/index.d.ts","publishConfig":{"access":"public"},"scripts":{"test":"echo \"Error: run tests from root\" && exit 1"},"dependencies":{"@types/yargs":"^12.0.1","dotenv":"^6.1.0","yargs":"^12.0.5"},"gitHead":"4f407e22e515db342a9cdc159f5cfaf37a10e514","_id":"@amazebot/config@0.1.0","dist":{"shasum":"9ce256369457f9398966761ed473aa41b0883413","integrity":"sha512-t/YgjGCzxMofP9RFWAICBu+C4ywI7mjg+0LlgmvR9fv9j0hGFw5Vfv1Y+UD1O6VoT8J0SS/0BN+PYWRSVqV9yA==","tarball":"https://registry.npmjs.org/@amazebot/config/-/config-0.1.0.tgz","fileCount":18,"unpackedSize":24661,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcCQi+CRA9TVsSAnZWagAAwGMP/2voSlnlG3bcHz+Rw9og\nsqOpnkngpzG8SC7cvaQvFPn0z1N9T3npDwL1cdNWpMcNvjP/2oLRRkO5PQC1\nNMNOqjH5Y2SxhKqEcqM5km7P2vA4wabVnUNJXBMyTg2oPW5WLIcu+W2BUDMo\nSQ5XgSK5AfztEbBeC4OlXBiao3zgk0aAqo/+Z7kDP6Co/+1ERYG5U3HNVzL+\n8fMtfc9Jl1IIkdPBEkj6pljq+ELFyKQMuu2f86sha7i0KaORHdJNS15se2U1\nTzIibNvtKx3UNqZ19ohALaFkdw5dD0MsOcfFZNJ9s7vCfOi5Cw8oe44nY6Yk\nE+LHzcV0cKiP1DZ9Dq8Zr96a3vdMH1vcbuV4DU2MtONCN3gw397AuM1NvUsu\ntMaixjfzi4/BS0TjR+3SKxPY0+qid2MLPAvr9sd4BQEzw1pk1EHNolzPP4x4\nbIDAjJodDi4gAuaCp1PbutsEkXLk+evZoW9sA5JR17rWHfA1csV5KMCYUdLz\n74Ti9EkBRecUx0wbFDlsMjMHNwIBCznWptVrtt5G3v/4Df40cAFXEK5S1KWj\n8zNf/6iCNWXsOgZJ8ePJmn520bYyo6k+/EVEiJEY5Seno41/8Db65ViZIf2n\nhFD5QGkeFIRIn73NqZwVT5Dc955K8hsagthu14PzNWQqmpukTIPwcBn5Ii2g\nUC4M\r\n=Cfxx\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCqf3dxDtntGyPvtlUtLgO2R2jbfWRezB9NBML1XKZ9AwIhAJn4kmxzZMYVRYf+KczwKqDMc9hSJrDSAZa1BfhNYYHG"}]},"maintainers":[{"name":"timkinnane","email":"timkinnane@gmail.com"}],"_npmUser":{"name":"timkinnane","email":"timkinnane@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/config_0.1.0_1544095934119_0.6726762224227547"},"_hasShrinkwrap":false},"0.1.1":{"name":"@amazebot/config","version":"0.1.1","description":"Centralised app configuration loaded from ENV, CLI and/or JSON.","homepage":"https://github.com/Amazebot/util/tree/master/packages/config","repository":{"type":"git","url":"git@github.com:Amazebot/util.git"},"author":{"name":"Tim Kinnane","email":"tim.kinnane@amazebot.chat"},"license":"MIT","engines":{"node":"> 8.0.0","npm":"> 5.0.0"},"keywords":["util","typescript","config","settings","yargs"],"main":"lib/index.js","types":"lib/index.d.ts","publishConfig":{"access":"public"},"scripts":{"test":"echo \"Error: run tests from root\" && exit 1"},"dependencies":{"@types/yargs":"^12.0.1","dotenv":"^6.1.0","yargs":"^12.0.5"},"gitHead":"0d77f2d4d44e4a54465640ce41fa40cd17e104fe","_id":"@amazebot/config@0.1.1","dist":{"shasum":"ab2c80429a3815a865ee1fc007f64505f019d71e","integrity":"sha512-wGBMFvYBkM3D9IVdyfPy3l2Oy7i5MR336ivaXRKDitBDcqc5X/z6y+e8YuReYPpyOU088u5l/tUyFNv1Vk1sRQ==","tarball":"https://registry.npmjs.org/@amazebot/config/-/config-0.1.1.tgz","fileCount":14,"unpackedSize":15477,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcD1OZCRA9TVsSAnZWagAAku8P/Rwrar+IL9oz2fcQFdQ4\nwR/PMxyiqPcc1bYNvhgcM7lqtHTuM+XhbNBVjZuZk+Z2IKOdWO7W/8ulDBcW\nCkwc2T9AD8Y0yeJBKsozF5mx8e4Cbo3KQs/PyVu4Kd918Tw2FhXDMNXRpDCA\nA30l03OsyQvSxKkAwxMUnWlKAdgTz3DhZnuG/80oTtkXm+G08VXNA8Pl+24A\noD6wU0h4G7n6oUHcfBjjjetivzCCbbZ/AkWfVpRBE8LkBmVpydiZ/xZUCMaH\nyakshEQMetDsMyi20gX5wWpcWtwj1QHgvaxH0rtUe9JO19IFQusqR24411Dn\nG+WeSJwxffFmB6tYT2mQp8cJYDC18bTZzzqsWtLySVs/DSllmZzUoP5UarFU\nEF0FaTQ33bco99IWs9WQ/ukq1lrrw/JLOBjzgrbEnuTQeyumYDupSYajol5J\nWiXaM1c/3tTU5QAHW8MWbxUM3RrQgQ11hTTSpGGEnxNwM6doMn/HzPIKTsEF\ncHBemlwvAbJN7uZXjFSA0XEQnBIV8/P1hUgQW+waQ1bZHl5uilcHmU/m92Zo\n+WXjMolarDzMrQscRDDxGG36PLOuFJFjXBiN32pKMFmCl3QmIlmk5IMxgzlw\nP0R68SkcMWP3e3t/X/4tt5eir/xAxbqp+i/VelwyHG+LlEnhoHqssXtICnHq\ntEtr\r\n=FeFn\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIH4nkhuuUoqlsdC2XOKfjyl/KMZXpMB3v6VnaSyM+a8DAiAb1jZH/KsmZR0AgDTuCHTlrFoQ4B2pCSTw0Af+Tqq9vA=="}]},"maintainers":[{"name":"timkinnane","email":"timkinnane@gmail.com"}],"_npmUser":{"name":"timkinnane","email":"timkinnane@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/config_0.1.1_1544508312627_0.9245654264663059"},"_hasShrinkwrap":false}},"time":{"created":"2018-12-06T11:32:13.820Z","0.1.0":"2018-12-06T11:32:14.261Z","modified":"2022-04-04T13:44:20.149Z","0.1.1":"2018-12-11T06:05:12.766Z"},"maintainers":[{"name":"timkinnane","email":"timkinnane@gmail.com"}],"description":"Centralised app configuration loaded from ENV, CLI and/or JSON.","homepage":"https://github.com/Amazebot/util/tree/master/packages/config","repository":{"type":"git","url":"git@github.com:Amazebot/util.git"},"author":{"name":"Tim Kinnane","email":"tim.kinnane@amazebot.chat"},"license":"MIT","readme":"[dotenv]: https://github.com/motdotla/dotenv\n[yargs]: https://yargs.js.org/\n\n# ⚙️ Config\nCentralised app/module configuration loaded from ENV, CLI and/or JSON.\n---\n\nThis utility wraps [Yargs][yargs] and [dotenv][dotenv] capabilities with some\nsimple interfaces for easily managing configuration from various sources.\n\nCan load a single configuration, or use the same options for a series of\ninstances, loading from different sources using custom prefixes.\n\nPossible config sources include:\n  - Command line args\n  - Local `.env` file\n  - Environment variables\n  - Package JSON `'config': {}`\n  - `config.json` file\n\nA note on syntax/format. Options are defined and stored with **hyphenated**\nnames, that match to their command line argument. However, the corresponding key\nin JSON would be **camelCase** and the env variable would be **all caps** with\nunderscore separators.\n\nPlease be aware of the semantics:\n- **Option**: Defines a possible value type and default.\n- **Value**: The current value assigned for an option.\n- **Settings**: An object containing all current values.\n- **Config**: Loads, gets, sets and extends options.\n- **Series**: Collection of configs with the same options.\n\n## Config\n\n### `new Config(options: IOptions, sourcePrefix?: string)`\n\nConfig instances accept an initial range of options, which can be extended, for\nsharing the config between modules that each add their own options. The options\nargument follows the [Yargs][yargs] syntax.\n\nThe optional prefix argument on the constructor is applied to the sources for\nloading all options.\n\n```ts\nimport { Config } from '@amazebot/config'\nconst config = new Config({\n  'amazing-enabled': {\n    type: 'boolean',\n    description: 'Makes everything amazing',\n    default: true\n  }\n}, 'my')\n```\n\nIn this example, the prefix 'my' would modify the source for the option as\n- env variable: `MY_AMAZING_ENABLED`\n- package json: `myConfig`\n- config file: `my-config.json`\n\n### `.load(keyPrefix?: string)`\n\nLoad values for the defined options from all recognised sources:\n\n```ts\nimport { Config } from '@amazebot/config'\nconst config = new Config({ 'amazing': { type: 'boolean', default: 'true' } })\nconfig.load()\nconsole.log(config.settings.amazing) // --> true\n```\n\nPassing a prefix to the load method modifies the key for all options, allowing\nmultiple instances to have unique settings, from a common source. e.g. `.env`\n\n```sh\nFOO_AMAZING='false'\nBAR_AMAZING='true'\n```\n\n```ts\nimport { Config } from '@amazebot/config'\nconst options = { 'amazing': { type: 'boolean', default: 'true' } }\nconst foo = new Config(options)\nconst bar = new Config(options)\nfoo.load('foo')\nfoo.load('bar')\nconsole.log(foo.settings.amazing) // --> false\nconsole.log(bar.settings.amazing) // --> true\n```\n\n### `.extend(options: IOptions)`\n\nAdd more options, possibly after initial options loaded (requiring load again).\nCalling load after extend will merge new options with the initial set.\n\n```ts\n// index.ts\nexport * from './app.ts'\nexport * from './module.ts'\n```\n\n```ts\n// app.ts\nimport { Config } from '@amazebot/config'\nexport const app = {\n  config: new Config({ 'amazing': { type: 'boolean', default: 'true' } }),\n  start: () => {\n    config.load()\n    console.log(config.settings)\n  }\n}\n```\n\n```ts\n// module.ts\nimport { app } from '.'\napp.config.extend({ 'more-amazing': { type: 'boolean', default: 'false' } })\napp.start() // --> { 'amazing': true, 'more-amazing': false }\n```\n\n### `.get(key: string)`\n\nGets the loaded value from settings.\n\n```ts\nimport { Config } from '@amazebot/config'\nconst config = new Config({ 'amazing': { type: 'boolean', default: 'true' } })\nconfig.load()\nconfig.get('amazing') // --> true\n```\n\n### `.set(key: string, value: any)`\n\nSet the value. Set values override loaded ones.\n\n```sh\nAMAZING='true'\n```\n\n```ts\nimport { Config } from '@amazebot/config'\nconst config = new Config({ 'amazing': { type: 'boolean' } })\nconfig.load()\nconfig.get('amazing') // --> true\nconfig.set('amazing', false)\nconfig.get('amazing') // --> false\n```\n\n```ts\nimport { Config } from '@amazebot/config'\nconst config = new Config({ 'amazing': { type: 'boolean' } })\nconfig.set('amazing', false)\nconfig.load()\nconfig.get('amazing') // --> false\n```\n\n### `.reset()`\n\nClear any loaded or set values.\n\n```ts\nimport { Config } from '@amazebot/config'\nconst config = new Config({ 'amazing': { type: 'boolean', default: 'true' } })\nconfig.load()\nconfig.set('amazing', false)\nconfig.reset()\nconfig.get('amazing') // --> true\n```\n\n## ConfigMap\n\nConfig Maps allow defining a set of config instances with common options and\ndefaults, with different values assigned by loading a unique prefixed source.\n\n### `new ConfigMap(options: IOptions, sourcePrefix?: string)`\n\nThe constructor uses the same arguments as normal configs. The map contains a\ncollection of config instance `items`, always with at least one `default` item.\n\n```ts\nimport { ConfigMap } from '@amazebot/config'\nconst map = new ConfigMap({ 'amazing': { type: 'boolean', default: 'true' } })\nconsole.log(map.items.default.settings['amazing'].default) // --> true\n```\n\n### `.item(key: string)`\n\nGet a config item by it's key, creating if it didn't exist.\n\n```ts\nimport { ConfigMap } from '@amazebot/config'\nconst map = new ConfigMap({ 'amazing': { type: 'boolean', default: 'true' } })\nmap.item('alt')\nconsole.log(map.items.alt.settings['amazing'].default) // --> true\n```\n\n### `.load()`\n\nLoads every item's config, using it's key as a prefix for value sources.\n\n```sh\nAMAZING='true'\nALT_AMAZING='false'\n```\n\n```ts\nimport { ConfigMap } from '@amazebot/config'\nconst map = new ConfigMap({ 'amazing': { type: 'boolean' } })\nmap.item('alt')\nmap.load()\nmap.item('default').get('amazing') // --> true\nmap.item('alt').get('amazing') // --> false\n```\n\n### `.extend(options: IOptions)`\n\nExtends every config item's options and for any newly created items.\n\n```ts\nimport { ConfigMap } from '@amazebot/config'\nconst map = new ConfigMap({ 'amazing': { type: 'boolean' } })\nmap.extend({ 'more-amazing': { type: 'boolean', default: true } })\nmap.item('alt')\nmap.load()\nmap.item('alt').get('more-amazing') // --> true\n```\n","readmeFilename":"README.md","keywords":["util","typescript","config","settings","yargs"]}