dragonfly_chrome_headless 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (228) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +12 -0
  4. data/Gemfile +4 -0
  5. data/README.md +53 -0
  6. data/Rakefile +10 -0
  7. data/bin/console +14 -0
  8. data/bin/setup +8 -0
  9. data/dragonfly_chrome_headless.gemspec +27 -0
  10. data/lib/dragonfly_chrome_headless.rb +9 -0
  11. data/lib/dragonfly_chrome_headless/plugin.rb +17 -0
  12. data/lib/dragonfly_chrome_headless/processors/rasterize.rb +33 -0
  13. data/lib/dragonfly_chrome_headless/version.rb +3 -0
  14. data/node_modules/.bin/chrome-remote-interface +1 -0
  15. data/node_modules/.bin/mkdirp +1 -0
  16. data/node_modules/.bin/rimraf +1 -0
  17. data/node_modules/@types/core-js/LICENSE +21 -0
  18. data/node_modules/@types/core-js/README.md +16 -0
  19. data/node_modules/@types/core-js/index.d.ts +2452 -0
  20. data/node_modules/@types/core-js/package.json +85 -0
  21. data/node_modules/@types/mkdirp/README.md +18 -0
  22. data/node_modules/@types/mkdirp/index.d.ts +14 -0
  23. data/node_modules/@types/mkdirp/package.json +77 -0
  24. data/node_modules/@types/mkdirp/types-metadata.json +25 -0
  25. data/node_modules/@types/node/README.md +16 -0
  26. data/node_modules/@types/node/index.d.ts +4132 -0
  27. data/node_modules/@types/node/package.json +84 -0
  28. data/node_modules/balanced-match/.npmignore +5 -0
  29. data/node_modules/balanced-match/LICENSE.md +21 -0
  30. data/node_modules/balanced-match/README.md +91 -0
  31. data/node_modules/balanced-match/index.js +59 -0
  32. data/node_modules/balanced-match/package.json +112 -0
  33. data/node_modules/brace-expansion/README.md +123 -0
  34. data/node_modules/brace-expansion/index.js +201 -0
  35. data/node_modules/brace-expansion/package.json +114 -0
  36. data/node_modules/chrome-launcher/.clang-format +6 -0
  37. data/node_modules/chrome-launcher/.npmignore +11 -0
  38. data/node_modules/chrome-launcher/README.md +123 -0
  39. data/node_modules/chrome-launcher/ask.js +32 -0
  40. data/node_modules/chrome-launcher/ask.ts +35 -0
  41. data/node_modules/chrome-launcher/chrome-finder.js +157 -0
  42. data/node_modules/chrome-launcher/chrome-finder.ts +186 -0
  43. data/node_modules/chrome-launcher/chrome-launcher.js +245 -0
  44. data/node_modules/chrome-launcher/chrome-launcher.ts +312 -0
  45. data/node_modules/chrome-launcher/compiled-check.js +14 -0
  46. data/node_modules/chrome-launcher/flags.js +27 -0
  47. data/node_modules/chrome-launcher/flags.ts +26 -0
  48. data/node_modules/chrome-launcher/index.js +7 -0
  49. data/node_modules/chrome-launcher/index.ts +1 -0
  50. data/node_modules/chrome-launcher/manual-chrome-launcher.js +30 -0
  51. data/node_modules/chrome-launcher/package.json +116 -0
  52. data/node_modules/chrome-launcher/random-port.js +24 -0
  53. data/node_modules/chrome-launcher/random-port.ts +23 -0
  54. data/node_modules/chrome-launcher/tsconfig.json +19 -0
  55. data/node_modules/chrome-launcher/utils.js +52 -0
  56. data/node_modules/chrome-launcher/utils.ts +44 -0
  57. data/node_modules/chrome-launcher/yarn.lock +1486 -0
  58. data/node_modules/chrome-remote-interface/LICENSE +18 -0
  59. data/node_modules/chrome-remote-interface/README.md +849 -0
  60. data/node_modules/chrome-remote-interface/bin/client.js +337 -0
  61. data/node_modules/chrome-remote-interface/chrome-remote-interface.js +11 -0
  62. data/node_modules/chrome-remote-interface/index.js +39 -0
  63. data/node_modules/chrome-remote-interface/lib/api.js +84 -0
  64. data/node_modules/chrome-remote-interface/lib/chrome.js +307 -0
  65. data/node_modules/chrome-remote-interface/lib/defaults.js +4 -0
  66. data/node_modules/chrome-remote-interface/lib/devtools.js +245 -0
  67. data/node_modules/chrome-remote-interface/lib/external-request.js +28 -0
  68. data/node_modules/chrome-remote-interface/lib/protocol.json +13780 -0
  69. data/node_modules/chrome-remote-interface/lib/websocket-wrapper.js +32 -0
  70. data/node_modules/chrome-remote-interface/package.json +128 -0
  71. data/node_modules/chrome-remote-interface/webpack.config.js +55 -0
  72. data/node_modules/commander/Readme.md +195 -0
  73. data/node_modules/commander/index.js +851 -0
  74. data/node_modules/commander/package.json +92 -0
  75. data/node_modules/concat-map/.travis.yml +4 -0
  76. data/node_modules/concat-map/LICENSE +18 -0
  77. data/node_modules/concat-map/README.markdown +62 -0
  78. data/node_modules/concat-map/example/map.js +6 -0
  79. data/node_modules/concat-map/index.js +13 -0
  80. data/node_modules/concat-map/package.json +117 -0
  81. data/node_modules/concat-map/test/map.js +39 -0
  82. data/node_modules/debug/.coveralls.yml +1 -0
  83. data/node_modules/debug/.eslintrc +11 -0
  84. data/node_modules/debug/.npmignore +9 -0
  85. data/node_modules/debug/.travis.yml +14 -0
  86. data/node_modules/debug/CHANGELOG.md +357 -0
  87. data/node_modules/debug/LICENSE +19 -0
  88. data/node_modules/debug/Makefile +50 -0
  89. data/node_modules/debug/Readme.md +312 -0
  90. data/node_modules/debug/component.json +19 -0
  91. data/node_modules/debug/karma.conf.js +70 -0
  92. data/node_modules/debug/node.js +1 -0
  93. data/node_modules/debug/package.json +124 -0
  94. data/node_modules/debug/src/browser.js +185 -0
  95. data/node_modules/debug/src/debug.js +202 -0
  96. data/node_modules/debug/src/index.js +10 -0
  97. data/node_modules/debug/src/node.js +246 -0
  98. data/node_modules/fs.realpath/LICENSE +43 -0
  99. data/node_modules/fs.realpath/README.md +33 -0
  100. data/node_modules/fs.realpath/index.js +66 -0
  101. data/node_modules/fs.realpath/old.js +303 -0
  102. data/node_modules/fs.realpath/package.json +94 -0
  103. data/node_modules/glob/LICENSE +15 -0
  104. data/node_modules/glob/README.md +368 -0
  105. data/node_modules/glob/changelog.md +67 -0
  106. data/node_modules/glob/common.js +240 -0
  107. data/node_modules/glob/glob.js +790 -0
  108. data/node_modules/glob/package.json +112 -0
  109. data/node_modules/glob/sync.js +486 -0
  110. data/node_modules/html-pdf-chrome/.npmignore +9 -0
  111. data/node_modules/html-pdf-chrome/LICENSE +21 -0
  112. data/node_modules/html-pdf-chrome/README.md +165 -0
  113. data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.d.ts +87 -0
  114. data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.js +4 -0
  115. data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.js.map +1 -0
  116. data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.d.ts +120 -0
  117. data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.js +206 -0
  118. data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.js.map +1 -0
  119. data/node_modules/html-pdf-chrome/lib/src/CreateResult.d.ts +70 -0
  120. data/node_modules/html-pdf-chrome/lib/src/CreateResult.js +98 -0
  121. data/node_modules/html-pdf-chrome/lib/src/CreateResult.js.map +1 -0
  122. data/node_modules/html-pdf-chrome/lib/src/index.d.ts +72 -0
  123. data/node_modules/html-pdf-chrome/lib/src/index.js +123 -0
  124. data/node_modules/html-pdf-chrome/lib/src/index.js.map +1 -0
  125. data/node_modules/html-pdf-chrome/package.json +133 -0
  126. data/node_modules/html-pdf-chrome/src/ChromePrintOptions.ts +99 -0
  127. data/node_modules/html-pdf-chrome/src/CompletionTrigger.ts +201 -0
  128. data/node_modules/html-pdf-chrome/src/CreateResult.ts +100 -0
  129. data/node_modules/html-pdf-chrome/src/index.ts +179 -0
  130. data/node_modules/inflight/LICENSE +15 -0
  131. data/node_modules/inflight/README.md +37 -0
  132. data/node_modules/inflight/inflight.js +54 -0
  133. data/node_modules/inflight/package.json +105 -0
  134. data/node_modules/inherits/LICENSE +16 -0
  135. data/node_modules/inherits/README.md +42 -0
  136. data/node_modules/inherits/inherits.js +7 -0
  137. data/node_modules/inherits/inherits_browser.js +23 -0
  138. data/node_modules/inherits/package.json +97 -0
  139. data/node_modules/lighthouse-logger/README.md +4 -0
  140. data/node_modules/lighthouse-logger/index.js +212 -0
  141. data/node_modules/lighthouse-logger/package.json +69 -0
  142. data/node_modules/lighthouse-logger/yarn.lock +13 -0
  143. data/node_modules/minimatch/LICENSE +15 -0
  144. data/node_modules/minimatch/README.md +209 -0
  145. data/node_modules/minimatch/minimatch.js +923 -0
  146. data/node_modules/minimatch/package.json +99 -0
  147. data/node_modules/minimist/.travis.yml +4 -0
  148. data/node_modules/minimist/LICENSE +18 -0
  149. data/node_modules/minimist/example/parse.js +2 -0
  150. data/node_modules/minimist/index.js +187 -0
  151. data/node_modules/minimist/package.json +101 -0
  152. data/node_modules/minimist/readme.markdown +73 -0
  153. data/node_modules/minimist/test/dash.js +24 -0
  154. data/node_modules/minimist/test/default_bool.js +20 -0
  155. data/node_modules/minimist/test/dotted.js +16 -0
  156. data/node_modules/minimist/test/long.js +31 -0
  157. data/node_modules/minimist/test/parse.js +318 -0
  158. data/node_modules/minimist/test/parse_modified.js +9 -0
  159. data/node_modules/minimist/test/short.js +67 -0
  160. data/node_modules/minimist/test/whitespace.js +8 -0
  161. data/node_modules/mkdirp/.travis.yml +8 -0
  162. data/node_modules/mkdirp/LICENSE +21 -0
  163. data/node_modules/mkdirp/bin/cmd.js +33 -0
  164. data/node_modules/mkdirp/bin/usage.txt +12 -0
  165. data/node_modules/mkdirp/examples/pow.js +6 -0
  166. data/node_modules/mkdirp/index.js +98 -0
  167. data/node_modules/mkdirp/package.json +93 -0
  168. data/node_modules/mkdirp/readme.markdown +100 -0
  169. data/node_modules/mkdirp/test/chmod.js +41 -0
  170. data/node_modules/mkdirp/test/clobber.js +38 -0
  171. data/node_modules/mkdirp/test/mkdirp.js +28 -0
  172. data/node_modules/mkdirp/test/opts_fs.js +29 -0
  173. data/node_modules/mkdirp/test/opts_fs_sync.js +27 -0
  174. data/node_modules/mkdirp/test/perm.js +32 -0
  175. data/node_modules/mkdirp/test/perm_sync.js +36 -0
  176. data/node_modules/mkdirp/test/race.js +37 -0
  177. data/node_modules/mkdirp/test/rel.js +32 -0
  178. data/node_modules/mkdirp/test/return.js +25 -0
  179. data/node_modules/mkdirp/test/return_sync.js +24 -0
  180. data/node_modules/mkdirp/test/root.js +19 -0
  181. data/node_modules/mkdirp/test/sync.js +32 -0
  182. data/node_modules/mkdirp/test/umask.js +28 -0
  183. data/node_modules/mkdirp/test/umask_sync.js +32 -0
  184. data/node_modules/ms/README.md +51 -0
  185. data/node_modules/ms/index.js +152 -0
  186. data/node_modules/ms/license.md +21 -0
  187. data/node_modules/ms/package.json +109 -0
  188. data/node_modules/once/LICENSE +15 -0
  189. data/node_modules/once/README.md +79 -0
  190. data/node_modules/once/once.js +42 -0
  191. data/node_modules/once/package.json +101 -0
  192. data/node_modules/path-is-absolute/index.js +20 -0
  193. data/node_modules/path-is-absolute/license +21 -0
  194. data/node_modules/path-is-absolute/package.json +111 -0
  195. data/node_modules/path-is-absolute/readme.md +59 -0
  196. data/node_modules/rimraf/LICENSE +15 -0
  197. data/node_modules/rimraf/README.md +101 -0
  198. data/node_modules/rimraf/bin.js +50 -0
  199. data/node_modules/rimraf/package.json +99 -0
  200. data/node_modules/rimraf/rimraf.js +363 -0
  201. data/node_modules/ultron/LICENSE +22 -0
  202. data/node_modules/ultron/index.js +138 -0
  203. data/node_modules/ultron/package.json +112 -0
  204. data/node_modules/wrappy/LICENSE +15 -0
  205. data/node_modules/wrappy/README.md +36 -0
  206. data/node_modules/wrappy/package.json +97 -0
  207. data/node_modules/wrappy/wrappy.js +33 -0
  208. data/node_modules/ws/LICENSE +21 -0
  209. data/node_modules/ws/README.md +259 -0
  210. data/node_modules/ws/SECURITY.md +33 -0
  211. data/node_modules/ws/index.js +15 -0
  212. data/node_modules/ws/lib/BufferUtil.fallback.js +56 -0
  213. data/node_modules/ws/lib/BufferUtil.js +15 -0
  214. data/node_modules/ws/lib/ErrorCodes.js +28 -0
  215. data/node_modules/ws/lib/EventTarget.js +158 -0
  216. data/node_modules/ws/lib/Extensions.js +69 -0
  217. data/node_modules/ws/lib/PerMessageDeflate.js +339 -0
  218. data/node_modules/ws/lib/Receiver.js +520 -0
  219. data/node_modules/ws/lib/Sender.js +438 -0
  220. data/node_modules/ws/lib/Validation.fallback.js +9 -0
  221. data/node_modules/ws/lib/Validation.js +17 -0
  222. data/node_modules/ws/lib/WebSocket.js +705 -0
  223. data/node_modules/ws/lib/WebSocketServer.js +336 -0
  224. data/node_modules/ws/package.json +122 -0
  225. data/package.json +26 -0
  226. data/samples/sample.html +13 -0
  227. data/script/rasterize.js +18 -0
  228. metadata +325 -0
