Skip to content

Commit cf55bf5

Browse files
committed
[docs] Move examples. Update readme, todo and changelog
1 parent 18731b2 commit cf55bf5

File tree

7 files changed

+58
-114
lines changed

7 files changed

+58
-114
lines changed

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
)
1313
```
1414
- Make type rules switch each other.
15+
- Add `optional`, `is` and `custom` checks.
16+
- Add strict type implementation.
1517

1618
### v0.9
1719

doc/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ Include scripts with integrity control:
3030
```html
3131
<script
3232
src="https://unpkg.com/typed-props@1.0.0/dist/typed-props.js"
33-
integrity="sha384-GlIQIsykUnZCr2koAs9hrk+hOPZaf6/46IqLb1dkuEeE3Ztf7jzMTqVWce7JcHjC"
33+
integrity="sha384-HJ1xePGzEGMbK5T23s6BURtTDxAQO1aCz8hy5nfKZdp2pbCRkfS2R6PnJ/x2FjK0"
3434
crossorigin="anonymous"
3535
></script>
3636
<script
3737
src="https://unpkg.com/typed-props@1.0.0/dist/typed-props.min.js"
38-
integrity="sha384-RxeNiFmGfqI7CsqvM0YvY81u6PyrMwBI4qlucXLV3yT4HdKDu3w6Wjh5P5bK4FdM"
38+
integrity="sha384-FdEeyPF4FQcR+L8Fmt1AizWCb0wAdCUxpXoayeFsrTuCCvygKNTszGN8PLPzWGxu"
3939
crossorigin="anonymous"
4040
></script>
4141
<script language="javascript">

example/api.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

example/uniq-items.js

Lines changed: 0 additions & 66 deletions
This file was deleted.

examples/api.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,38 @@ import {StrictType as T} from 'typed-props'
22

33
let userType
44
let postType
5+
let commentType
56

67
userType = T.exact({
8+
$type: T.is('http://api.rumk.in/v1#user'),
79
id: T.number,
810
username: T.string,
911
email: T.string,
1012
balance: T.number,
11-
// Posts has author which type is User
12-
posts: () => postType,
13+
// Posts is an array. Each post has an author which type is User
14+
posts: () => T.arrayOf(postType),
1315
})
1416

1517
postType = T.exact({
18+
$type: T.is('http://api.rumk.in/v1#post'),
19+
id: T.number,
1620
title: T.string,
17-
starts: T.number,
21+
text: T.string,
22+
stars: T.number,
1823
// Author has type User which has posts
1924
author: () => userType,
25+
// Comments property is an array It has reference to the post type
26+
comments: () => T.arrayOf(commentType),
27+
publishedAt: T.instanceOf(Date),
28+
})
29+
30+
commentType = T.exact({
31+
$type: T.is('http://api/rumk.in/v1#comment'),
32+
id: T.number,
33+
text: T.string,
34+
stars: T.number,
35+
author: () => userType,
36+
publishedAt: T.instanceOf(Date),
2037
})
2138

