vaderjs 1.3.2 → 1.3.4
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.
- package/create-vader-app/example_proj/dist/vaderjs/index.js +5 -0
- package/create-vader-app/example_proj/dist/vaderjs/vader-min.js +1115 -0
- package/create-vader-app/example_proj/dist/vaderjs/vaderRouter-min.js +1 -0
- package/create-vader-app/example_proj/dist/vaderjs/worker.js +327 -0
- package/create-vader-app/example_proj/index.html +20 -0
- package/create-vader-app/example_proj/readme.md +2 -0
- package/create-vader-app/example_proj/src/pages/Index.js +13 -0
- package/create-vader-app/example_proj/src/views/app.html +16 -0
- package/create-vader-app/index.js +20 -0
- package/create-vader-app/node_modules/.package-lock.json +350 -0
- package/create-vader-app/node_modules/chalk/license +9 -0
- package/create-vader-app/node_modules/chalk/package.json +83 -0
- package/create-vader-app/node_modules/chalk/readme.md +325 -0
- package/create-vader-app/node_modules/chalk/source/index.d.ts +320 -0
- package/create-vader-app/node_modules/chalk/source/index.js +225 -0
- package/create-vader-app/node_modules/chalk/source/utilities.js +33 -0
- package/create-vader-app/node_modules/chalk/source/vendor/ansi-styles/index.d.ts +236 -0
- package/create-vader-app/node_modules/chalk/source/vendor/ansi-styles/index.js +223 -0
- package/create-vader-app/node_modules/chalk/source/vendor/supports-color/browser.d.ts +1 -0
- package/create-vader-app/node_modules/chalk/source/vendor/supports-color/browser.js +30 -0
- package/create-vader-app/node_modules/chalk/source/vendor/supports-color/index.d.ts +55 -0
- package/create-vader-app/node_modules/chalk/source/vendor/supports-color/index.js +182 -0
- package/create-vader-app/node_modules/commander/LICENSE +22 -0
- package/create-vader-app/node_modules/commander/Readme.md +1146 -0
- package/create-vader-app/node_modules/commander/esm.mjs +16 -0
- package/create-vader-app/node_modules/commander/index.js +27 -0
- package/create-vader-app/node_modules/commander/lib/argument.js +147 -0
- package/create-vader-app/node_modules/commander/lib/command.js +2196 -0
- package/create-vader-app/node_modules/commander/lib/error.js +45 -0
- package/create-vader-app/node_modules/commander/lib/help.js +464 -0
- package/create-vader-app/node_modules/commander/lib/option.js +331 -0
- package/create-vader-app/node_modules/commander/lib/suggestSimilar.js +100 -0
- package/create-vader-app/node_modules/commander/package-support.json +16 -0
- package/create-vader-app/node_modules/commander/package.json +90 -0
- package/create-vader-app/node_modules/commander/typings/esm.d.mts +3 -0
- package/create-vader-app/node_modules/commander/typings/index.d.ts +889 -0
- package/create-vader-app/node_modules/fs-extra/LICENSE +15 -0
- package/create-vader-app/node_modules/fs-extra/README.md +292 -0
- package/create-vader-app/node_modules/fs-extra/lib/copy/copy-sync.js +161 -0
- package/create-vader-app/node_modules/fs-extra/lib/copy/copy.js +238 -0
- package/create-vader-app/node_modules/fs-extra/lib/copy/index.js +7 -0
- package/create-vader-app/node_modules/fs-extra/lib/empty/index.js +39 -0
- package/create-vader-app/node_modules/fs-extra/lib/ensure/file.js +69 -0
- package/create-vader-app/node_modules/fs-extra/lib/ensure/index.js +23 -0
- package/create-vader-app/node_modules/fs-extra/lib/ensure/link.js +64 -0
- package/create-vader-app/node_modules/fs-extra/lib/ensure/symlink-paths.js +99 -0
- package/create-vader-app/node_modules/fs-extra/lib/ensure/symlink-type.js +31 -0
- package/create-vader-app/node_modules/fs-extra/lib/ensure/symlink.js +82 -0
- package/create-vader-app/node_modules/fs-extra/lib/esm.mjs +68 -0
- package/create-vader-app/node_modules/fs-extra/lib/fs/index.js +140 -0
- package/create-vader-app/node_modules/fs-extra/lib/index.js +16 -0
- package/create-vader-app/node_modules/fs-extra/lib/json/index.js +16 -0
- package/create-vader-app/node_modules/fs-extra/lib/json/jsonfile.js +11 -0
- package/create-vader-app/node_modules/fs-extra/lib/json/output-json-sync.js +12 -0
- package/create-vader-app/node_modules/fs-extra/lib/json/output-json.js +12 -0
- package/create-vader-app/node_modules/fs-extra/lib/mkdirs/index.js +14 -0
- package/create-vader-app/node_modules/fs-extra/lib/mkdirs/make-dir.js +27 -0
- package/create-vader-app/node_modules/fs-extra/lib/mkdirs/utils.js +21 -0
- package/create-vader-app/node_modules/fs-extra/lib/move/index.js +7 -0
- package/create-vader-app/node_modules/fs-extra/lib/move/move-sync.js +55 -0
- package/create-vader-app/node_modules/fs-extra/lib/move/move.js +76 -0
- package/create-vader-app/node_modules/fs-extra/lib/output-file/index.js +40 -0
- package/create-vader-app/node_modules/fs-extra/lib/path-exists/index.js +12 -0
- package/create-vader-app/node_modules/fs-extra/lib/remove/index.js +17 -0
- package/create-vader-app/node_modules/fs-extra/lib/util/stat.js +154 -0
- package/create-vader-app/node_modules/fs-extra/lib/util/utimes.js +26 -0
- package/create-vader-app/node_modules/fs-extra/package.json +71 -0
- package/create-vader-app/node_modules/graceful-fs/LICENSE +15 -0
- package/create-vader-app/node_modules/graceful-fs/README.md +143 -0
- package/create-vader-app/node_modules/graceful-fs/clone.js +23 -0
- package/create-vader-app/node_modules/graceful-fs/graceful-fs.js +448 -0
- package/create-vader-app/node_modules/graceful-fs/legacy-streams.js +118 -0
- package/create-vader-app/node_modules/graceful-fs/package.json +53 -0
- package/create-vader-app/node_modules/graceful-fs/polyfills.js +355 -0
- package/create-vader-app/node_modules/inherits/LICENSE +16 -0
- package/create-vader-app/node_modules/inherits/README.md +42 -0
- package/create-vader-app/node_modules/inherits/inherits.js +7 -0
- package/create-vader-app/node_modules/inherits/inherits_browser.js +23 -0
- package/create-vader-app/node_modules/inherits/package.json +29 -0
- package/create-vader-app/node_modules/jsonfile/CHANGELOG.md +171 -0
- package/create-vader-app/node_modules/jsonfile/LICENSE +15 -0
- package/create-vader-app/node_modules/jsonfile/README.md +230 -0
- package/create-vader-app/node_modules/jsonfile/index.js +88 -0
- package/create-vader-app/node_modules/jsonfile/package.json +40 -0
- package/create-vader-app/node_modules/jsonfile/utils.js +14 -0
- package/create-vader-app/node_modules/path/LICENSE +18 -0
- package/create-vader-app/node_modules/path/README.md +15 -0
- package/create-vader-app/node_modules/path/package.json +24 -0
- package/create-vader-app/node_modules/path/path.js +628 -0
- package/create-vader-app/node_modules/process/.eslintrc +21 -0
- package/create-vader-app/node_modules/process/LICENSE +22 -0
- package/create-vader-app/node_modules/process/README.md +26 -0
- package/create-vader-app/node_modules/process/browser.js +184 -0
- package/create-vader-app/node_modules/process/index.js +2 -0
- package/create-vader-app/node_modules/process/package.json +27 -0
- package/create-vader-app/node_modules/process/test.js +199 -0
- package/create-vader-app/node_modules/universalify/LICENSE +20 -0
- package/create-vader-app/node_modules/universalify/README.md +76 -0
- package/create-vader-app/node_modules/universalify/index.js +24 -0
- package/create-vader-app/node_modules/universalify/package.json +34 -0
- package/create-vader-app/node_modules/util/LICENSE +18 -0
- package/create-vader-app/node_modules/util/README.md +15 -0
- package/create-vader-app/node_modules/util/package.json +35 -0
- package/create-vader-app/node_modules/util/support/isBuffer.js +3 -0
- package/create-vader-app/node_modules/util/support/isBufferBrowser.js +6 -0
- package/create-vader-app/node_modules/util/util.js +586 -0
- package/create-vader-app/package-lock.json +384 -0
- package/create-vader-app/package.json +18 -0
- package/images/router.png +0 -0
- package/images/state.png +0 -0
- package/package.json +1 -1
- package/ts.config.json +1 -0
- package/vader-min.js +1 -1
- package/vader.js +106 -326
- package/worker-min.js +1 -1
- package/worker.js +268 -168
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// shim for using process in browser
|
|
2
|
+
var process = module.exports = {};
|
|
3
|
+
|
|
4
|
+
// cached from whatever global is present so that test runners that stub it
|
|
5
|
+
// don't break things. But we need to wrap it in a try catch in case it is
|
|
6
|
+
// wrapped in strict mode code which doesn't define any globals. It's inside a
|
|
7
|
+
// function because try/catches deoptimize in certain engines.
|
|
8
|
+
|
|
9
|
+
var cachedSetTimeout;
|
|
10
|
+
var cachedClearTimeout;
|
|
11
|
+
|
|
12
|
+
function defaultSetTimout() {
|
|
13
|
+
throw new Error('setTimeout has not been defined');
|
|
14
|
+
}
|
|
15
|
+
function defaultClearTimeout () {
|
|
16
|
+
throw new Error('clearTimeout has not been defined');
|
|
17
|
+
}
|
|
18
|
+
(function () {
|
|
19
|
+
try {
|
|
20
|
+
if (typeof setTimeout === 'function') {
|
|
21
|
+
cachedSetTimeout = setTimeout;
|
|
22
|
+
} else {
|
|
23
|
+
cachedSetTimeout = defaultSetTimout;
|
|
24
|
+
}
|
|
25
|
+
} catch (e) {
|
|
26
|
+
cachedSetTimeout = defaultSetTimout;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
if (typeof clearTimeout === 'function') {
|
|
30
|
+
cachedClearTimeout = clearTimeout;
|
|
31
|
+
} else {
|
|
32
|
+
cachedClearTimeout = defaultClearTimeout;
|
|
33
|
+
}
|
|
34
|
+
} catch (e) {
|
|
35
|
+
cachedClearTimeout = defaultClearTimeout;
|
|
36
|
+
}
|
|
37
|
+
} ())
|
|
38
|
+
function runTimeout(fun) {
|
|
39
|
+
if (cachedSetTimeout === setTimeout) {
|
|
40
|
+
//normal enviroments in sane situations
|
|
41
|
+
return setTimeout(fun, 0);
|
|
42
|
+
}
|
|
43
|
+
// if setTimeout wasn't available but was latter defined
|
|
44
|
+
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
|
45
|
+
cachedSetTimeout = setTimeout;
|
|
46
|
+
return setTimeout(fun, 0);
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
// when when somebody has screwed with setTimeout but no I.E. maddness
|
|
50
|
+
return cachedSetTimeout(fun, 0);
|
|
51
|
+
} catch(e){
|
|
52
|
+
try {
|
|
53
|
+
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
|
54
|
+
return cachedSetTimeout.call(null, fun, 0);
|
|
55
|
+
} catch(e){
|
|
56
|
+
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
|
|
57
|
+
return cachedSetTimeout.call(this, fun, 0);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
function runClearTimeout(marker) {
|
|
64
|
+
if (cachedClearTimeout === clearTimeout) {
|
|
65
|
+
//normal enviroments in sane situations
|
|
66
|
+
return clearTimeout(marker);
|
|
67
|
+
}
|
|
68
|
+
// if clearTimeout wasn't available but was latter defined
|
|
69
|
+
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
|
70
|
+
cachedClearTimeout = clearTimeout;
|
|
71
|
+
return clearTimeout(marker);
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
// when when somebody has screwed with setTimeout but no I.E. maddness
|
|
75
|
+
return cachedClearTimeout(marker);
|
|
76
|
+
} catch (e){
|
|
77
|
+
try {
|
|
78
|
+
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
|
79
|
+
return cachedClearTimeout.call(null, marker);
|
|
80
|
+
} catch (e){
|
|
81
|
+
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
|
|
82
|
+
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
|
|
83
|
+
return cachedClearTimeout.call(this, marker);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
var queue = [];
|
|
91
|
+
var draining = false;
|
|
92
|
+
var currentQueue;
|
|
93
|
+
var queueIndex = -1;
|
|
94
|
+
|
|
95
|
+
function cleanUpNextTick() {
|
|
96
|
+
if (!draining || !currentQueue) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
draining = false;
|
|
100
|
+
if (currentQueue.length) {
|
|
101
|
+
queue = currentQueue.concat(queue);
|
|
102
|
+
} else {
|
|
103
|
+
queueIndex = -1;
|
|
104
|
+
}
|
|
105
|
+
if (queue.length) {
|
|
106
|
+
drainQueue();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function drainQueue() {
|
|
111
|
+
if (draining) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
var timeout = runTimeout(cleanUpNextTick);
|
|
115
|
+
draining = true;
|
|
116
|
+
|
|
117
|
+
var len = queue.length;
|
|
118
|
+
while(len) {
|
|
119
|
+
currentQueue = queue;
|
|
120
|
+
queue = [];
|
|
121
|
+
while (++queueIndex < len) {
|
|
122
|
+
if (currentQueue) {
|
|
123
|
+
currentQueue[queueIndex].run();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
queueIndex = -1;
|
|
127
|
+
len = queue.length;
|
|
128
|
+
}
|
|
129
|
+
currentQueue = null;
|
|
130
|
+
draining = false;
|
|
131
|
+
runClearTimeout(timeout);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
process.nextTick = function (fun) {
|
|
135
|
+
var args = new Array(arguments.length - 1);
|
|
136
|
+
if (arguments.length > 1) {
|
|
137
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
138
|
+
args[i - 1] = arguments[i];
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
queue.push(new Item(fun, args));
|
|
142
|
+
if (queue.length === 1 && !draining) {
|
|
143
|
+
runTimeout(drainQueue);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// v8 likes predictible objects
|
|
148
|
+
function Item(fun, array) {
|
|
149
|
+
this.fun = fun;
|
|
150
|
+
this.array = array;
|
|
151
|
+
}
|
|
152
|
+
Item.prototype.run = function () {
|
|
153
|
+
this.fun.apply(null, this.array);
|
|
154
|
+
};
|
|
155
|
+
process.title = 'browser';
|
|
156
|
+
process.browser = true;
|
|
157
|
+
process.env = {};
|
|
158
|
+
process.argv = [];
|
|
159
|
+
process.version = ''; // empty string to avoid regexp issues
|
|
160
|
+
process.versions = {};
|
|
161
|
+
|
|
162
|
+
function noop() {}
|
|
163
|
+
|
|
164
|
+
process.on = noop;
|
|
165
|
+
process.addListener = noop;
|
|
166
|
+
process.once = noop;
|
|
167
|
+
process.off = noop;
|
|
168
|
+
process.removeListener = noop;
|
|
169
|
+
process.removeAllListeners = noop;
|
|
170
|
+
process.emit = noop;
|
|
171
|
+
process.prependListener = noop;
|
|
172
|
+
process.prependOnceListener = noop;
|
|
173
|
+
|
|
174
|
+
process.listeners = function (name) { return [] }
|
|
175
|
+
|
|
176
|
+
process.binding = function (name) {
|
|
177
|
+
throw new Error('process.binding is not supported');
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
process.cwd = function () { return '/' };
|
|
181
|
+
process.chdir = function (dir) {
|
|
182
|
+
throw new Error('process.chdir is not supported');
|
|
183
|
+
};
|
|
184
|
+
process.umask = function() { return 0; };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"author": "Roman Shtylman <shtylman@gmail.com>",
|
|
3
|
+
"name": "process",
|
|
4
|
+
"description": "process information for node.js and browsers",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"process"
|
|
7
|
+
],
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "mocha test.js",
|
|
10
|
+
"browser": "zuul --no-coverage --ui mocha-bdd --local 8080 -- test.js"
|
|
11
|
+
},
|
|
12
|
+
"version": "0.11.10",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git://github.com/shtylman/node-process.git"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"browser": "./browser.js",
|
|
19
|
+
"main": "./index.js",
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">= 0.6.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"mocha": "2.2.1",
|
|
25
|
+
"zuul": "^3.10.3"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
var assert = require('assert');
|
|
2
|
+
var ourProcess = require('./browser');
|
|
3
|
+
describe('test against our process', function () {
|
|
4
|
+
test(ourProcess);
|
|
5
|
+
});
|
|
6
|
+
if (!process.browser) {
|
|
7
|
+
describe('test against node', function () {
|
|
8
|
+
test(process);
|
|
9
|
+
});
|
|
10
|
+
vmtest();
|
|
11
|
+
}
|
|
12
|
+
function test (ourProcess) {
|
|
13
|
+
describe('test arguments', function () {
|
|
14
|
+
it ('works', function (done) {
|
|
15
|
+
var order = 0;
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
ourProcess.nextTick(function (num) {
|
|
19
|
+
assert.equal(num, order++, 'first one works');
|
|
20
|
+
ourProcess.nextTick(function (num) {
|
|
21
|
+
assert.equal(num, order++, 'recursive one is 4th');
|
|
22
|
+
}, 3);
|
|
23
|
+
}, 0);
|
|
24
|
+
ourProcess.nextTick(function (num) {
|
|
25
|
+
assert.equal(num, order++, 'second one starts');
|
|
26
|
+
ourProcess.nextTick(function (num) {
|
|
27
|
+
assert.equal(num, order++, 'this is third');
|
|
28
|
+
ourProcess.nextTick(function (num) {
|
|
29
|
+
assert.equal(num, order++, 'this is last');
|
|
30
|
+
done();
|
|
31
|
+
}, 5);
|
|
32
|
+
}, 4);
|
|
33
|
+
}, 1);
|
|
34
|
+
ourProcess.nextTick(function (num) {
|
|
35
|
+
|
|
36
|
+
assert.equal(num, order++, '3rd schedualed happens after the error');
|
|
37
|
+
}, 2);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
if (!process.browser) {
|
|
41
|
+
describe('test errors', function (t) {
|
|
42
|
+
it ('works', function (done) {
|
|
43
|
+
var order = 0;
|
|
44
|
+
process.removeAllListeners('uncaughtException');
|
|
45
|
+
process.once('uncaughtException', function(err) {
|
|
46
|
+
assert.equal(2, order++, 'error is third');
|
|
47
|
+
ourProcess.nextTick(function () {
|
|
48
|
+
assert.equal(5, order++, 'schedualed in error is last');
|
|
49
|
+
done();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
ourProcess.nextTick(function () {
|
|
53
|
+
assert.equal(0, order++, 'first one works');
|
|
54
|
+
ourProcess.nextTick(function () {
|
|
55
|
+
assert.equal(4, order++, 'recursive one is 4th');
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
ourProcess.nextTick(function () {
|
|
59
|
+
assert.equal(1, order++, 'second one starts');
|
|
60
|
+
throw(new Error('an error is thrown'));
|
|
61
|
+
});
|
|
62
|
+
ourProcess.nextTick(function () {
|
|
63
|
+
assert.equal(3, order++, '3rd schedualed happens after the error');
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
describe('rename globals', function (t) {
|
|
69
|
+
var oldTimeout = setTimeout;
|
|
70
|
+
var oldClear = clearTimeout;
|
|
71
|
+
|
|
72
|
+
it('clearTimeout', function (done){
|
|
73
|
+
|
|
74
|
+
var ok = true;
|
|
75
|
+
clearTimeout = function () {
|
|
76
|
+
ok = false;
|
|
77
|
+
}
|
|
78
|
+
var ran = false;
|
|
79
|
+
function cleanup() {
|
|
80
|
+
clearTimeout = oldClear;
|
|
81
|
+
var err;
|
|
82
|
+
try {
|
|
83
|
+
assert.ok(ok, 'fake clearTimeout ran');
|
|
84
|
+
assert.ok(ran, 'should have run');
|
|
85
|
+
} catch (e) {
|
|
86
|
+
err = e;
|
|
87
|
+
}
|
|
88
|
+
done(err);
|
|
89
|
+
}
|
|
90
|
+
setTimeout(cleanup, 1000);
|
|
91
|
+
ourProcess.nextTick(function () {
|
|
92
|
+
ran = true;
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
it('just setTimeout', function (done){
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
setTimeout = function () {
|
|
99
|
+
setTimeout = oldTimeout;
|
|
100
|
+
try {
|
|
101
|
+
assert.ok(false, 'fake setTimeout called')
|
|
102
|
+
} catch (e) {
|
|
103
|
+
done(e);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
ourProcess.nextTick(function () {
|
|
109
|
+
setTimeout = oldTimeout;
|
|
110
|
+
done();
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
function vmtest() {
|
|
116
|
+
var vm = require('vm');
|
|
117
|
+
var fs = require('fs');
|
|
118
|
+
var process = fs.readFileSync('./browser.js', {encoding: 'utf8'});
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
describe('should work in vm in strict mode with no globals', function () {
|
|
122
|
+
it('should parse', function (done) {
|
|
123
|
+
var str = '"use strict";var module = {exports:{}};';
|
|
124
|
+
str += process;
|
|
125
|
+
str += 'this.works = process.browser;';
|
|
126
|
+
var script = new vm.Script(str);
|
|
127
|
+
var context = {
|
|
128
|
+
works: false
|
|
129
|
+
};
|
|
130
|
+
script.runInNewContext(context);
|
|
131
|
+
assert.ok(context.works);
|
|
132
|
+
done();
|
|
133
|
+
});
|
|
134
|
+
it('setTimeout throws error', function (done) {
|
|
135
|
+
var str = '"use strict";var module = {exports:{}};';
|
|
136
|
+
str += process;
|
|
137
|
+
str += 'try {process.nextTick(function () {})} catch (e){this.works = e;}';
|
|
138
|
+
var script = new vm.Script(str);
|
|
139
|
+
var context = {
|
|
140
|
+
works: false
|
|
141
|
+
};
|
|
142
|
+
script.runInNewContext(context);
|
|
143
|
+
assert.ok(context.works);
|
|
144
|
+
done();
|
|
145
|
+
});
|
|
146
|
+
it('should generally work', function (done) {
|
|
147
|
+
var str = '"use strict";var module = {exports:{}};';
|
|
148
|
+
str += process;
|
|
149
|
+
str += 'process.nextTick(function () {assert.ok(true);done();})';
|
|
150
|
+
var script = new vm.Script(str);
|
|
151
|
+
var context = {
|
|
152
|
+
clearTimeout: clearTimeout,
|
|
153
|
+
setTimeout: setTimeout,
|
|
154
|
+
done: done,
|
|
155
|
+
assert: assert
|
|
156
|
+
};
|
|
157
|
+
script.runInNewContext(context);
|
|
158
|
+
});
|
|
159
|
+
it('late defs setTimeout', function (done) {
|
|
160
|
+
var str = '"use strict";var module = {exports:{}};';
|
|
161
|
+
str += process;
|
|
162
|
+
str += 'var setTimeout = hiddenSetTimeout;process.nextTick(function () {assert.ok(true);done();})';
|
|
163
|
+
var script = new vm.Script(str);
|
|
164
|
+
var context = {
|
|
165
|
+
clearTimeout: clearTimeout,
|
|
166
|
+
hiddenSetTimeout: setTimeout,
|
|
167
|
+
done: done,
|
|
168
|
+
assert: assert
|
|
169
|
+
};
|
|
170
|
+
script.runInNewContext(context);
|
|
171
|
+
});
|
|
172
|
+
it('late defs clearTimeout', function (done) {
|
|
173
|
+
var str = '"use strict";var module = {exports:{}};';
|
|
174
|
+
str += process;
|
|
175
|
+
str += 'var clearTimeout = hiddenClearTimeout;process.nextTick(function () {assert.ok(true);done();})';
|
|
176
|
+
var script = new vm.Script(str);
|
|
177
|
+
var context = {
|
|
178
|
+
hiddenClearTimeout: clearTimeout,
|
|
179
|
+
setTimeout: setTimeout,
|
|
180
|
+
done: done,
|
|
181
|
+
assert: assert
|
|
182
|
+
};
|
|
183
|
+
script.runInNewContext(context);
|
|
184
|
+
});
|
|
185
|
+
it('late defs setTimeout and then redefine', function (done) {
|
|
186
|
+
var str = '"use strict";var module = {exports:{}};';
|
|
187
|
+
str += process;
|
|
188
|
+
str += 'var setTimeout = hiddenSetTimeout;process.nextTick(function () {setTimeout = function (){throw new Error("foo")};hiddenSetTimeout(function(){process.nextTick(function (){assert.ok(true);done();});});});';
|
|
189
|
+
var script = new vm.Script(str);
|
|
190
|
+
var context = {
|
|
191
|
+
clearTimeout: clearTimeout,
|
|
192
|
+
hiddenSetTimeout: setTimeout,
|
|
193
|
+
done: done,
|
|
194
|
+
assert: assert
|
|
195
|
+
};
|
|
196
|
+
script.runInNewContext(context);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
(The MIT License)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017, Ryan Zimmerman <opensrc@ryanzim.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the 'Software'), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
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, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# universalify
|
|
2
|
+
|
|
3
|
+
[](https://travis-ci.org/RyanZim/universalify)
|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
Make a callback- or promise-based function support both promises and callbacks.
|
|
9
|
+
|
|
10
|
+
Uses the native promise implementation.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install universalify
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## API
|
|
19
|
+
|
|
20
|
+
### `universalify.fromCallback(fn)`
|
|
21
|
+
|
|
22
|
+
Takes a callback-based function to universalify, and returns the universalified function.
|
|
23
|
+
|
|
24
|
+
Function must take a callback as the last parameter that will be called with the signature `(error, result)`. `universalify` does not support calling the callback with three or more arguments, and does not ensure that the callback is only called once.
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
function callbackFn (n, cb) {
|
|
28
|
+
setTimeout(() => cb(null, n), 15)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const fn = universalify.fromCallback(callbackFn)
|
|
32
|
+
|
|
33
|
+
// Works with Promises:
|
|
34
|
+
fn('Hello World!')
|
|
35
|
+
.then(result => console.log(result)) // -> Hello World!
|
|
36
|
+
.catch(error => console.error(error))
|
|
37
|
+
|
|
38
|
+
// Works with Callbacks:
|
|
39
|
+
fn('Hi!', (error, result) => {
|
|
40
|
+
if (error) return console.error(error)
|
|
41
|
+
console.log(result)
|
|
42
|
+
// -> Hi!
|
|
43
|
+
})
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### `universalify.fromPromise(fn)`
|
|
47
|
+
|
|
48
|
+
Takes a promise-based function to universalify, and returns the universalified function.
|
|
49
|
+
|
|
50
|
+
Function must return a valid JS promise. `universalify` does not ensure that a valid promise is returned.
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
function promiseFn (n) {
|
|
54
|
+
return new Promise(resolve => {
|
|
55
|
+
setTimeout(() => resolve(n), 15)
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const fn = universalify.fromPromise(promiseFn)
|
|
60
|
+
|
|
61
|
+
// Works with Promises:
|
|
62
|
+
fn('Hello World!')
|
|
63
|
+
.then(result => console.log(result)) // -> Hello World!
|
|
64
|
+
.catch(error => console.error(error))
|
|
65
|
+
|
|
66
|
+
// Works with Callbacks:
|
|
67
|
+
fn('Hi!', (error, result) => {
|
|
68
|
+
if (error) return console.error(error)
|
|
69
|
+
console.log(result)
|
|
70
|
+
// -> Hi!
|
|
71
|
+
})
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
MIT
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
exports.fromCallback = function (fn) {
|
|
4
|
+
return Object.defineProperty(function (...args) {
|
|
5
|
+
if (typeof args[args.length - 1] === 'function') fn.apply(this, args)
|
|
6
|
+
else {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
fn.call(
|
|
9
|
+
this,
|
|
10
|
+
...args,
|
|
11
|
+
(err, res) => (err != null) ? reject(err) : resolve(res)
|
|
12
|
+
)
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
}, 'name', { value: fn.name })
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
exports.fromPromise = function (fn) {
|
|
19
|
+
return Object.defineProperty(function (...args) {
|
|
20
|
+
const cb = args[args.length - 1]
|
|
21
|
+
if (typeof cb !== 'function') return fn.apply(this, args)
|
|
22
|
+
else fn.apply(this, args.slice(0, -1)).then(r => cb(null, r), cb)
|
|
23
|
+
}, 'name', { value: fn.name })
|
|
24
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "universalify",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Make a callback- or promise-based function support both promises and callbacks.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"callback",
|
|
7
|
+
"native",
|
|
8
|
+
"promise"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://github.com/RyanZim/universalify#readme",
|
|
11
|
+
"bugs": "https://github.com/RyanZim/universalify/issues",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "Ryan Zimmerman <opensrc@ryanzim.com>",
|
|
14
|
+
"files": [
|
|
15
|
+
"index.js"
|
|
16
|
+
],
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/RyanZim/universalify.git"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"test": "standard && nyc tape test/*.js | colortape"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"colortape": "^0.1.2",
|
|
26
|
+
"coveralls": "^3.0.1",
|
|
27
|
+
"nyc": "^15.0.0",
|
|
28
|
+
"standard": "^14.3.1",
|
|
29
|
+
"tape": "^5.0.1"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">= 10.0.0"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
|
2
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
3
|
+
of this software and associated documentation files (the "Software"), to
|
|
4
|
+
deal in the Software without restriction, including without limitation the
|
|
5
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
6
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
|
7
|
+
furnished to do so, subject to the following conditions:
|
|
8
|
+
|
|
9
|
+
The above copyright notice and this permission notice shall be included in
|
|
10
|
+
all copies or substantial portions of the Software.
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
13
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
14
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
15
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
16
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
17
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
18
|
+
IN THE SOFTWARE.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# util
|
|
2
|
+
|
|
3
|
+
[](https://travis-ci.org/defunctzombie/node-util)
|
|
4
|
+
|
|
5
|
+
node.js [util](http://nodejs.org/api/util.html) module as a module
|
|
6
|
+
|
|
7
|
+
## install via [npm](npmjs.org)
|
|
8
|
+
|
|
9
|
+
```shell
|
|
10
|
+
npm install util
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## browser support
|
|
14
|
+
|
|
15
|
+
This module also works in modern browsers. If you need legacy browser support you will need to polyfill ES5 features.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"author": {
|
|
3
|
+
"name": "Joyent",
|
|
4
|
+
"url": "http://www.joyent.com"
|
|
5
|
+
},
|
|
6
|
+
"name": "util",
|
|
7
|
+
"description": "Node.JS util module",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"util"
|
|
10
|
+
],
|
|
11
|
+
"version": "0.10.4",
|
|
12
|
+
"homepage": "https://github.com/defunctzombie/node-util",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git://github.com/defunctzombie/node-util"
|
|
16
|
+
},
|
|
17
|
+
"main": "./util.js",
|
|
18
|
+
"files": [
|
|
19
|
+
"util.js",
|
|
20
|
+
"support"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "node test/node/*.js && zuul test/browser/*.js"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"inherits": "2.0.3"
|
|
27
|
+
},
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"zuul": "~1.0.9"
|
|
31
|
+
},
|
|
32
|
+
"browser": {
|
|
33
|
+
"./support/isBuffer.js": "./support/isBufferBrowser.js"
|
|
34
|
+
}
|
|
35
|
+
}
|