dragonfly_chrome_headless 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +12 -0
- data/Gemfile +4 -0
- data/README.md +53 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dragonfly_chrome_headless.gemspec +27 -0
- data/lib/dragonfly_chrome_headless.rb +9 -0
- data/lib/dragonfly_chrome_headless/plugin.rb +17 -0
- data/lib/dragonfly_chrome_headless/processors/rasterize.rb +33 -0
- data/lib/dragonfly_chrome_headless/version.rb +3 -0
- data/node_modules/.bin/chrome-remote-interface +1 -0
- data/node_modules/.bin/mkdirp +1 -0
- data/node_modules/.bin/rimraf +1 -0
- data/node_modules/@types/core-js/LICENSE +21 -0
- data/node_modules/@types/core-js/README.md +16 -0
- data/node_modules/@types/core-js/index.d.ts +2452 -0
- data/node_modules/@types/core-js/package.json +85 -0
- data/node_modules/@types/mkdirp/README.md +18 -0
- data/node_modules/@types/mkdirp/index.d.ts +14 -0
- data/node_modules/@types/mkdirp/package.json +77 -0
- data/node_modules/@types/mkdirp/types-metadata.json +25 -0
- data/node_modules/@types/node/README.md +16 -0
- data/node_modules/@types/node/index.d.ts +4132 -0
- data/node_modules/@types/node/package.json +84 -0
- data/node_modules/balanced-match/.npmignore +5 -0
- data/node_modules/balanced-match/LICENSE.md +21 -0
- data/node_modules/balanced-match/README.md +91 -0
- data/node_modules/balanced-match/index.js +59 -0
- data/node_modules/balanced-match/package.json +112 -0
- data/node_modules/brace-expansion/README.md +123 -0
- data/node_modules/brace-expansion/index.js +201 -0
- data/node_modules/brace-expansion/package.json +114 -0
- data/node_modules/chrome-launcher/.clang-format +6 -0
- data/node_modules/chrome-launcher/.npmignore +11 -0
- data/node_modules/chrome-launcher/README.md +123 -0
- data/node_modules/chrome-launcher/ask.js +32 -0
- data/node_modules/chrome-launcher/ask.ts +35 -0
- data/node_modules/chrome-launcher/chrome-finder.js +157 -0
- data/node_modules/chrome-launcher/chrome-finder.ts +186 -0
- data/node_modules/chrome-launcher/chrome-launcher.js +245 -0
- data/node_modules/chrome-launcher/chrome-launcher.ts +312 -0
- data/node_modules/chrome-launcher/compiled-check.js +14 -0
- data/node_modules/chrome-launcher/flags.js +27 -0
- data/node_modules/chrome-launcher/flags.ts +26 -0
- data/node_modules/chrome-launcher/index.js +7 -0
- data/node_modules/chrome-launcher/index.ts +1 -0
- data/node_modules/chrome-launcher/manual-chrome-launcher.js +30 -0
- data/node_modules/chrome-launcher/package.json +116 -0
- data/node_modules/chrome-launcher/random-port.js +24 -0
- data/node_modules/chrome-launcher/random-port.ts +23 -0
- data/node_modules/chrome-launcher/tsconfig.json +19 -0
- data/node_modules/chrome-launcher/utils.js +52 -0
- data/node_modules/chrome-launcher/utils.ts +44 -0
- data/node_modules/chrome-launcher/yarn.lock +1486 -0
- data/node_modules/chrome-remote-interface/LICENSE +18 -0
- data/node_modules/chrome-remote-interface/README.md +849 -0
- data/node_modules/chrome-remote-interface/bin/client.js +337 -0
- data/node_modules/chrome-remote-interface/chrome-remote-interface.js +11 -0
- data/node_modules/chrome-remote-interface/index.js +39 -0
- data/node_modules/chrome-remote-interface/lib/api.js +84 -0
- data/node_modules/chrome-remote-interface/lib/chrome.js +307 -0
- data/node_modules/chrome-remote-interface/lib/defaults.js +4 -0
- data/node_modules/chrome-remote-interface/lib/devtools.js +245 -0
- data/node_modules/chrome-remote-interface/lib/external-request.js +28 -0
- data/node_modules/chrome-remote-interface/lib/protocol.json +13780 -0
- data/node_modules/chrome-remote-interface/lib/websocket-wrapper.js +32 -0
- data/node_modules/chrome-remote-interface/package.json +128 -0
- data/node_modules/chrome-remote-interface/webpack.config.js +55 -0
- data/node_modules/commander/Readme.md +195 -0
- data/node_modules/commander/index.js +851 -0
- data/node_modules/commander/package.json +92 -0
- data/node_modules/concat-map/.travis.yml +4 -0
- data/node_modules/concat-map/LICENSE +18 -0
- data/node_modules/concat-map/README.markdown +62 -0
- data/node_modules/concat-map/example/map.js +6 -0
- data/node_modules/concat-map/index.js +13 -0
- data/node_modules/concat-map/package.json +117 -0
- data/node_modules/concat-map/test/map.js +39 -0
- data/node_modules/debug/.coveralls.yml +1 -0
- data/node_modules/debug/.eslintrc +11 -0
- data/node_modules/debug/.npmignore +9 -0
- data/node_modules/debug/.travis.yml +14 -0
- data/node_modules/debug/CHANGELOG.md +357 -0
- data/node_modules/debug/LICENSE +19 -0
- data/node_modules/debug/Makefile +50 -0
- data/node_modules/debug/Readme.md +312 -0
- data/node_modules/debug/component.json +19 -0
- data/node_modules/debug/karma.conf.js +70 -0
- data/node_modules/debug/node.js +1 -0
- data/node_modules/debug/package.json +124 -0
- data/node_modules/debug/src/browser.js +185 -0
- data/node_modules/debug/src/debug.js +202 -0
- data/node_modules/debug/src/index.js +10 -0
- data/node_modules/debug/src/node.js +246 -0
- data/node_modules/fs.realpath/LICENSE +43 -0
- data/node_modules/fs.realpath/README.md +33 -0
- data/node_modules/fs.realpath/index.js +66 -0
- data/node_modules/fs.realpath/old.js +303 -0
- data/node_modules/fs.realpath/package.json +94 -0
- data/node_modules/glob/LICENSE +15 -0
- data/node_modules/glob/README.md +368 -0
- data/node_modules/glob/changelog.md +67 -0
- data/node_modules/glob/common.js +240 -0
- data/node_modules/glob/glob.js +790 -0
- data/node_modules/glob/package.json +112 -0
- data/node_modules/glob/sync.js +486 -0
- data/node_modules/html-pdf-chrome/.npmignore +9 -0
- data/node_modules/html-pdf-chrome/LICENSE +21 -0
- data/node_modules/html-pdf-chrome/README.md +165 -0
- data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.d.ts +87 -0
- data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.js +4 -0
- data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.js.map +1 -0
- data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.d.ts +120 -0
- data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.js +206 -0
- data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.js.map +1 -0
- data/node_modules/html-pdf-chrome/lib/src/CreateResult.d.ts +70 -0
- data/node_modules/html-pdf-chrome/lib/src/CreateResult.js +98 -0
- data/node_modules/html-pdf-chrome/lib/src/CreateResult.js.map +1 -0
- data/node_modules/html-pdf-chrome/lib/src/index.d.ts +72 -0
- data/node_modules/html-pdf-chrome/lib/src/index.js +123 -0
- data/node_modules/html-pdf-chrome/lib/src/index.js.map +1 -0
- data/node_modules/html-pdf-chrome/package.json +133 -0
- data/node_modules/html-pdf-chrome/src/ChromePrintOptions.ts +99 -0
- data/node_modules/html-pdf-chrome/src/CompletionTrigger.ts +201 -0
- data/node_modules/html-pdf-chrome/src/CreateResult.ts +100 -0
- data/node_modules/html-pdf-chrome/src/index.ts +179 -0
- data/node_modules/inflight/LICENSE +15 -0
- data/node_modules/inflight/README.md +37 -0
- data/node_modules/inflight/inflight.js +54 -0
- data/node_modules/inflight/package.json +105 -0
- data/node_modules/inherits/LICENSE +16 -0
- data/node_modules/inherits/README.md +42 -0
- data/node_modules/inherits/inherits.js +7 -0
- data/node_modules/inherits/inherits_browser.js +23 -0
- data/node_modules/inherits/package.json +97 -0
- data/node_modules/lighthouse-logger/README.md +4 -0
- data/node_modules/lighthouse-logger/index.js +212 -0
- data/node_modules/lighthouse-logger/package.json +69 -0
- data/node_modules/lighthouse-logger/yarn.lock +13 -0
- data/node_modules/minimatch/LICENSE +15 -0
- data/node_modules/minimatch/README.md +209 -0
- data/node_modules/minimatch/minimatch.js +923 -0
- data/node_modules/minimatch/package.json +99 -0
- data/node_modules/minimist/.travis.yml +4 -0
- data/node_modules/minimist/LICENSE +18 -0
- data/node_modules/minimist/example/parse.js +2 -0
- data/node_modules/minimist/index.js +187 -0
- data/node_modules/minimist/package.json +101 -0
- data/node_modules/minimist/readme.markdown +73 -0
- data/node_modules/minimist/test/dash.js +24 -0
- data/node_modules/minimist/test/default_bool.js +20 -0
- data/node_modules/minimist/test/dotted.js +16 -0
- data/node_modules/minimist/test/long.js +31 -0
- data/node_modules/minimist/test/parse.js +318 -0
- data/node_modules/minimist/test/parse_modified.js +9 -0
- data/node_modules/minimist/test/short.js +67 -0
- data/node_modules/minimist/test/whitespace.js +8 -0
- data/node_modules/mkdirp/.travis.yml +8 -0
- data/node_modules/mkdirp/LICENSE +21 -0
- data/node_modules/mkdirp/bin/cmd.js +33 -0
- data/node_modules/mkdirp/bin/usage.txt +12 -0
- data/node_modules/mkdirp/examples/pow.js +6 -0
- data/node_modules/mkdirp/index.js +98 -0
- data/node_modules/mkdirp/package.json +93 -0
- data/node_modules/mkdirp/readme.markdown +100 -0
- data/node_modules/mkdirp/test/chmod.js +41 -0
- data/node_modules/mkdirp/test/clobber.js +38 -0
- data/node_modules/mkdirp/test/mkdirp.js +28 -0
- data/node_modules/mkdirp/test/opts_fs.js +29 -0
- data/node_modules/mkdirp/test/opts_fs_sync.js +27 -0
- data/node_modules/mkdirp/test/perm.js +32 -0
- data/node_modules/mkdirp/test/perm_sync.js +36 -0
- data/node_modules/mkdirp/test/race.js +37 -0
- data/node_modules/mkdirp/test/rel.js +32 -0
- data/node_modules/mkdirp/test/return.js +25 -0
- data/node_modules/mkdirp/test/return_sync.js +24 -0
- data/node_modules/mkdirp/test/root.js +19 -0
- data/node_modules/mkdirp/test/sync.js +32 -0
- data/node_modules/mkdirp/test/umask.js +28 -0
- data/node_modules/mkdirp/test/umask_sync.js +32 -0
- data/node_modules/ms/README.md +51 -0
- data/node_modules/ms/index.js +152 -0
- data/node_modules/ms/license.md +21 -0
- data/node_modules/ms/package.json +109 -0
- data/node_modules/once/LICENSE +15 -0
- data/node_modules/once/README.md +79 -0
- data/node_modules/once/once.js +42 -0
- data/node_modules/once/package.json +101 -0
- data/node_modules/path-is-absolute/index.js +20 -0
- data/node_modules/path-is-absolute/license +21 -0
- data/node_modules/path-is-absolute/package.json +111 -0
- data/node_modules/path-is-absolute/readme.md +59 -0
- data/node_modules/rimraf/LICENSE +15 -0
- data/node_modules/rimraf/README.md +101 -0
- data/node_modules/rimraf/bin.js +50 -0
- data/node_modules/rimraf/package.json +99 -0
- data/node_modules/rimraf/rimraf.js +363 -0
- data/node_modules/ultron/LICENSE +22 -0
- data/node_modules/ultron/index.js +138 -0
- data/node_modules/ultron/package.json +112 -0
- data/node_modules/wrappy/LICENSE +15 -0
- data/node_modules/wrappy/README.md +36 -0
- data/node_modules/wrappy/package.json +97 -0
- data/node_modules/wrappy/wrappy.js +33 -0
- data/node_modules/ws/LICENSE +21 -0
- data/node_modules/ws/README.md +259 -0
- data/node_modules/ws/SECURITY.md +33 -0
- data/node_modules/ws/index.js +15 -0
- data/node_modules/ws/lib/BufferUtil.fallback.js +56 -0
- data/node_modules/ws/lib/BufferUtil.js +15 -0
- data/node_modules/ws/lib/ErrorCodes.js +28 -0
- data/node_modules/ws/lib/EventTarget.js +158 -0
- data/node_modules/ws/lib/Extensions.js +69 -0
- data/node_modules/ws/lib/PerMessageDeflate.js +339 -0
- data/node_modules/ws/lib/Receiver.js +520 -0
- data/node_modules/ws/lib/Sender.js +438 -0
- data/node_modules/ws/lib/Validation.fallback.js +9 -0
- data/node_modules/ws/lib/Validation.js +17 -0
- data/node_modules/ws/lib/WebSocket.js +705 -0
- data/node_modules/ws/lib/WebSocketServer.js +336 -0
- data/node_modules/ws/package.json +122 -0
- data/package.json +26 -0
- data/samples/sample.html +13 -0
- data/script/rasterize.js +18 -0
- metadata +325 -0
@@ -0,0 +1,152 @@
|
|
1
|
+
/**
|
2
|
+
* Helpers.
|
3
|
+
*/
|
4
|
+
|
5
|
+
var s = 1000;
|
6
|
+
var m = s * 60;
|
7
|
+
var h = m * 60;
|
8
|
+
var d = h * 24;
|
9
|
+
var y = d * 365.25;
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Parse or format the given `val`.
|
13
|
+
*
|
14
|
+
* Options:
|
15
|
+
*
|
16
|
+
* - `long` verbose formatting [false]
|
17
|
+
*
|
18
|
+
* @param {String|Number} val
|
19
|
+
* @param {Object} [options]
|
20
|
+
* @throws {Error} throw an error if val is not a non-empty string or a number
|
21
|
+
* @return {String|Number}
|
22
|
+
* @api public
|
23
|
+
*/
|
24
|
+
|
25
|
+
module.exports = function(val, options) {
|
26
|
+
options = options || {};
|
27
|
+
var type = typeof val;
|
28
|
+
if (type === 'string' && val.length > 0) {
|
29
|
+
return parse(val);
|
30
|
+
} else if (type === 'number' && isNaN(val) === false) {
|
31
|
+
return options.long ? fmtLong(val) : fmtShort(val);
|
32
|
+
}
|
33
|
+
throw new Error(
|
34
|
+
'val is not a non-empty string or a valid number. val=' +
|
35
|
+
JSON.stringify(val)
|
36
|
+
);
|
37
|
+
};
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Parse the given `str` and return milliseconds.
|
41
|
+
*
|
42
|
+
* @param {String} str
|
43
|
+
* @return {Number}
|
44
|
+
* @api private
|
45
|
+
*/
|
46
|
+
|
47
|
+
function parse(str) {
|
48
|
+
str = String(str);
|
49
|
+
if (str.length > 100) {
|
50
|
+
return;
|
51
|
+
}
|
52
|
+
var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(
|
53
|
+
str
|
54
|
+
);
|
55
|
+
if (!match) {
|
56
|
+
return;
|
57
|
+
}
|
58
|
+
var n = parseFloat(match[1]);
|
59
|
+
var type = (match[2] || 'ms').toLowerCase();
|
60
|
+
switch (type) {
|
61
|
+
case 'years':
|
62
|
+
case 'year':
|
63
|
+
case 'yrs':
|
64
|
+
case 'yr':
|
65
|
+
case 'y':
|
66
|
+
return n * y;
|
67
|
+
case 'days':
|
68
|
+
case 'day':
|
69
|
+
case 'd':
|
70
|
+
return n * d;
|
71
|
+
case 'hours':
|
72
|
+
case 'hour':
|
73
|
+
case 'hrs':
|
74
|
+
case 'hr':
|
75
|
+
case 'h':
|
76
|
+
return n * h;
|
77
|
+
case 'minutes':
|
78
|
+
case 'minute':
|
79
|
+
case 'mins':
|
80
|
+
case 'min':
|
81
|
+
case 'm':
|
82
|
+
return n * m;
|
83
|
+
case 'seconds':
|
84
|
+
case 'second':
|
85
|
+
case 'secs':
|
86
|
+
case 'sec':
|
87
|
+
case 's':
|
88
|
+
return n * s;
|
89
|
+
case 'milliseconds':
|
90
|
+
case 'millisecond':
|
91
|
+
case 'msecs':
|
92
|
+
case 'msec':
|
93
|
+
case 'ms':
|
94
|
+
return n;
|
95
|
+
default:
|
96
|
+
return undefined;
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
/**
|
101
|
+
* Short format for `ms`.
|
102
|
+
*
|
103
|
+
* @param {Number} ms
|
104
|
+
* @return {String}
|
105
|
+
* @api private
|
106
|
+
*/
|
107
|
+
|
108
|
+
function fmtShort(ms) {
|
109
|
+
if (ms >= d) {
|
110
|
+
return Math.round(ms / d) + 'd';
|
111
|
+
}
|
112
|
+
if (ms >= h) {
|
113
|
+
return Math.round(ms / h) + 'h';
|
114
|
+
}
|
115
|
+
if (ms >= m) {
|
116
|
+
return Math.round(ms / m) + 'm';
|
117
|
+
}
|
118
|
+
if (ms >= s) {
|
119
|
+
return Math.round(ms / s) + 's';
|
120
|
+
}
|
121
|
+
return ms + 'ms';
|
122
|
+
}
|
123
|
+
|
124
|
+
/**
|
125
|
+
* Long format for `ms`.
|
126
|
+
*
|
127
|
+
* @param {Number} ms
|
128
|
+
* @return {String}
|
129
|
+
* @api private
|
130
|
+
*/
|
131
|
+
|
132
|
+
function fmtLong(ms) {
|
133
|
+
return plural(ms, d, 'day') ||
|
134
|
+
plural(ms, h, 'hour') ||
|
135
|
+
plural(ms, m, 'minute') ||
|
136
|
+
plural(ms, s, 'second') ||
|
137
|
+
ms + ' ms';
|
138
|
+
}
|
139
|
+
|
140
|
+
/**
|
141
|
+
* Pluralization helper.
|
142
|
+
*/
|
143
|
+
|
144
|
+
function plural(ms, n, name) {
|
145
|
+
if (ms < n) {
|
146
|
+
return;
|
147
|
+
}
|
148
|
+
if (ms < n * 1.5) {
|
149
|
+
return Math.floor(ms / n) + ' ' + name;
|
150
|
+
}
|
151
|
+
return Math.ceil(ms / n) + ' ' + name + 's';
|
152
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Zeit, Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,109 @@
|
|
1
|
+
{
|
2
|
+
"_args": [
|
3
|
+
[
|
4
|
+
{
|
5
|
+
"raw": "ms@2.0.0",
|
6
|
+
"scope": null,
|
7
|
+
"escapedName": "ms",
|
8
|
+
"name": "ms",
|
9
|
+
"rawSpec": "2.0.0",
|
10
|
+
"spec": "2.0.0",
|
11
|
+
"type": "version"
|
12
|
+
},
|
13
|
+
"/Users/tomascelizna/Devel/dragonfly_chrome_headless/node_modules/debug"
|
14
|
+
]
|
15
|
+
],
|
16
|
+
"_from": "ms@2.0.0",
|
17
|
+
"_id": "ms@2.0.0",
|
18
|
+
"_inCache": true,
|
19
|
+
"_location": "/ms",
|
20
|
+
"_nodeVersion": "7.8.0",
|
21
|
+
"_npmOperationalInternal": {
|
22
|
+
"host": "packages-18-east.internal.npmjs.com",
|
23
|
+
"tmp": "tmp/ms-2.0.0.tgz_1494937565215_0.34005374647676945"
|
24
|
+
},
|
25
|
+
"_npmUser": {
|
26
|
+
"name": "leo",
|
27
|
+
"email": "leo@zeit.co"
|
28
|
+
},
|
29
|
+
"_npmVersion": "4.2.0",
|
30
|
+
"_phantomChildren": {},
|
31
|
+
"_requested": {
|
32
|
+
"raw": "ms@2.0.0",
|
33
|
+
"scope": null,
|
34
|
+
"escapedName": "ms",
|
35
|
+
"name": "ms",
|
36
|
+
"rawSpec": "2.0.0",
|
37
|
+
"spec": "2.0.0",
|
38
|
+
"type": "version"
|
39
|
+
},
|
40
|
+
"_requiredBy": [
|
41
|
+
"/debug"
|
42
|
+
],
|
43
|
+
"_resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
44
|
+
"_shasum": "5608aeadfc00be6c2901df5f9861788de0d597c8",
|
45
|
+
"_shrinkwrap": null,
|
46
|
+
"_spec": "ms@2.0.0",
|
47
|
+
"_where": "/Users/tomascelizna/Devel/dragonfly_chrome_headless/node_modules/debug",
|
48
|
+
"bugs": {
|
49
|
+
"url": "https://github.com/zeit/ms/issues"
|
50
|
+
},
|
51
|
+
"dependencies": {},
|
52
|
+
"description": "Tiny milisecond conversion utility",
|
53
|
+
"devDependencies": {
|
54
|
+
"eslint": "3.19.0",
|
55
|
+
"expect.js": "0.3.1",
|
56
|
+
"husky": "0.13.3",
|
57
|
+
"lint-staged": "3.4.1",
|
58
|
+
"mocha": "3.4.1"
|
59
|
+
},
|
60
|
+
"directories": {},
|
61
|
+
"dist": {
|
62
|
+
"shasum": "5608aeadfc00be6c2901df5f9861788de0d597c8",
|
63
|
+
"tarball": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz"
|
64
|
+
},
|
65
|
+
"eslintConfig": {
|
66
|
+
"extends": "eslint:recommended",
|
67
|
+
"env": {
|
68
|
+
"node": true,
|
69
|
+
"es6": true
|
70
|
+
}
|
71
|
+
},
|
72
|
+
"files": [
|
73
|
+
"index.js"
|
74
|
+
],
|
75
|
+
"gitHead": "9b88d1568a52ec9bb67ecc8d2aa224fa38fd41f4",
|
76
|
+
"homepage": "https://github.com/zeit/ms#readme",
|
77
|
+
"license": "MIT",
|
78
|
+
"lint-staged": {
|
79
|
+
"*.js": [
|
80
|
+
"npm run lint",
|
81
|
+
"prettier --single-quote --write",
|
82
|
+
"git add"
|
83
|
+
]
|
84
|
+
},
|
85
|
+
"main": "./index",
|
86
|
+
"maintainers": [
|
87
|
+
{
|
88
|
+
"name": "leo",
|
89
|
+
"email": "leo@zeit.co"
|
90
|
+
},
|
91
|
+
{
|
92
|
+
"name": "rauchg",
|
93
|
+
"email": "rauchg@gmail.com"
|
94
|
+
}
|
95
|
+
],
|
96
|
+
"name": "ms",
|
97
|
+
"optionalDependencies": {},
|
98
|
+
"readme": "ERROR: No README data found!",
|
99
|
+
"repository": {
|
100
|
+
"type": "git",
|
101
|
+
"url": "git+https://github.com/zeit/ms.git"
|
102
|
+
},
|
103
|
+
"scripts": {
|
104
|
+
"lint": "eslint lib/* bin/*",
|
105
|
+
"precommit": "lint-staged",
|
106
|
+
"test": "mocha tests.js"
|
107
|
+
},
|
108
|
+
"version": "2.0.0"
|
109
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
The ISC License
|
2
|
+
|
3
|
+
Copyright (c) Isaac Z. Schlueter and Contributors
|
4
|
+
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
15
|
+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# once
|
2
|
+
|
3
|
+
Only call a function once.
|
4
|
+
|
5
|
+
## usage
|
6
|
+
|
7
|
+
```javascript
|
8
|
+
var once = require('once')
|
9
|
+
|
10
|
+
function load (file, cb) {
|
11
|
+
cb = once(cb)
|
12
|
+
loader.load('file')
|
13
|
+
loader.once('load', cb)
|
14
|
+
loader.once('error', cb)
|
15
|
+
}
|
16
|
+
```
|
17
|
+
|
18
|
+
Or add to the Function.prototype in a responsible way:
|
19
|
+
|
20
|
+
```javascript
|
21
|
+
// only has to be done once
|
22
|
+
require('once').proto()
|
23
|
+
|
24
|
+
function load (file, cb) {
|
25
|
+
cb = cb.once()
|
26
|
+
loader.load('file')
|
27
|
+
loader.once('load', cb)
|
28
|
+
loader.once('error', cb)
|
29
|
+
}
|
30
|
+
```
|
31
|
+
|
32
|
+
Ironically, the prototype feature makes this module twice as
|
33
|
+
complicated as necessary.
|
34
|
+
|
35
|
+
To check whether you function has been called, use `fn.called`. Once the
|
36
|
+
function is called for the first time the return value of the original
|
37
|
+
function is saved in `fn.value` and subsequent calls will continue to
|
38
|
+
return this value.
|
39
|
+
|
40
|
+
```javascript
|
41
|
+
var once = require('once')
|
42
|
+
|
43
|
+
function load (cb) {
|
44
|
+
cb = once(cb)
|
45
|
+
var stream = createStream()
|
46
|
+
stream.once('data', cb)
|
47
|
+
stream.once('end', function () {
|
48
|
+
if (!cb.called) cb(new Error('not found'))
|
49
|
+
})
|
50
|
+
}
|
51
|
+
```
|
52
|
+
|
53
|
+
## `once.strict(func)`
|
54
|
+
|
55
|
+
Throw an error if the function is called twice.
|
56
|
+
|
57
|
+
Some functions are expected to be called only once. Using `once` for them would
|
58
|
+
potentially hide logical errors.
|
59
|
+
|
60
|
+
In the example below, the `greet` function has to call the callback only once:
|
61
|
+
|
62
|
+
```javascript
|
63
|
+
function greet (name, cb) {
|
64
|
+
// return is missing from the if statement
|
65
|
+
// when no name is passed, the callback is called twice
|
66
|
+
if (!name) cb('Hello anonymous')
|
67
|
+
cb('Hello ' + name)
|
68
|
+
}
|
69
|
+
|
70
|
+
function log (msg) {
|
71
|
+
console.log(msg)
|
72
|
+
}
|
73
|
+
|
74
|
+
// this will print 'Hello anonymous' but the logical error will be missed
|
75
|
+
greet(null, once(msg))
|
76
|
+
|
77
|
+
// once.strict will print 'Hello anonymous' and throw an error when the callback will be called the second time
|
78
|
+
greet(null, once.strict(msg))
|
79
|
+
```
|
@@ -0,0 +1,42 @@
|
|
1
|
+
var wrappy = require('wrappy')
|
2
|
+
module.exports = wrappy(once)
|
3
|
+
module.exports.strict = wrappy(onceStrict)
|
4
|
+
|
5
|
+
once.proto = once(function () {
|
6
|
+
Object.defineProperty(Function.prototype, 'once', {
|
7
|
+
value: function () {
|
8
|
+
return once(this)
|
9
|
+
},
|
10
|
+
configurable: true
|
11
|
+
})
|
12
|
+
|
13
|
+
Object.defineProperty(Function.prototype, 'onceStrict', {
|
14
|
+
value: function () {
|
15
|
+
return onceStrict(this)
|
16
|
+
},
|
17
|
+
configurable: true
|
18
|
+
})
|
19
|
+
})
|
20
|
+
|
21
|
+
function once (fn) {
|
22
|
+
var f = function () {
|
23
|
+
if (f.called) return f.value
|
24
|
+
f.called = true
|
25
|
+
return f.value = fn.apply(this, arguments)
|
26
|
+
}
|
27
|
+
f.called = false
|
28
|
+
return f
|
29
|
+
}
|
30
|
+
|
31
|
+
function onceStrict (fn) {
|
32
|
+
var f = function () {
|
33
|
+
if (f.called)
|
34
|
+
throw new Error(f.onceError)
|
35
|
+
f.called = true
|
36
|
+
return f.value = fn.apply(this, arguments)
|
37
|
+
}
|
38
|
+
var name = fn.name || 'Function wrapped with `once`'
|
39
|
+
f.onceError = name + " shouldn't be called more than once"
|
40
|
+
f.called = false
|
41
|
+
return f
|
42
|
+
}
|
@@ -0,0 +1,101 @@
|
|
1
|
+
{
|
2
|
+
"_args": [
|
3
|
+
[
|
4
|
+
{
|
5
|
+
"raw": "once@^1.3.0",
|
6
|
+
"scope": null,
|
7
|
+
"escapedName": "once",
|
8
|
+
"name": "once",
|
9
|
+
"rawSpec": "^1.3.0",
|
10
|
+
"spec": ">=1.3.0 <2.0.0",
|
11
|
+
"type": "range"
|
12
|
+
},
|
13
|
+
"/Users/tomascelizna/Devel/dragonfly_chrome_headless/node_modules/glob"
|
14
|
+
]
|
15
|
+
],
|
16
|
+
"_from": "once@>=1.3.0 <2.0.0",
|
17
|
+
"_id": "once@1.4.0",
|
18
|
+
"_inCache": true,
|
19
|
+
"_location": "/once",
|
20
|
+
"_nodeVersion": "6.5.0",
|
21
|
+
"_npmOperationalInternal": {
|
22
|
+
"host": "packages-12-west.internal.npmjs.com",
|
23
|
+
"tmp": "tmp/once-1.4.0.tgz_1473196269128_0.537820661207661"
|
24
|
+
},
|
25
|
+
"_npmUser": {
|
26
|
+
"name": "isaacs",
|
27
|
+
"email": "i@izs.me"
|
28
|
+
},
|
29
|
+
"_npmVersion": "3.10.7",
|
30
|
+
"_phantomChildren": {},
|
31
|
+
"_requested": {
|
32
|
+
"raw": "once@^1.3.0",
|
33
|
+
"scope": null,
|
34
|
+
"escapedName": "once",
|
35
|
+
"name": "once",
|
36
|
+
"rawSpec": "^1.3.0",
|
37
|
+
"spec": ">=1.3.0 <2.0.0",
|
38
|
+
"type": "range"
|
39
|
+
},
|
40
|
+
"_requiredBy": [
|
41
|
+
"/glob",
|
42
|
+
"/inflight"
|
43
|
+
],
|
44
|
+
"_resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
45
|
+
"_shasum": "583b1aa775961d4b113ac17d9c50baef9dd76bd1",
|
46
|
+
"_shrinkwrap": null,
|
47
|
+
"_spec": "once@^1.3.0",
|
48
|
+
"_where": "/Users/tomascelizna/Devel/dragonfly_chrome_headless/node_modules/glob",
|
49
|
+
"author": {
|
50
|
+
"name": "Isaac Z. Schlueter",
|
51
|
+
"email": "i@izs.me",
|
52
|
+
"url": "http://blog.izs.me/"
|
53
|
+
},
|
54
|
+
"bugs": {
|
55
|
+
"url": "https://github.com/isaacs/once/issues"
|
56
|
+
},
|
57
|
+
"dependencies": {
|
58
|
+
"wrappy": "1"
|
59
|
+
},
|
60
|
+
"description": "Run a function exactly one time",
|
61
|
+
"devDependencies": {
|
62
|
+
"tap": "^7.0.1"
|
63
|
+
},
|
64
|
+
"directories": {
|
65
|
+
"test": "test"
|
66
|
+
},
|
67
|
+
"dist": {
|
68
|
+
"shasum": "583b1aa775961d4b113ac17d9c50baef9dd76bd1",
|
69
|
+
"tarball": "https://registry.npmjs.org/once/-/once-1.4.0.tgz"
|
70
|
+
},
|
71
|
+
"files": [
|
72
|
+
"once.js"
|
73
|
+
],
|
74
|
+
"gitHead": "0e614d9f5a7e6f0305c625f6b581f6d80b33b8a6",
|
75
|
+
"homepage": "https://github.com/isaacs/once#readme",
|
76
|
+
"keywords": [
|
77
|
+
"once",
|
78
|
+
"function",
|
79
|
+
"one",
|
80
|
+
"single"
|
81
|
+
],
|
82
|
+
"license": "ISC",
|
83
|
+
"main": "once.js",
|
84
|
+
"maintainers": [
|
85
|
+
{
|
86
|
+
"name": "isaacs",
|
87
|
+
"email": "i@izs.me"
|
88
|
+
}
|
89
|
+
],
|
90
|
+
"name": "once",
|
91
|
+
"optionalDependencies": {},
|
92
|
+
"readme": "ERROR: No README data found!",
|
93
|
+
"repository": {
|
94
|
+
"type": "git",
|
95
|
+
"url": "git://github.com/isaacs/once.git"
|
96
|
+
},
|
97
|
+
"scripts": {
|
98
|
+
"test": "tap test/*.js"
|
99
|
+
},
|
100
|
+
"version": "1.4.0"
|
101
|
+
}
|