{"name":"parse-json-config","version":"0.2.1","description":"Works like the way Babel parses its presets","repository":{"url":"git+https://github.com/egoist/parse-json-config.git","type":"git"},"main":"index.js","files":["index.js"],"scripts":{"test:cov":"jest --coverage && npm run lint","test":"jest && npm run lint","test:watch":"jest --watch","lint":"xo"},"author":{"name":"egoist","email":"0x142857@gmail.com"},"license":"MIT","jest":{"testEnvironment":"node"},"dependencies":{},"devDependencies":{"jest-cli":"^19.0.0","eslint-config-rem":"^3.0.0","xo":"^0.18.0","@test/stub":"file:./test/fixture/stub-scoped","prefix-stub":"file:./test/fixture/stub-prefixed"},"xo":{"extends":"rem/prettier","envs":["jest"],"ignores":["fixture/**"]},"gitHead":"2fca50d779b25876335b0d24a4cd509062801c3a","bugs":{"url":"https://github.com/egoist/parse-json-config/issues"},"homepage":"https://github.com/egoist/parse-json-config#readme","_id":"parse-json-config@0.2.1","_npmVersion":"5.5.1","_nodeVersion":"8.6.0","_npmUser":{"name":"rem","email":"0x142857@gmail.com"},"dist":{"integrity":"sha512-y3fI061Qq2lWnT95n5ggBX4QtloGcM33MMNfE779jcRWN9CwV8Bk4Qd9nF7GY5gNItUtvB/iNWLIGFj5GP2PMA==","shasum":"8a71242d0cd259a0eb7a5e491cfc9f10156dd78f","tarball":"http://registry-npm.ywwl.com/parse-json-config/download/parse-json-config-0.2.1.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFdmGf0gypI4ktXp81osEnYEmwzHlrqEVTEVnivOfGGWAiEA1QzQW07sS0d5M3a2XhPczFNxhGJNqKVZeJ+VnOLQroE="}],"size":3301,"noattachment":false,"key":"/parse-json-config/-/parse-json-config-0.2.1.tgz"},"maintainers":[{"name":"rem","email":"0x142857@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/parse-json-config-0.2.1.tgz_1510112979145_0.09034415194764733"},"directories":{},"readme":"# parse-json-config\n\n[![NPM version](https://img.shields.io/npm/v/parse-json-config.svg?style=flat)](https://npmjs.com/package/parse-json-config) [![NPM downloads](https://img.shields.io/npm/dm/parse-json-config.svg?style=flat)](https://npmjs.com/package/parse-json-config) [![CircleCI](https://circleci.com/gh/egoist/parse-json-config/tree/master.svg?style=shield)](https://circleci.com/gh/egoist/parse-json-config/tree/master) [![codecov](https://codecov.io/gh/egoist/parse-json-config/branch/master/graph/badge.svg)](https://codecov.io/gh/egoist/parse-json-config)\n[![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 parse-json-config\n```\n\n## Usage\n\n```js\nconst parse = require(\"parse-json-config\");\n\nparse([\"foo\", \"bar\"])[\n  //=> return\n  (require(\"$cwd/node_modules/foo\")(), require(\"$cwd/node_modules/bar\")())\n];\n```\n\n### Use options\n\nTo provide options while calling the function:\n\n```js\nparse([[\"foo\", options], \"bar\"])[\n  //=> return\n  (require(\"$cwd/node_modules/foo\")(options),\n  require(\"$cwd/node_modules/bar\")())\n];\n```\n\n### Local path or function\n\nYou can also use a local path or function:\n\n```js\nparse([\n  function() {\n    return \"foo\";\n  },\n  [\"./bar.js\", options]\n])[\n  //=> return\n  (function() {\n    return \"foo\";\n  },\n  require(\"$cwd/bar.js\")(options))\n];\n```\n\nIf you're using a non-string, we directly return it without calling it with the options even if you provide it as `[resolved, options]`, since if you can use a function / object as `resolved` you can already execute it yourself, but there's also a [isCalled](#iscalled) option for you to customize it.\n\nBy default relative path is resolve from `process.cwd()`\n\n### Custom caller\n\nEach item in the config is in `name` or `[name, options]` format, by default we directly call the `name` with `option` as the only argument, but you can use a custom caller:\n\n```js\nparse([\"./foo.js\"], {\n  caller: (resolved, options) => resolved(options, \"hi\")\n})[\n  //=> return\n  require(\"$cwd/foo.js\")(options, \"hi\")\n];\n```\n\nDefault caller is `(resolved, options) => typeof resolved === 'object' ? resolve.apply(options) : resolved(options)`\n\n### Prefix\n\nUse a prefix:\n\n```js\nparse([\n  'es2015',\n  'babel-preset-stage-2',\n  '@org/async',\n], { prefix: 'babel-preset-' })\n//=> return\n[\n  require('$cwd/node_modules/babel-preset-es2015')(),\n  require('$cwd/node_modules/babel-preset-stage-2')(),\n  require('$cwd/node_modules/@org/babel-preset-async')(),\n]\n```\n\nYou can also use `addPrefix` method to handle some edge cases:\n\n```js\nparse([\n  'es2015',\n  'babel-preset-stage-2',\n  '@org/async',\n  '@my/async',\n], {\n  prefix: 'babel-preset-',\n  addPrefix(input, prefix) {\n    if (input.startsWith('@my/')) {\n      return input.replace(/^@my\\/(preset-)?/, '@my/preset-')\n    }\n    return true\n  }\n})\n//=> return\n[\n  require('$cwd/node_modules/babel-preset-es2015')(),\n  require('$cwd/node_modules/babel-preset-stage-2')(),\n  require('$cwd/node_modules/@org/babel-preset-async')(),\n  require('$cwd/node_modules/@my/preset-async')(),\n]\n```\n\n### Pure object\n\n**Use pure object as config:**\n\nSimilar to using an array:\n\n```js\n[\n  [\"foo\", options],\n  [\n    \"./bar.js\",\n    {\n      isBar: true\n    }\n  ]\n];\n```\n\nis equivalent to:\n\n```js\n{\n  'foo': options,\n  './bar.js': {\n    isBar: true\n  }\n}\n```\n\n## API\n\n### parse(config, [options])\n\n#### options\n\n##### cwd\n\nType: `string`<br>\nDefault: `process.cwd()`\n\nThe path to resolve relative path and npm packages.\n\n##### caller\n\nType: `function`<br>\nDefault: `(resolved, options) => resolved(options)`\n\nThe caller defines what to do with `resolved` and `options`.\n\n##### prefix\n\nType: `string`<br>\nDefault: `undefined`\n\nPrefix for package name.\n\n##### addPrefix\n\nType: `(originalItem, prefix) => string | boolean`\n\nReturn a string as prefixed value, return `true` to use default `addPrefix` handler, return `false` to skip adding prefix.\n\n##### isResolved\n\nType: `originalItem => boolean`<br>\nDefault: `item => item && typeof item !== 'string'`\n\nCheck if the item is resolved, by default considering all non-string types as resolved.\n\n##### isCalled\n\nType: `(originalItem, resolvedItem) => boolean`<br>\nDefault: Same as `isResolved`.\n\nCheck if the item is called with options, by default considering all non-string types as called, but you can customize it:\n\n```js\nparse(\n  [\n    function foo() {\n      return \"foo\";\n    },\n    function bar() {\n      return \"bar\";\n    }\n  ],\n  {\n    // Only used when config item is provided as function\n    isCalled(fn) {\n      // Consider it's called when its name is foo\n      return fn.name === \"foo\";\n    }\n  }\n)[\n  //=> return\n  (function foo() {\n    return \"foo\";\n  },\n  \"bar\")\n];\n// function bar will be called as `bar(options)`\n```\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## Author\n\n**parse-json-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/parse-json-config/contributors)).\n\n> [egoist.moe](https://egoist.moe) · GitHub [@egoist](https://github.com/egoist) · Twitter [@\\_egoistlily](https://twitter.com/_egoistlily)\n","publish_time":1510112979303,"_cnpm_publish_time":1510112979303,"dist-tags":{"latest":"0.4.2"}}