protobufjs 6.11.2 → 6.11.3

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 (202) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/bin/pbjs +0 -0
  3. package/bin/pbts +0 -0
  4. package/package-lock.json +7870 -0
  5. package/package.json +3 -3
  6. package/scripts/changelog.js +150 -0
  7. package/src/util.js +3 -0
  8. package/cli/node_modules/.package-lock.json +0 -256
  9. package/cli/node_modules/acorn/CHANGELOG.md +0 -620
  10. package/cli/node_modules/acorn/LICENSE +0 -21
  11. package/cli/node_modules/acorn/README.md +0 -269
  12. package/cli/node_modules/acorn/bin/acorn +0 -4
  13. package/cli/node_modules/acorn/dist/acorn.d.ts +0 -209
  14. package/cli/node_modules/acorn/dist/acorn.js +0 -5186
  15. package/cli/node_modules/acorn/dist/acorn.js.map +0 -1
  16. package/cli/node_modules/acorn/dist/acorn.mjs +0 -5155
  17. package/cli/node_modules/acorn/dist/acorn.mjs.d.ts +0 -2
  18. package/cli/node_modules/acorn/dist/acorn.mjs.map +0 -1
  19. package/cli/node_modules/acorn/dist/bin.js +0 -64
  20. package/cli/node_modules/acorn/package.json +0 -35
  21. package/cli/node_modules/acorn-jsx/LICENSE +0 -19
  22. package/cli/node_modules/acorn-jsx/README.md +0 -40
  23. package/cli/node_modules/acorn-jsx/index.js +0 -488
  24. package/cli/node_modules/acorn-jsx/package.json +0 -27
  25. package/cli/node_modules/acorn-jsx/xhtml.js +0 -255
  26. package/cli/node_modules/balanced-match/.npmignore +0 -5
  27. package/cli/node_modules/balanced-match/LICENSE.md +0 -21
  28. package/cli/node_modules/balanced-match/README.md +0 -91
  29. package/cli/node_modules/balanced-match/index.js +0 -59
  30. package/cli/node_modules/balanced-match/package.json +0 -49
  31. package/cli/node_modules/brace-expansion/LICENSE +0 -21
  32. package/cli/node_modules/brace-expansion/README.md +0 -129
  33. package/cli/node_modules/brace-expansion/index.js +0 -201
  34. package/cli/node_modules/brace-expansion/package.json +0 -47
  35. package/cli/node_modules/concat-map/.travis.yml +0 -4
  36. package/cli/node_modules/concat-map/LICENSE +0 -18
  37. package/cli/node_modules/concat-map/README.markdown +0 -62
  38. package/cli/node_modules/concat-map/example/map.js +0 -6
  39. package/cli/node_modules/concat-map/index.js +0 -13
  40. package/cli/node_modules/concat-map/package.json +0 -43
  41. package/cli/node_modules/concat-map/test/map.js +0 -39
  42. package/cli/node_modules/deep-is/.npmignore +0 -1
  43. package/cli/node_modules/deep-is/.travis.yml +0 -6
  44. package/cli/node_modules/deep-is/LICENSE +0 -22
  45. package/cli/node_modules/deep-is/README.markdown +0 -70
  46. package/cli/node_modules/deep-is/example/cmp.js +0 -11
  47. package/cli/node_modules/deep-is/index.js +0 -102
  48. package/cli/node_modules/deep-is/package.json +0 -61
  49. package/cli/node_modules/deep-is/test/NaN.js +0 -16
  50. package/cli/node_modules/deep-is/test/cmp.js +0 -23
  51. package/cli/node_modules/deep-is/test/neg-vs-pos-0.js +0 -15
  52. package/cli/node_modules/escodegen/LICENSE.BSD +0 -21
  53. package/cli/node_modules/escodegen/README.md +0 -84
  54. package/cli/node_modules/escodegen/bin/escodegen.js +0 -77
  55. package/cli/node_modules/escodegen/bin/esgenerate.js +0 -64
  56. package/cli/node_modules/escodegen/escodegen.js +0 -2647
  57. package/cli/node_modules/escodegen/package.json +0 -62
  58. package/cli/node_modules/eslint-visitor-keys/CHANGELOG.md +0 -25
  59. package/cli/node_modules/eslint-visitor-keys/LICENSE +0 -201
  60. package/cli/node_modules/eslint-visitor-keys/README.md +0 -98
  61. package/cli/node_modules/eslint-visitor-keys/lib/index.js +0 -81
  62. package/cli/node_modules/eslint-visitor-keys/lib/visitor-keys.json +0 -284
  63. package/cli/node_modules/eslint-visitor-keys/package.json +0 -40
  64. package/cli/node_modules/espree/CHANGELOG.md +0 -509
  65. package/cli/node_modules/espree/LICENSE +0 -25
  66. package/cli/node_modules/espree/README.md +0 -233
  67. package/cli/node_modules/espree/espree.js +0 -177
  68. package/cli/node_modules/espree/lib/ast-node-types.js +0 -96
  69. package/cli/node_modules/espree/lib/espree.js +0 -286
  70. package/cli/node_modules/espree/lib/features.js +0 -29
  71. package/cli/node_modules/espree/lib/options.js +0 -106
  72. package/cli/node_modules/espree/lib/token-translator.js +0 -263
  73. package/cli/node_modules/espree/lib/visitor-keys.js +0 -123
  74. package/cli/node_modules/espree/package.json +0 -64
  75. package/cli/node_modules/esprima/ChangeLog +0 -235
  76. package/cli/node_modules/esprima/LICENSE.BSD +0 -21
  77. package/cli/node_modules/esprima/README.md +0 -46
  78. package/cli/node_modules/esprima/bin/esparse.js +0 -139
  79. package/cli/node_modules/esprima/bin/esvalidate.js +0 -236
  80. package/cli/node_modules/esprima/dist/esprima.js +0 -6709
  81. package/cli/node_modules/esprima/package.json +0 -112
  82. package/cli/node_modules/estraverse/.jshintrc +0 -16
  83. package/cli/node_modules/estraverse/LICENSE.BSD +0 -19
  84. package/cli/node_modules/estraverse/README.md +0 -153
  85. package/cli/node_modules/estraverse/estraverse.js +0 -801
  86. package/cli/node_modules/estraverse/gulpfile.js +0 -70
  87. package/cli/node_modules/estraverse/package.json +0 -40
  88. package/cli/node_modules/esutils/LICENSE.BSD +0 -19
  89. package/cli/node_modules/esutils/README.md +0 -174
  90. package/cli/node_modules/esutils/lib/ast.js +0 -144
  91. package/cli/node_modules/esutils/lib/code.js +0 -135
  92. package/cli/node_modules/esutils/lib/keyword.js +0 -165
  93. package/cli/node_modules/esutils/lib/utils.js +0 -33
  94. package/cli/node_modules/esutils/package.json +0 -44
  95. package/cli/node_modules/fast-levenshtein/LICENSE.md +0 -25
  96. package/cli/node_modules/fast-levenshtein/README.md +0 -104
  97. package/cli/node_modules/fast-levenshtein/levenshtein.js +0 -136
  98. package/cli/node_modules/fast-levenshtein/package.json +0 -39
  99. package/cli/node_modules/fs.realpath/LICENSE +0 -43
  100. package/cli/node_modules/fs.realpath/README.md +0 -33
  101. package/cli/node_modules/fs.realpath/index.js +0 -66
  102. package/cli/node_modules/fs.realpath/old.js +0 -303
  103. package/cli/node_modules/fs.realpath/package.json +0 -26
  104. package/cli/node_modules/glob/LICENSE +0 -21
  105. package/cli/node_modules/glob/README.md +0 -375
  106. package/cli/node_modules/glob/changelog.md +0 -67
  107. package/cli/node_modules/glob/common.js +0 -240
  108. package/cli/node_modules/glob/glob.js +0 -790
  109. package/cli/node_modules/glob/package.json +0 -46
  110. package/cli/node_modules/glob/sync.js +0 -486
  111. package/cli/node_modules/inflight/LICENSE +0 -15
  112. package/cli/node_modules/inflight/README.md +0 -37
  113. package/cli/node_modules/inflight/inflight.js +0 -54
  114. package/cli/node_modules/inflight/package.json +0 -29
  115. package/cli/node_modules/inherits/LICENSE +0 -16
  116. package/cli/node_modules/inherits/README.md +0 -42
  117. package/cli/node_modules/inherits/inherits.js +0 -9
  118. package/cli/node_modules/inherits/inherits_browser.js +0 -27
  119. package/cli/node_modules/inherits/package.json +0 -29
  120. package/cli/node_modules/levn/LICENSE +0 -22
  121. package/cli/node_modules/levn/README.md +0 -196
  122. package/cli/node_modules/levn/lib/cast.js +0 -298
  123. package/cli/node_modules/levn/lib/coerce.js +0 -285
  124. package/cli/node_modules/levn/lib/index.js +0 -22
  125. package/cli/node_modules/levn/lib/parse-string.js +0 -113
  126. package/cli/node_modules/levn/lib/parse.js +0 -102
  127. package/cli/node_modules/levn/package.json +0 -47
  128. package/cli/node_modules/minimatch/LICENSE +0 -15
  129. package/cli/node_modules/minimatch/README.md +0 -209
  130. package/cli/node_modules/minimatch/minimatch.js +0 -923
  131. package/cli/node_modules/minimatch/package.json +0 -30
  132. package/cli/node_modules/once/LICENSE +0 -15
  133. package/cli/node_modules/once/README.md +0 -79
  134. package/cli/node_modules/once/once.js +0 -42
  135. package/cli/node_modules/once/package.json +0 -33
  136. package/cli/node_modules/optionator/CHANGELOG.md +0 -56
  137. package/cli/node_modules/optionator/LICENSE +0 -22
  138. package/cli/node_modules/optionator/README.md +0 -238
  139. package/cli/node_modules/optionator/lib/help.js +0 -260
  140. package/cli/node_modules/optionator/lib/index.js +0 -465
  141. package/cli/node_modules/optionator/lib/util.js +0 -54
  142. package/cli/node_modules/optionator/package.json +0 -44
  143. package/cli/node_modules/path-is-absolute/index.js +0 -20
  144. package/cli/node_modules/path-is-absolute/license +0 -21
  145. package/cli/node_modules/path-is-absolute/package.json +0 -43
  146. package/cli/node_modules/path-is-absolute/readme.md +0 -59
  147. package/cli/node_modules/prelude-ls/CHANGELOG.md +0 -99
  148. package/cli/node_modules/prelude-ls/LICENSE +0 -22
  149. package/cli/node_modules/prelude-ls/README.md +0 -15
  150. package/cli/node_modules/prelude-ls/lib/Func.js +0 -65
  151. package/cli/node_modules/prelude-ls/lib/List.js +0 -686
  152. package/cli/node_modules/prelude-ls/lib/Num.js +0 -130
  153. package/cli/node_modules/prelude-ls/lib/Obj.js +0 -154
  154. package/cli/node_modules/prelude-ls/lib/Str.js +0 -92
  155. package/cli/node_modules/prelude-ls/lib/index.js +0 -178
  156. package/cli/node_modules/prelude-ls/package.json +0 -52
  157. package/cli/node_modules/rimraf/CHANGELOG.md +0 -65
  158. package/cli/node_modules/rimraf/LICENSE +0 -15
  159. package/cli/node_modules/rimraf/README.md +0 -101
  160. package/cli/node_modules/rimraf/bin.js +0 -68
  161. package/cli/node_modules/rimraf/package.json +0 -32
  162. package/cli/node_modules/rimraf/rimraf.js +0 -360
  163. package/cli/node_modules/source-map/CHANGELOG.md +0 -301
  164. package/cli/node_modules/source-map/LICENSE +0 -28
  165. package/cli/node_modules/source-map/README.md +0 -742
  166. package/cli/node_modules/source-map/dist/source-map.debug.js +0 -3234
  167. package/cli/node_modules/source-map/dist/source-map.js +0 -3233
  168. package/cli/node_modules/source-map/dist/source-map.min.js +0 -2
  169. package/cli/node_modules/source-map/dist/source-map.min.js.map +0 -1
  170. package/cli/node_modules/source-map/lib/array-set.js +0 -121
  171. package/cli/node_modules/source-map/lib/base64-vlq.js +0 -140
  172. package/cli/node_modules/source-map/lib/base64.js +0 -67
  173. package/cli/node_modules/source-map/lib/binary-search.js +0 -111
  174. package/cli/node_modules/source-map/lib/mapping-list.js +0 -79
  175. package/cli/node_modules/source-map/lib/quick-sort.js +0 -114
  176. package/cli/node_modules/source-map/lib/source-map-consumer.js +0 -1145
  177. package/cli/node_modules/source-map/lib/source-map-generator.js +0 -425
  178. package/cli/node_modules/source-map/lib/source-node.js +0 -413
  179. package/cli/node_modules/source-map/lib/util.js +0 -488
  180. package/cli/node_modules/source-map/package.json +0 -73
  181. package/cli/node_modules/source-map/source-map.d.ts +0 -98
  182. package/cli/node_modules/source-map/source-map.js +0 -8
  183. package/cli/node_modules/tmp/CHANGELOG.md +0 -288
  184. package/cli/node_modules/tmp/LICENSE +0 -21
  185. package/cli/node_modules/tmp/README.md +0 -365
  186. package/cli/node_modules/tmp/lib/tmp.js +0 -780
  187. package/cli/node_modules/tmp/package.json +0 -58
  188. package/cli/node_modules/type-check/LICENSE +0 -22
  189. package/cli/node_modules/type-check/README.md +0 -210
  190. package/cli/node_modules/type-check/lib/check.js +0 -126
  191. package/cli/node_modules/type-check/lib/index.js +0 -16
  192. package/cli/node_modules/type-check/lib/parse-type.js +0 -196
  193. package/cli/node_modules/type-check/package.json +0 -40
  194. package/cli/node_modules/word-wrap/LICENSE +0 -21
  195. package/cli/node_modules/word-wrap/README.md +0 -182
  196. package/cli/node_modules/word-wrap/index.d.ts +0 -50
  197. package/cli/node_modules/word-wrap/index.js +0 -46
  198. package/cli/node_modules/word-wrap/package.json +0 -77
  199. package/cli/node_modules/wrappy/LICENSE +0 -15
  200. package/cli/node_modules/wrappy/README.md +0 -36
  201. package/cli/node_modules/wrappy/package.json +0 -29
  202. package/cli/node_modules/wrappy/wrappy.js +0 -33
