Browse Source

Minor tweaks

iss58
Sindre Sorhus 7 years ago
parent
commit
48f849ec81
  1. 26
      example.js
  2. 2
      package.json
  3. 12
      readme.md

26
example.js

@ -1,18 +1,22 @@
'use strict';
const ow = require('./dist');
const fn = (input, options) => {
ow(input, ow.string.minLength(10));
const logError = fn => {
try {
fn();
} catch (err) {
console.log(err.message);
}
};
// For objects, just an idea for now:
// ow.many(options, {
// tasks: ow.number.range(0, 10),
// extras: ow.arrayOf(ow.number)
// });
const fn = input => {
ow(input, ow.string.minLength(10));
};
//fn(10);
//=> ArgumentError: Expected argument to be of type `string` but received type `number`
logError(() => {
fn(10);
});
fn('foo');
//=> ArgumentError: Expected string length to be minimum 10
logError(() => {
fn('foo');
});

2
package.json

@ -1,7 +1,7 @@
{
"name": "ow",
"version": "0.2.0",
"description": "Argument type validation",
"description": "Function argument validation for humans",
"license": "MIT",
"repository": "sindresorhus/ow",
"author": {

12
readme.md

@ -6,9 +6,15 @@
[![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
> Function argument validation for humans
[View documentation](https://sindresorhus.com/ow)
## Highlights
- Expressive chainable API
- Lots of built-in validations
- Supports custom validations
- Written in TypeScript
## Install
@ -39,6 +45,8 @@ unicorn('yo');
## API
[Complete API documentation](https://sindresorhus.com/ow)
### ow(value, predicate)
Test if `value` matches the provided `predicate`.

Loading…
Cancel
Save