-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Maurits Rijk
committed
Apr 12, 2017
1 parent
d37a7fb
commit 7ff2b9d
Showing
4 changed files
with
60 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
alt | ||
===== | ||
|
||
Usage: ```alt(...)``` | ||
|
||
Returns a spec that accepts null and values satisfying pred. | ||
|
||
[Source](https://github.com/mrijk/speculaas/blob/master/lib/alt.js) | ||
|
||
Example: | ||
|
||
```js | ||
const s = require('speculaas'); | ||
const {isBoolean, isString} = require('lodash'); | ||
|
||
s.def('::bool-or-string', s.alt(':s', isString, ':b', isBoolean)); | ||
|
||
s.isValid('::bool-or-string', [true]); | ||
// true | ||
|
||
s.isValid('::bool-or-string', ['foo']); | ||
// true | ||
|
||
s.isValid('::bool-or-string', [1]); | ||
// false | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
intIn | ||
===== | ||
|
||
Usage: ```intIn(start end)``` | ||
|
||
Returns a spec that validates ints in the range from start (inclusive) to end (exclusive). | ||
|
||
[Source](https://github.com/mrijk/speculaas/blob/master/lib/intIn.js) | ||
|
||
Example: | ||
|
||
```js | ||
const s = require('speculaas'); | ||
|
||
// Define range of a single byte | ||
s.def('::oneByte', s.intIn(0, 256)); | ||
|
||
s.isValid('::oneByte', 0); | ||
// true | ||
|
||
s.isValid('::oneByte', 256); | ||
// false | ||
|
||
s.isValid('::oneByte', 512); | ||
// false | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters