@zipify/wysiwyg 1.1.0-2 → 1.1.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 (148) hide show
  1. package/dist/cli.js +1 -1
  2. package/dist/wysiwyg.mjs +10 -17
  3. package/lib/extensions/Alignment.js +10 -8
  4. package/lib/extensions/FontSize.js +8 -3
  5. package/lib/extensions/LineHeight.js +10 -4
  6. package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +3 -3
  7. package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +9 -9
  8. package/lib/extensions/__tests__/__snapshots__/LineHeight.test.js.snap +5 -5
  9. package/lib/services/NodeFactory.js +4 -1
  10. package/node_modules_lambda/acorn-globals/node_modules/.bin/acorn +4 -0
  11. package/node_modules_lambda/acorn-globals/node_modules/acorn/CHANGELOG.md +620 -0
  12. package/node_modules_lambda/acorn-globals/node_modules/acorn/LICENSE +21 -0
  13. package/node_modules_lambda/acorn-globals/node_modules/acorn/README.md +269 -0
  14. package/node_modules_lambda/acorn-globals/node_modules/acorn/bin/acorn +4 -0
  15. package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/acorn.d.ts +209 -0
  16. package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/acorn.js +5186 -0
  17. package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/acorn.js.map +1 -0
  18. package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/acorn.mjs +5155 -0
  19. package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/acorn.mjs.d.ts +2 -0
  20. package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/acorn.mjs.map +1 -0
  21. package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/bin.js +64 -0
  22. package/node_modules_lambda/acorn-globals/node_modules/acorn/package.json +35 -0
  23. package/node_modules_lambda/cssstyle/node_modules/cssom/LICENSE.txt +20 -0
  24. package/node_modules_lambda/cssstyle/node_modules/cssom/README.mdown +67 -0
  25. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSDocumentRule.js +39 -0
  26. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSFontFaceRule.js +36 -0
  27. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSHostRule.js +37 -0
  28. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSImportRule.js +132 -0
  29. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSKeyframeRule.js +37 -0
  30. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSKeyframesRule.js +39 -0
  31. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSMediaRule.js +41 -0
  32. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSOM.js +3 -0
  33. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSRule.js +43 -0
  34. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSStyleDeclaration.js +148 -0
  35. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSStyleRule.js +190 -0
  36. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSStyleSheet.js +88 -0
  37. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSSupportsRule.js +36 -0
  38. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSValue.js +43 -0
  39. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSValueExpression.js +344 -0
  40. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/MatcherList.js +62 -0
  41. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/MediaList.js +61 -0
  42. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/StyleSheet.js +17 -0
  43. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/clone.js +82 -0
  44. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/index.js +21 -0
  45. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/parse.js +464 -0
  46. package/node_modules_lambda/cssstyle/node_modules/cssom/package.json +18 -0
  47. package/node_modules_lambda/data-urls/node_modules/whatwg-url/LICENSE.txt +21 -0
  48. package/node_modules_lambda/data-urls/node_modules/whatwg-url/README.md +106 -0
  49. package/node_modules_lambda/data-urls/node_modules/whatwg-url/index.js +27 -0
  50. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/Function.js +42 -0
  51. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/URL-impl.js +209 -0
  52. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/URL.js +442 -0
  53. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/URLSearchParams-impl.js +130 -0
  54. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/URLSearchParams.js +472 -0
  55. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/VoidFunction.js +26 -0
  56. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/encoding.js +16 -0
  57. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/infra.js +26 -0
  58. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/percent-encoding.js +142 -0
  59. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/url-state-machine.js +1244 -0
  60. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/urlencoded.js +106 -0
  61. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/utils.js +190 -0
  62. package/node_modules_lambda/data-urls/node_modules/whatwg-url/package.json +58 -0
  63. package/node_modules_lambda/data-urls/node_modules/whatwg-url/webidl2js-wrapper.js +7 -0
  64. package/node_modules_lambda/escodegen/node_modules/estraverse/.jshintrc +16 -0
  65. package/node_modules_lambda/escodegen/node_modules/estraverse/LICENSE.BSD +19 -0
  66. package/node_modules_lambda/escodegen/node_modules/estraverse/README.md +153 -0
  67. package/node_modules_lambda/escodegen/node_modules/estraverse/estraverse.js +805 -0
  68. package/node_modules_lambda/escodegen/node_modules/estraverse/gulpfile.js +70 -0
  69. package/node_modules_lambda/escodegen/node_modules/estraverse/package.json +40 -0
  70. package/node_modules_lambda/escodegen/node_modules/levn/LICENSE +22 -0
  71. package/node_modules_lambda/escodegen/node_modules/levn/README.md +196 -0
  72. package/node_modules_lambda/escodegen/node_modules/levn/lib/cast.js +298 -0
  73. package/node_modules_lambda/escodegen/node_modules/levn/lib/coerce.js +285 -0
  74. package/node_modules_lambda/escodegen/node_modules/levn/lib/index.js +22 -0
  75. package/node_modules_lambda/escodegen/node_modules/levn/lib/parse-string.js +113 -0
  76. package/node_modules_lambda/escodegen/node_modules/levn/lib/parse.js +102 -0
  77. package/node_modules_lambda/escodegen/node_modules/levn/package.json +47 -0
  78. package/node_modules_lambda/escodegen/node_modules/optionator/CHANGELOG.md +56 -0
  79. package/node_modules_lambda/escodegen/node_modules/optionator/LICENSE +22 -0
  80. package/node_modules_lambda/escodegen/node_modules/optionator/README.md +238 -0
  81. package/node_modules_lambda/escodegen/node_modules/optionator/lib/help.js +260 -0
  82. package/node_modules_lambda/escodegen/node_modules/optionator/lib/index.js +465 -0
  83. package/node_modules_lambda/escodegen/node_modules/optionator/lib/util.js +54 -0
  84. package/node_modules_lambda/escodegen/node_modules/optionator/package.json +44 -0
  85. package/node_modules_lambda/escodegen/node_modules/prelude-ls/CHANGELOG.md +99 -0
  86. package/node_modules_lambda/escodegen/node_modules/prelude-ls/LICENSE +22 -0
  87. package/node_modules_lambda/escodegen/node_modules/prelude-ls/README.md +15 -0
  88. package/node_modules_lambda/escodegen/node_modules/prelude-ls/lib/Func.js +65 -0
  89. package/node_modules_lambda/escodegen/node_modules/prelude-ls/lib/List.js +686 -0
  90. package/node_modules_lambda/escodegen/node_modules/prelude-ls/lib/Num.js +130 -0
  91. package/node_modules_lambda/escodegen/node_modules/prelude-ls/lib/Obj.js +154 -0
  92. package/node_modules_lambda/escodegen/node_modules/prelude-ls/lib/Str.js +92 -0
  93. package/node_modules_lambda/escodegen/node_modules/prelude-ls/lib/index.js +178 -0
  94. package/node_modules_lambda/escodegen/node_modules/prelude-ls/package.json +52 -0
  95. package/node_modules_lambda/escodegen/node_modules/source-map/CHANGELOG.md +301 -0
  96. package/node_modules_lambda/escodegen/node_modules/source-map/LICENSE +28 -0
  97. package/node_modules_lambda/escodegen/node_modules/source-map/README.md +742 -0
  98. package/node_modules_lambda/escodegen/node_modules/source-map/dist/source-map.debug.js +3234 -0
  99. package/node_modules_lambda/escodegen/node_modules/source-map/dist/source-map.js +3233 -0
  100. package/node_modules_lambda/escodegen/node_modules/source-map/dist/source-map.min.js +2 -0
  101. package/node_modules_lambda/escodegen/node_modules/source-map/dist/source-map.min.js.map +1 -0
  102. package/node_modules_lambda/escodegen/node_modules/source-map/lib/array-set.js +121 -0
  103. package/node_modules_lambda/escodegen/node_modules/source-map/lib/base64-vlq.js +140 -0
  104. package/node_modules_lambda/escodegen/node_modules/source-map/lib/base64.js +67 -0
  105. package/node_modules_lambda/escodegen/node_modules/source-map/lib/binary-search.js +111 -0
  106. package/node_modules_lambda/escodegen/node_modules/source-map/lib/mapping-list.js +79 -0
  107. package/node_modules_lambda/escodegen/node_modules/source-map/lib/quick-sort.js +114 -0
  108. package/node_modules_lambda/escodegen/node_modules/source-map/lib/source-map-consumer.js +1145 -0
  109. package/node_modules_lambda/escodegen/node_modules/source-map/lib/source-map-generator.js +425 -0
  110. package/node_modules_lambda/escodegen/node_modules/source-map/lib/source-node.js +413 -0
  111. package/node_modules_lambda/escodegen/node_modules/source-map/lib/util.js +488 -0
  112. package/node_modules_lambda/escodegen/node_modules/source-map/package.json +73 -0
  113. package/node_modules_lambda/escodegen/node_modules/source-map/source-map.d.ts +98 -0
  114. package/node_modules_lambda/escodegen/node_modules/source-map/source-map.js +8 -0
  115. package/node_modules_lambda/escodegen/node_modules/type-check/LICENSE +22 -0
  116. package/node_modules_lambda/escodegen/node_modules/type-check/README.md +210 -0
  117. package/node_modules_lambda/escodegen/node_modules/type-check/lib/check.js +126 -0
  118. package/node_modules_lambda/escodegen/node_modules/type-check/lib/index.js +16 -0
  119. package/node_modules_lambda/escodegen/node_modules/type-check/lib/parse-type.js +196 -0
  120. package/node_modules_lambda/escodegen/node_modules/type-check/package.json +40 -0
  121. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/.github/dependabot.yml +11 -0
  122. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/Changelog.md +212 -0
  123. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/LICENSE +21 -0
  124. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/README.md +130 -0
  125. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/dbcs-codec.js +597 -0
  126. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/dbcs-data.js +188 -0
  127. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/index.js +23 -0
  128. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/internal.js +198 -0
  129. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/sbcs-codec.js +72 -0
  130. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/sbcs-data-generated.js +451 -0
  131. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/sbcs-data.js +179 -0
  132. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/big5-added.json +122 -0
  133. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/cp936.json +264 -0
  134. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/cp949.json +273 -0
  135. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/cp950.json +177 -0
  136. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/eucjp.json +182 -0
  137. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json +1 -0
  138. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/gbk-added.json +56 -0
  139. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/shiftjis.json +125 -0
  140. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/utf16.js +197 -0
  141. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/utf32.js +319 -0
  142. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/utf7.js +290 -0
  143. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/lib/bom-handling.js +52 -0
  144. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/lib/index.d.ts +41 -0
  145. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/lib/index.js +180 -0
  146. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/lib/streams.js +109 -0
  147. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/package.json +44 -0
  148. package/package.json +1 -1
