{"name":"use-config","version":"2.0.2","description":"Use a config file in your project.","repository":{"url":"git+https://github.com/egoist/use-config.git","type":"git"},"main":"dist/use-config.js","files":["dist"],"engines":{"node":">=6"},"scripts":{"test":"jest && npm run lint","test:cov":"jest --coverage && npm run lint","lint":"xo","build":"bili --filename use-config.js --buble.target.node 6","prepublishOnly":"npm run build"},"author":{"name":"egoist","email":"0x142857@gmail.com"},"license":"MIT","jest":{"testEnvironment":"node"},"dependencies":{"load-json-file":"^2.0.0","path-exists":"^3.0.0","pupa":"^1.0.0"},"devDependencies":{"babel-core":"^6.26.0","babel-jest":"^22.0.4","babel-preset-env":"^1.6.1","bili":"^1.3.7","eslint-config-rem":"^3.0.0","jest":"^22.0.4","xo":"^0.18.0"},"xo":{"extends":"rem/prettier","envs":["jest"],"rules":{"no-await-in-loop":0}},"babel":{"presets":[["env",{"targets":{"node":"current"}}]]},"gitHead":"045f380fab88adaeb581bb32b216c01ba38a52c7","bugs":{"url":"https://github.com/egoist/use-config/issues"},"homepage":"https://github.com/egoist/use-config#readme","_id":"use-config@2.0.2","_npmVersion":"5.5.1","_nodeVersion":"8.9.3","_npmUser":{"name":"rem","email":"0x142857@gmail.com"},"dist":{"integrity":"sha512-nFuzOsPsxIWQrGPKdYIm+BzYlEFHotjnyV91jMyAjGSL3jTYeeTjvYHA6VEQGe+HKX7MLKwHndgEKdO1NCoWCw==","shasum":"137fb6290e884efdbe29963c417ffc2b333465c0","tarball":"http://registry-npm.ywwl.com/use-config/download/use-config-2.0.2.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIElMHL7vhdK3ZtUKi9Q5VZzW6DRMZMm/sBbkvrHJaWWTAiEA9Aplb0wXJ6X7Ec4IP2G+WS4hxltY5wgLxReCUIxG0W4="}],"size":4481,"noattachment":false,"key":"/use-config/-/use-config-2.0.2.tgz"},"maintainers":[{"name":"rem","email":"0x142857@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/use-config-2.0.2.tgz_1515383409874_0.8704315507784486"},"directories":{},"readme":"# use-config\n\n[![NPM version](https://img.shields.io/npm/v/use-config.svg?style=flat)](https://npmjs.com/package/use-config) [![NPM downloads](https://img.shields.io/npm/dm/use-config.svg?style=flat)](https://npmjs.com/package/use-config) [![CircleCI](https://circleci.com/gh/egoist/use-config/tree/master.svg?style=shield)](https://circleci.com/gh/egoist/use-config/tree/master) [![codecov](https://codecov.io/gh/egoist/use-config/branch/master/graph/badge.svg)](https://codecov.io/gh/egoist/use-config)  [![donate](https://img.shields.io/badge/$-donate-ff69b4.svg?maxAge=2592000&style=flat)](https://github.com/egoist/donate)\n\n## Install\n\n```bash\nyarn add use-config\n```\n\n## Usage\n\n```js\nconst UseConfig = require('use-config')\n\n// Find config in order:\n// poi.config.js\n// package.json's poi property\nconst useConfig = new UseConfig({ name: 'poi' })\n\nuseConfig.load().then(res => {\n  res.path // path to found config\n  res.config // content of config\n\n  if (!res.path) {\n    // Config file is not found\n  }\n}).catch(err => {\n  // maybe a parse error\n})\n```\n\nYou can also specify the files we need to look for:\n\n```js\n// To make it use poi.config.js and .poirc and poi.config.yml only\nconst useConfig = new UseConfig({\n  name: 'poi',\n  files: ['{name}.config.js', '.{name}rc', '{name}.config.yml']\n})\n\n// By default all non-js file will be treated as JSON\n// But you can use custom loader for specific extension\nuseConfig.addLoader(/\\.yml$/, filepath => parseYamlFile(filepath))\n\nuseConfig.load().then(res => {/* ... */})\n```\n\n> **NOTE:** \n>\n> when config value is `undefined`, we will ignore it and find next file. For example, you have a `package.json` but `pkg[name]` does not exist. If it's the last file that we can find, we will return `{ path, config: undefined }`.\n\n## API\n\n### new UseConfig([options])\n\n#### options\n\n##### options.name\n\nType: `string`<br>\nRequired: `true`\n\nThe config name, for `name: 'poi'` and `files: ['{name}.config.js', 'package.json']`, it will search `poi.config.js` and `poi` property in `package.json`.\n\n##### options.files\n\nDefault: `['{name}.config.js', 'package.json']`\n\nThe files to search in order, when it's `package.json`, we return the `name` property of it.\n\n##### options.cwd\n\nDefault: `process.cwd()`\n\nThe path to search files.\n\n##### options.fallbackLoader\n\nType: `function`\n\nA fallback loader for non-js files, by default we load it with `load-json-file`:\n\n```js\nfunction fallbackLoader(filepath) {\n  return this.sync ? loadJsonFile.sync(filepath) : loadJsonFile(file)\n}\n```\n\n### useConfig.load()\n\nReturn: A Promise which resolves to `{ path, config }` or `{}` when no config file was found.\n\nBy default all `.js` files will be loaded via `require` and all other files will be treated as JSON format which is load using `fs` and `JSON.parse`.\n\n### useConfig.loadSync()\n\nReturn: `{ path, config }` or `{}` when no config file was found.\n\nTo use `.loadSync()` method you should ensure all custom loaders added via `.addLoader()` supports this.\n\n### useConfig.addLoader({ test, loader })\n\n#### test\n\nType: `RegExp`<br>\nRequired: `true`\n\nThe regular expression to match filepath.\n\n#### loader\n\nType: `function`<br>\nRequired: `true`\n\nThe function to get file content. Either synchronus or returns a Promise.\n\nIf you're using the `.loadSync()` method please ensure it performs no async operations when `this.sync === true`:\n\n```js\nfunction yamlLoader(filepath) {\n  return this.sync ? yaml.loadSync(filepath) : yaml.load(filepath)\n}\n```\n\nNote that you can't use `arrow function` here since you need access to `this`.\n\n## Contributing\n\n1. Fork it!\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request :D\n\n\n## Author\n\n**use-config** © [egoist](https://github.com/egoist), Released under the [MIT](./LICENSE) License.<br>\nAuthored and maintained by egoist with help from contributors ([list](https://github.com/egoist/use-config/contributors)).\n\n> [egoistian.com](https://egoistian.com) · GitHub [@egoist](https://github.com/egoist) · Twitter [@rem_rin_rin](https://twitter.com/rem_rin_rin)\n","publish_time":1515383409965,"_cnpm_publish_time":1515383409965,"dist-tags":{"latest":"2.0.4"}}