{"_id":"@auturge/config-resolver","_rev":"1-499ffda2b6ef11fac85f3eaa100717cc","name":"@auturge/config-resolver","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@auturge/config-resolver","version":"1.0.0","description":"auturge/config-resolver - finds and loads your config file, or returns null","author":{"name":"auturge"},"license":"MIT","bugs":{"url":"https://github.com/auturge/config-resolver/issues"},"repository":{"type":"git","url":"git+https://github.com/auturge/config-resolver.git"},"homepage":"https://github.com/auturge/config-resolver","main":"config-resolver.js","module":"config-resolver.es6.js","jsnext:main":"config-resolver.es6.js","engines":{"node":">=12.8.1"},"_id":"@auturge/config-resolver@1.0.0","_nodeVersion":"12.18.0","_npmVersion":"6.14.8","dist":{"integrity":"sha512-EoAYXuIJZ63VpBPL4MjbcH09sF68pGuDu+cCfNa7Aj/hsyeU5aYmb9nJa5SkuoOGnF1CCTOzr7ciw1OlY/ciKQ==","shasum":"31ab166b4d50471dfb09edc002e28294c7447eeb","tarball":"https://registry.npmjs.org/@auturge/config-resolver/-/config-resolver-1.0.0.tgz","fileCount":8,"unpackedSize":26930,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfxU2kCRA9TVsSAnZWagAANNkP/0ql/FcOywyq0nErN7rt\nww1mQLCjQDM3MndfeAWwSgILUv0ZNk/loucBpdTkhxi954w0K5xGhHd5QCgf\nK1h909NHq96Q+1QdqC8nRUVLW+1DpcxCD1vYKElAinV3G5uFEkPSLwx01bWL\nBFtrelLVh2F+J3fLmrlh1DNWgmzLu5l0O3qnRz67U4x8Iyl/4LF3oKuvdSVo\nFfnsWSqykftlf3owTIpPOefyLKcnY1kjQAJ9mcjt2+t8m5zAyf2rsktouXlS\n7mRAlZFouHo/xAlMZI2HXShCbwGvtX4g48OsKXgrLfqwI3VEa4aVR3VVpKR2\nqpDHogwdHj/7XQs2ZWvl/DhZy+ZqcJX9z5du7o4yBh4WES+cXdmSrvnFFfTS\nvsHdvorH5T9V3VaiJPkOvuT+abkzajlzM/o8JfRIgZNqU3BMtcjbZPGmoZt4\nTi2h/TPwPRj2Z6lFkeC2X0LTZ6rfNdH3BpzUxWdWPRcr5uqjFYPrlaHH0moa\nBwIagVTzdKke7srmSuSSlRF28u0C/np9lJbHPzPibMkruA6LXQZqqmHyXAq9\nA9rQ8joxpfjUZd+5ZUm8o1WNWAjQPu2HE/GmEmQfnZ71mGJIQKIiKBsKL+OZ\nniu8ARvj2wyluoitcME2JH7iLlj0LvFFmIkaTifoHWKGpkgppEp9VipOfL7H\n696l\r\n=eXEV\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDiVJEnTzey2Qzfw4/A1BSc0hE8015Ei8xkleeRr4fmUAIgX86Bp+eJ4XZSq26fJY2sLQ6WHyjm5hs254yRTFgE0II="}]},"_npmUser":{"name":"curtis.kaler","email":"curt.kaler@gmail.com"},"directories":{},"maintainers":[{"name":"curtis.kaler","email":"curt.kaler@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/config-resolver_1.0.0_1606765988427_0.6581181745700966"},"_hasShrinkwrap":false}},"time":{"created":"2020-11-30T19:53:08.206Z","1.0.0":"2020-11-30T19:53:08.588Z","modified":"2022-04-04T16:41:24.428Z"},"maintainers":[{"name":"curtis.kaler","email":"curt.kaler@gmail.com"}],"description":"auturge/config-resolver - finds and loads your config file, or returns null","homepage":"https://github.com/auturge/config-resolver","repository":{"type":"git","url":"git+https://github.com/auturge/config-resolver.git"},"author":{"name":"auturge"},"bugs":{"url":"https://github.com/auturge/config-resolver/issues"},"license":"MIT","readme":"# <h1 align=\"center\">config-resolver</h1>\r\n\r\n<p align=\"center\">\r\n  A function that resolves a config file and returns its content, or null if not found.\r\n</p>\r\n[![npm][npm]][npm-url] [![Build][travis-badge]][travis-url] [![Coverage Status][coverage-badge]][coverage-url]\r\n\r\n## Table of Contents\r\n\r\n-   [About](#about)\r\n    -   [How to install](#how-to-install)\r\n-   [Getting started](#getting-started-examples)\r\n    -   [Example: JSON config file](#example-json-config-file)\r\n    -   [Example: config file exporting a JS function](#example-JavaScript-function-config-file )\r\n    -   [Example: JavaScript config file exporting a JSON object](#EXAMPLE-JavaScript-config-file-exporting-a-JSON-object)\r\n    -   [Example: Loading a config file from one of several places or formats](#EXAMPLE-Loading-a-config-file-from-one-of-several-places-or-formats)\r\n-   [Contributing and Internal Documentation](#contributing-and-internal-documentation)\r\n\r\n## About\r\n\r\nReading a config file is a pretty standard operation for just about any node project. The config-resolver provides a function to avoid repeating the same boilerplate config-loading code in every project.\r\n\r\n### How to install\r\n\r\nThe following commands will install config-resolver:\r\n\r\n```shell\r\nnpm install --save-dev @auturge/config-resolver\r\n```\r\n\r\nor\r\n\r\n```shell\r\nyarn add @auturge/config-resolver --dev\r\n```\r\n\r\n## Getting Started (Examples)\r\n\r\nconfig-resolver supports JavaScript or JSON config files.\r\n\r\nThe following examples assume the project has this shape:\r\n\r\n```none\r\ndemo\r\n├── conf/\r\n│   ├── config.json\r\n│   ├── config.js\r\n│   └── config.export.js\r\n│\r\n├── src/\r\n│   ├── index.js\r\n```\r\n\r\n---\r\n\r\n### EXAMPLE: JSON config file\r\n\r\n#### config.json\r\n\r\n```JSON\r\n{\r\n        source: './package.json',\r\n        destination: './build/package.json',\r\n        keeplist: ['name', 'version'],\r\n        loglevel: 'INFO',\r\n}\r\n```\r\n\r\n#### index.js\r\n\r\n```JavaScript\r\nconst path = require('path')\r\nconst { resolveConfig } = require('@auturge/config-resolver')\r\n\r\nconst options = {\r\n    explicit: {\r\n        path: path.resolve(__dirname, '../conf/demo.config.json'),\r\n        type: 'json',\r\n    },\r\n}\r\nconst config = resolveConfig(options)\r\n\r\nconsole.log(JSON.stringify(config, undefined, 2))\r\n```\r\n\r\n#### result\r\n\r\n```JSON\r\n{\r\n  \"source\": \"./package.json\",\r\n  \"destination\": \"./build/package.json\",\r\n  \"keeplist\": [\r\n    \"name\",\r\n    \"version\"\r\n  ],\r\n  \"loglevel\": \"INFO\"\r\n}\r\n```\r\n\r\n---\r\n\r\n### EXAMPLE: JavaScript function config file\r\n\r\n#### config.js\r\n\r\n```JavaScript\r\nmodule.exports = (env) => {\r\n    const isProd = env && env['prod'] === true\r\n\r\n    const DESTINATION = './build/{0}/package.json'.replace(\r\n        '{0}', isProd ? 'prod' : 'dev'\r\n    )\r\n\r\n    const config = {\r\n        source: './package.json',\r\n        destination: DESTINATION,\r\n        keeplist: ['name', 'version'],\r\n        loglevel: 'INFO',\r\n    }\r\n\r\n    return config\r\n}\r\n```\r\n\r\n#### index.js\r\n\r\n```JavaScript\r\nconst path = require('path')\r\nconst { resolveConfig } = require('@auturge/config-resolver')\r\n\r\nconst env = { prod: true }\r\nconst options = {\r\n    explicit: {\r\n        path: path.resolve(__dirname, '../conf/demo.config.js'),\r\n        type: 'function',\r\n    },\r\n}\r\nconst configFunction = resolveConfig(options)\r\nconst config = configFunction(env)\r\n\r\nconsole.log(JSON.stringify(config, undefined, 2))\r\n```\r\n\r\n#### result\r\n\r\n```JSON\r\n{\r\n  \"source\": \"./package.json\",\r\n  \"destination\": \"./build/prod/package.json\",\r\n  \"keeplist\": [\r\n    \"name\",\r\n    \"version\"\r\n  ],\r\n  \"loglevel\": \"INFO\"\r\n}\r\n```\r\n\r\n---\r\n\r\n### EXAMPLE: JavaScript config file exporting a JSON object\r\n\r\n#### config.export.js\r\n\r\n```JavaScript\r\nmodule.exports = {\r\n    source: './package.json',\r\n    destination: './build/package.json',\r\n    keeplist: ['name', 'version'],\r\n    loglevel: 'INFO',\r\n}\r\n```\r\n\r\n#### index.js\r\n\r\n```JavaScript\r\nconst path = require('path')\r\nconst { resolveConfig } = require('@auturge/config-resolver')\r\n\r\nconst env = { prod: true }\r\nconst options = {\r\n    explicit: {\r\n        path: path.resolve(__dirname, '../conf/demo.config.js'),\r\n        type: 'json',\r\n    },\r\n}\r\nconst config = resolveConfig(options)\r\n\r\nconsole.log(JSON.stringify(config, undefined, 2))\r\n```\r\n\r\n#### result\r\n\r\n```JSON\r\n{\r\n  \"source\": \"./package.json\",\r\n  \"destination\": \"./build/package.json\",\r\n  \"keeplist\": [\r\n    \"name\",\r\n    \"version\"\r\n  ],\r\n  \"loglevel\": \"INFO\"\r\n}\r\n```\r\n\r\n---\r\n\r\n### EXAMPLE: Loading a config file from one of several places or formats\r\n\r\nSuppose you want to allow users to place their config files in one of several places, or support multiple formats. Say you want to search for config files with the following precedence (where higher on the list is where we look first):\r\n\r\n```none\r\n./.trimrc\t\tor\t \t./trim.config.js,\r\n./conf/.trimrc \tor\t\t./conf/trim.config.js\r\n./conf/demo.config.js\r\n./conf/demo.config.json\r\n```\r\n\r\n#### index.js\r\n\r\n```JavaScript\r\nconst path = require('path')\r\nconst { resolveConfig } = require('@auturge/config-resolver')\r\n\r\nconst env = { prod: true }\r\nconst options = {\r\n    alternatives: [\r\n        {\r\n\t\t\t// another file that does not exist in our demo\r\n\t\t\tpath: './.trimrc', type: 'json'\r\n        },\r\n        {\r\n\t\t\t// a file that does not exist in our demo\r\n\t\t\tpath: './trim.config.js', type: 'function',\r\n\t\t\tpriority: 0\r\n        },\r\n        {\r\n\t\t\t// a file that does not exist in our demo\r\n\t\t\tpath: './conf/trim.config.js', type: 'function',\r\n\t\t\tpriority: 1\r\n        },\r\n        {\r\n\t\t\t// another file that does not exist in our demo\r\n\t\t\tpath: './conf/.trimrc', type: 'json',\r\n\t\t\tpriority: 1\r\n        },\r\n        {\r\n            path: './conf/demo.config.js'), type: 'function',\r\n            priority: 2\r\n        },\r\n{\r\n            path: './conf/demo.config.json'), type: 'json',\r\n            priority: 3\r\n        },\r\n    ],\r\n}\r\nconst config = resolveConfig(options)\r\n\r\nconsole.log(JSON.stringify(config, undefined, 2))\r\n```\r\n\r\n#### result\r\n\r\nUsing the above code, config-resolver would find and attempt to load `./conf/demo.config.js`.\r\n\r\n---\r\n\r\n## Contributing and Internal Documentation\r\n\r\nThe auturge family welcomes any contributor, small or big. We are happy to elaborate, guide you through the source code and find issues you might want to work on! To get started have a look at our [documentation on contributing][contributing].\r\n\r\n[contributing]: https://github.com/auturge/config-resolver/blob/master/docs/CONTRIBUTING.md\r\n[npm]: https://img.shields.io/npm/v/auturge/config-resolver.svg\r\n[npm-url]: https://www.npmjs.com/package/auturge/config-resolver\r\n[travis-url]: https://travis-ci.com/github/auturge/config-resolver\r\n[travis-badge]: https://api.travis-ci.com/auturge/config-resolver.svg?branch=master\r\n[coverage-badge]: https://coveralls.io/repos/github/auturge/config-resolver/badge.svg\r\n[coverage-url]: https://coveralls.io/github/auturge/config-resolver\r\n","readmeFilename":"README.md"}