@augustofarnese/qs-patch 6.15.0-patched.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.
- package/.editorconfig +46 -0
- package/.github/FUNDING.yml +12 -0
- package/.github/SECURITY.md +11 -0
- package/.github/THREAT_MODEL.md +78 -0
- package/.nycrc +13 -0
- package/CHANGELOG.md +806 -0
- package/LICENSE.md +29 -0
- package/README.md +758 -0
- package/dist/qs.js +141 -0
- package/eslint.config.mjs +56 -0
- package/lib/formats.js +23 -0
- package/lib/index.js +11 -0
- package/lib/parse.js +373 -0
- package/lib/stringify.js +356 -0
- package/lib/utils.js +342 -0
- package/package.json +90 -0
- package/test/empty-keys-cases.js +267 -0
- package/test/parse.js +1568 -0
- package/test/stringify.js +1310 -0
- package/test/utils.js +404 -0
package/test/utils.js
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var test = require('tape');
|
|
4
|
+
var inspect = require('object-inspect');
|
|
5
|
+
var SaferBuffer = require('safer-buffer').Buffer;
|
|
6
|
+
var forEach = require('for-each');
|
|
7
|
+
var v = require('es-value-fixtures');
|
|
8
|
+
|
|
9
|
+
var utils = require('../lib/utils');
|
|
10
|
+
|
|
11
|
+
test('merge()', function (t) {
|
|
12
|
+
t.deepEqual(utils.merge(null, true), [null, true], 'merges true into null');
|
|
13
|
+
|
|
14
|
+
t.deepEqual(utils.merge(null, [42]), [null, 42], 'merges null into an array');
|
|
15
|
+
|
|
16
|
+
t.deepEqual(utils.merge({ a: 'b' }, { a: 'c' }), { a: ['b', 'c'] }, 'merges two objects with the same key');
|
|
17
|
+
|
|
18
|
+
var oneMerged = utils.merge({ foo: 'bar' }, { foo: { first: '123' } });
|
|
19
|
+
t.deepEqual(oneMerged, { foo: ['bar', { first: '123' }] }, 'merges a standalone and an object into an array');
|
|
20
|
+
|
|
21
|
+
var twoMerged = utils.merge({ foo: ['bar', { first: '123' }] }, { foo: { second: '456' } });
|
|
22
|
+
t.deepEqual(twoMerged, { foo: { 0: 'bar', 1: { first: '123' }, second: '456' } }, 'merges a standalone and two objects into an array');
|
|
23
|
+
|
|
24
|
+
var sandwiched = utils.merge({ foo: ['bar', { first: '123', second: '456' }] }, { foo: 'baz' });
|
|
25
|
+
t.deepEqual(sandwiched, { foo: ['bar', { first: '123', second: '456' }, 'baz'] }, 'merges an object sandwiched by two standalones into an array');
|
|
26
|
+
|
|
27
|
+
var nestedArrays = utils.merge({ foo: ['baz'] }, { foo: ['bar', 'xyzzy'] });
|
|
28
|
+
t.deepEqual(nestedArrays, { foo: ['baz', 'bar', 'xyzzy'] });
|
|
29
|
+
|
|
30
|
+
var noOptionsNonObjectSource = utils.merge({ foo: 'baz' }, 'bar');
|
|
31
|
+
t.deepEqual(noOptionsNonObjectSource, { foo: 'baz', bar: true });
|
|
32
|
+
|
|
33
|
+
var func = function f() {};
|
|
34
|
+
t.deepEqual(
|
|
35
|
+
utils.merge(func, { foo: 'bar' }),
|
|
36
|
+
[func, { foo: 'bar' }],
|
|
37
|
+
'functions can not be merged into'
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
func.bar = 'baz';
|
|
41
|
+
t.deepEqual(
|
|
42
|
+
utils.merge({ foo: 'bar' }, func),
|
|
43
|
+
{ foo: 'bar', bar: 'baz' },
|
|
44
|
+
'functions can be merge sources'
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
t.test(
|
|
48
|
+
'avoids invoking array setters unnecessarily',
|
|
49
|
+
{ skip: typeof Object.defineProperty !== 'function' },
|
|
50
|
+
function (st) {
|
|
51
|
+
var setCount = 0;
|
|
52
|
+
var getCount = 0;
|
|
53
|
+
var observed = [];
|
|
54
|
+
Object.defineProperty(observed, 0, {
|
|
55
|
+
get: function () {
|
|
56
|
+
getCount += 1;
|
|
57
|
+
return { bar: 'baz' };
|
|
58
|
+
},
|
|
59
|
+
set: function () { setCount += 1; }
|
|
60
|
+
});
|
|
61
|
+
utils.merge(observed, [null]);
|
|
62
|
+
st.equal(setCount, 0);
|
|
63
|
+
st.equal(getCount, 1);
|
|
64
|
+
observed[0] = observed[0]; // eslint-disable-line no-self-assign
|
|
65
|
+
st.equal(setCount, 1);
|
|
66
|
+
st.equal(getCount, 2);
|
|
67
|
+
st.end();
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
t.test('with overflow objects (from arrayLimit)', function (st) {
|
|
72
|
+
// arrayLimit is max index, so with limit 0, max index 0 is allowed (1 element)
|
|
73
|
+
// To create overflow, need 2+ elements with limit 0, or 3+ with limit 1, etc.
|
|
74
|
+
st.test('merges primitive into overflow object at next index', function (s2t) {
|
|
75
|
+
// Create an overflow object via combine: 3 elements (indices 0-2) with limit 0
|
|
76
|
+
var overflow = utils.combine(['a', 'b'], 'c', 0, false);
|
|
77
|
+
s2t.ok(utils.isOverflow(overflow), 'overflow object is marked');
|
|
78
|
+
var merged = utils.merge(overflow, 'd');
|
|
79
|
+
s2t.deepEqual(merged, { 0: 'a', 1: 'b', 2: 'c', 3: 'd' }, 'adds primitive at next numeric index');
|
|
80
|
+
s2t.end();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
st.test('merges primitive into regular object with numeric keys normally', function (s2t) {
|
|
84
|
+
var obj = { 0: 'a', 1: 'b' };
|
|
85
|
+
s2t.notOk(utils.isOverflow(obj), 'plain object is not marked as overflow');
|
|
86
|
+
var merged = utils.merge(obj, 'c');
|
|
87
|
+
s2t.deepEqual(merged, { 0: 'a', 1: 'b', c: true }, 'adds primitive as key (not at next index)');
|
|
88
|
+
s2t.end();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
st.test('merges primitive into object with non-numeric keys normally', function (s2t) {
|
|
92
|
+
var obj = { foo: 'bar' };
|
|
93
|
+
var merged = utils.merge(obj, 'baz');
|
|
94
|
+
s2t.deepEqual(merged, { foo: 'bar', baz: true }, 'adds primitive as key with value true');
|
|
95
|
+
s2t.end();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
st.test('with strictMerge, wraps object and primitive in array', function (s2t) {
|
|
99
|
+
var obj = { foo: 'bar' };
|
|
100
|
+
var merged = utils.merge(obj, 'baz', { strictMerge: true });
|
|
101
|
+
s2t.deepEqual(merged, [{ foo: 'bar' }, 'baz'], 'wraps in array with strictMerge');
|
|
102
|
+
s2t.end();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
st.test('merges overflow object into primitive', function (s2t) {
|
|
106
|
+
// Create an overflow object via combine: 2 elements (indices 0-1) with limit 0
|
|
107
|
+
var overflow = utils.combine(['a'], 'b', 0, false);
|
|
108
|
+
s2t.ok(utils.isOverflow(overflow), 'overflow object is marked');
|
|
109
|
+
var merged = utils.merge('c', overflow);
|
|
110
|
+
s2t.ok(utils.isOverflow(merged), 'result is also marked as overflow');
|
|
111
|
+
s2t.deepEqual(merged, { 0: 'c', 1: 'a', 2: 'b' }, 'creates object with primitive at 0, source values shifted');
|
|
112
|
+
s2t.end();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
st.test('merges overflow object with multiple values into primitive', function (s2t) {
|
|
116
|
+
// Create an overflow object via combine: 3 elements (indices 0-2) with limit 0
|
|
117
|
+
var overflow = utils.combine(['b', 'c'], 'd', 0, false);
|
|
118
|
+
s2t.ok(utils.isOverflow(overflow), 'overflow object is marked');
|
|
119
|
+
var merged = utils.merge('a', overflow);
|
|
120
|
+
s2t.deepEqual(merged, { 0: 'a', 1: 'b', 2: 'c', 3: 'd' }, 'shifts all source indices by 1');
|
|
121
|
+
s2t.end();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
st.test('merges regular object into primitive as array', function (s2t) {
|
|
125
|
+
var obj = { foo: 'bar' };
|
|
126
|
+
var merged = utils.merge('a', obj);
|
|
127
|
+
s2t.deepEqual(merged, ['a', { foo: 'bar' }], 'creates array with primitive and object');
|
|
128
|
+
s2t.end();
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
st.end();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
t.end();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test('assign()', function (t) {
|
|
138
|
+
var target = { a: 1, b: 2 };
|
|
139
|
+
var source = { b: 3, c: 4 };
|
|
140
|
+
var result = utils.assign(target, source);
|
|
141
|
+
|
|
142
|
+
t.equal(result, target, 'returns the target');
|
|
143
|
+
t.deepEqual(target, { a: 1, b: 3, c: 4 }, 'target and source are merged');
|
|
144
|
+
t.deepEqual(source, { b: 3, c: 4 }, 'source is untouched');
|
|
145
|
+
|
|
146
|
+
t.end();
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('combine()', function (t) {
|
|
150
|
+
t.test('both arrays', function (st) {
|
|
151
|
+
var a = [1];
|
|
152
|
+
var b = [2];
|
|
153
|
+
var combined = utils.combine(a, b);
|
|
154
|
+
|
|
155
|
+
st.deepEqual(a, [1], 'a is not mutated');
|
|
156
|
+
st.deepEqual(b, [2], 'b is not mutated');
|
|
157
|
+
st.notEqual(a, combined, 'a !== combined');
|
|
158
|
+
st.notEqual(b, combined, 'b !== combined');
|
|
159
|
+
st.deepEqual(combined, [1, 2], 'combined is a + b');
|
|
160
|
+
|
|
161
|
+
st.end();
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
t.test('one array, one non-array', function (st) {
|
|
165
|
+
var aN = 1;
|
|
166
|
+
var a = [aN];
|
|
167
|
+
var bN = 2;
|
|
168
|
+
var b = [bN];
|
|
169
|
+
|
|
170
|
+
var combinedAnB = utils.combine(aN, b);
|
|
171
|
+
st.deepEqual(b, [bN], 'b is not mutated');
|
|
172
|
+
st.notEqual(aN, combinedAnB, 'aN + b !== aN');
|
|
173
|
+
st.notEqual(a, combinedAnB, 'aN + b !== a');
|
|
174
|
+
st.notEqual(bN, combinedAnB, 'aN + b !== bN');
|
|
175
|
+
st.notEqual(b, combinedAnB, 'aN + b !== b');
|
|
176
|
+
st.deepEqual([1, 2], combinedAnB, 'first argument is array-wrapped when not an array');
|
|
177
|
+
|
|
178
|
+
var combinedABn = utils.combine(a, bN);
|
|
179
|
+
st.deepEqual(a, [aN], 'a is not mutated');
|
|
180
|
+
st.notEqual(aN, combinedABn, 'a + bN !== aN');
|
|
181
|
+
st.notEqual(a, combinedABn, 'a + bN !== a');
|
|
182
|
+
st.notEqual(bN, combinedABn, 'a + bN !== bN');
|
|
183
|
+
st.notEqual(b, combinedABn, 'a + bN !== b');
|
|
184
|
+
st.deepEqual([1, 2], combinedABn, 'second argument is array-wrapped when not an array');
|
|
185
|
+
|
|
186
|
+
st.end();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
t.test('neither is an array', function (st) {
|
|
190
|
+
var combined = utils.combine(1, 2);
|
|
191
|
+
st.notEqual(1, combined, '1 + 2 !== 1');
|
|
192
|
+
st.notEqual(2, combined, '1 + 2 !== 2');
|
|
193
|
+
st.deepEqual([1, 2], combined, 'both arguments are array-wrapped when not an array');
|
|
194
|
+
|
|
195
|
+
st.end();
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
t.test('with arrayLimit', function (st) {
|
|
199
|
+
st.test('under the limit', function (s2t) {
|
|
200
|
+
var combined = utils.combine(['a', 'b'], 'c', 10, false);
|
|
201
|
+
s2t.deepEqual(combined, ['a', 'b', 'c'], 'returns array when under limit');
|
|
202
|
+
s2t.ok(Array.isArray(combined), 'result is an array');
|
|
203
|
+
s2t.end();
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
st.test('exactly at the limit stays as array', function (s2t) {
|
|
207
|
+
var combined = utils.combine(['a', 'b'], 'c', 3, false);
|
|
208
|
+
s2t.deepEqual(combined, ['a', 'b', 'c'], 'stays as array when count equals limit');
|
|
209
|
+
s2t.ok(Array.isArray(combined), 'result is an array');
|
|
210
|
+
s2t.end();
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
st.test('over the limit', function (s2t) {
|
|
214
|
+
var combined = utils.combine(['a', 'b', 'c'], 'd', 3, false);
|
|
215
|
+
s2t.deepEqual(combined, { 0: 'a', 1: 'b', 2: 'c', 3: 'd' }, 'converts to object when over limit');
|
|
216
|
+
s2t.notOk(Array.isArray(combined), 'result is not an array');
|
|
217
|
+
s2t.end();
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
st.test('with arrayLimit 1', function (s2t) {
|
|
221
|
+
var combined = utils.combine([], 'a', 1, false);
|
|
222
|
+
s2t.deepEqual(combined, ['a'], 'stays as array when count equals limit');
|
|
223
|
+
s2t.ok(Array.isArray(combined), 'result is an array');
|
|
224
|
+
s2t.end();
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
st.test('with arrayLimit 0 converts single element to object', function (s2t) {
|
|
228
|
+
var combined = utils.combine([], 'a', 0, false);
|
|
229
|
+
s2t.deepEqual(combined, { 0: 'a' }, 'converts to object when count exceeds limit');
|
|
230
|
+
s2t.notOk(Array.isArray(combined), 'result is not an array');
|
|
231
|
+
s2t.end();
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
st.test('with arrayLimit 0 and two elements converts to object', function (s2t) {
|
|
235
|
+
var combined = utils.combine(['a'], 'b', 0, false);
|
|
236
|
+
s2t.deepEqual(combined, { 0: 'a', 1: 'b' }, 'converts to object when count exceeds limit');
|
|
237
|
+
s2t.notOk(Array.isArray(combined), 'result is not an array');
|
|
238
|
+
s2t.end();
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
st.test('with plainObjects option', function (s2t) {
|
|
242
|
+
var combined = utils.combine(['a', 'b'], 'c', 1, true);
|
|
243
|
+
var expected = { __proto__: null, 0: 'a', 1: 'b', 2: 'c' };
|
|
244
|
+
s2t.deepEqual(combined, expected, 'converts to object with null prototype');
|
|
245
|
+
s2t.equal(Object.getPrototypeOf(combined), null, 'result has null prototype when plainObjects is true');
|
|
246
|
+
s2t.end();
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
st.end();
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
t.test('with existing overflow object', function (st) {
|
|
253
|
+
st.test('adds to existing overflow object at next index', function (s2t) {
|
|
254
|
+
// Create overflow object first via combine: 3 elements (indices 0-2) with limit 0
|
|
255
|
+
var overflow = utils.combine(['a', 'b'], 'c', 0, false);
|
|
256
|
+
s2t.ok(utils.isOverflow(overflow), 'initial object is marked as overflow');
|
|
257
|
+
|
|
258
|
+
var combined = utils.combine(overflow, 'd', 10, false);
|
|
259
|
+
s2t.equal(combined, overflow, 'returns the same object (mutated)');
|
|
260
|
+
s2t.deepEqual(combined, { 0: 'a', 1: 'b', 2: 'c', 3: 'd' }, 'adds value at next numeric index');
|
|
261
|
+
s2t.end();
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
st.test('does not treat plain object with numeric keys as overflow', function (s2t) {
|
|
265
|
+
var plainObj = { 0: 'a', 1: 'b' };
|
|
266
|
+
s2t.notOk(utils.isOverflow(plainObj), 'plain object is not marked as overflow');
|
|
267
|
+
|
|
268
|
+
// combine treats this as a regular value, not an overflow object to append to
|
|
269
|
+
var combined = utils.combine(plainObj, 'c', 10, false);
|
|
270
|
+
s2t.deepEqual(combined, [{ 0: 'a', 1: 'b' }, 'c'], 'concatenates as regular values');
|
|
271
|
+
s2t.end();
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
st.end();
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
t.end();
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
test('decode', function (t) {
|
|
281
|
+
t.equal(
|
|
282
|
+
utils.decode('a+b'),
|
|
283
|
+
'a b',
|
|
284
|
+
'decodes + to space'
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
t.equal(
|
|
288
|
+
utils.decode('name%2Eobj'),
|
|
289
|
+
'name.obj',
|
|
290
|
+
'decodes a string'
|
|
291
|
+
);
|
|
292
|
+
t.equal(
|
|
293
|
+
utils.decode('name%2Eobj%2Efoo', null, 'iso-8859-1'),
|
|
294
|
+
'name.obj.foo',
|
|
295
|
+
'decodes a string in iso-8859-1'
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
t.end();
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
test('encode', function (t) {
|
|
302
|
+
forEach(v.nullPrimitives, function (nullish) {
|
|
303
|
+
t['throws'](
|
|
304
|
+
function () { utils.encode(nullish); },
|
|
305
|
+
TypeError,
|
|
306
|
+
inspect(nullish) + ' is not a string'
|
|
307
|
+
);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
t.equal(utils.encode(''), '', 'empty string returns itself');
|
|
311
|
+
t.deepEqual(utils.encode([]), [], 'empty array returns itself');
|
|
312
|
+
t.deepEqual(utils.encode({ length: 0 }), { length: 0 }, 'empty arraylike returns itself');
|
|
313
|
+
|
|
314
|
+
t.test('symbols', { skip: !v.hasSymbols }, function (st) {
|
|
315
|
+
st.equal(utils.encode(Symbol('x')), 'Symbol%28x%29', 'symbol is encoded');
|
|
316
|
+
|
|
317
|
+
st.end();
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
t.equal(
|
|
321
|
+
utils.encode('(abc)'),
|
|
322
|
+
'%28abc%29',
|
|
323
|
+
'encodes parentheses'
|
|
324
|
+
);
|
|
325
|
+
t.equal(
|
|
326
|
+
utils.encode({ toString: function () { return '(abc)'; } }),
|
|
327
|
+
'%28abc%29',
|
|
328
|
+
'toStrings and encodes parentheses'
|
|
329
|
+
);
|
|
330
|
+
|
|
331
|
+
t.equal(
|
|
332
|
+
utils.encode('abc 123 💩', null, 'iso-8859-1'),
|
|
333
|
+
'abc%20123%20%26%2355357%3B%26%2356489%3B',
|
|
334
|
+
'encodes in iso-8859-1'
|
|
335
|
+
);
|
|
336
|
+
|
|
337
|
+
var longString = '';
|
|
338
|
+
var expectedString = '';
|
|
339
|
+
for (var i = 0; i < 1500; i++) {
|
|
340
|
+
longString += ' ';
|
|
341
|
+
expectedString += '%20';
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
t.equal(
|
|
345
|
+
utils.encode(longString),
|
|
346
|
+
expectedString,
|
|
347
|
+
'encodes a long string'
|
|
348
|
+
);
|
|
349
|
+
|
|
350
|
+
t.equal(
|
|
351
|
+
utils.encode('\x28\x29'),
|
|
352
|
+
'%28%29',
|
|
353
|
+
'encodes parens normally'
|
|
354
|
+
);
|
|
355
|
+
t.equal(
|
|
356
|
+
utils.encode('\x28\x29', null, null, null, 'RFC1738'),
|
|
357
|
+
'()',
|
|
358
|
+
'does not encode parens in RFC1738'
|
|
359
|
+
);
|
|
360
|
+
|
|
361
|
+
// todo RFC1738 format
|
|
362
|
+
|
|
363
|
+
t.equal(
|
|
364
|
+
utils.encode('Āက豈'),
|
|
365
|
+
'%C4%80%E1%80%80%EF%A4%80',
|
|
366
|
+
'encodes multibyte chars'
|
|
367
|
+
);
|
|
368
|
+
|
|
369
|
+
t.equal(
|
|
370
|
+
utils.encode('\uD83D \uDCA9'),
|
|
371
|
+
'%F0%9F%90%A0%F0%BA%90%80',
|
|
372
|
+
'encodes lone surrogates'
|
|
373
|
+
);
|
|
374
|
+
|
|
375
|
+
t.end();
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
test('isBuffer()', function (t) {
|
|
379
|
+
forEach([null, undefined, true, false, '', 'abc', 42, 0, NaN, {}, [], function () {}, /a/g], function (x) {
|
|
380
|
+
t.equal(utils.isBuffer(x), false, inspect(x) + ' is not a buffer');
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
var fakeBuffer = { constructor: Buffer };
|
|
384
|
+
t.equal(utils.isBuffer(fakeBuffer), false, 'fake buffer is not a buffer');
|
|
385
|
+
|
|
386
|
+
var saferBuffer = SaferBuffer.from('abc');
|
|
387
|
+
t.equal(utils.isBuffer(saferBuffer), true, 'SaferBuffer instance is a buffer');
|
|
388
|
+
|
|
389
|
+
var buffer = Buffer.from && Buffer.alloc ? Buffer.from('abc') : new Buffer('abc');
|
|
390
|
+
t.equal(utils.isBuffer(buffer), true, 'real Buffer instance is a buffer');
|
|
391
|
+
t.end();
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
test('isRegExp()', function (t) {
|
|
395
|
+
t.equal(utils.isRegExp(/a/g), true, 'RegExp is a RegExp');
|
|
396
|
+
t.equal(utils.isRegExp(new RegExp('a', 'g')), true, 'new RegExp is a RegExp');
|
|
397
|
+
t.equal(utils.isRegExp(new Date()), false, 'Date is not a RegExp');
|
|
398
|
+
|
|
399
|
+
forEach(v.primitives, function (primitive) {
|
|
400
|
+
t.equal(utils.isRegExp(primitive), false, inspect(primitive) + ' is not a RegExp');
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
t.end();
|
|
404
|
+
});
|