2239
function typeIs(type) {
@@ -26,4 +43,5 @@ function typeIs(type) {
2643
export default T.select(
2744
[typeIs('http://api.rumk.in/v1#user'), userType],
2845
[typeIs('http://api.rumk.in/v1#post'), postType],
46+
[typeIs('http://api.rumk.in/v1#comment'), commentType],
2947
)

readme.md

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![npm](https://img.shields.io/npm/v/typed-props.svg?style=flat-square)](https://npmjs.com/package/typed-props)
66
[![Travis](https://img.shields.io/travis/rumkin/typed-props.svg?style=flat-square)](https://travis-ci.org/rumkin/typed-props)
77
![](https://img.shields.io/badge/coverage-100%25-green.svg?style=flat-square)
8-
![](https://img.shields.io/badge/size-12.6%20KiB-blue.svg?style=flat-square)
8+
![](https://img.shields.io/badge/size-12.60%20KiB-blue.svg?style=flat-square)
99
![](https://img.shields.io/badge/deps-0-blue.svg?style=flat-square)
1010
[![npm](https://img.shields.io/npm/dm/typed-props.svg?style=flat-square)](https://npmjs.com/packages/typed-props)
1111

@@ -105,7 +105,7 @@ Example:
105105
// Reason helps to identify kind of problem within one validator.
106106
// Usual values are mismatch, no_matches, and redundant.
107107
reason: 'mismatch',
108-
// The next values are validator dependant.
108+
// The next values are validator dependent.
109109
type: 'string',
110110
expect: true,
111111
is: false,
@@ -117,7 +117,7 @@ Example:
117117
## Examples
118118
119119
* Create [UniqItems check](examples/uniq-items.js).
120-
* [Describe API](examples/api.js) with TypedProps (with circular references resolution).
120+
* [Describe API](examples/api.js) with TypedProps (with circular types resolution).
121121
122122
## Standard checks
123123
@@ -185,7 +185,7 @@ Type.shape({
185185
// Make type optional
186186
optionalValue: Type.optional,
187187
// Determine type in runtime
188-
propertyDependantType: Type.select(
188+
propertyDependentType: Type.select(
189189
[
190190
({type}) => type === 'ADD_TODO',
191191
Type.shape({/* ADD_TODO action payload shape */}),
@@ -206,7 +206,7 @@ Type.shape({
206206

207207
TypedProps have it's own custom checks which make it more handful.
208208

209-
### `Type.optional`
209+
### `Checkable.optional`
210210

211211
This is pseudo check. This rule allows to make some property optional. It can
212212
switch off previously defined `.isRequired` check. It's better to use with `StrictType`.
@@ -215,9 +215,20 @@ switch off previously defined `.isRequired` check. It's better to use with `Stri
215215
StrictType.number.optional
216216
```
217217

218-
### `Type.select()`
218+
### `Checkable.is()`
219219
```
220-
(...Function|TypedProps) -> TypedProps
220+
(value:*) -> Checkable
221+
```
222+
223+
This check validates the checkable value to strict equal `value` argument.
224+
225+
```javascript
226+
Type.is('user')
227+
```
228+
229+
### `Checkable.select()`
230+
```
231+
(...Function|Checkable) -> Checkable
221232
```
222233

223234
This checker allow to dynamically switch between types depending on input value.
@@ -232,9 +243,9 @@ Type.select(
232243
)
233244
```
234245

235-
### `Type.custom()`
246+
### `Checkable.custom()`
236247
```
237-
(check:(it:*) -> bool) -> TypedProps
248+
(check:(it:*) -> bool) -> Checkable
238249
```
239250

240251
Custom check accepts `check` argument and use it to validate the value.
@@ -267,7 +278,7 @@ class Arith {
267278

268279
## Checks and groups
269280

270-
Currently there are several groups of checkers: existance, type and complex checks.
281+
Currently there are several groups of checkers: existence, type, exact, and complex checks.
271282

272283
* Existance:
273284
* isRequired
@@ -279,9 +290,11 @@ Currently there are several groups of checkers: existance, type and complex chec
279290
* func
280291
* object
281292
* array
282-
* any: removes type rule
283-
* Complex:
293+
* any: removes any other type check
294+
* Exact:
295+
* is
284296
* oneOf
297+
* Complex:
285298
* oneOfType
286299
* arrayOf: overwirites type check with `array`
287300
* objectOf: overwirites type check with `object`
@@ -290,7 +303,7 @@ Currently there are several groups of checkers: existance, type and complex chec
290303
* select
291304
* custom
292305

293-
Type and existance checks are switchable and can replace each other. It's made
306+
Type and existence checks are switchable and can replace each other. It's made
294307
for flexibility.
295308

296309
```javascript
@@ -387,7 +400,11 @@ class IsArray extends SimpleRule {
387400

388401
## API
389402

390-
### `TypedProps#getChecks()`
403+
### `Checkable()`
404+
405+
Checkable is a prototype of TypeProps. It contains only check logic and has no own rules.
406+
407+
### `Checkable#getChecks()`
391408
```
392409
() -> Checks[]
393410
```

todo.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
### v1.1
1111

12+
- [ ] Select should accept plain object as shapes.
13+
- [ ] Add context to prevent circular structures failures.
1214
- [ ] Inspect details.reason wider implementation.
1315
- [ ] Add rule referrences to remove dependant rules on replace:
1416
```javascript

0 commit comments

Comments
 (0)