arstotzka 0.11.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +2 -2
  2. package/package.json +1 -1
  3. package/readme.md +25 -0
package/index.js CHANGED
@@ -112,11 +112,11 @@ function stricterConstraints(raw){
112
112
  * - selfAlias ("_self"): Schema property name for referring nested object itself
113
113
  * @return Array of errors
114
114
  */
115
- export function validate(target = {}, schema = {}, options = {}){
115
+ export function validate(target, schema = {}, options = {}){
116
116
  options = Object.assign(VALIDATION_DEFAULTS, options)
117
117
  const errors = [];
118
118
 
119
- const targetKeys = Object.keys(target);
119
+ const targetKeys = Object.keys(target || {});
120
120
  const schemaKeys = Object.keys(schema);
121
121
 
122
122
  for (let sKey of schemaKeys){
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arstotzka",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "description": "JS validation utility",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/readme.md CHANGED
@@ -5,6 +5,31 @@ JS data validation tool featuring laconic schema format and a sexy name.
5
5
 
6
6
  See detailed usage example in **[usage.js](https://github.com/MilesVII/arstotzka/blob/master/usage.js)**
7
7
 
8
+ ```
9
+ const schema = {
10
+ id: "number",
11
+ username: ["string", x => x.length < 10],
12
+ post: "string",
13
+ comments: Arstotzka.ARRAY_OF({
14
+ author: ["string", Arstotzka.OPTIONAL],
15
+ text: "string"
16
+ })
17
+ }
18
+
19
+ const goodData = {
20
+ id: 1337,
21
+ username: "mr.hands",
22
+ post: "Henlo there",
23
+ comments: [
24
+ {author: "Johnny", text: "henlo"},
25
+ {text: "hey hey"},
26
+ {author: "miles", text: "birb"},
27
+ ]
28
+ }
29
+
30
+ console.log(Arstotzka.validate(goodData, schema, {allowExtraProperties: false}));
31
+ ```
32
+
8
33
  ### Import:
9
34
  `import * as Arstotzka from "Arstotzka";`
10
35