Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Maurits Rijk committed Apr 13, 2017
1 parent 145696b commit ac1372f
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 8 deletions.
2 changes: 1 addition & 1 deletion book.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"gitbook": "2.5.2",
"gitbook": "2.x.x",
"structure": {
"summary": "docs/SUMMARY.md"
}
Expand Down
1 change: 1 addition & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* [fdef](docs/api/fdef.md)
* [gen](docs/api/gen.md)
* [intIn](docs/api/intIn.md)
* [isIntInRange](docs/api/isIntInRange.md)
* [isValid](docs/api/isValid.md)
* [keys](docs/api/keys.md)
* [mapOf](docs/api/mapOf.md)
Expand Down
17 changes: 11 additions & 6 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
Descriptions for the different functions where copied from the original
[clojure.spec api description](https://clojure.github.io/clojure/branch-master/clojure.spec-api.html).

| clojure.spec | speculaas |
|:---------:|:--------:|
| & | amp |
| + | plus |
| * | star |
| col-of | colOf |
| clojure.spec | speculaas |
|:-------------:|:------------:|
| & | [amp](api/amp.md) |
| + | [plus](api/plus.md) |
| * | [star](api/star.md) |
| coll-of | [collOf](api/collOf.md) |
| double-in | [doubleIn](api/doubleIn.md) |
| int-in | [intIn](api/intIn.md) |
| int-in-range? | [isIntInRange](api/isIntInRange.md) |
| map-of | [mapOf](api/mapOf.md) |


2 changes: 1 addition & 1 deletion docs/api/intIn.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
intIn
=====

Usage: ```intIn(start end)```
Usage: ```intIn(start, end)```

Returns a spec that validates ints in the range from start (inclusive) to end (exclusive).

Expand Down
20 changes: 20 additions & 0 deletions docs/api/isIntInRange.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
isIntInRange
=====

Usage: ```isIntInRange(start, end, val)```

Return true if start <= val and val < end

[Source](https://github.com/mrijk/speculaas/blob/master/lib/intIn.js)

Example:

```js
const s = require('speculaas');

s.isIntInRange(0, 13, 0);
// true

s.isIntInRange(0, 13, -42);
// false
```
15 changes: 15 additions & 0 deletions docs/api/keys.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
keys
=====

Usage: ```keys(...)```

Creates and returns a map validating spec.

[Source](https://github.com/mrijk/speculaas/blob/master/lib/keys.js)

Example:

```js
const s = require('speculaas');
const {isBoolean, isString} = require('lodash');
```
11 changes: 11 additions & 0 deletions test/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('Test the keys function', () => {
s.def('::first-name', isString);
s.def('::last-name', isString);
s.def('::email', '::email-type');
s.def('::phone', isString);
s.def('::person', s.keys({req: ['::first-name', '::last-name', '::email'], opt: ['::phone']}));
});

Expand All @@ -28,6 +29,16 @@ describe('Test the keys function', () => {
'::email': 'elon@example.com'
})).to.be.true;
});

it('should should accept object with required and optional keys', () => {
expect(s.isValid('::person',
{
'::first-name': 'Elon',
'::last-name': 'Musk',
'::email': 'elon@example.com',
'::phone': '06 12345678'
})).to.be.true;
});

it('should fail if required key is missing', () => {
expect(s.isValid('::person',
Expand Down

0 comments on commit ac1372f

Please sign in to comment.