@mehmetb/rollup-plugin-node-builtins 3.0.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 (48) hide show
  1. package/README.md +101 -0
  2. package/dist/constants.js +474 -0
  3. package/dist/rollup-plugin-node-builtins.cjs.js +77 -0
  4. package/dist/rollup-plugin-node-builtins.es6.js +75 -0
  5. package/package.json +42 -0
  6. package/src/es6/assert.js +488 -0
  7. package/src/es6/console.js +13 -0
  8. package/src/es6/domain.js +100 -0
  9. package/src/es6/empty.js +1 -0
  10. package/src/es6/events.js +475 -0
  11. package/src/es6/http-lib/capability.js +52 -0
  12. package/src/es6/http-lib/request.js +278 -0
  13. package/src/es6/http-lib/response.js +185 -0
  14. package/src/es6/http-lib/to-arraybuffer.js +30 -0
  15. package/src/es6/http.js +167 -0
  16. package/src/es6/inherits.js +25 -0
  17. package/src/es6/os.js +113 -0
  18. package/src/es6/path.js +234 -0
  19. package/src/es6/punycode.js +475 -0
  20. package/src/es6/qs.js +147 -0
  21. package/src/es6/readable-stream/buffer-list.js +59 -0
  22. package/src/es6/readable-stream/duplex.js +45 -0
  23. package/src/es6/readable-stream/passthrough.js +15 -0
  24. package/src/es6/readable-stream/readable.js +896 -0
  25. package/src/es6/readable-stream/transform.js +174 -0
  26. package/src/es6/readable-stream/writable.js +483 -0
  27. package/src/es6/setimmediate.js +185 -0
  28. package/src/es6/stream.js +110 -0
  29. package/src/es6/string-decoder.js +220 -0
  30. package/src/es6/timers.js +76 -0
  31. package/src/es6/tty.js +20 -0
  32. package/src/es6/url.js +745 -0
  33. package/src/es6/util.js +598 -0
  34. package/src/es6/vm.js +202 -0
  35. package/src/es6/zlib-lib/LICENSE +21 -0
  36. package/src/es6/zlib-lib/adler32.js +31 -0
  37. package/src/es6/zlib-lib/binding.js +269 -0
  38. package/src/es6/zlib-lib/crc32.js +40 -0
  39. package/src/es6/zlib-lib/deflate.js +1862 -0
  40. package/src/es6/zlib-lib/inffast.js +325 -0
  41. package/src/es6/zlib-lib/inflate.js +1650 -0
  42. package/src/es6/zlib-lib/inftrees.js +329 -0
  43. package/src/es6/zlib-lib/messages.js +11 -0
  44. package/src/es6/zlib-lib/trees.js +1220 -0
  45. package/src/es6/zlib-lib/utils.js +73 -0
  46. package/src/es6/zlib-lib/zstream.js +28 -0
  47. package/src/es6/zlib.js +635 -0
  48. package/src/index.js +73 -0
@@ -0,0 +1,75 @@
1
+ import { join } from 'path';
2
+
3
+ var libs = new Map();
4
+
5
+ // our es6 versions
6
+ libs.set('process', require.resolve('process-es6'));
7
+ libs.set('buffer', require.resolve('buffer-es6'));
8
+ libs.set('util', require.resolve(join('..', 'src', 'es6', 'util')));
9
+ libs.set('sys', libs.get('util'));
10
+ libs.set('events', require.resolve(join('..', 'src', 'es6', 'events')));
11
+ libs.set('stream', require.resolve(join('..', 'src', 'es6', 'stream')));
12
+ libs.set('path', require.resolve(join('..', 'src', 'es6', 'path')));
13
+ libs.set('querystring', require.resolve(join('..', 'src', 'es6', 'qs')));
14
+ libs.set('punycode', require.resolve(join('..', 'src', 'es6', 'punycode')));
15
+ libs.set('url', require.resolve(join('..', 'src', 'es6', 'url')));
16
+ libs.set('string_decoder', require.resolve(join('..', 'src', 'es6', 'string-decoder')));
17
+ libs.set('http', require.resolve(join('..', 'src', 'es6', 'http')));
18
+ libs.set('https', require.resolve(join('..', 'src', 'es6', 'http')));
19
+ libs.set('os', require.resolve(join('..', 'src', 'es6', 'os')));
20
+ libs.set('assert', require.resolve(join('..', 'src', 'es6', 'assert')));
21
+ libs.set('constants', require.resolve('./constants'));
22
+ libs.set('_stream_duplex', require.resolve(join('..', 'src', 'es6', 'readable-stream', 'duplex')));
23
+ libs.set('_stream_passthrough', require.resolve(join('..', 'src', 'es6', 'readable-stream', 'passthrough')));
24
+ libs.set('_stream_readable', require.resolve(join('..', 'src', 'es6', 'readable-stream', 'readable')));
25
+ libs.set('_stream_writable', require.resolve(join('..', 'src', 'es6', 'readable-stream', 'writable')));
26
+ libs.set('_stream_transform', require.resolve(join('..', 'src', 'es6', 'readable-stream', 'transform')));
27
+ libs.set('timers', require.resolve(join('..', 'src', 'es6', 'timers')));
28
+ libs.set('console', require.resolve(join('..', 'src', 'es6', 'console')));
29
+ libs.set('vm', require.resolve(join('..', 'src', 'es6', 'vm')));
30
+ libs.set('zlib', require.resolve(join('..', 'src', 'es6', 'zlib')));
31
+ libs.set('tty', require.resolve(join('..', 'src', 'es6', 'tty')));
32
+ libs.set('domain', require.resolve(join('..', 'src', 'es6', 'domain')));
33
+ var CRYPTO_PATH = require.resolve('crypto-browserify');
34
+ var FS_PATH = require.resolve('browserify-fs');
35
+ var EMPTY_PATH = require.resolve(join('..', 'src', 'es6', 'empty'));
36
+
37
+ // not shimmed
38
+ libs.set('dns', EMPTY_PATH);
39
+ libs.set('dgram', EMPTY_PATH);
40
+ libs.set('child_process', EMPTY_PATH);
41
+ libs.set('cluster', EMPTY_PATH);
42
+ libs.set('module', EMPTY_PATH);
43
+ libs.set('net', EMPTY_PATH);
44
+ libs.set('readline', EMPTY_PATH);
45
+ libs.set('repl', EMPTY_PATH);
46
+ libs.set('tls', EMPTY_PATH);
47
+ function index (opts) {
48
+ opts = opts || {};
49
+ var cryptoPath = EMPTY_PATH;
50
+ var fsPath = EMPTY_PATH;
51
+ if (opts.crypto) {
52
+ cryptoPath = CRYPTO_PATH;
53
+ }
54
+ if (opts.fs) {
55
+ fsPath = FS_PATH;
56
+ }
57
+ return {
58
+ resolveId: function resolveId(importee) {
59
+ if (importee && importee.slice(-1) === '/') {
60
+ importee === importee.slice(0, -1);
61
+ }
62
+ if (libs.has(importee)) {
63
+ return libs.get(importee);
64
+ }
65
+ if (importee === 'crypto') {
66
+ return cryptoPath;
67
+ }
68
+ if (importee === 'fs') {
69
+ return fsPath;
70
+ }
71
+ }
72
+ };
73
+ }
74
+
75
+ export { index as default };
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@mehmetb/rollup-plugin-node-builtins",
3
+ "version": "3.0.1",
4
+ "description": "use node builtins in browser with rollup",
5
+ "main": "dist/rollup-plugin-node-builtins.cjs.js",
6
+ "jsnext:main": "dist/rollup-plugin-node-builtins.es6.js",
7
+ "scripts": {
8
+ "test": "mocha",
9
+ "pretest": "npm run build",
10
+ "build": "rollup -c -f cjs -o dist/rollup-plugin-node-builtins.cjs.js && rollup -c -f es -o dist/rollup-plugin-node-builtins.es6.js && node build-constants.js",
11
+ "prebuild": "rm -rf dist && mkdir dist",
12
+ "prepublish": "npm test",
13
+ "browser-test": "serve browser-test/dist",
14
+ "prebrowser-test": "rm -rf browser-test/dist/bundle.js && npm run build && node ./browser-test/index.js"
15
+ },
16
+ "keywords": [
17
+ "rollup-plugin"
18
+ ],
19
+ "author": "",
20
+ "license": "ISC",
21
+ "dependencies": {
22
+ "browserify-fs": "^1.0.0",
23
+ "buffer-es6": "^4.9.3",
24
+ "crypto-browserify": "^3.12.1",
25
+ "process-es6": "^0.11.6"
26
+ },
27
+ "devDependencies": {
28
+ "@babel/core": "^7.15.0",
29
+ "@babel/preset-env": "^7.26.9",
30
+ "@rollup/plugin-babel": "^6.0.4",
31
+ "debug": "^4.4.0",
32
+ "mocha": "^11.1.0",
33
+ "rollup": "^4.34.7",
34
+ "rollup-plugin-node-globals": "^1.4.0",
35
+ "serve": "^14.2.4"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+ssh://git@github.com/mehmetb/rollup-plugin-node-builtins.git"
40
+ },
41
+ "packageManager": "yarn@4.6.0"
42
+ }
@@ -0,0 +1,488 @@
1
+
2
+ function compare(a, b) {
3
+ if (a === b) {
4
+ return 0;
5
+ }
6
+
7
+ var x = a.length;
8
+ var y = b.length;
9
+
10
+ for (var i = 0, len = Math.min(x, y); i < len; ++i) {
11
+ if (a[i] !== b[i]) {
12
+ x = a[i];
13
+ y = b[i];
14
+ break;
15
+ }
16
+ }
17
+
18
+ if (x < y) {
19
+ return -1;
20
+ }
21
+ if (y < x) {
22
+ return 1;
23
+ }
24
+ return 0;
25
+ }
26
+ var hasOwn = Object.prototype.hasOwnProperty;
27
+
28
+ var objectKeys = Object.keys || function (obj) {
29
+ var keys = [];
30
+ for (var key in obj) {
31
+ if (hasOwn.call(obj, key)) keys.push(key);
32
+ }
33
+ return keys;
34
+ };
35
+ // based on node assert, original notice:
36
+
37
+ // http://wiki.commonjs.org/wiki/Unit_Testing/1.0
38
+ //
39
+ // THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8!
40
+ //
41
+ // Originally from narwhal.js (http://narwhaljs.org)
42
+ // Copyright (c) 2009 Thomas Robinson <280north.com>
43
+ //
44
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
45
+ // of this software and associated documentation files (the 'Software'), to
46
+ // deal in the Software without restriction, including without limitation the
47
+ // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
48
+ // sell copies of the Software, and to permit persons to whom the Software is
49
+ // furnished to do so, subject to the following conditions:
50
+ //
51
+ // The above copyright notice and this permission notice shall be included in
52
+ // all copies or substantial portions of the Software.
53
+ //
54
+ // THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
55
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
56
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
57
+ // AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
58
+ // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
59
+ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
60
+ import {isBuffer} from 'buffer';
61
+ import {isPrimitive, inherits, isError, isFunction, isRegExp, isDate, inspect as utilInspect} from 'util';
62
+ var pSlice = Array.prototype.slice;
63
+ var _functionsHaveNames;
64
+ function functionsHaveNames() {
65
+ if (typeof _functionsHaveNames !== 'undefined') {
66
+ return _functionsHaveNames;
67
+ }
68
+ return _functionsHaveNames = (function () {
69
+ return function foo() {}.name === 'foo';
70
+ }());
71
+ }
72
+ function pToString (obj) {
73
+ return Object.prototype.toString.call(obj);
74
+ }
75
+ function isView(arrbuf) {
76
+ if (isBuffer(arrbuf)) {
77
+ return false;
78
+ }
79
+ if (typeof global.ArrayBuffer !== 'function') {
80
+ return false;
81
+ }
82
+ if (typeof ArrayBuffer.isView === 'function') {
83
+ return ArrayBuffer.isView(arrbuf);
84
+ }
85
+ if (!arrbuf) {
86
+ return false;
87
+ }
88
+ if (arrbuf instanceof DataView) {
89
+ return true;
90
+ }
91
+ if (arrbuf.buffer && arrbuf.buffer instanceof ArrayBuffer) {
92
+ return true;
93
+ }
94
+ return false;
95
+ }
96
+ // 1. The assert module provides functions that throw
97
+ // AssertionError's when particular conditions are not met. The
98
+ // assert module must conform to the following interface.
99
+
100
+ function assert(value, message) {
101
+ if (!value) fail(value, true, message, '==', ok);
102
+ }
103
+ export default assert;
104
+
105
+ // 2. The AssertionError is defined in assert.
106
+ // new assert.AssertionError({ message: message,
107
+ // actual: actual,
108
+ // expected: expected })
109
+
110
+ var regex = /\s*function\s+([^\(\s]*)\s*/;
111
+ // based on https://github.com/ljharb/function.prototype.name/blob/adeeeec8bfcc6068b187d7d9fb3d5bb1d3a30899/implementation.js
112
+ function getName(func) {
113
+ if (!isFunction(func)) {
114
+ return;
115
+ }
116
+ if (functionsHaveNames()) {
117
+ return func.name;
118
+ }
119
+ var str = func.toString();
120
+ var match = str.match(regex);
121
+ return match && match[1];
122
+ }
123
+ assert.AssertionError = AssertionError;
124
+ export function AssertionError(options) {
125
+ this.name = 'AssertionError';
126
+ this.actual = options.actual;
127
+ this.expected = options.expected;
128
+ this.operator = options.operator;
129
+ if (options.message) {
130
+ this.message = options.message;
131
+ this.generatedMessage = false;
132
+ } else {
133
+ this.message = getMessage(this);
134
+ this.generatedMessage = true;
135
+ }
136
+ var stackStartFunction = options.stackStartFunction || fail;
137
+ if (Error.captureStackTrace) {
138
+ Error.captureStackTrace(this, stackStartFunction);
139
+ } else {
140
+ // non v8 browsers so we can have a stacktrace
141
+ var err = new Error();
142
+ if (err.stack) {
143
+ var out = err.stack;
144
+
145
+ // try to strip useless frames
146
+ var fn_name = getName(stackStartFunction);
147
+ var idx = out.indexOf('\n' + fn_name);
148
+ if (idx >= 0) {
149
+ // once we have located the function frame
150
+ // we need to strip out everything before it (and its line)
151
+ var next_line = out.indexOf('\n', idx + 1);
152
+ out = out.substring(next_line + 1);
153
+ }
154
+
155
+ this.stack = out;
156
+ }
157
+ }
158
+ }
159
+
160
+ // assert.AssertionError instanceof Error
161
+ inherits(AssertionError, Error);
162
+
163
+ function truncate(s, n) {
164
+ if (typeof s === 'string') {
165
+ return s.length < n ? s : s.slice(0, n);
166
+ } else {
167
+ return s;
168
+ }
169
+ }
170
+ function inspect(something) {
171
+ if (functionsHaveNames() || !isFunction(something)) {
172
+ return utilInspect(something);
173
+ }
174
+ var rawname = getName(something);
175
+ var name = rawname ? ': ' + rawname : '';
176
+ return '[Function' + name + ']';
177
+ }
178
+ function getMessage(self) {
179
+ return truncate(inspect(self.actual), 128) + ' ' +
180
+ self.operator + ' ' +
181
+ truncate(inspect(self.expected), 128);
182
+ }
183
+
184
+ // At present only the three keys mentioned above are used and
185
+ // understood by the spec. Implementations or sub modules can pass
186
+ // other keys to the AssertionError's constructor - they will be
187
+ // ignored.
188
+
189
+ // 3. All of the following functions must throw an AssertionError
190
+ // when a corresponding condition is not met, with a message that
191
+ // may be undefined if not provided. All assertion methods provide
192
+ // both the actual and expected values to the assertion error for
193
+ // display purposes.
194
+
195
+ export function fail(actual, expected, message, operator, stackStartFunction) {
196
+ throw new AssertionError({
197
+ message: message,
198
+ actual: actual,
199
+ expected: expected,
200
+ operator: operator,
201
+ stackStartFunction: stackStartFunction
202
+ });
203
+ }
204
+
205
+ // EXTENSION! allows for well behaved errors defined elsewhere.
206
+ assert.fail = fail;
207
+
208
+ // 4. Pure assertion tests whether a value is truthy, as determined
209
+ // by !!guard.
210
+ // assert.ok(guard, message_opt);
211
+ // This statement is equivalent to assert.equal(true, !!guard,
212
+ // message_opt);. To test strictly for the value true, use
213
+ // assert.strictEqual(true, guard, message_opt);.
214
+
215
+ export function ok(value, message) {
216
+ if (!value) fail(value, true, message, '==', ok);
217
+ }
218
+ assert.ok = ok;
219
+ export {ok as assert};
220
+
221
+ // 5. The equality assertion tests shallow, coercive equality with
222
+ // ==.
223
+ // assert.equal(actual, expected, message_opt);
224
+ assert.equal = equal;
225
+ export function equal(actual, expected, message) {
226
+ if (actual != expected) fail(actual, expected, message, '==', equal);
227
+ }
228
+
229
+ // 6. The non-equality assertion tests for whether two objects are not equal
230
+ // with != assert.notEqual(actual, expected, message_opt);
231
+ assert.notEqual = notEqual;
232
+ export function notEqual(actual, expected, message) {
233
+ if (actual == expected) {
234
+ fail(actual, expected, message, '!=', notEqual);
235
+ }
236
+ }
237
+
238
+ // 7. The equivalence assertion tests a deep equality relation.
239
+ // assert.deepEqual(actual, expected, message_opt);
240
+ assert.deepEqual = deepEqual;
241
+ export function deepEqual(actual, expected, message) {
242
+ if (!_deepEqual(actual, expected, false)) {
243
+ fail(actual, expected, message, 'deepEqual', deepEqual);
244
+ }
245
+ }
246
+ assert.deepStrictEqual = deepStrictEqual;
247
+ export function deepStrictEqual(actual, expected, message) {
248
+ if (!_deepEqual(actual, expected, true)) {
249
+ fail(actual, expected, message, 'deepStrictEqual', deepStrictEqual);
250
+ }
251
+ }
252
+
253
+ function _deepEqual(actual, expected, strict, memos) {
254
+ // 7.1. All identical values are equivalent, as determined by ===.
255
+ if (actual === expected) {
256
+ return true;
257
+ } else if (isBuffer(actual) && isBuffer(expected)) {
258
+ return compare(actual, expected) === 0;
259
+
260
+ // 7.2. If the expected value is a Date object, the actual value is
261
+ // equivalent if it is also a Date object that refers to the same time.
262
+ } else if (isDate(actual) && isDate(expected)) {
263
+ return actual.getTime() === expected.getTime();
264
+
265
+ // 7.3 If the expected value is a RegExp object, the actual value is
266
+ // equivalent if it is also a RegExp object with the same source and
267
+ // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).
268
+ } else if (isRegExp(actual) && isRegExp(expected)) {
269
+ return actual.source === expected.source &&
270
+ actual.global === expected.global &&
271
+ actual.multiline === expected.multiline &&
272
+ actual.lastIndex === expected.lastIndex &&
273
+ actual.ignoreCase === expected.ignoreCase;
274
+
275
+ // 7.4. Other pairs that do not both pass typeof value == 'object',
276
+ // equivalence is determined by ==.
277
+ } else if ((actual === null || typeof actual !== 'object') &&
278
+ (expected === null || typeof expected !== 'object')) {
279
+ return strict ? actual === expected : actual == expected;
280
+
281
+ // If both values are instances of typed arrays, wrap their underlying
282
+ // ArrayBuffers in a Buffer each to increase performance
283
+ // This optimization requires the arrays to have the same type as checked by
284
+ // Object.prototype.toString (aka pToString). Never perform binary
285
+ // comparisons for Float*Arrays, though, since e.g. +0 === -0 but their
286
+ // bit patterns are not identical.
287
+ } else if (isView(actual) && isView(expected) &&
288
+ pToString(actual) === pToString(expected) &&
289
+ !(actual instanceof Float32Array ||
290
+ actual instanceof Float64Array)) {
291
+ return compare(new Uint8Array(actual.buffer),
292
+ new Uint8Array(expected.buffer)) === 0;
293
+
294
+ // 7.5 For all other Object pairs, including Array objects, equivalence is
295
+ // determined by having the same number of owned properties (as verified
296
+ // with Object.prototype.hasOwnProperty.call), the same set of keys
297
+ // (although not necessarily the same order), equivalent values for every
298
+ // corresponding key, and an identical 'prototype' property. Note: this
299
+ // accounts for both named and indexed properties on Arrays.
300
+ } else if (isBuffer(actual) !== isBuffer(expected)) {
301
+ return false;
302
+ } else {
303
+ memos = memos || {actual: [], expected: []};
304
+
305
+ var actualIndex = memos.actual.indexOf(actual);
306
+ if (actualIndex !== -1) {
307
+ if (actualIndex === memos.expected.indexOf(expected)) {
308
+ return true;
309
+ }
310
+ }
311
+
312
+ memos.actual.push(actual);
313
+ memos.expected.push(expected);
314
+
315
+ return objEquiv(actual, expected, strict, memos);
316
+ }
317
+ }
318
+
319
+ function isArguments(object) {
320
+ return Object.prototype.toString.call(object) == '[object Arguments]';
321
+ }
322
+
323
+ function objEquiv(a, b, strict, actualVisitedObjects) {
324
+ if (a === null || a === undefined || b === null || b === undefined)
325
+ return false;
326
+ // if one is a primitive, the other must be same
327
+ if (isPrimitive(a) || isPrimitive(b))
328
+ return a === b;
329
+ if (strict && Object.getPrototypeOf(a) !== Object.getPrototypeOf(b))
330
+ return false;
331
+ var aIsArgs = isArguments(a);
332
+ var bIsArgs = isArguments(b);
333
+ if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs))
334
+ return false;
335
+ if (aIsArgs) {
336
+ a = pSlice.call(a);
337
+ b = pSlice.call(b);
338
+ return _deepEqual(a, b, strict);
339
+ }
340
+ var ka = objectKeys(a);
341
+ var kb = objectKeys(b);
342
+ var key, i;
343
+ // having the same number of owned properties (keys incorporates
344
+ // hasOwnProperty)
345
+ if (ka.length !== kb.length)
346
+ return false;
347
+ //the same set of keys (although not necessarily the same order),
348
+ ka.sort();
349
+ kb.sort();
350
+ //~~~cheap key test
351
+ for (i = ka.length - 1; i >= 0; i--) {
352
+ if (ka[i] !== kb[i])
353
+ return false;
354
+ }
355
+ //equivalent values for every corresponding key, and
356
+ //~~~possibly expensive deep test
357
+ for (i = ka.length - 1; i >= 0; i--) {
358
+ key = ka[i];
359
+ if (!_deepEqual(a[key], b[key], strict, actualVisitedObjects))
360
+ return false;
361
+ }
362
+ return true;
363
+ }
364
+
365
+ // 8. The non-equivalence assertion tests for any deep inequality.
366
+ // assert.notDeepEqual(actual, expected, message_opt);
367
+ assert.notDeepEqual = notDeepEqual;
368
+ export function notDeepEqual(actual, expected, message) {
369
+ if (_deepEqual(actual, expected, false)) {
370
+ fail(actual, expected, message, 'notDeepEqual', notDeepEqual);
371
+ }
372
+ }
373
+
374
+ assert.notDeepStrictEqual = notDeepStrictEqual;
375
+ export function notDeepStrictEqual(actual, expected, message) {
376
+ if (_deepEqual(actual, expected, true)) {
377
+ fail(actual, expected, message, 'notDeepStrictEqual', notDeepStrictEqual);
378
+ }
379
+ }
380
+
381
+
382
+ // 9. The strict equality assertion tests strict equality, as determined by ===.
383
+ // assert.strictEqual(actual, expected, message_opt);
384
+ assert.strictEqual = strictEqual;
385
+ export function strictEqual(actual, expected, message) {
386
+ if (actual !== expected) {
387
+ fail(actual, expected, message, '===', strictEqual);
388
+ }
389
+ }
390
+
391
+ // 10. The strict non-equality assertion tests for strict inequality, as
392
+ // determined by !==. assert.notStrictEqual(actual, expected, message_opt);
393
+ assert.notStrictEqual = notStrictEqual;
394
+ export function notStrictEqual(actual, expected, message) {
395
+ if (actual === expected) {
396
+ fail(actual, expected, message, '!==', notStrictEqual);
397
+ }
398
+ }
399
+
400
+ function expectedException(actual, expected) {
401
+ if (!actual || !expected) {
402
+ return false;
403
+ }
404
+
405
+ if (Object.prototype.toString.call(expected) == '[object RegExp]') {
406
+ return expected.test(actual);
407
+ }
408
+
409
+ try {
410
+ if (actual instanceof expected) {
411
+ return true;
412
+ }
413
+ } catch (e) {
414
+ // Ignore. The instanceof check doesn't work for arrow functions.
415
+ }
416
+
417
+ if (Error.isPrototypeOf(expected)) {
418
+ return false;
419
+ }
420
+
421
+ return expected.call({}, actual) === true;
422
+ }
423
+
424
+ function _tryBlock(block) {
425
+ var error;
426
+ try {
427
+ block();
428
+ } catch (e) {
429
+ error = e;
430
+ }
431
+ return error;
432
+ }
433
+
434
+ function _throws(shouldThrow, block, expected, message) {
435
+ var actual;
436
+
437
+ if (typeof block !== 'function') {
438
+ throw new TypeError('"block" argument must be a function');
439
+ }
440
+
441
+ if (typeof expected === 'string') {
442
+ message = expected;
443
+ expected = null;
444
+ }
445
+
446
+ actual = _tryBlock(block);
447
+
448
+ message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
449
+ (message ? ' ' + message : '.');
450
+
451
+ if (shouldThrow && !actual) {
452
+ fail(actual, expected, 'Missing expected exception' + message);
453
+ }
454
+
455
+ var userProvidedMessage = typeof message === 'string';
456
+ var isUnwantedException = !shouldThrow && isError(actual);
457
+ var isUnexpectedException = !shouldThrow && actual && !expected;
458
+
459
+ if ((isUnwantedException &&
460
+ userProvidedMessage &&
461
+ expectedException(actual, expected)) ||
462
+ isUnexpectedException) {
463
+ fail(actual, expected, 'Got unwanted exception' + message);
464
+ }
465
+
466
+ if ((shouldThrow && actual && expected &&
467
+ !expectedException(actual, expected)) || (!shouldThrow && actual)) {
468
+ throw actual;
469
+ }
470
+ }
471
+
472
+ // 11. Expected to throw an error:
473
+ // assert.throws(block, Error_opt, message_opt);
474
+ assert.throws = throws;
475
+ export function throws(block, /*optional*/error, /*optional*/message) {
476
+ _throws(true, block, error, message);
477
+ }
478
+
479
+ // EXTENSION! This is annoying to write outside this module.
480
+ assert.doesNotThrow = doesNotThrow;
481
+ export function doesNotThrow(block, /*optional*/error, /*optional*/message) {
482
+ _throws(false, block, error, message);
483
+ }
484
+
485
+ assert.ifError = ifError;
486
+ export function ifError(err) {
487
+ if (err) throw err;
488
+ }
@@ -0,0 +1,13 @@
1
+ function noop(){}
2
+
3
+ export default global.console ? global.console : {
4
+ log: noop,
5
+ info: noop,
6
+ warn: noop,
7
+ error: noop,
8
+ dir: noop,
9
+ assert: noop,
10
+ time: noop,
11
+ timeEnd: noop,
12
+ trace: noop
13
+ };