@@ -0,0 +1,210 @@
1
+ # type-check [![Build Status](https://travis-ci.org/gkz/type-check.png?branch=master)](https://travis-ci.org/gkz/type-check)
2
+
3
+ <a name="type-check" />
4
+
5
+ `type-check` is a library which allows you to check the types of JavaScript values at runtime with a Haskell like type syntax. It is great for checking external input, for testing, or even for adding a bit of safety to your internal code. It is a major component of [levn](https://github.com/gkz/levn). MIT license. Version 0.3.2. Check out the [demo](http://gkz.github.io/type-check/).
6
+
7
+ For updates on `type-check`, [follow me on twitter](https://twitter.com/gkzahariev).
8
+
9
+ npm install type-check
10
+
11
+ ## Quick Examples
12
+
13
+ ```js
14
+ // Basic types:
15
+ var typeCheck = require('type-check').typeCheck;
16
+ typeCheck('Number', 1); // true
17
+ typeCheck('Number', 'str'); // false
18
+ typeCheck('Error', new Error); // true
19
+ typeCheck('Undefined', undefined); // true
20
+
21
+ // Comment
22
+ typeCheck('count::Number', 1); // true
23
+
24
+ // One type OR another type:
25
+ typeCheck('Number | String', 2); // true
26
+ typeCheck('Number | String', 'str'); // true
27
+
28
+ // Wildcard, matches all types:
29
+ typeCheck('*', 2) // true
30
+
31
+ // Array, all elements of a single type:
32
+ typeCheck('[Number]', [1, 2, 3]); // true
33
+ typeCheck('[Number]', [1, 'str', 3]); // false
34
+
35
+ // Tuples, or fixed length arrays with elements of different types:
36
+ typeCheck('(String, Number)', ['str', 2]); // true
37
+ typeCheck('(String, Number)', ['str']); // false
38
+ typeCheck('(String, Number)', ['str', 2, 5]); // false
39
+
40
+ // Object properties:
41
+ typeCheck('{x: Number, y: Boolean}', {x: 2, y: false}); // true
42
+ typeCheck('{x: Number, y: Boolean}', {x: 2}); // false
43
+ typeCheck('{x: Number, y: Maybe Boolean}', {x: 2}); // true
44
+ typeCheck('{x: Number, y: Boolean}', {x: 2, y: false, z: 3}); // false
45
+ typeCheck('{x: Number, y: Boolean, ...}', {x: 2, y: false, z: 3}); // true
46
+
47
+ // A particular type AND object properties:
48
+ typeCheck('RegExp{source: String, ...}', /re/i); // true
49
+ typeCheck('RegExp{source: String, ...}', {source: 're'}); // false
50
+
51
+ // Custom types:
52
+ var opt = {customTypes:
53
+ {Even: { typeOf: 'Number', validate: function(x) { return x % 2 === 0; }}}};
54
+ typeCheck('Even', 2, opt); // true
55
+
56
+ // Nested:
57
+ var type = '{a: (String, [Number], {y: Array, ...}), b: Error{message: String, ...}}'
58
+ typeCheck(type, {a: ['hi', [1, 2, 3], {y: [1, 'ms']}], b: new Error('oh no')}); // true
59
+ ```
60
+
61
+ Check out the [type syntax format](#syntax) and [guide](#guide).
62
+
63
+ ## Usage
64
+
65
+ `require('type-check');` returns an object that exposes four properties. `VERSION` is the current version of the library as a string. `typeCheck`, `parseType`, and `parsedTypeCheck` are functions.
66
+
67
+ ```js
68
+ // typeCheck(type, input, options);
69
+ typeCheck('Number', 2); // true
70
+
71
+ // parseType(type);
72
+ var parsedType = parseType('Number'); // object
73
+
74
+ // parsedTypeCheck(parsedType, input, options);
75
+ parsedTypeCheck(parsedType, 2); // true
76
+ ```
77
+
78
+ ### typeCheck(type, input, options)
79
+
80
+ `typeCheck` checks a JavaScript value `input` against `type` written in the [type format](#type-format) (and taking account the optional `options`) and returns whether the `input` matches the `type`.
81
+
82
+ ##### arguments
83
+ * type - `String` - the type written in the [type format](#type-format) which to check against
84
+ * input - `*` - any JavaScript value, which is to be checked against the type
85
+ * options - `Maybe Object` - an optional parameter specifying additional options, currently the only available option is specifying [custom types](#custom-types)
86
+
87
+ ##### returns
88
+ `Boolean` - whether the input matches the type
89
+
90
+ ##### example
91
+ ```js
92
+ typeCheck('Number', 2); // true
93
+ ```
94
+
95
+ ### parseType(type)
96
+
97
+ `parseType` parses string `type` written in the [type format](#type-format) into an object representing the parsed type.
98
+
99
+ ##### arguments
100
+ * type - `String` - the type written in the [type format](#type-format) which to parse
101
+
102
+ ##### returns
103
+ `Object` - an object in the parsed type format representing the parsed type
104
+
105
+ ##### example
106
+ ```js
107
+ parseType('Number'); // [{type: 'Number'}]
108
+ ```
109
+ ### parsedTypeCheck(parsedType, input, options)
110
+
111
+ `parsedTypeCheck` checks a JavaScript value `input` against parsed `type` in the parsed type format (and taking account the optional `options`) and returns whether the `input` matches the `type`. Use this in conjunction with `parseType` if you are going to use a type more than once.
112
+
113
+ ##### arguments
114
+ * type - `Object` - the type in the parsed type format which to check against
115
+ * input - `*` - any JavaScript value, which is to be checked against the type
116
+ * options - `Maybe Object` - an optional parameter specifying additional options, currently the only available option is specifying [custom types](#custom-types)
117
+
118
+ ##### returns
119
+ `Boolean` - whether the input matches the type
120
+
121
+ ##### example
122
+ ```js
123
+ parsedTypeCheck([{type: 'Number'}], 2); // true
124
+ var parsedType = parseType('String');
125
+ parsedTypeCheck(parsedType, 'str'); // true
126
+ ```
127
+
128
+ <a name="type-format" />
129
+ ## Type Format
130
+
131
+ ### Syntax
132
+
133
+ White space is ignored. The root node is a __Types__.
134
+
135
+ * __Identifier__ = `[\$\w]+` - a group of any lower or upper case letters, numbers, underscores, or dollar signs - eg. `String`
136
+ * __Type__ = an `Identifier`, an `Identifier` followed by a `Structure`, just a `Structure`, or a wildcard `*` - eg. `String`, `Object{x: Number}`, `{x: Number}`, `Array{0: String, 1: Boolean, length: Number}`, `*`
137
+ * __Types__ = optionally a comment (an `Indentifier` followed by a `::`), optionally the identifier `Maybe`, one or more `Type`, separated by `|` - eg. `Number`, `String | Date`, `Maybe Number`, `Maybe Boolean | String`
138
+ * __Structure__ = `Fields`, or a `Tuple`, or an `Array` - eg. `{x: Number}`, `(String, Number)`, `[Date]`
139
+ * __Fields__ = a `{`, followed one or more `Field` separated by a comma `,` (trailing comma `,` is permitted), optionally an `...` (always preceded by a comma `,`), followed by a `}` - eg. `{x: Number, y: String}`, `{k: Function, ...}`
140
+ * __Field__ = an `Identifier`, followed by a colon `:`, followed by `Types` - eg. `x: Date | String`, `y: Boolean`
141
+ * __Tuple__ = a `(`, followed by one or more `Types` separated by a comma `,` (trailing comma `,` is permitted), followed by a `)` - eg `(Date)`, `(Number, Date)`
142
+ * __Array__ = a `[` followed by exactly one `Types` followed by a `]` - eg. `[Boolean]`, `[Boolean | Null]`
143
+
144
+ ### Guide
145
+
146
+ `type-check` uses `Object.toString` to find out the basic type of a value. Specifically,
147
+
148
+ ```js
149
+ {}.toString.call(VALUE).slice(8, -1)
150
+ {}.toString.call(true).slice(8, -1) // 'Boolean'
151
+ ```
152
+ A basic type, eg. `Number`, uses this check. This is much more versatile than using `typeof` - for example, with `document`, `typeof` produces `'object'` which isn't that useful, and our technique produces `'HTMLDocument'`.
153
+
154
+ You may check for multiple types by separating types with a `|`. The checker proceeds from left to right, and passes if the value is any of the types - eg. `String | Boolean` first checks if the value is a string, and then if it is a boolean. If it is none of those, then it returns false.
155
+
156
+ Adding a `Maybe` in front of a list of multiple types is the same as also checking for `Null` and `Undefined` - eg. `Maybe String` is equivalent to `Undefined | Null | String`.
157
+
158
+ You may add a comment to remind you of what the type is for by following an identifier with a `::` before a type (or multiple types). The comment is simply thrown out.
159
+
160
+ The wildcard `*` matches all types.
161
+
162
+ There are three types of structures for checking the contents of a value: 'fields', 'tuple', and 'array'.
163
+
164
+ If used by itself, a 'fields' structure will pass with any type of object as long as it is an instance of `Object` and the properties pass - this allows for duck typing - eg. `{x: Boolean}`.
165
+
166
+ To check if the properties pass, and the value is of a certain type, you can specify the type - eg. `Error{message: String}`.
167
+
168
+ If you want to make a field optional, you can simply use `Maybe` - eg. `{x: Boolean, y: Maybe String}` will still pass if `y` is undefined (or null).
169
+
170
+ If you don't care if the value has properties beyond what you have specified, you can use the 'etc' operator `...` - eg. `{x: Boolean, ...}` will match an object with an `x` property that is a boolean, and with zero or more other properties.
171
+
172
+ For an array, you must specify one or more types (separated by `|`) - it will pass for something of any length as long as each element passes the types provided - eg. `[Number]`, `[Number | String]`.
173
+
174
+ A tuple checks for a fixed number of elements, each of a potentially different type. Each element is separated by a comma - eg. `(String, Number)`.
175
+
176
+ An array and tuple structure check that the value is of type `Array` by default, but if another type is specified, they will check for that instead - eg. `Int32Array[Number]`. You can use the wildcard `*` to search for any type at all.
177
+
178
+ Check out the [type precedence](https://github.com/zaboco/type-precedence) library for type-check.
179
+
180
+ ## Options
181
+
182
+ Options is an object. It is an optional parameter to the `typeCheck` and `parsedTypeCheck` functions. The only current option is `customTypes`.
183
+
184
+ <a name="custom-types" />
185
+ ### Custom Types
186
+
187
+ __Example:__
188
+
189
+ ```js
190
+ var options = {
191
+ customTypes: {
192
+ Even: {
193
+ typeOf: 'Number',
194
+ validate: function(x) {
195
+ return x % 2 === 0;
196
+ }
197
+ }
198
+ }
199
+ };
200
+ typeCheck('Even', 2, options); // true
201
+ typeCheck('Even', 3, options); // false
202
+ ```
203
+
204
+ `customTypes` allows you to set up custom types for validation. The value of this is an object. The keys of the object are the types you will be matching. Each value of the object will be an object having a `typeOf` property - a string, and `validate` property - a function.
205
+
206
+ The `typeOf` property is the type the value should be, and `validate` is a function which should return true if the value is of that type. `validate` receives one parameter, which is the value that we are checking.
207
+
208
+ ## Technical About
209
+
210
+ `type-check` is written in [LiveScript](http://livescript.net/) - a language that compiles to JavaScript. It also uses the [prelude.ls](http://preludels.com/) library.
@@ -0,0 +1,126 @@
1
+ // Generated by LiveScript 1.4.0
2
+ (function(){
3
+ var ref$, any, all, isItNaN, types, defaultType, customTypes, toString$ = {}.toString;
4
+ ref$ = require('prelude-ls'), any = ref$.any, all = ref$.all, isItNaN = ref$.isItNaN;
5
+ types = {
6
+ Number: {
7
+ typeOf: 'Number',
8
+ validate: function(it){
9
+ return !isItNaN(it);
10
+ }
11
+ },
12
+ NaN: {
13
+ typeOf: 'Number',
14
+ validate: isItNaN
15
+ },
16
+ Int: {
17
+ typeOf: 'Number',
18
+ validate: function(it){
19
+ return !isItNaN(it) && it % 1 === 0;
20
+ }
21
+ },
22
+ Float: {
23
+ typeOf: 'Number',
24
+ validate: function(it){
25
+ return !isItNaN(it);
26
+ }
27
+ },
28
+ Date: {
29
+ typeOf: 'Date',
30
+ validate: function(it){
31
+ return !isItNaN(it.getTime());
32
+ }
33
+ }
34
+ };
35
+ defaultType = {
36
+ array: 'Array',
37
+ tuple: 'Array'
38
+ };
39
+ function checkArray(input, type){
40
+ return all(function(it){
41
+ return checkMultiple(it, type.of);
42
+ }, input);
43
+ }
44
+ function checkTuple(input, type){
45
+ var i, i$, ref$, len$, types;
46
+ i = 0;
47
+ for (i$ = 0, len$ = (ref$ = type.of).length; i$ < len$; ++i$) {
48
+ types = ref$[i$];
49
+ if (!checkMultiple(input[i], types)) {
50
+ return false;
51
+ }
52
+ i++;
53
+ }
54
+ return input.length <= i;
55
+ }
56
+ function checkFields(input, type){
57
+ var inputKeys, numInputKeys, k, numOfKeys, key, ref$, types;
58
+ inputKeys = {};
59
+ numInputKeys = 0;
60
+ for (k in input) {
61
+ inputKeys[k] = true;
62
+ numInputKeys++;
63
+ }
64
+ numOfKeys = 0;
65
+ for (key in ref$ = type.of) {
66
+ types = ref$[key];
67
+ if (!checkMultiple(input[key], types)) {
68
+ return false;
69
+ }
70
+ if (inputKeys[key]) {
71
+ numOfKeys++;
72
+ }
73
+ }
74
+ return type.subset || numInputKeys === numOfKeys;
75
+ }
76
+ function checkStructure(input, type){
77
+ if (!(input instanceof Object)) {
78
+ return false;
79
+ }
80
+ switch (type.structure) {
81
+ case 'fields':
82
+ return checkFields(input, type);
83
+ case 'array':
84
+ return checkArray(input, type);
85
+ case 'tuple':
86
+ return checkTuple(input, type);
87
+ }
88
+ }
89
+ function check(input, typeObj){
90
+ var type, structure, setting, that;
91
+ type = typeObj.type, structure = typeObj.structure;
92
+ if (type) {
93
+ if (type === '*') {
94
+ return true;
95
+ }
96
+ setting = customTypes[type] || types[type];
97
+ if (setting) {
98
+ return setting.typeOf === toString$.call(input).slice(8, -1) && setting.validate(input);
99
+ } else {
100
+ return type === toString$.call(input).slice(8, -1) && (!structure || checkStructure(input, typeObj));
101
+ }
102
+ } else if (structure) {
103
+ if (that = defaultType[structure]) {
104
+ if (that !== toString$.call(input).slice(8, -1)) {
105
+ return false;
106
+ }
107
+ }
108
+ return checkStructure(input, typeObj);
109
+ } else {
110
+ throw new Error("No type defined. Input: " + input + ".");
111
+ }
112
+ }
113
+ function checkMultiple(input, types){
114
+ if (toString$.call(types).slice(8, -1) !== 'Array') {
115
+ throw new Error("Types must be in an array. Input: " + input + ".");
116
+ }
117
+ return any(function(it){
118
+ return check(input, it);
119
+ }, types);
120
+ }
121
+ module.exports = function(parsedType, input, options){
122
+ options == null && (options = {});
123
+ customTypes = options.customTypes || {};
124
+ return checkMultiple(input, parsedType);
125
+ };
126
+ }).call(this);
@@ -0,0 +1,16 @@
1
+ // Generated by LiveScript 1.4.0
2
+ (function(){
3
+ var VERSION, parseType, parsedTypeCheck, typeCheck;
4
+ VERSION = '0.3.2';
5
+ parseType = require('./parse-type');
6
+ parsedTypeCheck = require('./check');
7
+ typeCheck = function(type, input, options){
8
+ return parsedTypeCheck(parseType(type), input, options);
9
+ };
10
+ module.exports = {
11
+ VERSION: VERSION,
12
+ typeCheck: typeCheck,
13
+ parsedTypeCheck: parsedTypeCheck,
14
+ parseType: parseType
15
+ };
16
+ }).call(this);
@@ -0,0 +1,196 @@
1
+ // Generated by LiveScript 1.4.0
2
+ (function(){
3
+ var identifierRegex, tokenRegex;
4
+ identifierRegex = /[\$\w]+/;
5
+ function peek(tokens){
6
+ var token;
7
+ token = tokens[0];
8
+ if (token == null) {
9
+ throw new Error('Unexpected end of input.');
10
+ }
11
+ return token;
12
+ }
13
+ function consumeIdent(tokens){
14
+ var token;
15
+ token = peek(tokens);
16
+ if (!identifierRegex.test(token)) {
17
+ throw new Error("Expected text, got '" + token + "' instead.");
18
+ }
19
+ return tokens.shift();
20
+ }
21
+ function consumeOp(tokens, op){
22
+ var token;
23
+ token = peek(tokens);
24
+ if (token !== op) {
25
+ throw new Error("Expected '" + op + "', got '" + token + "' instead.");
26
+ }
27
+ return tokens.shift();
28
+ }
29
+ function maybeConsumeOp(tokens, op){
30
+ var token;
31
+ token = tokens[0];
32
+ if (token === op) {
33
+ return tokens.shift();
34
+ } else {
35
+ return null;
36
+ }
37
+ }
38
+ function consumeArray(tokens){
39
+ var types;
40
+ consumeOp(tokens, '[');
41
+ if (peek(tokens) === ']') {
42
+ throw new Error("Must specify type of Array - eg. [Type], got [] instead.");
43
+ }
44
+ types = consumeTypes(tokens);
45
+ consumeOp(tokens, ']');
46
+ return {
47
+ structure: 'array',
48
+ of: types
49
+ };
50
+ }
51
+ function consumeTuple(tokens){
52
+ var components;
53
+ components = [];
54
+ consumeOp(tokens, '(');
55
+ if (peek(tokens) === ')') {
56
+ throw new Error("Tuple must be of at least length 1 - eg. (Type), got () instead.");
57
+ }
58
+ for (;;) {
59
+ components.push(consumeTypes(tokens));
60
+ maybeConsumeOp(tokens, ',');
61
+ if (')' === peek(tokens)) {
62
+ break;
63
+ }
64
+ }
65
+ consumeOp(tokens, ')');
66
+ return {
67
+ structure: 'tuple',
68
+ of: components
69
+ };
70
+ }
71
+ function consumeFields(tokens){
72
+ var fields, subset, ref$, key, types;
73
+ fields = {};
74
+ consumeOp(tokens, '{');
75
+ subset = false;
76
+ for (;;) {
77
+ if (maybeConsumeOp(tokens, '...')) {
78
+ subset = true;
79
+ break;
80
+ }
81
+ ref$ = consumeField(tokens), key = ref$[0], types = ref$[1];
82
+ fields[key] = types;
83
+ maybeConsumeOp(tokens, ',');
84
+ if ('}' === peek(tokens)) {
85
+ break;
86
+ }
87
+ }
88
+ consumeOp(tokens, '}');
89
+ return {
90
+ structure: 'fields',
91
+ of: fields,
92
+ subset: subset
93
+ };
94
+ }
95
+ function consumeField(tokens){
96
+ var key, types;
97
+ key = consumeIdent(tokens);
98
+ consumeOp(tokens, ':');
99
+ types = consumeTypes(tokens);
100
+ return [key, types];
101
+ }
102
+ function maybeConsumeStructure(tokens){
103
+ switch (tokens[0]) {
104
+ case '[':
105
+ return consumeArray(tokens);
106
+ case '(':
107
+ return consumeTuple(tokens);
108
+ case '{':
109
+ return consumeFields(tokens);
110
+ }
111
+ }
112
+ function consumeType(tokens){
113
+ var token, wildcard, type, structure;
114
+ token = peek(tokens);
115
+ wildcard = token === '*';
116
+ if (wildcard || identifierRegex.test(token)) {
117
+ type = wildcard
118
+ ? consumeOp(tokens, '*')
119
+ : consumeIdent(tokens);
120
+ structure = maybeConsumeStructure(tokens);
121
+ if (structure) {
122
+ return structure.type = type, structure;
123
+ } else {
124
+ return {
125
+ type: type
126
+ };
127
+ }
128
+ } else {
129
+ structure = maybeConsumeStructure(tokens);
130
+ if (!structure) {
131
+ throw new Error("Unexpected character: " + token);
132
+ }
133
+ return structure;
134
+ }
135
+ }
136
+ function consumeTypes(tokens){
137
+ var lookahead, types, typesSoFar, typeObj, type;
138
+ if ('::' === peek(tokens)) {
139
+ throw new Error("No comment before comment separator '::' found.");
140
+ }
141
+ lookahead = tokens[1];
142
+ if (lookahead != null && lookahead === '::') {
143
+ tokens.shift();
144
+ tokens.shift();
145
+ }
146
+ types = [];
147
+ typesSoFar = {};
148
+ if ('Maybe' === peek(tokens)) {
149
+ tokens.shift();
150
+ types = [
151
+ {
152
+ type: 'Undefined'
153
+ }, {
154
+ type: 'Null'
155
+ }
156
+ ];
157
+ typesSoFar = {
158
+ Undefined: true,
159
+ Null: true
160
+ };
161
+ }
162
+ for (;;) {
163
+ typeObj = consumeType(tokens), type = typeObj.type;
164
+ if (!typesSoFar[type]) {
165
+ types.push(typeObj);
166
+ }
167
+ typesSoFar[type] = true;
168
+ if (!maybeConsumeOp(tokens, '|')) {
169
+ break;
170
+ }
171
+ }
172
+ return types;
173
+ }
174
+ tokenRegex = RegExp('\\.\\.\\.|::|->|' + identifierRegex.source + '|\\S', 'g');
175
+ module.exports = function(input){
176
+ var tokens, e;
177
+ if (!input.length) {
178
+ throw new Error('No type specified.');
179
+ }
180
+ tokens = input.match(tokenRegex) || [];
181
+ if (in$('->', tokens)) {
182
+ throw new Error("Function types are not supported.\ To validate that something is a function, you may use 'Function'.");
183
+ }
184
+ try {
185
+ return consumeTypes(tokens);
186
+ } catch (e$) {
187
+ e = e$;
188
+ throw new Error(e.message + " - Remaining tokens: " + JSON.stringify(tokens) + " - Initial input: '" + input + "'");
189
+ }
190
+ };
191
+ function in$(x, xs){
192
+ var i = -1, l = xs.length >>> 0;
193
+ while (++i < l) if (x === xs[i]) return true;
194
+ return false;
195
+ }
196
+ }).call(this);
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "type-check",
3
+ "version": "0.3.2",
4
+ "author": "George Zahariev <z@georgezahariev.com>",
5
+ "description": "type-check allows you to check the types of JavaScript values at runtime with a Haskell like type syntax.",
6
+ "homepage": "https://github.com/gkz/type-check",
7
+ "keywords": [
8
+ "type",
9
+ "check",
10
+ "checking",
11
+ "library"
12
+ ],
13
+ "files": [
14
+ "lib",
15
+ "README.md",
16
+ "LICENSE"
17
+ ],
18
+ "main": "./lib/",
19
+ "bugs": "https://github.com/gkz/type-check/issues",
20
+ "license": "MIT",
21
+ "engines": {
22
+ "node": ">= 0.8.0"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git://github.com/gkz/type-check.git"
27
+ },
28
+ "scripts": {
29
+ "test": "make test"
30
+ },
31
+ "dependencies": {
32
+ "prelude-ls": "~1.1.2"
33
+ },
34
+ "devDependencies": {
35
+ "livescript": "~1.4.0",
36
+ "mocha": "~2.3.4",
37
+ "istanbul": "~0.4.1",
38
+ "browserify": "~12.0.1"
39
+ }
40
+ }
@@ -0,0 +1,11 @@
1
+ # Please see the documentation for all configuration options:
2
+ # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
3
+
4
+ version: 2
5
+ updates:
6
+ - package-ecosystem: "npm"
7
+ directory: "/"
8
+ schedule:
9
+ interval: "daily"
10
+ allow:
11
+ - dependency-type: production