opal 0.7.0 → 0.7.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 (202) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -1
  3. data/lib/opal/cli.rb +9 -1
  4. data/lib/opal/cli_options.rb +12 -3
  5. data/lib/opal/cli_runners/nodejs.rb +3 -2
  6. data/lib/opal/version.rb +1 -1
  7. data/opal/corelib/kernel.rb +7 -0
  8. data/opal/corelib/runtime.js +4 -0
  9. data/spec/lib/cli_spec.rb +16 -0
  10. data/stdlib/nodejs.rb +1 -2
  11. data/stdlib/nodejs/{process.rb → kernel.rb} +7 -4
  12. data/stdlib/nodejs/node_modules/.bin/js-yaml +140 -0
  13. data/stdlib/nodejs/node_modules/glob/LICENSE +15 -0
  14. data/stdlib/nodejs/node_modules/glob/README.md +357 -0
  15. data/stdlib/nodejs/node_modules/glob/common.js +177 -0
  16. data/stdlib/nodejs/node_modules/glob/glob.js +649 -0
  17. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/.eslintrc +17 -0
  18. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/LICENSE +15 -0
  19. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/README.md +37 -0
  20. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/inflight.js +44 -0
  21. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/LICENSE +15 -0
  22. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/README.md +36 -0
  23. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/package.json +52 -0
  24. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/test/basic.js +51 -0
  25. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/wrappy.js +33 -0
  26. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/package.json +61 -0
  27. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/test.js +97 -0
  28. data/stdlib/nodejs/node_modules/glob/node_modules/inherits/LICENSE +16 -0
  29. data/stdlib/nodejs/node_modules/glob/node_modules/inherits/README.md +42 -0
  30. data/stdlib/nodejs/node_modules/glob/node_modules/inherits/inherits.js +1 -0
  31. data/stdlib/nodejs/node_modules/glob/node_modules/inherits/inherits_browser.js +23 -0
  32. data/stdlib/nodejs/node_modules/glob/node_modules/inherits/package.json +51 -0
  33. data/stdlib/nodejs/node_modules/glob/node_modules/inherits/test.js +25 -0
  34. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/.npmignore +1 -0
  35. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/.travis.yml +4 -0
  36. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/LICENSE +23 -0
  37. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/README.md +216 -0
  38. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/benchmark.js +15 -0
  39. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/browser.js +1181 -0
  40. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/minimatch.js +845 -0
  41. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/.npmignore +2 -0
  42. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/.travis.yml +3 -0
  43. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/README.md +121 -0
  44. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/example.js +8 -0
  45. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/index.js +191 -0
  46. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/.npmignore +2 -0
  47. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/.travis.yml +4 -0
  48. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/Makefile +6 -0
  49. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/README.md +80 -0
  50. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/example.js +5 -0
  51. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/index.js +38 -0
  52. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/package.json +73 -0
  53. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/test/balanced.js +56 -0
  54. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/.travis.yml +4 -0
  55. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/LICENSE +18 -0
  56. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/README.markdown +62 -0
  57. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/example/map.js +6 -0
  58. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/index.js +13 -0
  59. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/package.json +83 -0
  60. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/test/map.js +39 -0
  61. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/package.json +75 -0
  62. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/bash-comparison.js +32 -0
  63. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/bash-results.txt +1075 -0
  64. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/cases.txt +182 -0
  65. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/dollar.js +9 -0
  66. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/empty-option.js +10 -0
  67. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/generate.sh +24 -0
  68. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/negative-increment.js +15 -0
  69. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/nested.js +16 -0
  70. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/order.js +10 -0
  71. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/pad.js +13 -0
  72. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/same-type.js +7 -0
  73. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/sequence.js +50 -0
  74. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/package.json +60 -0
  75. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/test/basic.js +399 -0
  76. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/test/brace-expand.js +45 -0
  77. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/test/defaults.js +274 -0
  78. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/test/extglob-ending-with-state-char.js +8 -0
  79. data/stdlib/nodejs/node_modules/glob/node_modules/once/LICENSE +27 -0
  80. data/stdlib/nodejs/node_modules/glob/node_modules/once/README.md +51 -0
  81. data/stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/LICENSE +15 -0
  82. data/stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/README.md +36 -0
  83. data/stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/package.json +52 -0
  84. data/stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/test/basic.js +51 -0
  85. data/stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/wrappy.js +33 -0
  86. data/stdlib/nodejs/node_modules/glob/node_modules/once/once.js +21 -0
  87. data/stdlib/nodejs/node_modules/glob/node_modules/once/package.json +60 -0
  88. data/stdlib/nodejs/node_modules/glob/node_modules/once/test/once.js +23 -0
  89. data/stdlib/nodejs/node_modules/glob/package.json +72 -0
  90. data/stdlib/nodejs/node_modules/glob/sync.js +409 -0
  91. data/stdlib/nodejs/node_modules/js-yaml/HISTORY.md +277 -0
  92. data/stdlib/nodejs/node_modules/js-yaml/LICENSE +21 -0
  93. data/stdlib/nodejs/node_modules/js-yaml/README.md +288 -0
  94. data/stdlib/nodejs/node_modules/js-yaml/bin/js-yaml.js +140 -0
  95. data/stdlib/nodejs/node_modules/js-yaml/bower.json +23 -0
  96. data/stdlib/nodejs/node_modules/js-yaml/dist/js-yaml.js +3666 -0
  97. data/stdlib/nodejs/node_modules/js-yaml/dist/js-yaml.min.js +3 -0
  98. data/stdlib/nodejs/node_modules/js-yaml/examples/custom_types.js +102 -0
  99. data/stdlib/nodejs/node_modules/js-yaml/examples/custom_types.yml +18 -0
  100. data/stdlib/nodejs/node_modules/js-yaml/examples/dumper.js +31 -0
  101. data/stdlib/nodejs/node_modules/js-yaml/examples/dumper.json +22 -0
  102. data/stdlib/nodejs/node_modules/js-yaml/examples/sample_document.js +18 -0
  103. data/stdlib/nodejs/node_modules/js-yaml/examples/sample_document.yml +197 -0
  104. data/stdlib/nodejs/node_modules/js-yaml/index.js +7 -0
  105. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml.js +39 -0
  106. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/common.js +62 -0
  107. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/dumper.js +554 -0
  108. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/exception.js +25 -0
  109. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/loader.js +1581 -0
  110. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/mark.js +78 -0
  111. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/schema.js +103 -0
  112. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/schema/core.js +18 -0
  113. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/schema/default_full.js +25 -0
  114. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/schema/default_safe.js +28 -0
  115. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/schema/failsafe.js +17 -0
  116. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/schema/json.js +25 -0
  117. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type.js +61 -0
  118. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/binary.js +133 -0
  119. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/bool.js +37 -0
  120. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/float.js +110 -0
  121. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/int.js +183 -0
  122. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/js/function.js +85 -0
  123. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/js/regexp.js +84 -0
  124. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/js/undefined.js +27 -0
  125. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/map.js +8 -0
  126. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/merge.js +12 -0
  127. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/null.js +36 -0
  128. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/omap.js +56 -0
  129. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/pairs.js +61 -0
  130. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/seq.js +8 -0
  131. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/set.js +33 -0
  132. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/str.js +8 -0
  133. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/timestamp.js +98 -0
  134. data/stdlib/nodejs/node_modules/js-yaml/node_modules/.bin/esparse +117 -0
  135. data/stdlib/nodejs/node_modules/js-yaml/node_modules/.bin/esvalidate +177 -0
  136. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/HISTORY.md +115 -0
  137. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/LICENSE +21 -0
  138. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/README.md +239 -0
  139. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/arguments.js +36 -0
  140. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/choice.js +22 -0
  141. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/constants.js +59 -0
  142. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/help.js +13 -0
  143. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/nargs.js +33 -0
  144. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/parents.js +28 -0
  145. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/prefix_chars.js +23 -0
  146. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/sub_commands.js +49 -0
  147. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/sum.js +35 -0
  148. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/testformatters.js +270 -0
  149. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/index.js +1 -0
  150. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action.js +146 -0
  151. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/append.js +55 -0
  152. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/append/constant.js +47 -0
  153. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/count.js +40 -0
  154. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/help.js +48 -0
  155. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/store.js +50 -0
  156. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/store/constant.js +43 -0
  157. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/store/false.js +27 -0
  158. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/store/true.js +26 -0
  159. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/subparsers.js +148 -0
  160. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/version.js +50 -0
  161. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action_container.js +481 -0
  162. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/argparse.js +14 -0
  163. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/argument/error.js +50 -0
  164. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/argument/exclusive.js +54 -0
  165. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/argument/group.js +75 -0
  166. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/argument_parser.js +1168 -0
  167. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/const.js +18 -0
  168. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/help/added_formatters.js +88 -0
  169. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/help/formatter.js +798 -0
  170. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/namespace.js +77 -0
  171. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/.npmignore +2 -0
  172. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/.travis.yml +8 -0
  173. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/README.markdown +825 -0
  174. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/bower.json +33 -0
  175. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/component.json +11 -0
  176. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/foo.js +10 -0
  177. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/gulpfile.js +26 -0
  178. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/lib/underscore.string.js +673 -0
  179. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/libpeerconnection.log +0 -0
  180. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/package.json +107 -0
  181. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore/LICENSE +23 -0
  182. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore/README.md +22 -0
  183. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore/package.json +69 -0
  184. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore/underscore-min.js +6 -0
  185. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore/underscore.js +1415 -0
  186. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/package.json +62 -0
  187. data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/README.md +73 -0
  188. data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/bin/esparse.js +117 -0
  189. data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/bin/esvalidate.js +177 -0
  190. data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/esprima.js +3908 -0
  191. data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/package.json +69 -0
  192. data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/test/compat.js +239 -0
  193. data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/test/reflect.js +422 -0
  194. data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/test/run.js +66 -0
  195. data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/test/runner.js +387 -0
  196. data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/test/test.js +20238 -0
  197. data/stdlib/nodejs/node_modules/js-yaml/package.json +83 -0
  198. data/{package.json → stdlib/nodejs/package.json} +0 -3
  199. data/stdlib/phantomjs.rb +1 -6
  200. data/tasks/testing.rake +1 -4
  201. metadata +191 -6
  202. data/stdlib/nodejs/runtime.rb +0 -26
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ var Type = require('../type');
4
+
5
+ function resolveYamlBoolean(data) {
6
+ if (null === data) {
7
+ return false;
8
+ }
9
+
10
+ var max = data.length;
11
+
12
+ return (max === 4 && (data === 'true' || data === 'True' || data === 'TRUE')) ||
13
+ (max === 5 && (data === 'false' || data === 'False' || data === 'FALSE'));
14
+ }
15
+
16
+ function constructYamlBoolean(data) {
17
+ return data === 'true' ||
18
+ data === 'True' ||
19
+ data === 'TRUE';
20
+ }
21
+
22
+ function isBoolean(object) {
23
+ return '[object Boolean]' === Object.prototype.toString.call(object);
24
+ }
25
+
26
+ module.exports = new Type('tag:yaml.org,2002:bool', {
27
+ kind: 'scalar',
28
+ resolve: resolveYamlBoolean,
29
+ construct: constructYamlBoolean,
30
+ predicate: isBoolean,
31
+ represent: {
32
+ lowercase: function (object) { return object ? 'true' : 'false'; },
33
+ uppercase: function (object) { return object ? 'TRUE' : 'FALSE'; },
34
+ camelcase: function (object) { return object ? 'True' : 'False'; }
35
+ },
36
+ defaultStyle: 'lowercase'
37
+ });
@@ -0,0 +1,110 @@
1
+ 'use strict';
2
+
3
+ var common = require('../common');
4
+ var Type = require('../type');
5
+
6
+ var YAML_FLOAT_PATTERN = new RegExp(
7
+ '^(?:[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+][0-9]+)?' +
8
+ '|\\.[0-9_]+(?:[eE][-+][0-9]+)?' +
9
+ '|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*' +
10
+ '|[-+]?\\.(?:inf|Inf|INF)' +
11
+ '|\\.(?:nan|NaN|NAN))$');
12
+
13
+ function resolveYamlFloat(data) {
14
+ if (null === data) {
15
+ return false;
16
+ }
17
+
18
+ var value, sign, base, digits;
19
+
20
+ if (!YAML_FLOAT_PATTERN.test(data)) {
21
+ return false;
22
+ }
23
+ return true;
24
+ }
25
+
26
+ function constructYamlFloat(data) {
27
+ var value, sign, base, digits;
28
+
29
+ value = data.replace(/_/g, '').toLowerCase();
30
+ sign = '-' === value[0] ? -1 : 1;
31
+ digits = [];
32
+
33
+ if (0 <= '+-'.indexOf(value[0])) {
34
+ value = value.slice(1);
35
+ }
36
+
37
+ if ('.inf' === value) {
38
+ return (1 === sign) ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
39
+
40
+ } else if ('.nan' === value) {
41
+ return NaN;
42
+
43
+ } else if (0 <= value.indexOf(':')) {
44
+ value.split(':').forEach(function (v) {
45
+ digits.unshift(parseFloat(v, 10));
46
+ });
47
+
48
+ value = 0.0;
49
+ base = 1;
50
+
51
+ digits.forEach(function (d) {
52
+ value += d * base;
53
+ base *= 60;
54
+ });
55
+
56
+ return sign * value;
57
+
58
+ } else {
59
+ return sign * parseFloat(value, 10);
60
+ }
61
+ }
62
+
63
+ function representYamlFloat(object, style) {
64
+ if (isNaN(object)) {
65
+ switch (style) {
66
+ case 'lowercase':
67
+ return '.nan';
68
+ case 'uppercase':
69
+ return '.NAN';
70
+ case 'camelcase':
71
+ return '.NaN';
72
+ }
73
+ } else if (Number.POSITIVE_INFINITY === object) {
74
+ switch (style) {
75
+ case 'lowercase':
76
+ return '.inf';
77
+ case 'uppercase':
78
+ return '.INF';
79
+ case 'camelcase':
80
+ return '.Inf';
81
+ }
82
+ } else if (Number.NEGATIVE_INFINITY === object) {
83
+ switch (style) {
84
+ case 'lowercase':
85
+ return '-.inf';
86
+ case 'uppercase':
87
+ return '-.INF';
88
+ case 'camelcase':
89
+ return '-.Inf';
90
+ }
91
+ } else if (common.isNegativeZero(object)) {
92
+ return '-0.0';
93
+ } else {
94
+ return object.toString(10);
95
+ }
96
+ }
97
+
98
+ function isFloat(object) {
99
+ return ('[object Number]' === Object.prototype.toString.call(object)) &&
100
+ (0 !== object % 1 || common.isNegativeZero(object));
101
+ }
102
+
103
+ module.exports = new Type('tag:yaml.org,2002:float', {
104
+ kind: 'scalar',
105
+ resolve: resolveYamlFloat,
106
+ construct: constructYamlFloat,
107
+ predicate: isFloat,
108
+ represent: representYamlFloat,
109
+ defaultStyle: 'lowercase'
110
+ });
@@ -0,0 +1,183 @@
1
+ 'use strict';
2
+
3
+ var common = require('../common');
4
+ var Type = require('../type');
5
+
6
+ function isHexCode(c) {
7
+ return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) ||
8
+ ((0x41/* A */ <= c) && (c <= 0x46/* F */)) ||
9
+ ((0x61/* a */ <= c) && (c <= 0x66/* f */));
10
+ }
11
+
12
+ function isOctCode(c) {
13
+ return ((0x30/* 0 */ <= c) && (c <= 0x37/* 7 */));
14
+ }
15
+
16
+ function isDecCode(c) {
17
+ return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */));
18
+ }
19
+
20
+ function resolveYamlInteger(data) {
21
+ if (null === data) {
22
+ return false;
23
+ }
24
+
25
+ var max = data.length,
26
+ index = 0,
27
+ hasDigits = false,
28
+ ch;
29
+
30
+ if (!max) { return false; }
31
+
32
+ ch = data[index];
33
+
34
+ // sign
35
+ if (ch === '-' || ch === '+') {
36
+ ch = data[++index];
37
+ }
38
+
39
+ if (ch === '0') {
40
+ // 0
41
+ if (index+1 === max) { return true; }
42
+ ch = data[++index];
43
+
44
+ // base 2, base 8, base 16
45
+
46
+ if (ch === 'b') {
47
+ // base 2
48
+ index++;
49
+
50
+ for (; index < max; index++) {
51
+ ch = data[index];
52
+ if (ch === '_') { continue; }
53
+ if (ch !== '0' && ch !== '1') {
54
+ return false;
55
+ }
56
+ hasDigits = true;
57
+ }
58
+ return hasDigits;
59
+ }
60
+
61
+
62
+ if (ch === 'x') {
63
+ // base 16
64
+ index++;
65
+
66
+ for (; index < max; index++) {
67
+ ch = data[index];
68
+ if (ch === '_') { continue; }
69
+ if (!isHexCode(data.charCodeAt(index))) {
70
+ return false;
71
+ }
72
+ hasDigits = true;
73
+ }
74
+ return hasDigits;
75
+ }
76
+
77
+ // base 8
78
+ for (; index < max; index++) {
79
+ ch = data[index];
80
+ if (ch === '_') { continue; }
81
+ if (!isOctCode(data.charCodeAt(index))) {
82
+ return false;
83
+ }
84
+ hasDigits = true;
85
+ }
86
+ return hasDigits;
87
+ }
88
+
89
+ // base 10 (except 0) or base 60
90
+
91
+ for (; index < max; index++) {
92
+ ch = data[index];
93
+ if (ch === '_') { continue; }
94
+ if (ch === ':') { break; }
95
+ if (!isDecCode(data.charCodeAt(index))) {
96
+ return false;
97
+ }
98
+ hasDigits = true;
99
+ }
100
+
101
+ if (!hasDigits) { return false; }
102
+
103
+ // if !base60 - done;
104
+ if (ch !== ':') { return true; }
105
+
106
+ // base60 almost not used, no needs to optimize
107
+ return /^(:[0-5]?[0-9])+$/.test(data.slice(index));
108
+ }
109
+
110
+ function constructYamlInteger(data) {
111
+ var value = data, sign = 1, ch, base, digits = [];
112
+
113
+ if (value.indexOf('_') !== -1) {
114
+ value = value.replace(/_/g, '');
115
+ }
116
+
117
+ ch = value[0];
118
+
119
+ if (ch === '-' || ch === '+') {
120
+ if (ch === '-') { sign = -1; }
121
+ value = value.slice(1);
122
+ ch = value[0];
123
+ }
124
+
125
+ if ('0' === value) {
126
+ return 0;
127
+ }
128
+
129
+ if (ch === '0') {
130
+ if (value[1] === 'b') {
131
+ return sign * parseInt(value.slice(2), 2);
132
+ }
133
+ if (value[1] === 'x') {
134
+ return sign * parseInt(value, 16);
135
+ }
136
+ return sign * parseInt(value, 8);
137
+
138
+ }
139
+
140
+ if (value.indexOf(':') !== -1) {
141
+ value.split(':').forEach(function (v) {
142
+ digits.unshift(parseInt(v, 10));
143
+ });
144
+
145
+ value = 0;
146
+ base = 1;
147
+
148
+ digits.forEach(function (d) {
149
+ value += (d * base);
150
+ base *= 60;
151
+ });
152
+
153
+ return sign * value;
154
+
155
+ }
156
+
157
+ return sign * parseInt(value, 10);
158
+ }
159
+
160
+ function isInteger(object) {
161
+ return ('[object Number]' === Object.prototype.toString.call(object)) &&
162
+ (0 === object % 1 && !common.isNegativeZero(object));
163
+ }
164
+
165
+ module.exports = new Type('tag:yaml.org,2002:int', {
166
+ kind: 'scalar',
167
+ resolve: resolveYamlInteger,
168
+ construct: constructYamlInteger,
169
+ predicate: isInteger,
170
+ represent: {
171
+ binary: function (object) { return '0b' + object.toString(2); },
172
+ octal: function (object) { return '0' + object.toString(8); },
173
+ decimal: function (object) { return object.toString(10); },
174
+ hexadecimal: function (object) { return '0x' + object.toString(16).toUpperCase(); }
175
+ },
176
+ defaultStyle: 'decimal',
177
+ styleAliases: {
178
+ binary: [ 2, 'bin' ],
179
+ octal: [ 8, 'oct' ],
180
+ decimal: [ 10, 'dec' ],
181
+ hexadecimal: [ 16, 'hex' ]
182
+ }
183
+ });
@@ -0,0 +1,85 @@
1
+ 'use strict';
2
+
3
+ var esprima;
4
+
5
+ // Browserified version does not have esprima
6
+ //
7
+ // 1. For node.js just require module as deps
8
+ // 2. For browser try to require mudule via external AMD system.
9
+ // If not found - try to fallback to window.esprima. If not
10
+ // found too - then fail to parse.
11
+ //
12
+ try {
13
+ esprima = require('esprima');
14
+ } catch (_) {
15
+ /*global window */
16
+ if (typeof window !== 'undefined') { esprima = window.esprima; }
17
+ }
18
+
19
+ var Type = require('../../type');
20
+
21
+ function resolveJavascriptFunction(data) {
22
+ if (null === data) {
23
+ return false;
24
+ }
25
+
26
+ try {
27
+ var source = '(' + data + ')',
28
+ ast = esprima.parse(source, { range: true }),
29
+ params = [],
30
+ body;
31
+
32
+ if ('Program' !== ast.type ||
33
+ 1 !== ast.body.length ||
34
+ 'ExpressionStatement' !== ast.body[0].type ||
35
+ 'FunctionExpression' !== ast.body[0].expression.type) {
36
+ return false;
37
+ }
38
+
39
+ return true;
40
+ } catch (err) {
41
+ return false;
42
+ }
43
+ }
44
+
45
+ function constructJavascriptFunction(data) {
46
+ /*jslint evil:true*/
47
+
48
+ var source = '(' + data + ')',
49
+ ast = esprima.parse(source, { range: true }),
50
+ params = [],
51
+ body;
52
+
53
+ if ('Program' !== ast.type ||
54
+ 1 !== ast.body.length ||
55
+ 'ExpressionStatement' !== ast.body[0].type ||
56
+ 'FunctionExpression' !== ast.body[0].expression.type) {
57
+ throw new Error('Failed to resolve function');
58
+ }
59
+
60
+ ast.body[0].expression.params.forEach(function (param) {
61
+ params.push(param.name);
62
+ });
63
+
64
+ body = ast.body[0].expression.body.range;
65
+
66
+ // Esprima's ranges include the first '{' and the last '}' characters on
67
+ // function expressions. So cut them out.
68
+ return new Function(params, source.slice(body[0]+1, body[1]-1));
69
+ }
70
+
71
+ function representJavascriptFunction(object /*, style*/) {
72
+ return object.toString();
73
+ }
74
+
75
+ function isFunction(object) {
76
+ return '[object Function]' === Object.prototype.toString.call(object);
77
+ }
78
+
79
+ module.exports = new Type('tag:yaml.org,2002:js/function', {
80
+ kind: 'scalar',
81
+ resolve: resolveJavascriptFunction,
82
+ construct: constructJavascriptFunction,
83
+ predicate: isFunction,
84
+ represent: representJavascriptFunction
85
+ });
@@ -0,0 +1,84 @@
1
+ 'use strict';
2
+
3
+ var Type = require('../../type');
4
+
5
+ function resolveJavascriptRegExp(data) {
6
+ if (null === data) {
7
+ return false;
8
+ }
9
+
10
+ if (0 === data.length) {
11
+ return false;
12
+ }
13
+
14
+ var regexp = data,
15
+ tail = /\/([gim]*)$/.exec(data),
16
+ modifiers = '';
17
+
18
+ // if regexp starts with '/' it can have modifiers and must be properly closed
19
+ // `/foo/gim` - modifiers tail can be maximum 3 chars
20
+ if ('/' === regexp[0]) {
21
+ if (tail) {
22
+ modifiers = tail[1];
23
+ }
24
+
25
+ if (modifiers.length > 3) { return false; }
26
+ // if expression starts with /, is should be properly terminated
27
+ if (regexp[regexp.length - modifiers.length - 1] !== '/') { return false; }
28
+
29
+ regexp = regexp.slice(1, regexp.length - modifiers.length - 1);
30
+ }
31
+
32
+ try {
33
+ var dummy = new RegExp(regexp, modifiers);
34
+ return true;
35
+ } catch (error) {
36
+ return false;
37
+ }
38
+ }
39
+
40
+ function constructJavascriptRegExp(data) {
41
+ var regexp = data,
42
+ tail = /\/([gim]*)$/.exec(data),
43
+ modifiers = '';
44
+
45
+ // `/foo/gim` - tail can be maximum 4 chars
46
+ if ('/' === regexp[0]) {
47
+ if (tail) {
48
+ modifiers = tail[1];
49
+ }
50
+ regexp = regexp.slice(1, regexp.length - modifiers.length - 1);
51
+ }
52
+
53
+ return new RegExp(regexp, modifiers);
54
+ }
55
+
56
+ function representJavascriptRegExp(object /*, style*/) {
57
+ var result = '/' + object.source + '/';
58
+
59
+ if (object.global) {
60
+ result += 'g';
61
+ }
62
+
63
+ if (object.multiline) {
64
+ result += 'm';
65
+ }
66
+
67
+ if (object.ignoreCase) {
68
+ result += 'i';
69
+ }
70
+
71
+ return result;
72
+ }
73
+
74
+ function isRegExp(object) {
75
+ return '[object RegExp]' === Object.prototype.toString.call(object);
76
+ }
77
+
78
+ module.exports = new Type('tag:yaml.org,2002:js/regexp', {
79
+ kind: 'scalar',
80
+ resolve: resolveJavascriptRegExp,
81
+ construct: constructJavascriptRegExp,
82
+ predicate: isRegExp,
83
+ represent: representJavascriptRegExp
84
+ });