@zipify/wysiwyg 1.1.1 → 1.2.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 (176) hide show
  1. package/.github/actions/lint-css/action.yaml +1 -3
  2. package/.release-it.json +2 -1
  3. package/dist/cli.js +3 -3
  4. package/dist/wysiwyg.css +24 -25
  5. package/dist/wysiwyg.mjs +641 -618
  6. package/jest.config.js +3 -0
  7. package/lib/components/base/Modal.vue +21 -2
  8. package/lib/components/base/__tests__/Modal.test.js +1 -0
  9. package/lib/components/toolbar/controls/link/LinkControl.vue +22 -10
  10. package/lib/components/toolbar/controls/link/LinkControlHeader.vue +3 -3
  11. package/lib/components/toolbar/controls/link/__tests__/LinkControl.test.js +8 -8
  12. package/lib/components/toolbar/controls/link/__tests__/LinkControlHeader.test.js +1 -1
  13. package/lib/components/toolbar/controls/link/composables/useLink.js +10 -6
  14. package/lib/composables/__tests__/__snapshots__/useEditor.test.js.snap +1 -1
  15. package/lib/composables/useEditor.js +4 -3
  16. package/lib/enums/TextSettings.js +2 -0
  17. package/lib/extensions/FontStyle.js +2 -2
  18. package/lib/extensions/FontWeight.js +2 -0
  19. package/lib/extensions/Link.js +13 -15
  20. package/lib/extensions/StylePreset.js +33 -3
  21. package/lib/extensions/TextDecoration.js +6 -12
  22. package/lib/extensions/__tests__/FontFamily.test.js +7 -6
  23. package/lib/extensions/__tests__/FontWeight.test.js +19 -10
  24. package/lib/extensions/__tests__/StylePreset.test.js +52 -2
  25. package/lib/extensions/__tests__/TextDecoration.test.js +11 -40
  26. package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +2 -2
  27. package/lib/extensions/__tests__/__snapshots__/BackgroundColor.test.js.snap +1 -1
  28. package/lib/extensions/__tests__/__snapshots__/FontColor.test.js.snap +1 -1
  29. package/lib/extensions/__tests__/__snapshots__/FontFamily.test.js.snap +19 -1
  30. package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +2 -2
  31. package/lib/extensions/__tests__/__snapshots__/FontStyle.test.js.snap +17 -1
  32. package/lib/extensions/__tests__/__snapshots__/FontWeight.test.js.snap +26 -1
  33. package/lib/extensions/__tests__/__snapshots__/LineHeight.test.js.snap +2 -2
  34. package/lib/extensions/__tests__/__snapshots__/Margin.test.js.snap +2 -2
  35. package/lib/extensions/__tests__/__snapshots__/StylePreset.test.js.snap +22 -2
  36. package/lib/extensions/__tests__/__snapshots__/TextDecoration.test.js.snap +3 -46
  37. package/package.json +22 -22
  38. package/lib/components/toolbar/controls/link/LinkControlApply.vue +0 -35
  39. package/node_modules_lambda/acorn-globals/node_modules/.bin/acorn +0 -4
  40. package/node_modules_lambda/acorn-globals/node_modules/acorn/CHANGELOG.md +0 -620
  41. package/node_modules_lambda/acorn-globals/node_modules/acorn/LICENSE +0 -21
  42. package/node_modules_lambda/acorn-globals/node_modules/acorn/README.md +0 -269
  43. package/node_modules_lambda/acorn-globals/node_modules/acorn/bin/acorn +0 -4
  44. package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/acorn.d.ts +0 -209
  45. package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/acorn.js +0 -5186
  46. package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/acorn.js.map +0 -1
  47. package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/acorn.mjs +0 -5155
  48. package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/acorn.mjs.d.ts +0 -2
  49. package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/acorn.mjs.map +0 -1
  50. package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/bin.js +0 -64
  51. package/node_modules_lambda/acorn-globals/node_modules/acorn/package.json +0 -35
  52. package/node_modules_lambda/cssstyle/node_modules/cssom/LICENSE.txt +0 -20
  53. package/node_modules_lambda/cssstyle/node_modules/cssom/README.mdown +0 -67
  54. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSDocumentRule.js +0 -39
  55. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSFontFaceRule.js +0 -36
  56. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSHostRule.js +0 -37
  57. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSImportRule.js +0 -132
  58. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSKeyframeRule.js +0 -37
  59. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSKeyframesRule.js +0 -39
  60. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSMediaRule.js +0 -41
  61. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSOM.js +0 -3
  62. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSRule.js +0 -43
  63. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSStyleDeclaration.js +0 -148
  64. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSStyleRule.js +0 -190
  65. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSStyleSheet.js +0 -88
  66. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSSupportsRule.js +0 -36
  67. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSValue.js +0 -43
  68. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSValueExpression.js +0 -344
  69. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/MatcherList.js +0 -62
  70. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/MediaList.js +0 -61
  71. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/StyleSheet.js +0 -17
  72. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/clone.js +0 -82
  73. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/index.js +0 -21
  74. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/parse.js +0 -464
  75. package/node_modules_lambda/cssstyle/node_modules/cssom/package.json +0 -18
  76. package/node_modules_lambda/data-urls/node_modules/whatwg-url/LICENSE.txt +0 -21
  77. package/node_modules_lambda/data-urls/node_modules/whatwg-url/README.md +0 -106
  78. package/node_modules_lambda/data-urls/node_modules/whatwg-url/index.js +0 -27
  79. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/Function.js +0 -42
  80. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/URL-impl.js +0 -209
  81. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/URL.js +0 -442
  82. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/URLSearchParams-impl.js +0 -130
  83. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/URLSearchParams.js +0 -472
  84. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/VoidFunction.js +0 -26
  85. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/encoding.js +0 -16
  86. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/infra.js +0 -26
  87. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/percent-encoding.js +0 -142
  88. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/url-state-machine.js +0 -1244
  89. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/urlencoded.js +0 -106
  90. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/utils.js +0 -190
  91. package/node_modules_lambda/data-urls/node_modules/whatwg-url/package.json +0 -58
  92. package/node_modules_lambda/data-urls/node_modules/whatwg-url/webidl2js-wrapper.js +0 -7
  93. package/node_modules_lambda/escodegen/node_modules/estraverse/.jshintrc +0 -16
  94. package/node_modules_lambda/escodegen/node_modules/estraverse/LICENSE.BSD +0 -19
  95. package/node_modules_lambda/escodegen/node_modules/estraverse/README.md +0 -153
  96. package/node_modules_lambda/escodegen/node_modules/estraverse/estraverse.js +0 -805
  97. package/node_modules_lambda/escodegen/node_modules/estraverse/gulpfile.js +0 -70
  98. package/node_modules_lambda/escodegen/node_modules/estraverse/package.json +0 -40
  99. package/node_modules_lambda/escodegen/node_modules/levn/LICENSE +0 -22
  100. package/node_modules_lambda/escodegen/node_modules/levn/README.md +0 -196
  101. package/node_modules_lambda/escodegen/node_modules/levn/lib/cast.js +0 -298
  102. package/node_modules_lambda/escodegen/node_modules/levn/lib/coerce.js +0 -285
  103. package/node_modules_lambda/escodegen/node_modules/levn/lib/index.js +0 -22
  104. package/node_modules_lambda/escodegen/node_modules/levn/lib/parse-string.js +0 -113
  105. package/node_modules_lambda/escodegen/node_modules/levn/lib/parse.js +0 -102
  106. package/node_modules_lambda/escodegen/node_modules/levn/package.json +0 -47
  107. package/node_modules_lambda/escodegen/node_modules/optionator/CHANGELOG.md +0 -56
  108. package/node_modules_lambda/escodegen/node_modules/optionator/LICENSE +0 -22
  109. package/node_modules_lambda/escodegen/node_modules/optionator/README.md +0 -238
  110. package/node_modules_lambda/escodegen/node_modules/optionator/lib/help.js +0 -260
  111. package/node_modules_lambda/escodegen/node_modules/optionator/lib/index.js +0 -465
  112. package/node_modules_lambda/escodegen/node_modules/optionator/lib/util.js +0 -54
  113. package/node_modules_lambda/escodegen/node_modules/optionator/package.json +0 -44
  114. package/node_modules_lambda/escodegen/node_modules/prelude-ls/CHANGELOG.md +0 -99
  115. package/node_modules_lambda/escodegen/node_modules/prelude-ls/LICENSE +0 -22
  116. package/node_modules_lambda/escodegen/node_modules/prelude-ls/README.md +0 -15
  117. package/node_modules_lambda/escodegen/node_modules/prelude-ls/lib/Func.js +0 -65
  118. package/node_modules_lambda/escodegen/node_modules/prelude-ls/lib/List.js +0 -686
  119. package/node_modules_lambda/escodegen/node_modules/prelude-ls/lib/Num.js +0 -130
  120. package/node_modules_lambda/escodegen/node_modules/prelude-ls/lib/Obj.js +0 -154
  121. package/node_modules_lambda/escodegen/node_modules/prelude-ls/lib/Str.js +0 -92
  122. package/node_modules_lambda/escodegen/node_modules/prelude-ls/lib/index.js +0 -178
  123. package/node_modules_lambda/escodegen/node_modules/prelude-ls/package.json +0 -52
  124. package/node_modules_lambda/escodegen/node_modules/source-map/CHANGELOG.md +0 -301
  125. package/node_modules_lambda/escodegen/node_modules/source-map/LICENSE +0 -28
  126. package/node_modules_lambda/escodegen/node_modules/source-map/README.md +0 -742
  127. package/node_modules_lambda/escodegen/node_modules/source-map/dist/source-map.debug.js +0 -3234
  128. package/node_modules_lambda/escodegen/node_modules/source-map/dist/source-map.js +0 -3233
  129. package/node_modules_lambda/escodegen/node_modules/source-map/dist/source-map.min.js +0 -2
  130. package/node_modules_lambda/escodegen/node_modules/source-map/dist/source-map.min.js.map +0 -1
  131. package/node_modules_lambda/escodegen/node_modules/source-map/lib/array-set.js +0 -121
  132. package/node_modules_lambda/escodegen/node_modules/source-map/lib/base64-vlq.js +0 -140
  133. package/node_modules_lambda/escodegen/node_modules/source-map/lib/base64.js +0 -67
  134. package/node_modules_lambda/escodegen/node_modules/source-map/lib/binary-search.js +0 -111
  135. package/node_modules_lambda/escodegen/node_modules/source-map/lib/mapping-list.js +0 -79
  136. package/node_modules_lambda/escodegen/node_modules/source-map/lib/quick-sort.js +0 -114
  137. package/node_modules_lambda/escodegen/node_modules/source-map/lib/source-map-consumer.js +0 -1145
  138. package/node_modules_lambda/escodegen/node_modules/source-map/lib/source-map-generator.js +0 -425
  139. package/node_modules_lambda/escodegen/node_modules/source-map/lib/source-node.js +0 -413
  140. package/node_modules_lambda/escodegen/node_modules/source-map/lib/util.js +0 -488
  141. package/node_modules_lambda/escodegen/node_modules/source-map/package.json +0 -73
  142. package/node_modules_lambda/escodegen/node_modules/source-map/source-map.d.ts +0 -98
  143. package/node_modules_lambda/escodegen/node_modules/source-map/source-map.js +0 -8
  144. package/node_modules_lambda/escodegen/node_modules/type-check/LICENSE +0 -22
  145. package/node_modules_lambda/escodegen/node_modules/type-check/README.md +0 -210
  146. package/node_modules_lambda/escodegen/node_modules/type-check/lib/check.js +0 -126
  147. package/node_modules_lambda/escodegen/node_modules/type-check/lib/index.js +0 -16
  148. package/node_modules_lambda/escodegen/node_modules/type-check/lib/parse-type.js +0 -196
  149. package/node_modules_lambda/escodegen/node_modules/type-check/package.json +0 -40
  150. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/.github/dependabot.yml +0 -11
  151. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/Changelog.md +0 -212
  152. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/LICENSE +0 -21
  153. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/README.md +0 -130
  154. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/dbcs-codec.js +0 -597
  155. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/dbcs-data.js +0 -188
  156. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/index.js +0 -23
  157. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/internal.js +0 -198
  158. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/sbcs-codec.js +0 -72
  159. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/sbcs-data-generated.js +0 -451
  160. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/sbcs-data.js +0 -179
  161. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/big5-added.json +0 -122
  162. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/cp936.json +0 -264
  163. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/cp949.json +0 -273
  164. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/cp950.json +0 -177
  165. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/eucjp.json +0 -182
  166. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json +0 -1
  167. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/gbk-added.json +0 -56
  168. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/shiftjis.json +0 -125
  169. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/utf16.js +0 -197
  170. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/utf32.js +0 -319
  171. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/utf7.js +0 -290
  172. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/lib/bom-handling.js +0 -52
  173. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/lib/index.d.ts +0 -41
  174. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/lib/index.js +0 -180
  175. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/lib/streams.js +0 -109
  176. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/package.json +0 -44
@@ -1,210 +0,0 @@
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.
@@ -1,126 +0,0 @@
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);
@@ -1,16 +0,0 @@
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);
@@ -1,196 +0,0 @@
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);
@@ -1,40 +0,0 @@
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
- }
@@ -1,11 +0,0 @@
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