@@ -1,42 +0,0 @@
1
- Browser-friendly inheritance fully compatible with standard node.js
2
- [inherits](http://nodejs.org/api/util.html#util_util_inherits_constructor_superconstructor).
3
-
4
- This package exports standard `inherits` from node.js `util` module in
5
- node environment, but also provides alternative browser-friendly
6
- implementation through [browser
7
- field](https://gist.github.com/shtylman/4339901). Alternative
8
- implementation is a literal copy of standard one located in standalone
9
- module to avoid requiring of `util`. It also has a shim for old
10
- browsers with no `Object.create` support.
11
-
12
- While keeping you sure you are using standard `inherits`
13
- implementation in node.js environment, it allows bundlers such as
14
- [browserify](https://github.com/substack/node-browserify) to not
15
- include full `util` package to your client code if all you need is
16
- just `inherits` function. It worth, because browser shim for `util`
17
- package is large and `inherits` is often the single function you need
18
- from it.
19
-
20
- It's recommended to use this package instead of
21
- `require('util').inherits` for any code that has chances to be used
22
- not only in node.js but in browser too.
23
-
24
- ## usage
25
-
26
- ```js
27
- var inherits = require('inherits');
28
- // then use exactly as the standard one
29
- ```
30
-
31
- ## note on version ~1.0
32
-
33
- Version ~1.0 had completely different motivation and is not compatible
34
- neither with 2.0 nor with standard node.js `inherits`.
35
-
36
- If you are using version ~1.0 and planning to switch to ~2.0, be
37
- careful:
38
-
39
- * new version uses `super_` instead of `super` for referencing
40
- superclass
41
- * new version overwrites current prototype while old one preserves any
42
- existing fields on it
@@ -1,9 +0,0 @@
1
- try {
2
- var util = require('util');
3
- /* istanbul ignore next */
4
- if (typeof util.inherits !== 'function') throw '';
5
- module.exports = util.inherits;
6
- } catch (e) {
7
- /* istanbul ignore next */
8
- module.exports = require('./inherits_browser.js');
9
- }
@@ -1,27 +0,0 @@
1
- if (typeof Object.create === 'function') {
2
- // implementation from standard node.js 'util' module
3
- module.exports = function inherits(ctor, superCtor) {
4
- if (superCtor) {
5
- ctor.super_ = superCtor
6
- ctor.prototype = Object.create(superCtor.prototype, {
7
- constructor: {
8
- value: ctor,
9
- enumerable: false,
10
- writable: true,
11
- configurable: true
12
- }
13
- })
14
- }
15
- };
16
- } else {
17
- // old school shim for old browsers
18
- module.exports = function inherits(ctor, superCtor) {
19
- if (superCtor) {
20
- ctor.super_ = superCtor
21
- var TempCtor = function () {}
22
- TempCtor.prototype = superCtor.prototype
23
- ctor.prototype = new TempCtor()
24
- ctor.prototype.constructor = ctor
25
- }
26
- }
27
- }
@@ -1,29 +0,0 @@
1
- {
2
- "name": "inherits",
3
- "description": "Browser-friendly inheritance fully compatible with standard node.js inherits()",
4
- "version": "2.0.4",
5
- "keywords": [
6
- "inheritance",
7
- "class",
8
- "klass",
9
- "oop",
10
- "object-oriented",
11
- "inherits",
12
- "browser",
13
- "browserify"
14
- ],
15
- "main": "./inherits.js",
16
- "browser": "./inherits_browser.js",
17
- "repository": "git://github.com/isaacs/inherits",
18
- "license": "ISC",
19
- "scripts": {
20
- "test": "tap"
21
- },
22
- "devDependencies": {
23
- "tap": "^14.2.4"
24
- },
25
- "files": [
26
- "inherits.js",
27
- "inherits_browser.js"
28
- ]
29
- }
@@ -1,22 +0,0 @@
1
- Copyright (c) George Zahariev
2
-
3
- Permission is hereby granted, free of charge, to any person
4
- obtaining a copy of this software and associated documentation
5
- files (the "Software"), to deal in the Software without
6
- restriction, including without limitation the rights to use,
7
- copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the
9
- Software is furnished to do so, subject to the following
10
- conditions:
11
-
12
- The above copyright notice and this permission notice shall be
13
- included in all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
- OTHER DEALINGS IN THE SOFTWARE.
@@ -1,196 +0,0 @@
1
- # levn [![Build Status](https://travis-ci.org/gkz/levn.png)](https://travis-ci.org/gkz/levn) <a name="levn" />
2
- __Light ECMAScript (JavaScript) Value Notation__
3
- Levn is a library which allows you to parse a string into a JavaScript value based on an expected type. It is meant for short amounts of human entered data (eg. config files, command line arguments).
4
-
5
- Levn aims to concisely describe JavaScript values in text, and allow for the extraction and validation of those values. Levn uses [type-check](https://github.com/gkz/type-check) for its type format, and to validate the results. MIT license. Version 0.3.0.
6
-
7
- __How is this different than JSON?__ levn is meant to be written by humans only, is (due to the previous point) much more concise, can be validated against supplied types, has regex and date literals, and can easily be extended with custom types. On the other hand, it is probably slower and thus less efficient at transporting large amounts of data, which is fine since this is not its purpose.
8
-
9
- npm install levn
10
-
11
- For updates on levn, [follow me on twitter](https://twitter.com/gkzahariev).
12
-
13
-
14
- ## Quick Examples
15
-
16
- ```js
17
- var parse = require('levn').parse;
18
- parse('Number', '2'); // 2
19
- parse('String', '2'); // '2'
20
- parse('String', 'levn'); // 'levn'
21
- parse('String', 'a b'); // 'a b'
22
- parse('Boolean', 'true'); // true
23
-
24
- parse('Date', '#2011-11-11#'); // (Date object)
25
- parse('Date', '2011-11-11'); // (Date object)
26
- parse('RegExp', '/[a-z]/gi'); // /[a-z]/gi
27
- parse('RegExp', 're'); // /re/
28
- parse('Int', '2'); // 2
29
-
30
- parse('Number | String', 'str'); // 'str'
31
- parse('Number | String', '2'); // 2
32
-
33
- parse('[Number]', '[1,2,3]'); // [1,2,3]
34
- parse('(String, Boolean)', '(hi, false)'); // ['hi', false]
35
- parse('{a: String, b: Number}', '{a: str, b: 2}'); // {a: 'str', b: 2}
36
-
37
- // at the top level, you can ommit surrounding delimiters
38
- parse('[Number]', '1,2,3'); // [1,2,3]
39
- parse('(String, Boolean)', 'hi, false'); // ['hi', false]
40
- parse('{a: String, b: Number}', 'a: str, b: 2'); // {a: 'str', b: 2}
41
-
42
- // wildcard - auto choose type
43
- parse('*', '[hi,(null,[42]),{k: true}]'); // ['hi', [null, [42]], {k: true}]
44
- ```
45
- ## Usage
46
-
47
- `require('levn');` returns an object that exposes three properties. `VERSION` is the current version of the library as a string. `parse` and `parsedTypeParse` are functions.
48
-
49
- ```js
50
- // parse(type, input, options);
51
- parse('[Number]', '1,2,3'); // [1, 2, 3]
52
-
53
- // parsedTypeParse(parsedType, input, options);
54
- var parsedType = require('type-check').parseType('[Number]');
55
- parsedTypeParse(parsedType, '1,2,3'); // [1, 2, 3]
56
- ```
57
-
58
- ### parse(type, input, options)
59
-
60
- `parse` casts the string `input` into a JavaScript value according to the specified `type` in the [type format](https://github.com/gkz/type-check#type-format) (and taking account the optional `options`) and returns the resulting JavaScript value.
61
-
62
- ##### arguments
63
- * type - `String` - the type written in the [type format](https://github.com/gkz/type-check#type-format) which to check against
64
- * input - `String` - the value written in the [levn format](#levn-format)
65
- * options - `Maybe Object` - an optional parameter specifying additional [options](#options)
66
-
67
- ##### returns
68
- `*` - the resulting JavaScript value
69
-
70
- ##### example
71
- ```js
72
- parse('[Number]', '1,2,3'); // [1, 2, 3]
73
- ```
74
-
75
- ### parsedTypeParse(parsedType, input, options)
76
-
77
- `parsedTypeParse` casts the string `input` into a JavaScript value according to the specified `type` which has already been parsed (and taking account the optional `options`) and returns the resulting JavaScript value. You can parse a type using the [type-check](https://github.com/gkz/type-check) library's `parseType` function.
78
-
79
- ##### arguments
80
- * type - `Object` - the type in the parsed type format which to check against
81
- * input - `String` - the value written in the [levn format](#levn-format)
82
- * options - `Maybe Object` - an optional parameter specifying additional [options](#options)
83
-
84
- ##### returns
85
- `*` - the resulting JavaScript value
86
-
87
- ##### example
88
- ```js
89
- var parsedType = require('type-check').parseType('[Number]');
90
- parsedTypeParse(parsedType, '1,2,3'); // [1, 2, 3]
91
- ```
92
-
93
- ## Levn Format
94
-
95
- Levn can use the type information you provide to choose the appropriate value to produce from the input. For the same input, it will choose a different output value depending on the type provided. For example, `parse('Number', '2')` will produce the number `2`, but `parse('String', '2')` will produce the string `"2"`.
96
-
97
- If you do not provide type information, and simply use `*`, levn will parse the input according the unambiguous "explicit" mode, which we will now detail - you can also set the `explicit` option to true manually in the [options](#options).
98
-
99
- * `"string"`, `'string'` are parsed as a String, eg. `"a msg"` is `"a msg"`
100
- * `#date#` is parsed as a Date, eg. `#2011-11-11#` is `new Date('2011-11-11')`
101
- * `/regexp/flags` is parsed as a RegExp, eg. `/re/gi` is `/re/gi`
102
- * `undefined`, `null`, `NaN`, `true`, and `false` are all their JavaScript equivalents
103
- * `[element1, element2, etc]` is an Array, and the casting procedure is recursively applied to each element. Eg. `[1,2,3]` is `[1,2,3]`.
104
- * `(element1, element2, etc)` is an tuple, and the casting procedure is recursively applied to each element. Eg. `(1, a)` is `(1, a)` (is `[1, 'a']`).
105
- * `{key1: val1, key2: val2, ...}` is an Object, and the casting procedure is recursively applied to each property. Eg. `{a: 1, b: 2}` is `{a: 1, b: 2}`.
106
- * Any test which does not fall under the above, and which does not contain special characters (`[``]``(``)``{``}``:``,`) is a string, eg. `$12- blah` is `"$12- blah"`.
107
-
108
- If you do provide type information, you can make your input more concise as the program already has some information about what it expects. Please see the [type format](https://github.com/gkz/type-check#type-format) section of [type-check](https://github.com/gkz/type-check) for more information about how to specify types. There are some rules about what levn can do with the information:
109
-
110
- * If a String is expected, and only a String, all characters of the input (including any special ones) will become part of the output. Eg. `[({})]` is `"[({})]"`, and `"hi"` is `'"hi"'`.
111
- * If a Date is expected, the surrounding `#` can be omitted from date literals. Eg. `2011-11-11` is `new Date('2011-11-11')`.
112
- * If a RegExp is expected, no flags need to be specified, and the regex is not using any of the special characters,the opening and closing `/` can be omitted - this will have the affect of setting the source of the regex to the input. Eg. `regex` is `/regex/`.
113
- * If an Array is expected, and it is the root node (at the top level), the opening `[` and closing `]` can be omitted. Eg. `1,2,3` is `[1,2,3]`.
114
- * If a tuple is expected, and it is the root node (at the top level), the opening `(` and closing `)` can be omitted. Eg. `1, a` is `(1, a)` (is `[1, 'a']`).
115
- * If an Object is expected, and it is the root node (at the top level), the opening `{` and closing `}` can be omitted. Eg `a: 1, b: 2` is `{a: 1, b: 2}`.
116
-
117
- If you list multiple types (eg. `Number | String`), it will first attempt to cast to the first type and then validate - if the validation fails it will move on to the next type and so forth, left to right. You must be careful as some types will succeed with any input, such as String. Thus put String at the end of your list. In non-explicit mode, Date and RegExp will succeed with a large variety of input - also be careful with these and list them near the end if not last in your list.
118
-
119
- Whitespace between special characters and elements is inconsequential.
120
-
121
- ## Options
122
-
123
- Options is an object. It is an optional parameter to the `parse` and `parsedTypeParse` functions.
124
-
125
- ### Explicit
126
-
127
- A `Boolean`. By default it is `false`.
128
-
129
- __Example:__
130
-
131
- ```js
132
- parse('RegExp', 're', {explicit: false}); // /re/
133
- parse('RegExp', 're', {explicit: true}); // Error: ... does not type check...
134
- parse('RegExp | String', 're', {explicit: true}); // 're'
135
- ```
136
-
137
- `explicit` sets whether to be in explicit mode or not. Using `*` automatically activates explicit mode. For more information, read the [levn format](#levn-format) section.
138
-
139
- ### customTypes
140
-
141
- An `Object`. Empty `{}` by default.
142
-
143
- __Example:__
144
-
145
- ```js
146
- var options = {
147
- customTypes: {
148
- Even: {
149
- typeOf: 'Number',
150
- validate: function (x) {
151
- return x % 2 === 0;
152
- },
153
- cast: function (x) {
154
- return {type: 'Just', value: parseInt(x)};
155
- }
156
- }
157
- }
158
- }
159
- parse('Even', '2', options); // 2
160
- parse('Even', '3', options); // Error: Value: "3" does not type check...
161
- ```
162
-
163
- __Another Example:__
164
- ```js
165
- function Person(name, age){
166
- this.name = name;
167
- this.age = age;
168
- }
169
- var options = {
170
- customTypes: {
171
- Person: {
172
- typeOf: 'Object',
173
- validate: function (x) {
174
- x instanceof Person;
175
- },
176
- cast: function (value, options, typesCast) {
177
- var name, age;
178
- if ({}.toString.call(value).slice(8, -1) !== 'Object') {
179
- return {type: 'Nothing'};
180
- }
181
- name = typesCast(value.name, [{type: 'String'}], options);
182
- age = typesCast(value.age, [{type: 'Numger'}], options);
183
- return {type: 'Just', value: new Person(name, age)};
184
- }
185
- }
186
- }
187
- parse('Person', '{name: Laura, age: 25}', options); // Person {name: 'Laura', age: 25}
188
- ```
189
-
190
- `customTypes` is an object whose keys are the name of the types, and whose values are an object with three properties, `typeOf`, `validate`, and `cast`. For more information about `typeOf` and `validate`, please see the [custom types](https://github.com/gkz/type-check#custom-types) section of type-check.
191
-
192
- `cast` is a function which receives three arguments, the value under question, options, and the typesCast function. In `cast`, attempt to cast the value into the specified type. If you are successful, return an object in the format `{type: 'Just', value: CAST-VALUE}`, if you know it won't work, return `{type: 'Nothing'}`. You can use the `typesCast` function to cast any child values. Remember to pass `options` to it. In your function you can also check for `options.explicit` and act accordingly.
193
-
194
- ## Technical About
195
-
196
- `levn` is written in [LiveScript](http://livescript.net/) - a language that compiles to JavaScript. It uses [type-check](https://github.com/gkz/type-check) to both parse types and validate values. It also uses the [prelude.ls](http://preludels.com/) library.
@@ -1,298 +0,0 @@
1
- // Generated by LiveScript 1.4.0
2
- (function(){
3
- var parsedTypeCheck, types, toString$ = {}.toString;
4
- parsedTypeCheck = require('type-check').parsedTypeCheck;
5
- types = {
6
- '*': function(value, options){
7
- switch (toString$.call(value).slice(8, -1)) {
8
- case 'Array':
9
- return typeCast(value, {
10
- type: 'Array'
11
- }, options);
12
- case 'Object':
13
- return typeCast(value, {
14
- type: 'Object'
15
- }, options);
16
- default:
17
- return {
18
- type: 'Just',
19
- value: typesCast(value, [
20
- {
21
- type: 'Undefined'
22
- }, {
23
- type: 'Null'
24
- }, {
25
- type: 'NaN'
26
- }, {
27
- type: 'Boolean'
28
- }, {
29
- type: 'Number'
30
- }, {
31
- type: 'Date'
32
- }, {
33
- type: 'RegExp'
34
- }, {
35
- type: 'Array'
36
- }, {
37
- type: 'Object'
38
- }, {
39
- type: 'String'
40
- }
41
- ], (options.explicit = true, options))
42
- };
43
- }
44
- },
45
- Undefined: function(it){
46
- if (it === 'undefined' || it === void 8) {
47
- return {
48
- type: 'Just',
49
- value: void 8
50
- };
51
- } else {
52
- return {
53
- type: 'Nothing'
54
- };
55
- }
56
- },
57
- Null: function(it){
58
- if (it === 'null') {
59
- return {
60
- type: 'Just',
61
- value: null
62
- };
63
- } else {
64
- return {
65
- type: 'Nothing'
66
- };
67
- }
68
- },
69
- NaN: function(it){
70
- if (it === 'NaN') {
71
- return {
72
- type: 'Just',
73
- value: NaN
74
- };
75
- } else {
76
- return {
77
- type: 'Nothing'
78
- };
79
- }
80
- },
81
- Boolean: function(it){
82
- if (it === 'true') {
83
- return {
84
- type: 'Just',
85
- value: true
86
- };
87
- } else if (it === 'false') {
88
- return {
89
- type: 'Just',
90
- value: false
91
- };
92
- } else {
93
- return {
94
- type: 'Nothing'
95
- };
96
- }
97
- },
98
- Number: function(it){
99
- return {
100
- type: 'Just',
101
- value: +it
102
- };
103
- },
104
- Int: function(it){
105
- return {
106
- type: 'Just',
107
- value: +it
108
- };
109
- },
110
- Float: function(it){
111
- return {
112
- type: 'Just',
113
- value: +it
114
- };
115
- },
116
- Date: function(value, options){
117
- var that;
118
- if (that = /^\#([\s\S]*)\#$/.exec(value)) {
119
- return {
120
- type: 'Just',
121
- value: new Date(+that[1] || that[1])
122
- };
123
- } else if (options.explicit) {
124
- return {
125
- type: 'Nothing'
126
- };
127
- } else {
128
- return {
129
- type: 'Just',
130
- value: new Date(+value || value)
131
- };
132
- }
133
- },
134
- RegExp: function(value, options){
135
- var that;
136
- if (that = /^\/([\s\S]*)\/([gimy]*)$/.exec(value)) {
137
- return {
138
- type: 'Just',
139
- value: new RegExp(that[1], that[2])
140
- };
141
- } else if (options.explicit) {
142
- return {
143
- type: 'Nothing'
144
- };
145
- } else {
146
- return {
147
- type: 'Just',
148
- value: new RegExp(value)
149
- };
150
- }
151
- },
152
- Array: function(value, options){
153
- return castArray(value, {
154
- of: [{
155
- type: '*'
156
- }]
157
- }, options);
158
- },
159
- Object: function(value, options){
160
- return castFields(value, {
161
- of: {}
162
- }, options);
163
- },
164
- String: function(it){
165
- var that;
166
- if (toString$.call(it).slice(8, -1) !== 'String') {
167
- return {
168
- type: 'Nothing'
169
- };
170
- }
171
- if (that = it.match(/^'([\s\S]*)'$/)) {
172
- return {
173
- type: 'Just',
174
- value: that[1].replace(/\\'/g, "'")
175
- };
176
- } else if (that = it.match(/^"([\s\S]*)"$/)) {
177
- return {
178
- type: 'Just',
179
- value: that[1].replace(/\\"/g, '"')
180
- };
181
- } else {
182
- return {
183
- type: 'Just',
184
- value: it
185
- };
186
- }
187
- }
188
- };
189
- function castArray(node, type, options){
190
- var typeOf, element;
191
- if (toString$.call(node).slice(8, -1) !== 'Array') {
192
- return {
193
- type: 'Nothing'
194
- };
195
- }
196
- typeOf = type.of;
197
- return {
198
- type: 'Just',
199
- value: (function(){
200
- var i$, ref$, len$, results$ = [];
201
- for (i$ = 0, len$ = (ref$ = node).length; i$ < len$; ++i$) {
202
- element = ref$[i$];
203
- results$.push(typesCast(element, typeOf, options));
204
- }
205
- return results$;
206
- }())
207
- };
208
- }
209
- function castTuple(node, type, options){
210
- var result, i, i$, ref$, len$, types, cast;
211
- if (toString$.call(node).slice(8, -1) !== 'Array') {
212
- return {
213
- type: 'Nothing'
214
- };
215
- }
216
- result = [];
217
- i = 0;
218
- for (i$ = 0, len$ = (ref$ = type.of).length; i$ < len$; ++i$) {
219
- types = ref$[i$];
220
- cast = typesCast(node[i], types, options);
221
- if (toString$.call(cast).slice(8, -1) !== 'Undefined') {
222
- result.push(cast);
223
- }
224
- i++;
225
- }
226
- if (node.length <= i) {
227
- return {
228
- type: 'Just',
229
- value: result
230
- };
231
- } else {
232
- return {
233
- type: 'Nothing'
234
- };
235
- }
236
- }
237
- function castFields(node, type, options){
238
- var typeOf, key, value;
239
- if (toString$.call(node).slice(8, -1) !== 'Object') {
240
- return {
241
- type: 'Nothing'
242
- };
243
- }
244
- typeOf = type.of;
245
- return {
246
- type: 'Just',
247
- value: (function(){
248
- var ref$, resultObj$ = {};
249
- for (key in ref$ = node) {
250
- value = ref$[key];
251
- resultObj$[typesCast(key, [{
252
- type: 'String'
253
- }], options)] = typesCast(value, typeOf[key] || [{
254
- type: '*'
255
- }], options);
256
- }
257
- return resultObj$;
258
- }())
259
- };
260
- }
261
- function typeCast(node, typeObj, options){
262
- var type, structure, castFunc, ref$;
263
- type = typeObj.type, structure = typeObj.structure;
264
- if (type) {
265
- castFunc = ((ref$ = options.customTypes[type]) != null ? ref$.cast : void 8) || types[type];
266
- if (!castFunc) {
267
- throw new Error("Type not defined: " + type + ".");
268
- }
269
- return castFunc(node, options, typesCast);
270
- } else {
271
- switch (structure) {
272
- case 'array':
273
- return castArray(node, typeObj, options);
274
- case 'tuple':
275
- return castTuple(node, typeObj, options);
276
- case 'fields':
277
- return castFields(node, typeObj, options);
278
- }
279
- }
280
- }
281
- function typesCast(node, types, options){
282
- var i$, len$, type, ref$, valueType, value;
283
- for (i$ = 0, len$ = types.length; i$ < len$; ++i$) {
284
- type = types[i$];
285
- ref$ = typeCast(node, type, options), valueType = ref$.type, value = ref$.value;
286
- if (valueType === 'Nothing') {
287
- continue;
288
- }
289
- if (parsedTypeCheck([type], value, {
290
- customTypes: options.customTypes
291
- })) {
292
- return value;
293
- }
294
- }
295
- throw new Error("Value " + JSON.stringify(node) + " does not type check against " + JSON.stringify(types) + ".");
296
- }
297
- module.exports = typesCast;
298
- }).call(this);