{"name":"ow","version":"0.0.1-security","description":"security holding package","repository":{"type":"git","url":"git+https://github.com/npm/security-holder.git"},"gitHead":"ac50be87aafecba67fcacca3b32bf36a1f8f7a71","bugs":{"url":"https://github.com/npm/security-holder/issues"},"homepage":"https://github.com/npm/security-holder#readme","_id":"ow@0.0.1-security","_npmVersion":"5.4.1","_nodeVersion":"8.2.1","_npmUser":{"name":"kmanion","email":"kiera@npmjs.com"},"dist":{"integrity":"sha512-oRdYy+obHUeN6nTQ07YrEE1nXgbR+Cnj4ScuvYDzlZaAbQtejpQntu3lKwn+xkagafgD1QEOVT1JKwIgB0DT6Q==","shasum":"e265570ca316427e9c524bf26d259e84d17e1822","tarball":"http://registry-npm.ywwl.com/ow/download/ow-0.0.1-security.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDNarA1FxoWGgRkEUYotlTa+4aaHHSaGzHFMPGOml2qIgIgFY9DbptXBndltUk7mNLPK4/x8Sp+05OG4NbQAYKSghI="}],"size":423,"noattachment":false,"key":"/ow/-/ow-0.0.1-security.tgz"},"maintainers":[{"name":"kmanion","email":"kiera@npmjs.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ow-0.0.1-security.tgz_1505240252022_0.9686083716806024"},"directories":{},"readme":"<p align=\"center\">\n\t<img src=\"media/logo.png\" width=\"300\">\n\t<br>\n\t<br>\n</p>\n\n[![Coverage Status](https://codecov.io/gh/sindresorhus/ow/branch/main/graph/badge.svg)](https://codecov.io/gh/sindresorhus/ow)\n[![gzip size](https://badgen.net/bundlephobia/minzip/ow)](https://bundlephobia.com/result?p=ow)\n[![install size](https://packagephobia.now.sh/badge?p=ow)](https://packagephobia.now.sh/result?p=ow)\n\n> Function argument validation for humans\n\nFor schema validation, I recommend [`zod`](https://github.com/colinhacks/zod).\n\n## Highlights\n\n- Expressive chainable API\n- Lots of built-in validations\n- Supports custom validations\n- Automatic label inference in Node.js\n- Written in TypeScript\n\n## Install\n\n```sh\nnpm install ow\n```\n\n## Usage\n\n```ts\nimport ow from 'ow';\n\nconst unicorn = input => {\n\tow(input, ow.string.minLength(5));\n\n\t// …\n};\n\nunicorn(3);\n//=> ArgumentError: Expected `input` to be of type `string` but received type `number`\n\nunicorn('yo');\n//=> ArgumentError: Expected string `input` to have a minimum length of `5`, got `yo`\n```\n\nWe can also match the shape of an object.\n\n```ts\nimport ow from 'ow';\n\nconst unicorn = {\n\trainbow: '🌈',\n\tstars: {\n\t\tvalue: '🌟'\n\t}\n};\n\now(unicorn, ow.object.exactShape({\n\trainbow: ow.string,\n\tstars: {\n\t\tvalue: ow.number\n\t}\n}));\n//=> ArgumentError: Expected property `stars.value` to be of type `number` but received type `string` in object `unicorn`\n```\n\n***Note:*** If you intend on using `ow` for development purposes only, use `import ow from 'ow/dev-only'` instead of the usual `import ow from 'ow'`, and run the bundler with `NODE_ENV` set to `production` (e.g. `$ NODE_ENV=\"production\" parcel build index.js`). This will make `ow` automatically export a shim when running in production, which should result in a significantly lower bundle size.\n\n## API\n\n[Complete API documentation](https://sindresorhus.com/ow/)\n\nOw includes TypeScript type guards, so using it will narrow the type of previously-unknown values.\n\n```ts\nfunction (input: unknown) {\n\tinput.slice(0, 3) // Error, Property 'slice' does not exist on type 'unknown'\n\n\tow(input, ow.string)\n\n\tinput.slice(0, 3) // OK\n}\n```\n\n### ow(value, predicate)\n\nTest if `value` matches the provided `predicate`. Throws an `ArgumentError` if the test fails.\n\n### ow(value, label, predicate)\n\nTest if `value` matches the provided `predicate`. Throws an `ArgumentError` with the specified `label` if the test fails.\n\nThe `label` is automatically inferred in Node.js but you can override it by passing in a value for `label`. The automatic label inference doesn't work in the browser.\n\n### ow.isValid(value, predicate)\n\nReturns `true` if the value matches the predicate, otherwise returns `false`.\n\n### ow.create(predicate)\n\nCreate a reusable validator.\n\n```ts\nconst checkPassword = ow.create(ow.string.minLength(6));\n\nconst password = 'foo';\n\ncheckPassword(password);\n//=> ArgumentError: Expected string `password` to have a minimum length of `6`, got `foo`\n```\n\n### ow.create(label, predicate)\n\nCreate a reusable validator with a specific `label`.\n\n```ts\nconst checkPassword = ow.create('password', ow.string.minLength(6));\n\ncheckPassword('foo');\n//=> ArgumentError: Expected string `password` to have a minimum length of `6`, got `foo`\n```\n\n### ow.any(...predicate[])\n\nReturns a predicate that verifies if the value matches at least one of the given predicates.\n\n```ts\now('foo', ow.any(ow.string.maxLength(3), ow.number));\n```\n\n### ow.optional.{type}\n\nMakes the predicate optional. An optional predicate means that it doesn't fail if the value is `undefined`.\n\n```ts\now(1, ow.optional.number);\n\now(undefined, ow.optional.number);\n```\n\n### ow.{type}\n\nAll the below types return a predicate. Every predicate has some extra operators that you can use to test the value even more fine-grained.\n\n[Predicate docs.](https://sindresorhus.com/ow/types/Predicates.html)\n\n#### Primitives\n\n- `undefined`\n- `null`\n- `string`\n- `number`\n- `boolean`\n- `symbol`\n\n#### Built-in types\n\n- `array`\n- `function`\n- `buffer`\n- `object`\n- `regExp`\n- `date`\n- `error`\n- `promise`\n- `map`\n- `set`\n- `weakMap`\n- `weakSet`\n\n#### Typed arrays\n\n- `int8Array`\n- `uint8Array`\n- `uint8ClampedArray`\n- `int16Array`\n- `uint16Array`\n- `int32Array`\n- `uint32Array`\n- `float32Array`\n- `float64Array`\n\n#### Structured data\n\n- `arrayBuffer`\n- `dataView`\n- `sharedArrayBuffer`\n\n#### Miscellaneous\n\n- `nan`\n- `nullOrUndefined`\n- `iterable`\n- `typedArray`\n\n### Predicates\n\nThe following predicates are available on every type.\n\n#### not\n\nInverts the following predicate.\n\n```ts\now(1, ow.number.not.infinite);\n\now('', ow.string.not.empty);\n//=> ArgumentError: Expected string to not be empty, got ``\n```\n\n#### is(fn)\n\nUse a custom validation function. Return `true` if the value matches the validation, return `false` if it doesn't.\n\n```ts\now(1, ow.number.is(x => x < 10));\n\now(1, ow.number.is(x => x > 10));\n//=> ArgumentError: Expected `1` to pass custom validation function\n```\n\nInstead of returning `false`, you can also return a custom error message which results in a failure.\n\n```ts\nconst greaterThan = (max: number, x: number) => {\n\treturn x > max || `Expected \\`${x}\\` to be greater than \\`${max}\\``;\n};\n\now(5, ow.number.is(x => greaterThan(10, x)));\n//=> ArgumentError: Expected `5` to be greater than `10`\n```\n\n#### validate(fn)\n\nUse a custom validation object. The difference with `is` is that the function should return a validation object, which allows more flexibility.\n\n```ts\now(1, ow.number.validate(value => ({\n\tvalidator: value > 10,\n\tmessage: `Expected value to be greater than 10, got ${value}`\n})));\n//=> ArgumentError: (number) Expected value to be greater than 10, got 1\n```\n\nYou can also pass in a function as `message` value which accepts the label as argument.\n\n```ts\now(1, 'input', ow.number.validate(value => ({\n\tvalidator: value > 10,\n\tmessage: label => `Expected ${label} to be greater than 10, got ${value}`\n})));\n//=> ArgumentError: Expected number `input` to be greater than 10, got 1\n```\n\n#### message(string | fn)\n\nProvide a custom message:\n\n```ts\now('🌈', 'unicorn', ow.string.equals('🦄').message('Expected unicorn, got rainbow'));\n//=> ArgumentError: Expected unicorn, got rainbow\n```\n\nYou can also pass in a function which receives the value as the first parameter and the label as the second parameter and is expected to return the message.\n\n```ts\now('🌈', ow.string.minLength(5).message((value, label) => `Expected ${label}, to have a minimum length of 5, got \\`${value}\\``));\n//=> ArgumentError: Expected string, to be have a minimum length of 5, got `🌈`\n```\n\nIt's also possible to add a separate message per validation:\n\n```ts\now(\n\t'1234',\n\tow.string\n\t\t.minLength(5).message((value, label) => `Expected ${label}, to be have a minimum length of 5, got \\`${value}\\``)\n\t\t.url.message('This is no url')\n);\n//=> ArgumentError: Expected string, to be have a minimum length of 5, got `1234`\n\now(\n\t'12345',\n\tow.string\n\t\t.minLength(5).message((value, label) => `Expected ${label}, to be have a minimum length of 5, got \\`${value}\\``)\n\t\t.url.message('This is no url')\n);\n//=> ArgumentError: This is no url\n```\n\nThis can be useful for creating your own reusable validators which can be extracted to a separate npm package.\n\n### TypeScript\n\n**Requires TypeScript 4.7 or later.**\n\nOw includes a type utility that lets you to extract a TypeScript type from the given predicate.\n\n```ts\nimport ow, {Infer} from 'ow';\n\nconst userPredicate = ow.object.exactShape({\n\tname: ow.string\n});\n\ntype User = Infer<typeof userPredicate>;\n```\n\n## Related\n\n- [@sindresorhus/is](https://github.com/sindresorhus/is) - Type check values\n- [ngx-ow](https://github.com/SamVerschueren/ngx-ow) - Angular form validation on steroids\n","publish_time":1505240252164,"_cnpm_publish_time":1505240252164,"dist-tags":{"latest":"3.1.1","version-0-28":"0.28.2"}}