@@ -0,0 +1,24 @@
1
+ var parse = require('../');
2
+ var test = require('tape');
3
+
4
+ test('-', function (t) {
5
+ t.plan(5);
6
+ t.deepEqual(parse([ '-n', '-' ]), { n: '-', _: [] });
7
+ t.deepEqual(parse([ '-' ]), { _: [ '-' ] });
8
+ t.deepEqual(parse([ '-f-' ]), { f: '-', _: [] });
9
+ t.deepEqual(
10
+ parse([ '-b', '-' ], { boolean: 'b' }),
11
+ { b: true, _: [ '-' ] }
12
+ );
13
+ t.deepEqual(
14
+ parse([ '-s', '-' ], { string: 's' }),
15
+ { s: '-', _: [] }
16
+ );
17
+ });
18
+
19
+ test('-a -- b', function (t) {
20
+ t.plan(3);
21
+ t.deepEqual(parse([ '-a', '--', 'b' ]), { a: true, _: [ 'b' ] });
22
+ t.deepEqual(parse([ '--a', '--', 'b' ]), { a: true, _: [ 'b' ] });
23
+ t.deepEqual(parse([ '--a', '--', 'b' ]), { a: true, _: [ 'b' ] });
24
+ });
@@ -0,0 +1,20 @@
1
+ var test = require('tape');
2
+ var parse = require('../');
3
+
4
+ test('boolean default true', function (t) {
5
+ var argv = parse([], {
6
+ boolean: 'sometrue',
7
+ default: { sometrue: true }
8
+ });
9
+ t.equal(argv.sometrue, true);
10
+ t.end();
11
+ });
12
+
13
+ test('boolean default false', function (t) {
14
+ var argv = parse([], {
15
+ boolean: 'somefalse',
16
+ default: { somefalse: false }
17
+ });
18
+ t.equal(argv.somefalse, false);
19
+ t.end();
20
+ });
@@ -0,0 +1,16 @@
1
+ var parse = require('../');
2
+ var test = require('tape');
3
+
4
+ test('dotted alias', function (t) {
5
+ var argv = parse(['--a.b', '22'], {default: {'a.b': 11}, alias: {'a.b': 'aa.bb'}});
6
+ t.equal(argv.a.b, 22);
7
+ t.equal(argv.aa.bb, 22);
8
+ t.end();
9
+ });
10
+
11
+ test('dotted default', function (t) {
12
+ var argv = parse('', {default: {'a.b': 11}, alias: {'a.b': 'aa.bb'}});
13
+ t.equal(argv.a.b, 11);
14
+ t.equal(argv.aa.bb, 11);
15
+ t.end();
16
+ });
@@ -0,0 +1,31 @@
1
+ var test = require('tape');
2
+ var parse = require('../');
3
+
4
+ test('long opts', function (t) {
5
+ t.deepEqual(
6
+ parse([ '--bool' ]),
7
+ { bool : true, _ : [] },
8
+ 'long boolean'
9
+ );
10
+ t.deepEqual(
11
+ parse([ '--pow', 'xixxle' ]),
12
+ { pow : 'xixxle', _ : [] },
13
+ 'long capture sp'
14
+ );
15
+ t.deepEqual(
16
+ parse([ '--pow=xixxle' ]),
17
+ { pow : 'xixxle', _ : [] },
18
+ 'long capture eq'
19
+ );
20
+ t.deepEqual(
21
+ parse([ '--host', 'localhost', '--port', '555' ]),
22
+ { host : 'localhost', port : 555, _ : [] },
23
+ 'long captures sp'
24
+ );
25
+ t.deepEqual(
26
+ parse([ '--host=localhost', '--port=555' ]),
27
+ { host : 'localhost', port : 555, _ : [] },
28
+ 'long captures eq'
29
+ );
30
+ t.end();
31
+ });
@@ -0,0 +1,318 @@
1
+ var parse = require('../');
2
+ var test = require('tape');
3
+
4
+ test('parse args', function (t) {
5
+ t.deepEqual(
6
+ parse([ '--no-moo' ]),
7
+ { moo : false, _ : [] },
8
+ 'no'
9
+ );
10
+ t.deepEqual(
11
+ parse([ '-v', 'a', '-v', 'b', '-v', 'c' ]),
12
+ { v : ['a','b','c'], _ : [] },
13
+ 'multi'
14
+ );
15
+ t.end();
16
+ });
17
+
18
+ test('comprehensive', function (t) {
19
+ t.deepEqual(
20
+ parse([
21
+ '--name=meowmers', 'bare', '-cats', 'woo',
22
+ '-h', 'awesome', '--multi=quux',
23
+ '--key', 'value',
24
+ '-b', '--bool', '--no-meep', '--multi=baz',
25
+ '--', '--not-a-flag', 'eek'
26
+ ]),
27
+ {
28
+ c : true,
29
+ a : true,
30
+ t : true,
31
+ s : 'woo',
32
+ h : 'awesome',
33
+ b : true,
34
+ bool : true,
35
+ key : 'value',
36
+ multi : [ 'quux', 'baz' ],
37
+ meep : false,
38
+ name : 'meowmers',
39
+ _ : [ 'bare', '--not-a-flag', 'eek' ]
40
+ }
41
+ );
42
+ t.end();
43
+ });
44
+
45
+ test('nums', function (t) {
46
+ var argv = parse([
47
+ '-x', '1234',
48
+ '-y', '5.67',
49
+ '-z', '1e7',
50
+ '-w', '10f',
51
+ '--hex', '0xdeadbeef',
52
+ '789'
53
+ ]);
54
+ t.deepEqual(argv, {
55
+ x : 1234,
56
+ y : 5.67,
57
+ z : 1e7,
58
+ w : '10f',
59
+ hex : 0xdeadbeef,
60
+ _ : [ 789 ]
61
+ });
62
+ t.deepEqual(typeof argv.x, 'number');
63
+ t.deepEqual(typeof argv.y, 'number');
64
+ t.deepEqual(typeof argv.z, 'number');
65
+ t.deepEqual(typeof argv.w, 'string');
66
+ t.deepEqual(typeof argv.hex, 'number');
67
+ t.deepEqual(typeof argv._[0], 'number');
68
+ t.end();
69
+ });
70
+
71
+ test('flag boolean', function (t) {
72
+ var argv = parse([ '-t', 'moo' ], { boolean: 't' });
73
+ t.deepEqual(argv, { t : true, _ : [ 'moo' ] });
74
+ t.deepEqual(typeof argv.t, 'boolean');
75
+ t.end();
76
+ });
77
+
78
+ test('flag boolean value', function (t) {
79
+ var argv = parse(['--verbose', 'false', 'moo', '-t', 'true'], {
80
+ boolean: [ 't', 'verbose' ],
81
+ default: { verbose: true }
82
+ });
83
+
84
+ t.deepEqual(argv, {
85
+ verbose: false,
86
+ t: true,
87
+ _: ['moo']
88
+ });
89
+
90
+ t.deepEqual(typeof argv.verbose, 'boolean');
91
+ t.deepEqual(typeof argv.t, 'boolean');
92
+ t.end();
93
+ });
94
+
95
+ test('flag boolean default false', function (t) {
96
+ var argv = parse(['moo'], {
97
+ boolean: ['t', 'verbose'],
98
+ default: { verbose: false, t: false }
99
+ });
100
+
101
+ t.deepEqual(argv, {
102
+ verbose: false,
103
+ t: false,
104
+ _: ['moo']
105
+ });
106
+
107
+ t.deepEqual(typeof argv.verbose, 'boolean');
108
+ t.deepEqual(typeof argv.t, 'boolean');
109
+ t.end();
110
+
111
+ });
112
+
113
+ test('boolean groups', function (t) {
114
+ var argv = parse([ '-x', '-z', 'one', 'two', 'three' ], {
115
+ boolean: ['x','y','z']
116
+ });
117
+
118
+ t.deepEqual(argv, {
119
+ x : true,
120
+ y : false,
121
+ z : true,
122
+ _ : [ 'one', 'two', 'three' ]
123
+ });
124
+
125
+ t.deepEqual(typeof argv.x, 'boolean');
126
+ t.deepEqual(typeof argv.y, 'boolean');
127
+ t.deepEqual(typeof argv.z, 'boolean');
128
+ t.end();
129
+ });
130
+
131
+ test('newlines in params' , function (t) {
132
+ var args = parse([ '-s', "X\nX" ])
133
+ t.deepEqual(args, { _ : [], s : "X\nX" });
134
+
135
+ // reproduce in bash:
136
+ // VALUE="new
137
+ // line"
138
+ // node program.js --s="$VALUE"
139
+ args = parse([ "--s=X\nX" ])
140
+ t.deepEqual(args, { _ : [], s : "X\nX" });
141
+ t.end();
142
+ });
143
+
144
+ test('strings' , function (t) {
145
+ var s = parse([ '-s', '0001234' ], { string: 's' }).s;
146
+ t.equal(s, '0001234');
147
+ t.equal(typeof s, 'string');
148
+
149
+ var x = parse([ '-x', '56' ], { string: 'x' }).x;
150
+ t.equal(x, '56');
151
+ t.equal(typeof x, 'string');
152
+ t.end();
153
+ });
154
+
155
+ test('stringArgs', function (t) {
156
+ var s = parse([ ' ', ' ' ], { string: '_' })._;
157
+ t.same(s.length, 2);
158
+ t.same(typeof s[0], 'string');
159
+ t.same(s[0], ' ');
160
+ t.same(typeof s[1], 'string');
161
+ t.same(s[1], ' ');
162
+ t.end();
163
+ });
164
+
165
+ test('empty strings', function(t) {
166
+ var s = parse([ '-s' ], { string: 's' }).s;
167
+ t.equal(s, '');
168
+ t.equal(typeof s, 'string');
169
+
170
+ var str = parse([ '--str' ], { string: 'str' }).str;
171
+ t.equal(str, '');
172
+ t.equal(typeof str, 'string');
173
+
174
+ var letters = parse([ '-art' ], {
175
+ string: [ 'a', 't' ]
176
+ });
177
+
178
+ t.equal(letters.a, '');
179
+ t.equal(letters.r, true);
180
+ t.equal(letters.t, '');
181
+
182
+ t.end();
183
+ });
184
+
185
+
186
+ test('slashBreak', function (t) {
187
+ t.same(
188
+ parse([ '-I/foo/bar/baz' ]),
189
+ { I : '/foo/bar/baz', _ : [] }
190
+ );
191
+ t.same(
192
+ parse([ '-xyz/foo/bar/baz' ]),
193
+ { x : true, y : true, z : '/foo/bar/baz', _ : [] }
194
+ );
195
+ t.end();
196
+ });
197
+
198
+ test('alias', function (t) {
199
+ var argv = parse([ '-f', '11', '--zoom', '55' ], {
200
+ alias: { z: 'zoom' }
201
+ });
202
+ t.equal(argv.zoom, 55);
203
+ t.equal(argv.z, argv.zoom);
204
+ t.equal(argv.f, 11);
205
+ t.end();
206
+ });
207
+
208
+ test('multiAlias', function (t) {
209
+ var argv = parse([ '-f', '11', '--zoom', '55' ], {
210
+ alias: { z: [ 'zm', 'zoom' ] }
211
+ });
212
+ t.equal(argv.zoom, 55);
213
+ t.equal(argv.z, argv.zoom);
214
+ t.equal(argv.z, argv.zm);
215
+ t.equal(argv.f, 11);
216
+ t.end();
217
+ });
218
+
219
+ test('nested dotted objects', function (t) {
220
+ var argv = parse([
221
+ '--foo.bar', '3', '--foo.baz', '4',
222
+ '--foo.quux.quibble', '5', '--foo.quux.o_O',
223
+ '--beep.boop'
224
+ ]);
225
+
226
+ t.same(argv.foo, {
227
+ bar : 3,
228
+ baz : 4,
229
+ quux : {
230
+ quibble : 5,
231
+ o_O : true
232
+ }
233
+ });
234
+ t.same(argv.beep, { boop : true });
235
+ t.end();
236
+ });
237
+
238
+ test('boolean and alias with chainable api', function (t) {
239
+ var aliased = [ '-h', 'derp' ];
240
+ var regular = [ '--herp', 'derp' ];
241
+ var opts = {
242
+ herp: { alias: 'h', boolean: true }
243
+ };
244
+ var aliasedArgv = parse(aliased, {
245
+ boolean: 'herp',
246
+ alias: { h: 'herp' }
247
+ });
248
+ var propertyArgv = parse(regular, {
249
+ boolean: 'herp',
250
+ alias: { h: 'herp' }
251
+ });
252
+ var expected = {
253
+ herp: true,
254
+ h: true,
255
+ '_': [ 'derp' ]
256
+ };
257
+
258
+ t.same(aliasedArgv, expected);
259
+ t.same(propertyArgv, expected);
260
+ t.end();
261
+ });
262
+
263
+ test('boolean and alias with options hash', function (t) {
264
+ var aliased = [ '-h', 'derp' ];
265
+ var regular = [ '--herp', 'derp' ];
266
+ var opts = {
267
+ alias: { 'h': 'herp' },
268
+ boolean: 'herp'
269
+ };
270
+ var aliasedArgv = parse(aliased, opts);
271
+ var propertyArgv = parse(regular, opts);
272
+ var expected = {
273
+ herp: true,
274
+ h: true,
275
+ '_': [ 'derp' ]
276
+ };
277
+ t.same(aliasedArgv, expected);
278
+ t.same(propertyArgv, expected);
279
+ t.end();
280
+ });
281
+
282
+ test('boolean and alias using explicit true', function (t) {
283
+ var aliased = [ '-h', 'true' ];
284
+ var regular = [ '--herp', 'true' ];
285
+ var opts = {
286
+ alias: { h: 'herp' },
287
+ boolean: 'h'
288
+ };
289
+ var aliasedArgv = parse(aliased, opts);
290
+ var propertyArgv = parse(regular, opts);
291
+ var expected = {
292
+ herp: true,
293
+ h: true,
294
+ '_': [ ]
295
+ };
296
+
297
+ t.same(aliasedArgv, expected);
298
+ t.same(propertyArgv, expected);
299
+ t.end();
300
+ });
301
+
302
+ // regression, see https://github.com/substack/node-optimist/issues/71
303
+ test('boolean and --x=true', function(t) {
304
+ var parsed = parse(['--boool', '--other=true'], {
305
+ boolean: 'boool'
306
+ });
307
+
308
+ t.same(parsed.boool, true);
309
+ t.same(parsed.other, 'true');
310
+
311
+ parsed = parse(['--boool', '--other=false'], {
312
+ boolean: 'boool'
313
+ });
314
+
315
+ t.same(parsed.boool, true);
316
+ t.same(parsed.other, 'false');
317
+ t.end();
318
+ });
@@ -0,0 +1,9 @@
1
+ var parse = require('../');
2
+ var test = require('tape');
3
+
4
+ test('parse with modifier functions' , function (t) {
5
+ t.plan(1);
6
+
7
+ var argv = parse([ '-b', '123' ], { boolean: 'b' });
8
+ t.deepEqual(argv, { b: true, _: ['123'] });
9
+ });
@@ -0,0 +1,67 @@
1
+ var parse = require('../');
2
+ var test = require('tape');
3
+
4
+ test('numeric short args', function (t) {
5
+ t.plan(2);
6
+ t.deepEqual(parse([ '-n123' ]), { n: 123, _: [] });
7
+ t.deepEqual(
8
+ parse([ '-123', '456' ]),
9
+ { 1: true, 2: true, 3: 456, _: [] }
10
+ );
11
+ });
12
+
13
+ test('short', function (t) {
14
+ t.deepEqual(
15
+ parse([ '-b' ]),
16
+ { b : true, _ : [] },
17
+ 'short boolean'
18
+ );
19
+ t.deepEqual(
20
+ parse([ 'foo', 'bar', 'baz' ]),
21
+ { _ : [ 'foo', 'bar', 'baz' ] },
22
+ 'bare'
23
+ );
24
+ t.deepEqual(
25
+ parse([ '-cats' ]),
26
+ { c : true, a : true, t : true, s : true, _ : [] },
27
+ 'group'
28
+ );
29
+ t.deepEqual(
30
+ parse([ '-cats', 'meow' ]),
31
+ { c : true, a : true, t : true, s : 'meow', _ : [] },
32
+ 'short group next'
33
+ );
34
+ t.deepEqual(
35
+ parse([ '-h', 'localhost' ]),
36
+ { h : 'localhost', _ : [] },
37
+ 'short capture'
38
+ );
39
+ t.deepEqual(
40
+ parse([ '-h', 'localhost', '-p', '555' ]),
41
+ { h : 'localhost', p : 555, _ : [] },
42
+ 'short captures'
43
+ );
44
+ t.end();
45
+ });
46
+
47
+ test('mixed short bool and capture', function (t) {
48
+ t.same(
49
+ parse([ '-h', 'localhost', '-fp', '555', 'script.js' ]),
50
+ {
51
+ f : true, p : 555, h : 'localhost',
52
+ _ : [ 'script.js' ]
53
+ }
54
+ );
55
+ t.end();
56
+ });
57
+
58
+ test('short and long', function (t) {
59
+ t.deepEqual(
60
+ parse([ '-h', 'localhost', '-fp', '555', 'script.js' ]),
61
+ {
62
+ f : true, p : 555, h : 'localhost',
63
+ _ : [ 'script.js' ]
64
+ }
65
+ );
66
+ t.end();
67
+ });