Comparing version 0.0.1 to 0.1.0
{ | ||
"name": "ow", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Argument type validation", | ||
@@ -12,11 +12,18 @@ "license": "MIT", | ||
}, | ||
"main": "dist/index.js", | ||
"engines": { | ||
"node": ">=4" | ||
"node": ">=6" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
"prerelease": "npm run build", | ||
"pretest": "npm run compile -- --sourceMap", | ||
"test": "npm run lint && nyc ava dist/test", | ||
"lint": "tslint --format stylish --project .", | ||
"build": "npm run clean && webpack", | ||
"compile": "npm run clean && tsc", | ||
"clean": "del dist", | ||
"docs": "typedoc source" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"example.js" | ||
"dist" | ||
], | ||
@@ -43,9 +50,32 @@ "keywords": [ | ||
], | ||
"dependencies": { | ||
"@sindresorhus/is": "^0.1.0" | ||
}, | ||
"devDependencies": { | ||
"@sindresorhus/is": "^0.8.0", | ||
"@types/dot-prop": "^4.2.0", | ||
"@types/highlight.js": "^9.12.2", | ||
"@types/lodash.isequal": "^4.5.2", | ||
"@types/node": "^10.0.0", | ||
"@types/vali-date": "^1.0.0", | ||
"add-module-exports-webpack-plugin": "^0.1.0", | ||
"ava": "*", | ||
"xo": "*" | ||
"awesome-typescript-loader": "^5.0.0", | ||
"codecov": "^3.0.0", | ||
"del-cli": "^1.1.0", | ||
"dot-prop": "^4.2.0", | ||
"license-webpack-plugin": "^1.1.1", | ||
"lodash.isequal": "^4.5.0", | ||
"nyc": "^11.2.1", | ||
"tslint": "^5.9.1", | ||
"tslint-xo": "^0.7.0", | ||
"typedoc": "^0.11.1", | ||
"typescript": "^2.8.1", | ||
"vali-date": "^1.0.0", | ||
"webpack": "^4.3.0", | ||
"webpack-cli": "^2.0.13" | ||
}, | ||
"typings": "dist/index.d.ts", | ||
"nyc": { | ||
"exclude": [ | ||
"dist/test" | ||
] | ||
} | ||
} |
146
readme.md
@@ -1,6 +0,12 @@ | ||
# ow [![Build Status](https://travis-ci.org/sindresorhus/ow.svg?branch=master)](https://travis-ci.org/sindresorhus/ow) | ||
<p align="center"> | ||
<img src="media/logo.png" width="300"> | ||
<br> | ||
<br> | ||
</p> | ||
[![Build Status](https://travis-ci.org/sindresorhus/ow.svg?branch=master)](https://travis-ci.org/sindresorhus/ow) [![Coverage Status](https://codecov.io/gh/sindresorhus/ow/branch/master/graph/badge.svg)](https://codecov.io/gh/sindresorhus/ow) | ||
> Argument type validation | ||
<img src="header.gif" width="220" align="right"> | ||
[View documentation](https://sindresorhus.com/ow) | ||
@@ -17,4 +23,4 @@ | ||
```js | ||
const ow = require('ow'); | ||
```ts | ||
import ow from 'ow'; | ||
@@ -25,3 +31,3 @@ const unicorn = input => { | ||
… | ||
); | ||
}; | ||
@@ -32,8 +38,134 @@ unicorn(3); | ||
unicorn('yo'); | ||
//=> ArgumentError: Expected string length to be minimum 10 | ||
//=> ArgumentError: Expected string to have a minimum length of `5`, got `yo` | ||
``` | ||
## API | ||
### ow(value, predicate) | ||
Test if `value` matches the provided `predicate`. | ||
### ow.create(predicate) | ||
Create a reusable validator. | ||
```ts | ||
const checkPassword = ow.create(ow.string.minLength(6)); | ||
checkPassword('foo'); | ||
//=> ArgumentError: Expected string to have a minimum length of `6`, got `foo` | ||
``` | ||
### ow.any(...predicate[]) | ||
Returns a predicate that verifies if the value matches at least one of the given predicates. | ||
```ts | ||
ow('foo', ow.any(ow.string.maxLength(3), ow.number)); | ||
``` | ||
### ow.{type} | ||
All the below types return a predicate. Every predicate has some extra operators that you can use to test the value even more fine-grained. | ||
#### Primitives | ||
- [`undefined`](https://sindresorhus.com/ow/interfaces/ow.html#undefined) | ||
- [`null`](https://sindresorhus.com/ow/interfaces/ow.html#null) | ||
- [`string`](https://sindresorhus.com/ow/classes/stringpredicate.html) | ||
- [`number`](https://sindresorhus.com/ow/classes/numberpredicate.html) | ||
- [`boolean`](https://sindresorhus.com/ow/classes/booleanpredicate.html) | ||
- [`symbol`](https://sindresorhus.com/ow/interfaces/ow.html#symbol) | ||
#### Built-in types | ||
- [`array`](https://sindresorhus.com/ow/classes/arraypredicate.html) | ||
- [`function`](https://sindresorhus.com/ow/interfaces/ow.html#function) | ||
- [`buffer`](https://sindresorhus.com/ow/interfaces/ow.html#buffer) | ||
- [`object`](https://sindresorhus.com/ow/classes/objectpredicate.html) | ||
- [`regExp`](https://sindresorhus.com/ow/interfaces/ow.html#regexp) | ||
- [`date`](https://sindresorhus.com/ow/classes/datepredicate.html) | ||
- [`error`](https://sindresorhus.com/ow/classes/errorpredicate.html) | ||
- [`promise`](https://sindresorhus.com/ow/interfaces/ow.html#promise) | ||
- [`map`](https://sindresorhus.com/ow/classes/mappredicate.html) | ||
- [`set`](https://sindresorhus.com/ow/classes/setpredicate.html) | ||
- [`weakMap`](https://sindresorhus.com/ow/classes/weakmappredicate.html) | ||
- [`weakSet`](https://sindresorhus.com/ow/classes/weaksetpredicate.html) | ||
#### Typed arrays | ||
- [`int8Array`](https://sindresorhus.com/ow/interfaces/ow.html#int8Array) | ||
- [`uint8Array`](https://sindresorhus.com/ow/interfaces/ow.html#uint8Array) | ||
- [`uint8ClampedArray`](https://sindresorhus.com/ow/interfaces/ow.html#uint8ClampedArray) | ||
- [`int16Array`](https://sindresorhus.com/ow/interfaces/ow.html#int16Array) | ||
- [`uint16Array`](https://sindresorhus.com/ow/interfaces/ow.html#uint16Array) | ||
- [`int32Array`](https://sindresorhus.com/ow/interfaces/ow.html#in32Array) | ||
- [`uint32Array`](https://sindresorhus.com/ow/interfaces/ow.html#uin32Array) | ||
- [`float32Array`](https://sindresorhus.com/ow/interfaces/ow.html#float32Array) | ||
- [`float64Array`](https://sindresorhus.com/ow/interfaces/ow.html#float64Array) | ||
#### Structured data | ||
- [`arrayBuffer`](https://sindresorhus.com/ow/interfaces/ow.html#arraybuffer) | ||
- [`dataView`](https://sindresorhus.com/ow/interfaces/ow.html#dataview) | ||
#### Miscellaneous | ||
- [`nan`](https://sindresorhus.com/ow/interfaces/ow.html#nan) | ||
- [`nullOrUndefined`](https://sindresorhus.com/ow/interfaces/ow.html#nullorundefined) | ||
- [`iterable`](https://sindresorhus.com/ow/interfaces/ow.html#iterable) | ||
- [`typedArray`](https://sindresorhus.com/ow/interfaces/ow.html#typedarray) | ||
### Predicates | ||
The following predicates are available on every type. | ||
#### not | ||
Inverts the following predicates. | ||
```ts | ||
m(1, m.number.not.infinite); | ||
m('', m.string.not.empty); | ||
//=> ArgumentError: [NOT] Expected string to be empty, got `` | ||
``` | ||
#### is(fn) | ||
Use a custom validation function. Return `true` if the value matches the validation, return `false` if it doesn't. | ||
```ts | ||
m(1, m.number.is(x => x < 10)); | ||
m(1, m.number.is(x => x > 10)); | ||
//=> ArgumentError: Expected `1` to pass custom validation function | ||
``` | ||
Instead of returning `false`, you can also return a custom error message which results in a failure. | ||
```ts | ||
const greaterThan = (max: number, x: number) => { | ||
return x > max || `Expected \`${x}\` to be greater than \`${max}\``; | ||
}; | ||
m(5, m.number.is(x => greaterThan(10, x))); | ||
//=> ArgumentError: Expected `5` to be greater than `10` | ||
``` | ||
## Maintainers | ||
- [Sindre Sorhus](https://github.com/sindresorhus) | ||
- [Sam Verschueren](https://github.com/SamVerschueren) | ||
## Logo | ||
Logo is based on [Comic Book Elements](https://creativemarket.com/swedishpoints/232087-Comic-Book-Elements) by Carl Eriksson. | ||
## License | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) | ||
MIT |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
237443
0
141
3099
169
22
- Removed@sindresorhus/is@^0.1.0
- Removed@sindresorhus/is@0.1.0(transitive)