{"name":"jest-validate","version":"21.3.0-alpha.eff7a1cf","license":"MIT","_id":"jest-validate@21.3.0-alpha.eff7a1cf","maintainers":[{"name":"mjesun","email":"mjesun@hotmail.com"},{"name":"aaronabramov","email":"aaron@abramov.io"},{"name":"jeanlauliac","email":"jean@lauliac.com"},{"name":"cpojer","email":"christoph.pojer@gmail.com"},{"name":"fb","email":"opensource+npm@fb.com"}],"homepage":"https://github.com/facebook/jest#readme","bugs":{"url":"https://github.com/facebook/jest/issues"},"dist":{"shasum":"3510e22808f740f1a8259351b82057fa726dd05c","tarball":"http://registry-npm.ywwl.com/jest-validate/download/jest-validate-21.3.0-alpha.eff7a1cf.tgz","integrity":"sha512-Lzi0lRI+JlGYf+vJIi6KYIk6KJ46+hGlXNQj/aIDdYapm6jLyDgoskzhmB2abs5yamg0cgOjOiZXhf8JMLMLnQ==","signatures":[{"sig":"MEYCIQDbDIK/OzTCKebTvZyrCSknBSUwAHQ42CeCNm0xJhScpwIhAPCkLXy+mxe43NmETMQYCuem9yFVKbOPeX6ngx2aSkXy","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"size":4442,"noattachment":false,"key":"/jest-validate/-/jest-validate-21.3.0-alpha.eff7a1cf.tgz"},"main":"build/index.js","_npmUser":{"name":"cpojer","email":"christoph.pojer@gmail.com"},"repository":{"url":"git+https://github.com/facebook/jest.git","type":"git"},"_npmVersion":"5.3.0","description":"Generic configuration validation tool that helps you with warnings, errors and deprecation messages as well as showing users examples of correct configuration.","directories":{},"_nodeVersion":"8.4.0","dependencies":{"chalk":"^2.0.1","leven":"^2.1.0","jest-get-type":"21.3.0-alpha.eff7a1cf","pretty-format":"21.3.0-alpha.eff7a1cf"},"_npmOperationalInternal":{"tmp":"tmp/jest-validate-21.3.0-alpha.eff7a1cf.tgz_1506876418059_0.393013431224972","host":"s3://npm-registry-packages"},"readme":"# jest-validate\n\nGeneric configuration validation tool that helps you with warnings, errors and deprecation messages as well as showing users examples of correct configuration.\n\n```bash\nnpm install --save jest-validate\n```\n\n## Usage\n\n```js\nimport {validate} from 'jest-validate';\n\nvalidate(config, validationOptions); // => {hasDeprecationWarnings: boolean, isValid: boolean}\n```\n\nWhere `ValidationOptions` are:\n\n```ts\ntype ValidationOptions = {\n  comment?: string;\n  condition?: (option: unknown, validOption: unknown) => boolean;\n  deprecate?: (\n    config: Record<string, unknown>,\n    option: string,\n    deprecatedOptions: DeprecatedOptions,\n    options: ValidationOptions,\n  ) => boolean;\n  deprecatedConfig?: DeprecatedOptions;\n  error?: (\n    option: string,\n    received: unknown,\n    defaultValue: unknown,\n    options: ValidationOptions,\n    path?: Array<string>,\n  ) => void;\n  exampleConfig: Record<string, unknown>;\n  recursive?: boolean;\n  recursiveBlacklist?: Array<string>;\n  recursiveDenylist?: Array<string>;\n  title?: Title;\n  unknown?: (\n    config: Record<string, unknown>,\n    exampleConfig: Record<string, unknown>,\n    option: string,\n    options: ValidationOptions,\n    path?: Array<string>,\n  ) => void;\n};\n\ntype Title = {\n  deprecation?: string;\n  error?: string;\n  warning?: string;\n};\n```\n\n`exampleConfig` is the only option required.\n\n## API\n\nBy default `jest-validate` will print generic warning and error messages. You can however customize this behavior by providing `options: ValidationOptions` object as a second argument:\n\nAlmost anything can be overwritten to suite your needs.\n\n### Options\n\n- `recursiveDenylist` – optional array of string keyPaths that should be excluded from deep (recursive) validation.\n- `comment` – optional string to be rendered below error/warning message.\n- `condition` – an optional function with validation condition.\n- `deprecate`, `error`, `unknown` – optional functions responsible for displaying warning and error messages.\n- `deprecatedConfig` – optional object with deprecated config keys.\n- `exampleConfig` – the only **required** option with configuration against which you'd like to test.\n- `recursive` - optional boolean determining whether recursively compare `exampleConfig` to `config` (default: `true`).\n- `title` – optional object of titles for errors and messages.\n\nYou will find examples of `condition`, `deprecate`, `error`, `unknown`, and `deprecatedConfig` inside source of this repository, named respectively.\n\n## exampleConfig syntax\n\n`exampleConfig` should be an object with key/value pairs that contain an example of a valid value for each key. A configuration value is considered valid when:\n\n- it matches the JavaScript type of the example value, e.g. `string`, `number`, `array`, `boolean`, `function`, or `object`\n- it is `null` or `undefined`\n- it matches the Javascript type of any of arguments passed to `MultipleValidOptions(...)`\n\nThe last condition is a special syntax that allows validating where more than one type is permissible; see example below. It's acceptable to have multiple values of the same type in the example, so you can also use this syntax to provide more than one example. When a validation failure occurs, the error message will show all other values in the array as examples.\n\n## Examples\n\nMinimal example:\n\n```js\nvalidate(config, {exampleConfig});\n```\n\nExample with slight modifications:\n\n```js\nvalidate(config, {\n  comment: '  Documentation: http://custom-docs.com',\n  deprecatedConfig,\n  exampleConfig,\n  title: {\n    deprecation: 'Custom Deprecation',\n    // leaving 'error' and 'warning' as default\n  },\n});\n```\n\nThis will output:\n\n#### Warning:\n\n```bash\n● Validation Warning:\n\n  Unknown option transformx with value \"<rootDir>/node_modules/babel-jest\" was found.\n  This is either a typing error or a user mistake. Fixing it will remove this message.\n\n  Documentation: http://custom-docs.com\n```\n\n#### Error:\n\n```bash\n● Validation Error:\n\n  Option transform must be of type:\n    object\n  but instead received:\n    string\n\n  Example:\n  {\n    \"transform\": {\n      \"\\\\.js$\": \"<rootDir>/preprocessor.js\"\n    }\n  }\n\n  Documentation: http://custom-docs.com\n```\n\n## Example validating multiple types\n\n```js\nimport {multipleValidOptions} from 'jest-validate';\n\nvalidate(config, {\n  // `bar` will accept either a string or a number\n  bar: multipleValidOptions('string is ok', 2),\n});\n```\n\n#### Error:\n\n```bash\n● Validation Error:\n\n  Option foo must be of type:\n    string or number\n  but instead received:\n    array\n\n  Example:\n  {\n    \"bar\": \"string is ok\"\n  }\n\n  or\n\n  {\n    \"bar\": 2\n  }\n\n  Documentation: http://custom-docs.com\n```\n\n#### Deprecation\n\nBased on `deprecatedConfig` object with proper deprecation messages. Note custom title:\n\n```bash\nCustom Deprecation:\n\n  Option scriptPreprocessor was replaced by transform, which support multiple preprocessors.\n\n  Jest now treats your current configuration as:\n  {\n    \"transform\": {\".*\": \"xxx\"}\n  }\n\n  Please update your configuration.\n\n  Documentation: http://custom-docs.com\n```\n\n## Example validating CLI arguments\n\n```js\nimport {validate} from 'jest-validate';\n\nvalidateCLIOptions(argv, {...allowedOptions, deprecatedOptions});\n```\n\nIf `argv` contains a deprecated option that is not specified in `allowedOptions`, `validateCLIOptions` will throw an error with the message specified in the `deprecatedOptions` config:\n\n```bash\n● collectCoverageOnlyFrom:\n\n  Option \"collectCoverageOnlyFrom\" was replaced by \"collectCoverageFrom\"\n\n  CLI Options Documentation: https://jestjs.io/docs/en/cli.html\n```\n\nIf the deprecation option is still listed in the `allowedOptions` config, then `validateCLIOptions` will print the warning without throwing an error.\n","publish_time":1506876419110,"_cnpm_publish_time":1506876419110,"dist-tags":{"latest":"30.5.1","next":"30.0.0-rc.1"}}