vite-plugin-php 2.0.3 → 3.0.0-beta.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/README.md +132 -65
- package/dist/index.cjs +3589 -378
- package/dist/index.mjs +3584 -374
- package/package.json +8 -10
package/dist/index.cjs
CHANGED
|
@@ -3,29 +3,31 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const node_child_process = require('node:child_process');
|
|
6
|
-
const
|
|
6
|
+
const node_url = require('node:url');
|
|
7
7
|
const node_path = require('node:path');
|
|
8
|
-
const
|
|
9
|
-
const require$$0 = require('
|
|
10
|
-
const require$$0$1 = require('
|
|
11
|
-
const require$$0$2 = require('
|
|
12
|
-
const require$$0$3 = require('
|
|
13
|
-
const require$$0$
|
|
14
|
-
const require$$0$
|
|
8
|
+
const require$$1 = require('net');
|
|
9
|
+
const require$$0 = require('util');
|
|
10
|
+
const require$$0$1 = require('tty');
|
|
11
|
+
const require$$0$2 = require('os');
|
|
12
|
+
const require$$0$3 = require('path');
|
|
13
|
+
const require$$0$4 = require('stream');
|
|
14
|
+
const require$$0$6 = require('events');
|
|
15
|
+
const require$$0$5 = require('fs');
|
|
15
16
|
const node_fs = require('node:fs');
|
|
16
|
-
const http = require('node:http');
|
|
17
17
|
const vite = require('vite');
|
|
18
|
+
const http = require('node:http');
|
|
18
19
|
|
|
19
20
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
20
21
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
21
22
|
|
|
22
|
-
const
|
|
23
|
+
const require$$1__default = /*#__PURE__*/_interopDefaultCompat(require$$1);
|
|
23
24
|
const require$$0__default = /*#__PURE__*/_interopDefaultCompat(require$$0);
|
|
24
25
|
const require$$0__default$1 = /*#__PURE__*/_interopDefaultCompat(require$$0$1);
|
|
25
26
|
const require$$0__default$2 = /*#__PURE__*/_interopDefaultCompat(require$$0$2);
|
|
26
27
|
const require$$0__default$3 = /*#__PURE__*/_interopDefaultCompat(require$$0$3);
|
|
27
|
-
const require$$0__default$5 = /*#__PURE__*/_interopDefaultCompat(require$$0$5);
|
|
28
28
|
const require$$0__default$4 = /*#__PURE__*/_interopDefaultCompat(require$$0$4);
|
|
29
|
+
const require$$0__default$6 = /*#__PURE__*/_interopDefaultCompat(require$$0$6);
|
|
30
|
+
const require$$0__default$5 = /*#__PURE__*/_interopDefaultCompat(require$$0$5);
|
|
29
31
|
const http__default = /*#__PURE__*/_interopDefaultCompat(http);
|
|
30
32
|
|
|
31
33
|
const EPHPError = {
|
|
@@ -49,6 +51,7 @@ const EPHPError = {
|
|
|
49
51
|
|
|
50
52
|
const internalParam = "__314159265359__";
|
|
51
53
|
const shared = {
|
|
54
|
+
projectRoot: process.cwd(),
|
|
52
55
|
viteConfig: void 0,
|
|
53
56
|
devConfig: {
|
|
54
57
|
cleanup: true,
|
|
@@ -64,6 +67,31 @@ function getDefaultExportFromCjs (x) {
|
|
|
64
67
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
65
68
|
}
|
|
66
69
|
|
|
70
|
+
function getAugmentedNamespace(n) {
|
|
71
|
+
if (Object.prototype.hasOwnProperty.call(n, '__esModule')) return n;
|
|
72
|
+
var f = n.default;
|
|
73
|
+
if (typeof f == "function") {
|
|
74
|
+
var a = function a () {
|
|
75
|
+
if (this instanceof a) {
|
|
76
|
+
return Reflect.construct(f, arguments, this.constructor);
|
|
77
|
+
}
|
|
78
|
+
return f.apply(this, arguments);
|
|
79
|
+
};
|
|
80
|
+
a.prototype = f.prototype;
|
|
81
|
+
} else a = {};
|
|
82
|
+
Object.defineProperty(a, '__esModule', {value: true});
|
|
83
|
+
Object.keys(n).forEach(function (k) {
|
|
84
|
+
var d = Object.getOwnPropertyDescriptor(n, k);
|
|
85
|
+
Object.defineProperty(a, k, d.get ? d : {
|
|
86
|
+
enumerable: true,
|
|
87
|
+
get: function () {
|
|
88
|
+
return n[k];
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
return a;
|
|
93
|
+
}
|
|
94
|
+
|
|
67
95
|
var picocolors = {exports: {}};
|
|
68
96
|
|
|
69
97
|
var hasRequiredPicocolors;
|
|
@@ -92,130 +120,3156 @@ function requirePicocolors () {
|
|
|
92
120
|
return result + string.substring(cursor)
|
|
93
121
|
};
|
|
94
122
|
|
|
95
|
-
let createColors = (enabled = isColorSupported) => {
|
|
96
|
-
let f = enabled ? formatter : () => String;
|
|
97
|
-
return {
|
|
98
|
-
isColorSupported: enabled,
|
|
99
|
-
reset: f("\x1b[0m", "\x1b[0m"),
|
|
100
|
-
bold: f("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m"),
|
|
101
|
-
dim: f("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m"),
|
|
102
|
-
italic: f("\x1b[3m", "\x1b[23m"),
|
|
103
|
-
underline: f("\x1b[4m", "\x1b[24m"),
|
|
104
|
-
inverse: f("\x1b[7m", "\x1b[27m"),
|
|
105
|
-
hidden: f("\x1b[8m", "\x1b[28m"),
|
|
106
|
-
strikethrough: f("\x1b[9m", "\x1b[29m"),
|
|
123
|
+
let createColors = (enabled = isColorSupported) => {
|
|
124
|
+
let f = enabled ? formatter : () => String;
|
|
125
|
+
return {
|
|
126
|
+
isColorSupported: enabled,
|
|
127
|
+
reset: f("\x1b[0m", "\x1b[0m"),
|
|
128
|
+
bold: f("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m"),
|
|
129
|
+
dim: f("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m"),
|
|
130
|
+
italic: f("\x1b[3m", "\x1b[23m"),
|
|
131
|
+
underline: f("\x1b[4m", "\x1b[24m"),
|
|
132
|
+
inverse: f("\x1b[7m", "\x1b[27m"),
|
|
133
|
+
hidden: f("\x1b[8m", "\x1b[28m"),
|
|
134
|
+
strikethrough: f("\x1b[9m", "\x1b[29m"),
|
|
135
|
+
|
|
136
|
+
black: f("\x1b[30m", "\x1b[39m"),
|
|
137
|
+
red: f("\x1b[31m", "\x1b[39m"),
|
|
138
|
+
green: f("\x1b[32m", "\x1b[39m"),
|
|
139
|
+
yellow: f("\x1b[33m", "\x1b[39m"),
|
|
140
|
+
blue: f("\x1b[34m", "\x1b[39m"),
|
|
141
|
+
magenta: f("\x1b[35m", "\x1b[39m"),
|
|
142
|
+
cyan: f("\x1b[36m", "\x1b[39m"),
|
|
143
|
+
white: f("\x1b[37m", "\x1b[39m"),
|
|
144
|
+
gray: f("\x1b[90m", "\x1b[39m"),
|
|
145
|
+
|
|
146
|
+
bgBlack: f("\x1b[40m", "\x1b[49m"),
|
|
147
|
+
bgRed: f("\x1b[41m", "\x1b[49m"),
|
|
148
|
+
bgGreen: f("\x1b[42m", "\x1b[49m"),
|
|
149
|
+
bgYellow: f("\x1b[43m", "\x1b[49m"),
|
|
150
|
+
bgBlue: f("\x1b[44m", "\x1b[49m"),
|
|
151
|
+
bgMagenta: f("\x1b[45m", "\x1b[49m"),
|
|
152
|
+
bgCyan: f("\x1b[46m", "\x1b[49m"),
|
|
153
|
+
bgWhite: f("\x1b[47m", "\x1b[49m"),
|
|
154
|
+
|
|
155
|
+
blackBright: f("\x1b[90m", "\x1b[39m"),
|
|
156
|
+
redBright: f("\x1b[91m", "\x1b[39m"),
|
|
157
|
+
greenBright: f("\x1b[92m", "\x1b[39m"),
|
|
158
|
+
yellowBright: f("\x1b[93m", "\x1b[39m"),
|
|
159
|
+
blueBright: f("\x1b[94m", "\x1b[39m"),
|
|
160
|
+
magentaBright: f("\x1b[95m", "\x1b[39m"),
|
|
161
|
+
cyanBright: f("\x1b[96m", "\x1b[39m"),
|
|
162
|
+
whiteBright: f("\x1b[97m", "\x1b[39m"),
|
|
163
|
+
|
|
164
|
+
bgBlackBright: f("\x1b[100m", "\x1b[49m"),
|
|
165
|
+
bgRedBright: f("\x1b[101m", "\x1b[49m"),
|
|
166
|
+
bgGreenBright: f("\x1b[102m", "\x1b[49m"),
|
|
167
|
+
bgYellowBright: f("\x1b[103m", "\x1b[49m"),
|
|
168
|
+
bgBlueBright: f("\x1b[104m", "\x1b[49m"),
|
|
169
|
+
bgMagentaBright: f("\x1b[105m", "\x1b[49m"),
|
|
170
|
+
bgCyanBright: f("\x1b[106m", "\x1b[49m"),
|
|
171
|
+
bgWhiteBright: f("\x1b[107m", "\x1b[49m"),
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
picocolors.exports = createColors();
|
|
176
|
+
picocolors.exports.createColors = createColors;
|
|
177
|
+
return picocolors.exports;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
var picocolorsExports = /*@__PURE__*/ requirePicocolors();
|
|
181
|
+
const colors = /*@__PURE__*/getDefaultExportFromCjs(picocolorsExports);
|
|
182
|
+
|
|
183
|
+
function hasViteConfig(input) {
|
|
184
|
+
if (!input) {
|
|
185
|
+
throw new Error("Vite config not initialized!");
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function log(message, { type = "info", prefix = true, ...options } = {}) {
|
|
190
|
+
hasViteConfig(shared.viteConfig);
|
|
191
|
+
let output = "";
|
|
192
|
+
if (prefix) {
|
|
193
|
+
output += colors.bgMagenta(colors.white("\u2009php\u2009")) + " ";
|
|
194
|
+
}
|
|
195
|
+
output += message;
|
|
196
|
+
shared.viteConfig.logger[type](output, options);
|
|
197
|
+
}
|
|
198
|
+
log.error = function(json, options = {}) {
|
|
199
|
+
let output = json;
|
|
200
|
+
let type = "info";
|
|
201
|
+
try {
|
|
202
|
+
const data = JSON.parse(json);
|
|
203
|
+
output = "";
|
|
204
|
+
switch (data.code) {
|
|
205
|
+
case EPHPError.PARSE:
|
|
206
|
+
case EPHPError.ERROR:
|
|
207
|
+
case EPHPError.CORE_ERROR:
|
|
208
|
+
case EPHPError.COMPILE_ERROR:
|
|
209
|
+
case EPHPError.USER_ERROR:
|
|
210
|
+
type = "error";
|
|
211
|
+
output += colors.bgRedBright(colors.white("Fatal Error"));
|
|
212
|
+
break;
|
|
213
|
+
case EPHPError.WARNING:
|
|
214
|
+
case EPHPError.USER_WARNING:
|
|
215
|
+
case EPHPError.COMPILE_WARNING:
|
|
216
|
+
case EPHPError.RECOVERABLE_ERROR:
|
|
217
|
+
type = "warn";
|
|
218
|
+
output += colors.yellowBright("Warning");
|
|
219
|
+
break;
|
|
220
|
+
case EPHPError.NOTICE:
|
|
221
|
+
case EPHPError.USER_NOTICE:
|
|
222
|
+
type = "info";
|
|
223
|
+
output += colors.bgWhite(colors.black("Notice"));
|
|
224
|
+
break;
|
|
225
|
+
case EPHPError.STRICT:
|
|
226
|
+
type = "info";
|
|
227
|
+
output += colors.yellow("Strict");
|
|
228
|
+
break;
|
|
229
|
+
case EPHPError.DEPRECATED:
|
|
230
|
+
case EPHPError.USER_DEPRECATED:
|
|
231
|
+
type = "info";
|
|
232
|
+
output += colors.cyan("Deprecated");
|
|
233
|
+
break;
|
|
234
|
+
default:
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
output += " " + data.message + "\r\n";
|
|
238
|
+
output += " In: " + data.file.replace(
|
|
239
|
+
node_path.resolve(shared.tempDir),
|
|
240
|
+
shared.viteConfig?.root
|
|
241
|
+
) + "\r\n";
|
|
242
|
+
output += " On line: " + data.line;
|
|
243
|
+
} catch (error) {
|
|
244
|
+
}
|
|
245
|
+
log(output, { ...options, type });
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
var tcpPortUsed$1 = {};
|
|
249
|
+
|
|
250
|
+
var is2 = {};
|
|
251
|
+
|
|
252
|
+
var deepIs = {exports: {}};
|
|
253
|
+
|
|
254
|
+
var hasRequiredDeepIs;
|
|
255
|
+
|
|
256
|
+
function requireDeepIs () {
|
|
257
|
+
if (hasRequiredDeepIs) return deepIs.exports;
|
|
258
|
+
hasRequiredDeepIs = 1;
|
|
259
|
+
var pSlice = Array.prototype.slice;
|
|
260
|
+
var Object_keys = typeof Object.keys === 'function'
|
|
261
|
+
? Object.keys
|
|
262
|
+
: function (obj) {
|
|
263
|
+
var keys = [];
|
|
264
|
+
for (var key in obj) keys.push(key);
|
|
265
|
+
return keys;
|
|
266
|
+
}
|
|
267
|
+
;
|
|
268
|
+
|
|
269
|
+
var deepEqual = deepIs.exports = function (actual, expected) {
|
|
270
|
+
// enforce Object.is +0 !== -0
|
|
271
|
+
if (actual === 0 && expected === 0) {
|
|
272
|
+
return areZerosEqual(actual, expected);
|
|
273
|
+
|
|
274
|
+
// 7.1. All identical values are equivalent, as determined by ===.
|
|
275
|
+
} else if (actual === expected) {
|
|
276
|
+
return true;
|
|
277
|
+
|
|
278
|
+
} else if (actual instanceof Date && expected instanceof Date) {
|
|
279
|
+
return actual.getTime() === expected.getTime();
|
|
280
|
+
|
|
281
|
+
} else if (isNumberNaN(actual)) {
|
|
282
|
+
return isNumberNaN(expected);
|
|
283
|
+
|
|
284
|
+
// 7.3. Other pairs that do not both pass typeof value == 'object',
|
|
285
|
+
// equivalence is determined by ==.
|
|
286
|
+
} else if (typeof actual != 'object' && typeof expected != 'object') {
|
|
287
|
+
return actual == expected;
|
|
288
|
+
|
|
289
|
+
// 7.4. For all other Object pairs, including Array objects, equivalence is
|
|
290
|
+
// determined by having the same number of owned properties (as verified
|
|
291
|
+
// with Object.prototype.hasOwnProperty.call), the same set of keys
|
|
292
|
+
// (although not necessarily the same order), equivalent values for every
|
|
293
|
+
// corresponding key, and an identical 'prototype' property. Note: this
|
|
294
|
+
// accounts for both named and indexed properties on Arrays.
|
|
295
|
+
} else {
|
|
296
|
+
return objEquiv(actual, expected);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
function isUndefinedOrNull(value) {
|
|
301
|
+
return value === null || value === undefined;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function isArguments(object) {
|
|
305
|
+
return Object.prototype.toString.call(object) == '[object Arguments]';
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function isNumberNaN(value) {
|
|
309
|
+
// NaN === NaN -> false
|
|
310
|
+
return typeof value == 'number' && value !== value;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function areZerosEqual(zeroA, zeroB) {
|
|
314
|
+
// (1 / +0|0) -> Infinity, but (1 / -0) -> -Infinity and (Infinity !== -Infinity)
|
|
315
|
+
return (1 / zeroA) === (1 / zeroB);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function objEquiv(a, b) {
|
|
319
|
+
if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
|
|
320
|
+
return false;
|
|
321
|
+
|
|
322
|
+
// an identical 'prototype' property.
|
|
323
|
+
if (a.prototype !== b.prototype) return false;
|
|
324
|
+
//~~~I've managed to break Object.keys through screwy arguments passing.
|
|
325
|
+
// Converting to array solves the problem.
|
|
326
|
+
if (isArguments(a)) {
|
|
327
|
+
if (!isArguments(b)) {
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
a = pSlice.call(a);
|
|
331
|
+
b = pSlice.call(b);
|
|
332
|
+
return deepEqual(a, b);
|
|
333
|
+
}
|
|
334
|
+
try {
|
|
335
|
+
var ka = Object_keys(a),
|
|
336
|
+
kb = Object_keys(b),
|
|
337
|
+
key, i;
|
|
338
|
+
} catch (e) {//happens when one is a string literal and the other isn't
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
// having the same number of owned properties (keys incorporates
|
|
342
|
+
// hasOwnProperty)
|
|
343
|
+
if (ka.length != kb.length)
|
|
344
|
+
return false;
|
|
345
|
+
//the same set of keys (although not necessarily the same order),
|
|
346
|
+
ka.sort();
|
|
347
|
+
kb.sort();
|
|
348
|
+
//~~~cheap key test
|
|
349
|
+
for (i = ka.length - 1; i >= 0; i--) {
|
|
350
|
+
if (ka[i] != kb[i])
|
|
351
|
+
return false;
|
|
352
|
+
}
|
|
353
|
+
//equivalent values for every corresponding key, and
|
|
354
|
+
//~~~possibly expensive deep test
|
|
355
|
+
for (i = ka.length - 1; i >= 0; i--) {
|
|
356
|
+
key = ka[i];
|
|
357
|
+
if (!deepEqual(a[key], b[key])) return false;
|
|
358
|
+
}
|
|
359
|
+
return true;
|
|
360
|
+
}
|
|
361
|
+
return deepIs.exports;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
var ipRegex;
|
|
365
|
+
var hasRequiredIpRegex;
|
|
366
|
+
|
|
367
|
+
function requireIpRegex () {
|
|
368
|
+
if (hasRequiredIpRegex) return ipRegex;
|
|
369
|
+
hasRequiredIpRegex = 1;
|
|
370
|
+
|
|
371
|
+
const word = '[a-fA-F\\d:]';
|
|
372
|
+
const b = options => options && options.includeBoundaries ?
|
|
373
|
+
`(?:(?<=\\s|^)(?=${word})|(?<=${word})(?=\\s|$))` :
|
|
374
|
+
'';
|
|
375
|
+
|
|
376
|
+
const v4 = '(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}';
|
|
377
|
+
|
|
378
|
+
const v6seg = '[a-fA-F\\d]{1,4}';
|
|
379
|
+
const v6 = `
|
|
380
|
+
(?:
|
|
381
|
+
(?:${v6seg}:){7}(?:${v6seg}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
|
|
382
|
+
(?:${v6seg}:){6}(?:${v4}|:${v6seg}|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4
|
|
383
|
+
(?:${v6seg}:){5}(?::${v4}|(?::${v6seg}){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4
|
|
384
|
+
(?:${v6seg}:){4}(?:(?::${v6seg}){0,1}:${v4}|(?::${v6seg}){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4
|
|
385
|
+
(?:${v6seg}:){3}(?:(?::${v6seg}){0,2}:${v4}|(?::${v6seg}){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4
|
|
386
|
+
(?:${v6seg}:){2}(?:(?::${v6seg}){0,3}:${v4}|(?::${v6seg}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4
|
|
387
|
+
(?:${v6seg}:){1}(?:(?::${v6seg}){0,4}:${v4}|(?::${v6seg}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
|
|
388
|
+
(?::(?:(?::${v6seg}){0,5}:${v4}|(?::${v6seg}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
|
|
389
|
+
)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1
|
|
390
|
+
`.replace(/\s*\/\/.*$/gm, '').replace(/\n/g, '').trim();
|
|
391
|
+
|
|
392
|
+
// Pre-compile only the exact regexes because adding a global flag make regexes stateful
|
|
393
|
+
const v46Exact = new RegExp(`(?:^${v4}$)|(?:^${v6}$)`);
|
|
394
|
+
const v4exact = new RegExp(`^${v4}$`);
|
|
395
|
+
const v6exact = new RegExp(`^${v6}$`);
|
|
396
|
+
|
|
397
|
+
const ip = options => options && options.exact ?
|
|
398
|
+
v46Exact :
|
|
399
|
+
new RegExp(`(?:${b(options)}${v4}${b(options)})|(?:${b(options)}${v6}${b(options)})`, 'g');
|
|
400
|
+
|
|
401
|
+
ip.v4 = options => options && options.exact ? v4exact : new RegExp(`${b(options)}${v4}${b(options)}`, 'g');
|
|
402
|
+
ip.v6 = options => options && options.exact ? v6exact : new RegExp(`${b(options)}${v6}${b(options)}`, 'g');
|
|
403
|
+
|
|
404
|
+
ipRegex = ip;
|
|
405
|
+
return ipRegex;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const name = "is2";
|
|
409
|
+
const version = "2.0.9";
|
|
410
|
+
const description = "A type checking library where each exported function returns either true or false and does not throw. Also added tests.";
|
|
411
|
+
const license = "MIT";
|
|
412
|
+
const tags = [
|
|
413
|
+
"type",
|
|
414
|
+
"check",
|
|
415
|
+
"checker",
|
|
416
|
+
"checking",
|
|
417
|
+
"utilities",
|
|
418
|
+
"network",
|
|
419
|
+
"networking",
|
|
420
|
+
"credit",
|
|
421
|
+
"card",
|
|
422
|
+
"validation"
|
|
423
|
+
];
|
|
424
|
+
const keywords = [
|
|
425
|
+
"type",
|
|
426
|
+
"check",
|
|
427
|
+
"checker",
|
|
428
|
+
"checking",
|
|
429
|
+
"utilities",
|
|
430
|
+
"network",
|
|
431
|
+
"networking",
|
|
432
|
+
"credit",
|
|
433
|
+
"card",
|
|
434
|
+
"validation"
|
|
435
|
+
];
|
|
436
|
+
const author = "Enrico Marino <enrico.marino@email.com>";
|
|
437
|
+
const maintainers = "Edmond Meinfelder <edmond@stdarg.com>, Chris Oyler <christopher.oyler@gmail.com>";
|
|
438
|
+
const homepage = "http://github.com/stdarg/is2";
|
|
439
|
+
const repository = {
|
|
440
|
+
type: "git",
|
|
441
|
+
url: "git@github.com:stdarg/is2.git"
|
|
442
|
+
};
|
|
443
|
+
const bugs = {
|
|
444
|
+
url: "http://github.com/stdarg/is/issues"
|
|
445
|
+
};
|
|
446
|
+
const main = "./index.js";
|
|
447
|
+
const scripts = {
|
|
448
|
+
test: "./node_modules/.bin/mocha -C --reporter list tests.js"
|
|
449
|
+
};
|
|
450
|
+
const engines = {
|
|
451
|
+
node: ">=v0.10.0"
|
|
452
|
+
};
|
|
453
|
+
const dependencies = {
|
|
454
|
+
"deep-is": "^0.1.3",
|
|
455
|
+
"ip-regex": "^4.1.0",
|
|
456
|
+
"is-url": "^1.2.4"
|
|
457
|
+
};
|
|
458
|
+
const devDependencies = {
|
|
459
|
+
mocha: "6.2.3",
|
|
460
|
+
mongodb: "3.2.4"
|
|
461
|
+
};
|
|
462
|
+
const _package = {
|
|
463
|
+
name: name,
|
|
464
|
+
version: version,
|
|
465
|
+
description: description,
|
|
466
|
+
license: license,
|
|
467
|
+
tags: tags,
|
|
468
|
+
keywords: keywords,
|
|
469
|
+
author: author,
|
|
470
|
+
maintainers: maintainers,
|
|
471
|
+
homepage: homepage,
|
|
472
|
+
repository: repository,
|
|
473
|
+
bugs: bugs,
|
|
474
|
+
main: main,
|
|
475
|
+
scripts: scripts,
|
|
476
|
+
engines: engines,
|
|
477
|
+
dependencies: dependencies,
|
|
478
|
+
devDependencies: devDependencies
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
const _package$1 = {
|
|
482
|
+
__proto__: null,
|
|
483
|
+
author: author,
|
|
484
|
+
bugs: bugs,
|
|
485
|
+
default: _package,
|
|
486
|
+
dependencies: dependencies,
|
|
487
|
+
description: description,
|
|
488
|
+
devDependencies: devDependencies,
|
|
489
|
+
engines: engines,
|
|
490
|
+
homepage: homepage,
|
|
491
|
+
keywords: keywords,
|
|
492
|
+
license: license,
|
|
493
|
+
main: main,
|
|
494
|
+
maintainers: maintainers,
|
|
495
|
+
name: name,
|
|
496
|
+
repository: repository,
|
|
497
|
+
scripts: scripts,
|
|
498
|
+
tags: tags,
|
|
499
|
+
version: version
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
const require$$2 = /*@__PURE__*/getAugmentedNamespace(_package$1);
|
|
503
|
+
|
|
504
|
+
var isUrl_1;
|
|
505
|
+
var hasRequiredIsUrl;
|
|
506
|
+
|
|
507
|
+
function requireIsUrl () {
|
|
508
|
+
if (hasRequiredIsUrl) return isUrl_1;
|
|
509
|
+
hasRequiredIsUrl = 1;
|
|
510
|
+
/**
|
|
511
|
+
* Expose `isUrl`.
|
|
512
|
+
*/
|
|
513
|
+
|
|
514
|
+
isUrl_1 = isUrl;
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* RegExps.
|
|
518
|
+
* A URL must match #1 and then at least one of #2/#3.
|
|
519
|
+
* Use two levels of REs to avoid REDOS.
|
|
520
|
+
*/
|
|
521
|
+
|
|
522
|
+
var protocolAndDomainRE = /^(?:\w+:)?\/\/(\S+)$/;
|
|
523
|
+
|
|
524
|
+
var localhostDomainRE = /^localhost[\:?\d]*(?:[^\:?\d]\S*)?$/;
|
|
525
|
+
var nonLocalhostDomainRE = /^[^\s\.]+\.\S{2,}$/;
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Loosely validate a URL `string`.
|
|
529
|
+
*
|
|
530
|
+
* @param {String} string
|
|
531
|
+
* @return {Boolean}
|
|
532
|
+
*/
|
|
533
|
+
|
|
534
|
+
function isUrl(string){
|
|
535
|
+
if (typeof string !== 'string') {
|
|
536
|
+
return false;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
var match = string.match(protocolAndDomainRE);
|
|
540
|
+
if (!match) {
|
|
541
|
+
return false;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
var everythingAfterProtocol = match[1];
|
|
545
|
+
if (!everythingAfterProtocol) {
|
|
546
|
+
return false;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
if (localhostDomainRE.test(everythingAfterProtocol) ||
|
|
550
|
+
nonLocalhostDomainRE.test(everythingAfterProtocol)) {
|
|
551
|
+
return true;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
return false;
|
|
555
|
+
}
|
|
556
|
+
return isUrl_1;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* @fileOverview
|
|
561
|
+
* is2 derived from is by Enrico Marino, adapted for Node.js.
|
|
562
|
+
* Slightly modified by Edmond Meinfelder
|
|
563
|
+
*
|
|
564
|
+
* is
|
|
565
|
+
* the definitive JavaScript type testing library
|
|
566
|
+
* Copyright(c) 2013,2014 Edmond Meinfelder <edmond@stdarg.com>
|
|
567
|
+
* Copyright(c) 2011 Enrico Marino <enrico.marino@email.com>
|
|
568
|
+
* MIT license
|
|
569
|
+
*/
|
|
570
|
+
|
|
571
|
+
var hasRequiredIs2;
|
|
572
|
+
|
|
573
|
+
function requireIs2 () {
|
|
574
|
+
if (hasRequiredIs2) return is2;
|
|
575
|
+
hasRequiredIs2 = 1;
|
|
576
|
+
(function (exports) {
|
|
577
|
+
const owns = {}.hasOwnProperty;
|
|
578
|
+
const toString = {}.toString;
|
|
579
|
+
const is = exports;
|
|
580
|
+
const deepIs = requireDeepIs();
|
|
581
|
+
const ipRegEx = requireIpRegex();
|
|
582
|
+
is.version = require$$2.version;
|
|
583
|
+
|
|
584
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
585
|
+
// Environment
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* Tests if is is running under a browser.
|
|
589
|
+
* @return {Boolean} true if the environment has process, process.version and process.versions.
|
|
590
|
+
*/
|
|
591
|
+
is.browser = function() {
|
|
592
|
+
return (!is.node() && typeof window !== 'undefined' && toString.call(window) === '[object global]');
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* Test if 'value' is defined.
|
|
597
|
+
* Alias: def
|
|
598
|
+
* @param {Any} value The value to test.
|
|
599
|
+
* @return {Boolean} true if 'value' is defined, false otherwise.
|
|
600
|
+
*/
|
|
601
|
+
is.defined = function(value) {
|
|
602
|
+
return typeof value !== 'undefined';
|
|
603
|
+
};
|
|
604
|
+
is.def = is.defined;
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Tests if is is running under node.js
|
|
608
|
+
* @return {Boolean} true if the environment has process, process.version and process.versions.
|
|
609
|
+
*/
|
|
610
|
+
is.nodejs = function() {
|
|
611
|
+
return (process && process.hasOwnProperty('version') &&
|
|
612
|
+
process.hasOwnProperty('versions'));
|
|
613
|
+
};
|
|
614
|
+
is.node = is.nodejs;
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* Test if 'value' is undefined.
|
|
618
|
+
* Aliases: undef, udef
|
|
619
|
+
* @param {Any} value value to test.
|
|
620
|
+
* @return {Boolean} true if 'value' is undefined, false otherwise.
|
|
621
|
+
*/
|
|
622
|
+
is.undefined = function(value) {
|
|
623
|
+
return value === undefined;
|
|
624
|
+
};
|
|
625
|
+
is.udef = is.undef = is.undefined;
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
629
|
+
// Types
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Test if 'value' is an array.
|
|
633
|
+
* Alias: ary, arry
|
|
634
|
+
* @param {Any} value value to test.
|
|
635
|
+
* @return {Boolean} true if 'value' is an array, false otherwise.
|
|
636
|
+
*/
|
|
637
|
+
is.array = function(value) {
|
|
638
|
+
return '[object Array]' === toString.call(value);
|
|
639
|
+
};
|
|
640
|
+
is.arr = is.ary = is.arry = is.array;
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Test if 'value' is an arraylike object (i.e. it has a length property with a valid value)
|
|
644
|
+
* Aliases: arraylike, arryLike, aryLike
|
|
645
|
+
* @param {Any} value value to test.
|
|
646
|
+
* @return {Boolean} true if 'value' is an arguments object, false otherwise.
|
|
647
|
+
*/
|
|
648
|
+
is.arrayLike = function(value) {
|
|
649
|
+
if (is.nullOrUndef(value))
|
|
650
|
+
return false;
|
|
651
|
+
return value !== undefined &&
|
|
652
|
+
owns.call(value, 'length') &&
|
|
653
|
+
isFinite(value.length);
|
|
654
|
+
};
|
|
655
|
+
is.arrLike = is.arryLike = is.aryLike = is.arraylike = is.arrayLike;
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* Test if 'value' is an arguments object.
|
|
659
|
+
* Alias: args
|
|
660
|
+
* @param {Any} value value to test
|
|
661
|
+
* @return {Boolean} true if 'value' is an arguments object, false otherwise
|
|
662
|
+
*/
|
|
663
|
+
is.arguments = function(value) {
|
|
664
|
+
return '[object Arguments]' === toString.call(value);
|
|
665
|
+
};
|
|
666
|
+
is.args = is.arguments;
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* Test if 'value' is a boolean.
|
|
670
|
+
* Alias: bool
|
|
671
|
+
* @param {Any} value value to test.
|
|
672
|
+
* @return {Boolean} true if 'value' is a boolean, false otherwise.
|
|
673
|
+
*/
|
|
674
|
+
is.boolean = function(value) {
|
|
675
|
+
return '[object Boolean]' === toString.call(value);
|
|
676
|
+
};
|
|
677
|
+
is.bool = is.boolean;
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* Test if 'value' is an instance of Buffer.
|
|
681
|
+
* Aliases: instOf, instanceof
|
|
682
|
+
* @param {Any} value value to test.
|
|
683
|
+
* @return {Boolean} true if 'value' is an instance of 'constructor'.
|
|
684
|
+
*/
|
|
685
|
+
is.buffer = function(value) {
|
|
686
|
+
return is.nodejs() && Buffer && Buffer.hasOwnProperty('isBuffer') && Buffer.isBuffer(value);
|
|
687
|
+
};
|
|
688
|
+
is.buff = is.buf = is.buffer;
|
|
689
|
+
|
|
690
|
+
/**
|
|
691
|
+
* Test if 'value' is a date.
|
|
692
|
+
* @param {Any} value value to test.
|
|
693
|
+
* @return {Boolean} true if 'value' is a date, false otherwise.
|
|
694
|
+
*/
|
|
695
|
+
is.date = function(value) {
|
|
696
|
+
return '[object Date]' === toString.call(value);
|
|
697
|
+
};
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* Test if 'value' is an error object.
|
|
701
|
+
* Alias: err
|
|
702
|
+
* @param value value to test.
|
|
703
|
+
* @return {Boolean} true if 'value' is an error object, false otherwise.
|
|
704
|
+
*/
|
|
705
|
+
is.error = function(value) {
|
|
706
|
+
return '[object Error]' === toString.call(value);
|
|
707
|
+
};
|
|
708
|
+
is.err = is.error;
|
|
709
|
+
|
|
710
|
+
/**
|
|
711
|
+
* Test if 'value' is false.
|
|
712
|
+
* @param {Any} value value to test.
|
|
713
|
+
* @return {Boolean} true if 'value' is false, false otherwise
|
|
714
|
+
*/
|
|
715
|
+
is.false = function(value) {
|
|
716
|
+
return value === false;
|
|
717
|
+
};
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* Test if 'value' is a function or async function.
|
|
721
|
+
* Alias: func
|
|
722
|
+
* @param {Any} value value to test.
|
|
723
|
+
* @return {Boolean} true if 'value' is a function, false otherwise.
|
|
724
|
+
*/
|
|
725
|
+
is.function = function(value) {
|
|
726
|
+
return is.syncFunction(value) || is.asyncFunction(value)
|
|
727
|
+
};
|
|
728
|
+
is.fun = is.func = is.function;
|
|
729
|
+
|
|
730
|
+
/**
|
|
731
|
+
* Test if 'value' is an async function using `async () => {}` or `async function () {}`.
|
|
732
|
+
* Alias: func
|
|
733
|
+
* @param {Any} value value to test.
|
|
734
|
+
* @return {Boolean} true if 'value' is a function, false otherwise.
|
|
735
|
+
*/
|
|
736
|
+
is.asyncFunction = function(value) {
|
|
737
|
+
return '[object AsyncFunction]' === toString.call(value);
|
|
738
|
+
};
|
|
739
|
+
is.asyncFun = is.asyncFunc = is.asyncFunction;
|
|
740
|
+
|
|
741
|
+
/**
|
|
742
|
+
* Test if 'value' is a synchronous function.
|
|
743
|
+
* Alias: syncFunc
|
|
744
|
+
* @param {Any} value value to test.
|
|
745
|
+
* @return {Boolean} true if 'value' is a function, false otherwise.
|
|
746
|
+
*/
|
|
747
|
+
is.syncFunction = function (value) {
|
|
748
|
+
return '[object Function]' === toString.call(value);
|
|
749
|
+
};
|
|
750
|
+
is.syncFun = is.syncFunc = is.syncFunction;
|
|
751
|
+
/**
|
|
752
|
+
* Test if 'value' is null.
|
|
753
|
+
* @param {Any} value to test.
|
|
754
|
+
* @return {Boolean} true if 'value' is null, false otherwise.
|
|
755
|
+
*/
|
|
756
|
+
is.null = function(value) {
|
|
757
|
+
return value === null;
|
|
758
|
+
};
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* Test is 'value' is either null or undefined.
|
|
762
|
+
* Alias: nullOrUndef
|
|
763
|
+
* @param {Any} value value to test.
|
|
764
|
+
* @return {Boolean} True if value is null or undefined, false otherwise.
|
|
765
|
+
*/
|
|
766
|
+
is.nullOrUndefined = function(value) {
|
|
767
|
+
return value === null || typeof value === 'undefined';
|
|
768
|
+
};
|
|
769
|
+
is.nullOrUndef = is.nullOrUndefined;
|
|
770
|
+
|
|
771
|
+
/**
|
|
772
|
+
* Test if 'value' is a number.
|
|
773
|
+
* Alias: num
|
|
774
|
+
* @param {Any} value to test.
|
|
775
|
+
* @return {Boolean} true if 'value' is a number, false otherwise.
|
|
776
|
+
*/
|
|
777
|
+
is.number = function(value) {
|
|
778
|
+
return '[object Number]' === toString.call(value);
|
|
779
|
+
};
|
|
780
|
+
is.num = is.number;
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* Test if 'value' is an object. Note: Arrays, RegExps, Date, Error, etc all return false.
|
|
784
|
+
* Alias: obj
|
|
785
|
+
* @param {Any} value to test.
|
|
786
|
+
* @return {Boolean} true if 'value' is an object, false otherwise.
|
|
787
|
+
*/
|
|
788
|
+
is.object = function(value) {
|
|
789
|
+
return '[object Object]' === toString.call(value);
|
|
790
|
+
};
|
|
791
|
+
is.obj = is.object;
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* Test if 'value' is a regular expression.
|
|
795
|
+
* Alias: regexp
|
|
796
|
+
* @param {Any} value to test.
|
|
797
|
+
* @return {Boolean} true if 'value' is a regexp, false otherwise.
|
|
798
|
+
*/
|
|
799
|
+
is.regExp = function(value) {
|
|
800
|
+
return '[object RegExp]' === toString.call(value);
|
|
801
|
+
};
|
|
802
|
+
is.re = is.regexp = is.regExp;
|
|
803
|
+
|
|
804
|
+
/**
|
|
805
|
+
* Test if 'value' is a string.
|
|
806
|
+
* Alias: str
|
|
807
|
+
* @param {Any} value to test.
|
|
808
|
+
* @return {Boolean} true if 'value' is a string, false otherwise.
|
|
809
|
+
*/
|
|
810
|
+
is.string = function(value) {
|
|
811
|
+
return '[object String]' === toString.call(value);
|
|
812
|
+
};
|
|
813
|
+
is.str = is.string;
|
|
814
|
+
|
|
815
|
+
/**
|
|
816
|
+
* Test if 'value' is true.
|
|
817
|
+
* @param {Any} value to test.
|
|
818
|
+
* @return {Boolean} true if 'value' is true, false otherwise.
|
|
819
|
+
*/
|
|
820
|
+
is.true = function(value) {
|
|
821
|
+
return value === true;
|
|
822
|
+
};
|
|
823
|
+
|
|
824
|
+
/**
|
|
825
|
+
* Test if 'value' is a uuid (v1-v5)
|
|
826
|
+
* @param {Any} value to test.
|
|
827
|
+
* @return {Boolean} true if 'value is a valid RFC4122 UUID. Case non-specific.
|
|
828
|
+
*/
|
|
829
|
+
var uuidRegExp = new RegExp('[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab]'+
|
|
830
|
+
'[0-9a-f]{3}-[0-9a-f]{12}', 'i');
|
|
831
|
+
is.uuid = function(value) {
|
|
832
|
+
return uuidRegExp.test(value);
|
|
833
|
+
};
|
|
834
|
+
|
|
835
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
836
|
+
// Object Relationships
|
|
837
|
+
|
|
838
|
+
/**
|
|
839
|
+
* Test if 'value' is equal to 'other'. Works for objects and arrays and will do deep comparisions,
|
|
840
|
+
* using recursion.
|
|
841
|
+
* Alias: eq
|
|
842
|
+
* @param {Any} value value.
|
|
843
|
+
* @param {Any} other value to compare with.
|
|
844
|
+
* @return {Boolean} true if 'value' is equal to 'other', false otherwise
|
|
845
|
+
*/
|
|
846
|
+
is.equal = function(value, other) {
|
|
847
|
+
var type = toString.call(value);
|
|
848
|
+
|
|
849
|
+
if (typeof value !== typeof other) {
|
|
850
|
+
return false;
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
if (type !== toString.call(other)) {
|
|
854
|
+
return false;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
if ('[object Object]' === type || '[object Array]' === type) {
|
|
858
|
+
return deepIs(value, other);
|
|
859
|
+
} else if ('[object Function]' === type) {
|
|
860
|
+
return value.prototype === other.prototype;
|
|
861
|
+
} else if ('[object Date]' === type) {
|
|
862
|
+
return value.getTime() === other.getTime();
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
return value === other;
|
|
866
|
+
};
|
|
867
|
+
is.objEquals = is.eq = is.equal;
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* JS Type definitions which cannot host values.
|
|
871
|
+
* @api private
|
|
872
|
+
*/
|
|
873
|
+
var NON_HOST_TYPES = {
|
|
874
|
+
'boolean': 1,
|
|
875
|
+
'number': 1,
|
|
876
|
+
'string': 1,
|
|
877
|
+
'undefined': 1
|
|
878
|
+
};
|
|
879
|
+
|
|
880
|
+
/**
|
|
881
|
+
* Test if 'key' in host is an object. To be hosted means host[value] is an object.
|
|
882
|
+
* @param {Any} value The value to test.
|
|
883
|
+
* @param {Any} host Host that may contain value.
|
|
884
|
+
* @return {Boolean} true if 'value' is hosted by 'host', false otherwise.
|
|
885
|
+
*/
|
|
886
|
+
is.hosted = function(value, host) {
|
|
887
|
+
if (is.nullOrUndef(value))
|
|
888
|
+
return false;
|
|
889
|
+
var type = typeof host[value];
|
|
890
|
+
return type === 'object' ? !!host[value] : !NON_HOST_TYPES[type];
|
|
891
|
+
};
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* Test if 'value' is an instance of 'constructor'.
|
|
895
|
+
* Aliases: instOf, instanceof
|
|
896
|
+
* @param {Any} value value to test.
|
|
897
|
+
* @return {Boolean} true if 'value' is an instance of 'constructor'.
|
|
898
|
+
*/
|
|
899
|
+
is.instanceOf = function(value, constructor) {
|
|
900
|
+
if (is.nullOrUndef(value) || is.nullOrUndef(constructor))
|
|
901
|
+
return false;
|
|
902
|
+
return (value instanceof constructor);
|
|
903
|
+
};
|
|
904
|
+
is.instOf = is.instanceof = is.instanceOf;
|
|
905
|
+
|
|
906
|
+
/**
|
|
907
|
+
* Test if 'value' is an instance type objType.
|
|
908
|
+
* Aliases: objInstOf, objectinstanceof, instOf, instanceOf
|
|
909
|
+
* @param {object} objInst an object to testfor type.
|
|
910
|
+
* @param {object} objType an object type to compare.
|
|
911
|
+
* @return {Boolean} true if 'value' is an object, false otherwise.
|
|
912
|
+
*/
|
|
913
|
+
is.objectInstanceOf = function(objInst, objType) {
|
|
914
|
+
try {
|
|
915
|
+
return '[object Object]' === toString.call(objInst) && (objInst instanceof objType);
|
|
916
|
+
} catch(err) {
|
|
917
|
+
return false;
|
|
918
|
+
}
|
|
919
|
+
};
|
|
920
|
+
is.instOf = is.instanceOf = is.objInstOf = is.objectInstanceOf;
|
|
921
|
+
|
|
922
|
+
/**
|
|
923
|
+
* Test if 'value' is a type of 'type'.
|
|
924
|
+
* Alias: a
|
|
925
|
+
* @param value value to test.
|
|
926
|
+
* @param {String} type The name of the type.
|
|
927
|
+
* @return {Boolean} true if 'value' is an arguments object, false otherwise.
|
|
928
|
+
*/
|
|
929
|
+
is.type = function(value, type) {
|
|
930
|
+
return typeof value === type;
|
|
931
|
+
};
|
|
932
|
+
is.a = is.type;
|
|
933
|
+
|
|
934
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
935
|
+
// Object State
|
|
936
|
+
|
|
937
|
+
/**
|
|
938
|
+
* Test if 'value' is empty. To be empty means to be an array, object or string with nothing contained.
|
|
939
|
+
* @param {Any} value value to test.
|
|
940
|
+
* @return {Boolean} true if 'value' is empty, false otherwise.
|
|
941
|
+
*/
|
|
942
|
+
is.empty = function(value) {
|
|
943
|
+
var type = toString.call(value);
|
|
944
|
+
|
|
945
|
+
if ('[object Array]' === type || '[object Arguments]' === type) {
|
|
946
|
+
return value.length === 0;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
if ('[object Object]' === type) {
|
|
950
|
+
for (var key in value) if (owns.call(value, key)) return false;
|
|
951
|
+
return true;
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
if ('[object String]' === type) {
|
|
955
|
+
return value === '';
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
return false;
|
|
959
|
+
};
|
|
960
|
+
|
|
961
|
+
/**
|
|
962
|
+
* Test if 'value' is an arguments object that is empty.
|
|
963
|
+
* Alias: args
|
|
964
|
+
* @param {Any} value value to test
|
|
965
|
+
* @return {Boolean} true if 'value' is an arguments object with no args, false otherwise
|
|
966
|
+
*/
|
|
967
|
+
is.emptyArguments = function(value) {
|
|
968
|
+
return '[object Arguments]' === toString.call(value) && value.length === 0;
|
|
969
|
+
};
|
|
970
|
+
is.noArgs = is.emptyArgs = is.emptyArguments;
|
|
971
|
+
|
|
972
|
+
/**
|
|
973
|
+
* Test if 'value' is an array containing no entries.
|
|
974
|
+
* Aliases: emptyArry, emptyAry
|
|
975
|
+
* @param {Any} value The value to test.
|
|
976
|
+
* @return {Boolean} true if 'value' is an array with no elemnets.
|
|
977
|
+
*/
|
|
978
|
+
is.emptyArray = function(value) {
|
|
979
|
+
return '[object Array]' === toString.call(value) && value.length === 0;
|
|
980
|
+
};
|
|
981
|
+
is.emptyArry = is.emptyAry = is.emptyArray;
|
|
982
|
+
|
|
983
|
+
/**
|
|
984
|
+
* Test if 'value' is an empty array(like) object.
|
|
985
|
+
* Aliases: arguents.empty, args.empty, ary.empty, arry.empty
|
|
986
|
+
* @param {Any} value value to test.
|
|
987
|
+
* @return {Boolean} true if 'value' is an empty array(like), false otherwise.
|
|
988
|
+
*/
|
|
989
|
+
is.emptyArrayLike = function(value) {
|
|
990
|
+
return value.length === 0;
|
|
991
|
+
};
|
|
992
|
+
is.emptyArrLike = is.emptyArrayLike;
|
|
993
|
+
|
|
994
|
+
/**
|
|
995
|
+
* Test if 'value' is an empty string.
|
|
996
|
+
* Alias: emptyStr
|
|
997
|
+
* @param {Any} value to test.
|
|
998
|
+
* @return {Boolean} true if 'value' is am empty string, false otherwise.
|
|
999
|
+
*/
|
|
1000
|
+
is.emptyString = function(value) {
|
|
1001
|
+
return is.string(value) && value.length === 0;
|
|
1002
|
+
};
|
|
1003
|
+
is.emptyStr = is.emptyString;
|
|
1004
|
+
|
|
1005
|
+
/**
|
|
1006
|
+
* Test if 'value' is an array containing at least 1 entry.
|
|
1007
|
+
* Aliases: nonEmptyArry, nonEmptyAry
|
|
1008
|
+
* @param {Any} value The value to test.
|
|
1009
|
+
* @return {Boolean} true if 'value' is an array with at least 1 value, false otherwise.
|
|
1010
|
+
*/
|
|
1011
|
+
is.nonEmptyArray = function(value) {
|
|
1012
|
+
return '[object Array]' === toString.call(value) && value.length > 0;
|
|
1013
|
+
};
|
|
1014
|
+
is.nonEmptyArr = is.nonEmptyArry = is.nonEmptyAry = is.nonEmptyArray;
|
|
1015
|
+
|
|
1016
|
+
/**
|
|
1017
|
+
* Test if 'value' is an object with properties. Note: Arrays are objects.
|
|
1018
|
+
* Alias: nonEmptyObj
|
|
1019
|
+
* @param {Any} value to test.
|
|
1020
|
+
* @return {Boolean} true if 'value' is an object, false otherwise.
|
|
1021
|
+
*/
|
|
1022
|
+
is.nonEmptyObject = function(value) {
|
|
1023
|
+
return '[object Object]' === toString.call(value) && Object.keys(value).length > 0;
|
|
1024
|
+
};
|
|
1025
|
+
is.nonEmptyObj = is.nonEmptyObject;
|
|
1026
|
+
|
|
1027
|
+
/**
|
|
1028
|
+
* Test if 'value' is an object with no properties. Note: Arrays are objects.
|
|
1029
|
+
* Alias: nonEmptyObj
|
|
1030
|
+
* @param {Any} value to test.
|
|
1031
|
+
* @return {Boolean} true if 'value' is an object, false otherwise.
|
|
1032
|
+
*/
|
|
1033
|
+
is.emptyObject = function(value) {
|
|
1034
|
+
return '[object Object]' === toString.call(value) && Object.keys(value).length === 0;
|
|
1035
|
+
};
|
|
1036
|
+
is.emptyObj = is.emptyObject;
|
|
1037
|
+
|
|
1038
|
+
/**
|
|
1039
|
+
* Test if 'value' is a non-empty string.
|
|
1040
|
+
* Alias: nonEmptyStr
|
|
1041
|
+
* @param {Any} value to test.
|
|
1042
|
+
* @return {Boolean} true if 'value' is a non-empty string, false otherwise.
|
|
1043
|
+
*/
|
|
1044
|
+
is.nonEmptyString = function(value) {
|
|
1045
|
+
return is.string(value) && value.length > 0;
|
|
1046
|
+
};
|
|
1047
|
+
is.nonEmptyStr = is.nonEmptyString;
|
|
1048
|
+
|
|
1049
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
1050
|
+
// Numeric Types within Number
|
|
1051
|
+
|
|
1052
|
+
/**
|
|
1053
|
+
* Test if 'value' is an even number.
|
|
1054
|
+
* @param {Number} value to test.
|
|
1055
|
+
* @return {Boolean} true if 'value' is an even number, false otherwise.
|
|
1056
|
+
*/
|
|
1057
|
+
is.even = function(value) {
|
|
1058
|
+
return '[object Number]' === toString.call(value) && value % 2 === 0;
|
|
1059
|
+
};
|
|
1060
|
+
|
|
1061
|
+
/**
|
|
1062
|
+
* Test if 'value' is a decimal number.
|
|
1063
|
+
* Aliases: decimalNumber, decNum
|
|
1064
|
+
* @param {Any} value value to test.
|
|
1065
|
+
* @return {Boolean} true if 'value' is a decimal number, false otherwise.
|
|
1066
|
+
*/
|
|
1067
|
+
is.decimal = function(value) {
|
|
1068
|
+
return '[object Number]' === toString.call(value) && value % 1 !== 0;
|
|
1069
|
+
};
|
|
1070
|
+
is.dec = is.decNum = is.decimal;
|
|
1071
|
+
|
|
1072
|
+
/**
|
|
1073
|
+
* Test if 'value' is an integer.
|
|
1074
|
+
* Alias: integer
|
|
1075
|
+
* @param {Any} value to test.
|
|
1076
|
+
* @return {Boolean} true if 'value' is an integer, false otherwise.
|
|
1077
|
+
*/
|
|
1078
|
+
is.integer = function(value) {
|
|
1079
|
+
return '[object Number]' === toString.call(value) && value % 1 === 0;
|
|
1080
|
+
};
|
|
1081
|
+
is.int = is.integer;
|
|
1082
|
+
|
|
1083
|
+
/**
|
|
1084
|
+
* is.nan
|
|
1085
|
+
* Test if `value` is not a number.
|
|
1086
|
+
*
|
|
1087
|
+
* @param {Mixed} value value to test
|
|
1088
|
+
* @return {Boolean} true if `value` is not a number, false otherwise
|
|
1089
|
+
* @api public
|
|
1090
|
+
*/
|
|
1091
|
+
is.notANumber = function(value) {
|
|
1092
|
+
return !is.num(value) || value !== value;
|
|
1093
|
+
};
|
|
1094
|
+
is.nan = is.notANum = is.notANumber;
|
|
1095
|
+
|
|
1096
|
+
/**
|
|
1097
|
+
* Test if 'value' is an odd number.
|
|
1098
|
+
* @param {Number} value to test.
|
|
1099
|
+
* @return {Boolean} true if 'value' is an odd number, false otherwise.
|
|
1100
|
+
*/
|
|
1101
|
+
is.odd = function(value) {
|
|
1102
|
+
return !is.decimal(value) && '[object Number]' === toString.call(value) && value % 2 !== 0;
|
|
1103
|
+
};
|
|
1104
|
+
is.oddNumber = is.oddNum = is.odd;
|
|
1105
|
+
|
|
1106
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
1107
|
+
// Numeric Type & State
|
|
1108
|
+
|
|
1109
|
+
/**
|
|
1110
|
+
* Test if 'value' is a positive number.
|
|
1111
|
+
* Alias: positiveNum, posNum
|
|
1112
|
+
* @param {Any} value to test.
|
|
1113
|
+
* @return {Boolean} true if 'value' is a number, false otherwise.
|
|
1114
|
+
*/
|
|
1115
|
+
is.positiveNumber = function(value) {
|
|
1116
|
+
return '[object Number]' === toString.call(value) && value > 0;
|
|
1117
|
+
};
|
|
1118
|
+
is.pos = is.positive = is.posNum = is.positiveNum = is.positiveNumber;
|
|
1119
|
+
|
|
1120
|
+
/**
|
|
1121
|
+
* Test if 'value' is a negative number.
|
|
1122
|
+
* Aliases: negNum, negativeNum
|
|
1123
|
+
* @param {Any} value to test.
|
|
1124
|
+
* @return {Boolean} true if 'value' is a number, false otherwise.
|
|
1125
|
+
*/
|
|
1126
|
+
is.negativeNumber = function(value) {
|
|
1127
|
+
return '[object Number]' === toString.call(value) && value < 0;
|
|
1128
|
+
};
|
|
1129
|
+
is.neg = is.negNum = is.negativeNum = is.negativeNumber;
|
|
1130
|
+
|
|
1131
|
+
/**
|
|
1132
|
+
* Test if 'value' is a negative integer.
|
|
1133
|
+
* Aliases: negInt, negativeInteger
|
|
1134
|
+
* @param {Any} value to test.
|
|
1135
|
+
* @return {Boolean} true if 'value' is a negative integer, false otherwise.
|
|
1136
|
+
*/
|
|
1137
|
+
is.negativeInteger = function(value) {
|
|
1138
|
+
return '[object Number]' === toString.call(value) && value % 1 === 0 && value < 0;
|
|
1139
|
+
};
|
|
1140
|
+
is.negativeInt = is.negInt = is.negativeInteger;
|
|
1141
|
+
|
|
1142
|
+
/**
|
|
1143
|
+
* Test if 'value' is a positive integer.
|
|
1144
|
+
* Alias: posInt
|
|
1145
|
+
* @param {Any} value to test.
|
|
1146
|
+
* @return {Boolean} true if 'value' is a positive integer, false otherwise.
|
|
1147
|
+
*/
|
|
1148
|
+
is.positiveInteger = function(value) {
|
|
1149
|
+
return '[object Number]' === toString.call(value) && value % 1 === 0 && value > 0;
|
|
1150
|
+
};
|
|
1151
|
+
is.posInt = is.positiveInt = is.positiveInteger;
|
|
1152
|
+
|
|
1153
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
1154
|
+
// Numeric Relationships
|
|
1155
|
+
|
|
1156
|
+
/**
|
|
1157
|
+
* Test if 'value' is divisible by 'n'.
|
|
1158
|
+
* Alias: divisBy
|
|
1159
|
+
* @param {Number} value value to test.
|
|
1160
|
+
* @param {Number} n dividend.
|
|
1161
|
+
* @return {Boolean} true if 'value' is divisible by 'n', false otherwise.
|
|
1162
|
+
*/
|
|
1163
|
+
is.divisibleBy = function(value, n) {
|
|
1164
|
+
if (value === 0)
|
|
1165
|
+
return false;
|
|
1166
|
+
return '[object Number]' === toString.call(value) &&
|
|
1167
|
+
n !== 0 &&
|
|
1168
|
+
value % n === 0;
|
|
1169
|
+
};
|
|
1170
|
+
is.divBy = is.divisBy = is.divisibleBy;
|
|
1171
|
+
|
|
1172
|
+
/**
|
|
1173
|
+
* Test if 'value' is greater than or equal to 'other'.
|
|
1174
|
+
* Aliases: greaterOrEq, greaterOrEqual
|
|
1175
|
+
* @param {Number} value value to test.
|
|
1176
|
+
* @param {Number} other value to compare with.
|
|
1177
|
+
* @return {Boolean} true, if value is greater than or equal to other, false otherwise.
|
|
1178
|
+
*/
|
|
1179
|
+
is.greaterOrEqualTo = function(value, other) {
|
|
1180
|
+
return value >= other;
|
|
1181
|
+
};
|
|
1182
|
+
is.greaterOrEqual = is.ge = is.greaterOrEqualTo;
|
|
1183
|
+
|
|
1184
|
+
/**
|
|
1185
|
+
* Test if 'value' is greater than 'other'.
|
|
1186
|
+
* Aliases: greaterThan
|
|
1187
|
+
* @param {Number} value value to test.
|
|
1188
|
+
* @param {Number} other value to compare with.
|
|
1189
|
+
* @return {Boolean} true, if value is greater than other, false otherwise.
|
|
1190
|
+
*/
|
|
1191
|
+
is.greaterThan = function(value, other) {
|
|
1192
|
+
return value > other;
|
|
1193
|
+
};
|
|
1194
|
+
is.gt = is.greaterThan;
|
|
1195
|
+
|
|
1196
|
+
/**
|
|
1197
|
+
* Test if 'value' is less than or equal to 'other'.
|
|
1198
|
+
* Alias: lessThanOrEq, lessThanOrEqual
|
|
1199
|
+
* @param {Number} value value to test
|
|
1200
|
+
* @param {Number} other value to compare with
|
|
1201
|
+
* @return {Boolean} true, if 'value' is less than or equal to 'other', false otherwise.
|
|
1202
|
+
*/
|
|
1203
|
+
is.lessThanOrEqualTo = function(value, other) {
|
|
1204
|
+
return value <= other;
|
|
1205
|
+
};
|
|
1206
|
+
is.lessThanOrEq = is.lessThanOrEqual = is.le = is.lessThanOrEqualTo;
|
|
1207
|
+
|
|
1208
|
+
/**
|
|
1209
|
+
* Test if 'value' is less than 'other'.
|
|
1210
|
+
* Alias: lessThan
|
|
1211
|
+
* @param {Number} value value to test
|
|
1212
|
+
* @param {Number} other value to compare with
|
|
1213
|
+
* @return {Boolean} true, if 'value' is less than 'other', false otherwise.
|
|
1214
|
+
*/
|
|
1215
|
+
is.lessThan = function(value, other) {
|
|
1216
|
+
return value < other;
|
|
1217
|
+
};
|
|
1218
|
+
is.lt = is.lessThan;
|
|
1219
|
+
|
|
1220
|
+
/**
|
|
1221
|
+
* Test if 'value' is greater than 'others' values.
|
|
1222
|
+
* Alias: max
|
|
1223
|
+
* @param {Number} value value to test.
|
|
1224
|
+
* @param {Array} others values to compare with.
|
|
1225
|
+
* @return {Boolean} true if 'value' is greater than 'others' values.
|
|
1226
|
+
*/
|
|
1227
|
+
is.maximum = function(value, others) {
|
|
1228
|
+
if (!is.arrayLike(others) || !is.number(value))
|
|
1229
|
+
return false;
|
|
1230
|
+
|
|
1231
|
+
var len = others.length;
|
|
1232
|
+
while (--len > -1) {
|
|
1233
|
+
if (value < others[len]) {
|
|
1234
|
+
return false;
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
return true;
|
|
1239
|
+
};
|
|
1240
|
+
is.max = is.maximum;
|
|
1241
|
+
|
|
1242
|
+
/**
|
|
1243
|
+
* Test if 'value' is less than 'others' values.
|
|
1244
|
+
* Alias: min
|
|
1245
|
+
* @param {Number} value value to test.
|
|
1246
|
+
* @param {Array} others values to compare with.
|
|
1247
|
+
* @return {Boolean} true if 'value' is less than 'others' values.
|
|
1248
|
+
*/
|
|
1249
|
+
is.minimum = function(value, others) {
|
|
1250
|
+
if (!is.arrayLike(others) || !is.number(value))
|
|
1251
|
+
return false;
|
|
1252
|
+
|
|
1253
|
+
var len = others.length;
|
|
1254
|
+
while (--len > -1) {
|
|
1255
|
+
if (value > others[len]) {
|
|
1256
|
+
return false;
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
return true;
|
|
1261
|
+
};
|
|
1262
|
+
is.min = is.minimum;
|
|
1263
|
+
|
|
1264
|
+
/**
|
|
1265
|
+
* Test if 'value' is within 'start' and 'finish'.
|
|
1266
|
+
* Alias: withIn
|
|
1267
|
+
* @param {Number} value value to test.
|
|
1268
|
+
* @param {Number} start lower bound.
|
|
1269
|
+
* @param {Number} finish upper bound.
|
|
1270
|
+
* @return {Boolean} true if 'value' is is within 'start' and 'finish', false otherwise.
|
|
1271
|
+
*/
|
|
1272
|
+
is.within = function(value, start, finish) {
|
|
1273
|
+
return value >= start && value <= finish;
|
|
1274
|
+
};
|
|
1275
|
+
is.withIn = is.within;
|
|
1276
|
+
|
|
1277
|
+
/**
|
|
1278
|
+
* Test if 'value' is within 'precision' decimal places from 'comparitor'.
|
|
1279
|
+
* Alias: closish, near.
|
|
1280
|
+
* @param {Number} value value to test
|
|
1281
|
+
* @param {Number} comparitor value to test 'value' against
|
|
1282
|
+
* @param {Number} precision number of decimals to compare floating points, defaults to 2
|
|
1283
|
+
* @return {Boolean} true if 'value' is within 'precision' decimal places from 'comparitor', false otherwise.
|
|
1284
|
+
*/
|
|
1285
|
+
is.prettyClose = function(value, comparitor, precision) {
|
|
1286
|
+
if (!is.number(value) || !is.number(comparitor)) return false;
|
|
1287
|
+
if (is.defined(precision) && !is.posInt(precision)) return false;
|
|
1288
|
+
if (is.undefined(precision)) precision = 2;
|
|
1289
|
+
|
|
1290
|
+
return value.toFixed(precision) === comparitor.toFixed(precision);
|
|
1291
|
+
};
|
|
1292
|
+
is.closish = is.near = is.prettyClose;
|
|
1293
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
1294
|
+
// Networking
|
|
1295
|
+
|
|
1296
|
+
/**
|
|
1297
|
+
* Test if a value is a valid DNS address. eg www.stdarg.com is true while
|
|
1298
|
+
* 127.0.0.1 is false.
|
|
1299
|
+
* @param {Any} value to test if a DNS address.
|
|
1300
|
+
* @return {Boolean} true if a DNS address, false otherwise.
|
|
1301
|
+
* DNS Address is made up of labels separated by '.'
|
|
1302
|
+
* Each label must be between 1 and 63 characters long
|
|
1303
|
+
* The entire hostname (including the delimiting dots) has a maximum of 255 characters.
|
|
1304
|
+
* Hostname may not contain other characters, such as the underscore character (_)
|
|
1305
|
+
* other DNS names may contain the underscore.
|
|
1306
|
+
*/
|
|
1307
|
+
is.dnsAddress = function(value) {
|
|
1308
|
+
if (!is.nonEmptyStr(value)) return false;
|
|
1309
|
+
if (value.length > 255) return false;
|
|
1310
|
+
if (numbersLabel.test(value)) return false;
|
|
1311
|
+
if (!dnsLabel.test(value)) return false;
|
|
1312
|
+
return true;
|
|
1313
|
+
//var names = value.split('.');
|
|
1314
|
+
//if (!is.array(names) || !names.length) return false;
|
|
1315
|
+
//if (names[0].indexOf('_') > -1) return false;
|
|
1316
|
+
//for (var i=0; i<names.length; i++) {
|
|
1317
|
+
//if (!dnsLabel.test(names[i])) return false;
|
|
1318
|
+
//}
|
|
1319
|
+
//return true;
|
|
1320
|
+
};
|
|
1321
|
+
is.dnsAddr = is.dns = is.dnsAddress;
|
|
1322
|
+
var dnsLabel = /^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$/;
|
|
1323
|
+
var numbersLabel = /^([0-9]|[0-9][0-9\-]{0,61}[0-9])(\.([0-9]|[0-9][0-9\-]{0,61}[0-9]))*$/;
|
|
1324
|
+
|
|
1325
|
+
/**
|
|
1326
|
+
* Test if value is a valid email address.
|
|
1327
|
+
* @param {Any} value to test if an email address.
|
|
1328
|
+
* @return {Boolean} true if an email address, false otherwise.
|
|
1329
|
+
*/
|
|
1330
|
+
is.emailAddress = function(value) {
|
|
1331
|
+
if (!is.nonEmptyStr(value))
|
|
1332
|
+
return false;
|
|
1333
|
+
return emailRegexp.test(value);
|
|
1334
|
+
};
|
|
1335
|
+
is.email = is.emailAddr = is.emailAddress;
|
|
1336
|
+
var emailRegexp = /^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$/;
|
|
1337
|
+
|
|
1338
|
+
/**
|
|
1339
|
+
* Test if a value is either an IPv4 numeric IP address.
|
|
1340
|
+
* The rules are:
|
|
1341
|
+
* must be a string
|
|
1342
|
+
* length must be 15 characters or less
|
|
1343
|
+
* There must be four octets separated by a '.'
|
|
1344
|
+
* No octet can be less than 0 or greater than 255.
|
|
1345
|
+
* @param {Any} value to test if an ip address.
|
|
1346
|
+
* @return {Boolean} true if an ip address, false otherwise.
|
|
1347
|
+
*/
|
|
1348
|
+
is.ipv4Address = function(value) {
|
|
1349
|
+
if (!is.nonEmptyStr(value)) return false;
|
|
1350
|
+
if (value.length > 15) return false;
|
|
1351
|
+
var octets = value.split('.');
|
|
1352
|
+
if (!is.array(octets) || octets.length !== 4) return false;
|
|
1353
|
+
for (var i=0; i<octets.length; i++) {
|
|
1354
|
+
var val = parseInt(octets[i], 10);
|
|
1355
|
+
if (isNaN(val)) return false;
|
|
1356
|
+
if (val < 0 || val > 255) return false;
|
|
1357
|
+
}
|
|
1358
|
+
return true;
|
|
1359
|
+
};
|
|
1360
|
+
is.ipv4 = is.ipv4Addr = is.ipv4Address;
|
|
1361
|
+
|
|
1362
|
+
/**
|
|
1363
|
+
* Test if a value is either an IPv6 numeric IP address.
|
|
1364
|
+
* @param {Any} value to test if an ip address.
|
|
1365
|
+
* @return {Boolean} true if an ip address, false otherwise.
|
|
1366
|
+
*/
|
|
1367
|
+
is.ipv6Address = function(value) {
|
|
1368
|
+
if (!is.nonEmptyStr(value)) return false;
|
|
1369
|
+
return ipRegEx.v6({extract: true}).test(value);
|
|
1370
|
+
};
|
|
1371
|
+
is.ipv6 = is.ipv6Addr = is.ipv6Address;
|
|
1372
|
+
|
|
1373
|
+
/**
|
|
1374
|
+
* Test if a value is either an IPv4 or IPv6 numeric IP address.
|
|
1375
|
+
* @param {Any} value to test if an ip address.
|
|
1376
|
+
* @return {Boolean} true if an ip address, false otherwise.
|
|
1377
|
+
*/
|
|
1378
|
+
is.ipAddress = function(value) {
|
|
1379
|
+
if (!is.nonEmptyStr(value)) return false;
|
|
1380
|
+
return is.ipv4Address(value) || is.ipv6Address(value)
|
|
1381
|
+
};
|
|
1382
|
+
is.ip = is.ipAddr = is.ipAddress;
|
|
1383
|
+
|
|
1384
|
+
/**
|
|
1385
|
+
* Test is a value is a valid ipv4, ipv6 or DNS name.
|
|
1386
|
+
* Aliases: host, hostAddr, hostAddress.
|
|
1387
|
+
* @param {Any} value to test if a host address.
|
|
1388
|
+
* @return {Boolean} true if a host address, false otherwise.
|
|
1389
|
+
*/
|
|
1390
|
+
is.hostAddress = function(value) {
|
|
1391
|
+
if (!is.nonEmptyStr(value)) return false;
|
|
1392
|
+
return is.dns(value) || is.ipv4(value) || is.ipv6(value);
|
|
1393
|
+
};
|
|
1394
|
+
is.host = is.hostIp = is.hostAddr = is.hostAddress;
|
|
1395
|
+
|
|
1396
|
+
/**
|
|
1397
|
+
* Test if a number is a valid TCP port
|
|
1398
|
+
* @param {Any} value to test if its a valid TCP port
|
|
1399
|
+
*/
|
|
1400
|
+
is.port = function(value) {
|
|
1401
|
+
if (!is.num(value) || is.negativeInt(value) || value > 65535)
|
|
1402
|
+
return false;
|
|
1403
|
+
return true;
|
|
1404
|
+
};
|
|
1405
|
+
|
|
1406
|
+
/**
|
|
1407
|
+
* Test if a number is a valid TCP port in the range 0-1023.
|
|
1408
|
+
* Alias: is.sysPort.
|
|
1409
|
+
* @param {Any} value to test if its a valid TCP port
|
|
1410
|
+
*/
|
|
1411
|
+
is.systemPort = function(value) {
|
|
1412
|
+
if (is.port(value) && value < 1024)
|
|
1413
|
+
return true;
|
|
1414
|
+
return false;
|
|
1415
|
+
};
|
|
1416
|
+
is.sysPort = is.systemPort;
|
|
1417
|
+
|
|
1418
|
+
/**
|
|
1419
|
+
* Test if a number is a valid TCP port in the range 1024-65535.
|
|
1420
|
+
* @param {Any} value to test if its a valid TCP port
|
|
1421
|
+
*/
|
|
1422
|
+
is.userPort = function(value) {
|
|
1423
|
+
if (is.port(value) && value > 1023)
|
|
1424
|
+
return true;
|
|
1425
|
+
return false;
|
|
1426
|
+
};
|
|
1427
|
+
|
|
1428
|
+
/*
|
|
1429
|
+
function sumDigits(num) {
|
|
1430
|
+
var str = num.toString();
|
|
1431
|
+
var sum = 0;
|
|
1432
|
+
for (var i = 0; i < str.length; i++)
|
|
1433
|
+
sum += (str[i]-0);
|
|
1434
|
+
return sum;
|
|
1435
|
+
}
|
|
1436
|
+
*/
|
|
1437
|
+
|
|
1438
|
+
/**
|
|
1439
|
+
* Test if a string is a credit card.
|
|
1440
|
+
* From http://en.wikipedia.org/wiki/Luhn_algorithm
|
|
1441
|
+
* @param {String} value to test if a credit card.
|
|
1442
|
+
* @return true if the string is the correct format, false otherwise
|
|
1443
|
+
*/
|
|
1444
|
+
is.creditCardNumber = function(str) {
|
|
1445
|
+
if (!is.str(str))
|
|
1446
|
+
return false;
|
|
1447
|
+
|
|
1448
|
+
var ary = str.split('');
|
|
1449
|
+
var i, cnt;
|
|
1450
|
+
// From the rightmost digit, which is the check digit, moving left, double
|
|
1451
|
+
// the value of every second digit;
|
|
1452
|
+
for (i=ary.length-1, cnt=1; i>-1; i--, cnt++) {
|
|
1453
|
+
if (cnt%2 === 0)
|
|
1454
|
+
ary[i] *= 2;
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
str = ary.join('');
|
|
1458
|
+
var sum = 0;
|
|
1459
|
+
// if the product of the previous doubling operation is greater than 9
|
|
1460
|
+
// (e.g., 7 * 2 = 14), then sum the digits of the products (e.g., 10: 1 + 0
|
|
1461
|
+
// = 1, 14: 1 + 4 = 5). We do the this by joining the array of numbers and
|
|
1462
|
+
// add adding the int value of all the characters in the string.
|
|
1463
|
+
for (i=0; i<str.length; i++)
|
|
1464
|
+
sum += Math.floor(str[i]);
|
|
1465
|
+
|
|
1466
|
+
// If the total (sum) modulo 10 is equal to 0 (if the total ends in zero)
|
|
1467
|
+
// then the number is valid according to the Luhn formula; else it is not
|
|
1468
|
+
// valid.
|
|
1469
|
+
return sum % 10 === 0;
|
|
1470
|
+
};
|
|
1471
|
+
is.creditCard = is.creditCardNum = is.creditCardNumber;
|
|
1472
|
+
|
|
1473
|
+
|
|
1474
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
1475
|
+
// The following credit card info is from:
|
|
1476
|
+
// http://en.wikipedia.org/wiki/Bank_card_number#Issuer_identification_number_.28IIN.29
|
|
1477
|
+
|
|
1478
|
+
/**
|
|
1479
|
+
* Test if card number is an American Express card.
|
|
1480
|
+
* @param {String} the credit card number string to test.
|
|
1481
|
+
* @return true if the string is the correct format, false otherwise
|
|
1482
|
+
*/
|
|
1483
|
+
is.americanExpressCardNumber = function(str) {
|
|
1484
|
+
if (!is.str(str) || str.length !== 15)
|
|
1485
|
+
return false;
|
|
1486
|
+
|
|
1487
|
+
var prefix = Math.floor(str.slice(0,2));
|
|
1488
|
+
if (prefix !== 34 && prefix !== 37)
|
|
1489
|
+
return false;
|
|
1490
|
+
|
|
1491
|
+
if (!is.creditCardNumber(str))
|
|
1492
|
+
return false;
|
|
1493
|
+
|
|
1494
|
+
return true;
|
|
1495
|
+
};
|
|
1496
|
+
is.amexCard = is.amexCardNum = is.americanExpressCardNumber;
|
|
1497
|
+
|
|
1498
|
+
/**
|
|
1499
|
+
* Test if card number is a China UnionPay card.
|
|
1500
|
+
* @param {String} the credit card number string to test.
|
|
1501
|
+
* @return true if the string is the correct format, false otherwise
|
|
1502
|
+
*/
|
|
1503
|
+
is.chinaUnionPayCardNumber = function(str) {
|
|
1504
|
+
if (!is.str(str) || (str.length < 16 && str.length > 19))
|
|
1505
|
+
return false;
|
|
1506
|
+
|
|
1507
|
+
var prefix = Math.floor(str.slice(0,2));
|
|
1508
|
+
if (prefix !== 62 && prefix !== 88)
|
|
1509
|
+
return false;
|
|
1510
|
+
|
|
1511
|
+
// no validation for this card
|
|
1512
|
+
return true;
|
|
1513
|
+
};
|
|
1514
|
+
is.chinaUnion = is.chinaUnionPayCard = is.chinaUnionPayCardNumber;
|
|
1515
|
+
|
|
1516
|
+
/**
|
|
1517
|
+
* Test if card number is a Diner's Club Carte Blance card.
|
|
1518
|
+
* @param {String} the credit card number string to test.
|
|
1519
|
+
* @return true if the string is the correct format, false otherwise
|
|
1520
|
+
*/
|
|
1521
|
+
is.dinersClubCarteBlancheCardNumber = function(str) {
|
|
1522
|
+
if (!is.str(str) || str.length !== 14)
|
|
1523
|
+
return false;
|
|
1524
|
+
|
|
1525
|
+
var prefix = Math.floor(str.slice(0,3));
|
|
1526
|
+
if (prefix < 300 || prefix > 305)
|
|
1527
|
+
return false;
|
|
1528
|
+
|
|
1529
|
+
if (!is.creditCardNumber(str))
|
|
1530
|
+
return false;
|
|
1531
|
+
|
|
1532
|
+
return true;
|
|
1533
|
+
};
|
|
1534
|
+
is.dinersClubCB = is.dinersClubCarteBlancheCard =
|
|
1535
|
+
is.dinersClubCarteBlancheCardNumber;
|
|
1536
|
+
|
|
1537
|
+
/**
|
|
1538
|
+
* Test if card number is a Diner's Club International card.
|
|
1539
|
+
* @param {String} the credit card number string to test.
|
|
1540
|
+
* @return true if the string is the correct format, false otherwise
|
|
1541
|
+
*/
|
|
1542
|
+
is.dinersClubInternationalCardNumber = function(str) {
|
|
1543
|
+
if (!is.str(str) || str.length !== 14)
|
|
1544
|
+
return false;
|
|
1545
|
+
var prefix = Math.floor(str.slice(0,3));
|
|
1546
|
+
var prefix2 = Math.floor(str.slice(0,2));
|
|
1547
|
+
|
|
1548
|
+
// 300-305, 309, 36, 38-39
|
|
1549
|
+
if ((prefix < 300 || prefix > 305) && prefix !== 309 && prefix2 !== 36 &&
|
|
1550
|
+
(prefix2 < 38 || prefix2 > 39)) {
|
|
1551
|
+
return false;
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
if (!is.creditCardNumber(str))
|
|
1555
|
+
return false;
|
|
1556
|
+
|
|
1557
|
+
return true;
|
|
1558
|
+
};
|
|
1559
|
+
is.dinersClubInt = is.dinersClubInternationalCard =
|
|
1560
|
+
is.dinersClubInternationalCardNumber;
|
|
1561
|
+
|
|
1562
|
+
/**
|
|
1563
|
+
* Test if card number is a Diner's Club USA & CA card.
|
|
1564
|
+
* @param {String} the credit card number string to test.
|
|
1565
|
+
* @return true if the string is the correct format, false otherwise
|
|
1566
|
+
*/
|
|
1567
|
+
is.dinersClubUSACanadaCardNumber = function(str) {
|
|
1568
|
+
if (!is.str(str) || str.length !== 16)
|
|
1569
|
+
return false;
|
|
1570
|
+
var prefix = Math.floor(str.slice(0,2));
|
|
1571
|
+
|
|
1572
|
+
if (prefix !== 54 && prefix !== 55)
|
|
1573
|
+
return false;
|
|
1574
|
+
|
|
1575
|
+
if (!is.creditCardNumber(str))
|
|
1576
|
+
return false;
|
|
1577
|
+
|
|
1578
|
+
return true;
|
|
1579
|
+
};
|
|
1580
|
+
is.dinersClub = is.dinersClubUSACanCard = is.dinersClubUSACanadaCardNumber;
|
|
1581
|
+
|
|
1582
|
+
/**
|
|
1583
|
+
* Test if card number is a Diner's Club USA/CA card.
|
|
1584
|
+
* @param {String} the credit card number string to test.
|
|
1585
|
+
* @return true if the string is the correct format, false otherwise
|
|
1586
|
+
*/
|
|
1587
|
+
is.discoverCardNumber = function(str) {
|
|
1588
|
+
if (!is.str(str) || str.length !== 16)
|
|
1589
|
+
return false;
|
|
1590
|
+
|
|
1591
|
+
var prefix = Math.floor(str.slice(0,6));
|
|
1592
|
+
var prefix2 = Math.floor(str.slice(0,3));
|
|
1593
|
+
|
|
1594
|
+
if (str.slice(0,4) !== '6011' && (prefix < 622126 || prefix > 622925) &&
|
|
1595
|
+
(prefix2 < 644 || prefix2 > 649) && str.slice(0,2) !== '65') {
|
|
1596
|
+
return false;
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
if (!is.creditCardNumber(str))
|
|
1600
|
+
return false;
|
|
1601
|
+
|
|
1602
|
+
return true;
|
|
1603
|
+
};
|
|
1604
|
+
is.discover = is.discoverCard = is.discoverCardNumber;
|
|
1605
|
+
|
|
1606
|
+
/**
|
|
1607
|
+
* Test if card number is an InstaPayment card number
|
|
1608
|
+
* @param {String} the credit card number string to test.
|
|
1609
|
+
* @return true if the string is the correct format, false otherwise
|
|
1610
|
+
*/
|
|
1611
|
+
is.instaPaymentCardNumber = function(str) {
|
|
1612
|
+
if (!is.str(str) || str.length !== 16)
|
|
1613
|
+
return false;
|
|
1614
|
+
|
|
1615
|
+
var prefix = Math.floor(str.slice(0,3));
|
|
1616
|
+
if (prefix < 637 || prefix > 639)
|
|
1617
|
+
return false;
|
|
1618
|
+
|
|
1619
|
+
if (!is.creditCardNumber(str))
|
|
1620
|
+
return false;
|
|
1621
|
+
|
|
1622
|
+
return true;
|
|
1623
|
+
};
|
|
1624
|
+
is.instaPayment = is.instaPaymentCardNumber;
|
|
1625
|
+
|
|
1626
|
+
/**
|
|
1627
|
+
* Test if card number is a JCB card number
|
|
1628
|
+
* @param {String} the credit card number string to test.
|
|
1629
|
+
* @return true if the string is the correct format, false otherwise
|
|
1630
|
+
*/
|
|
1631
|
+
is.jcbCardNumber = function(str) {
|
|
1632
|
+
if (!is.str(str) || str.length !== 16)
|
|
1633
|
+
return false;
|
|
1634
|
+
|
|
1635
|
+
var prefix = Math.floor(str.slice(0,4));
|
|
1636
|
+
if (prefix < 3528 || prefix > 3589)
|
|
1637
|
+
return false;
|
|
1638
|
+
|
|
1639
|
+
if (!is.creditCardNumber(str))
|
|
1640
|
+
return false;
|
|
1641
|
+
|
|
1642
|
+
return true;
|
|
1643
|
+
};
|
|
1644
|
+
is.jcb = is.jcbCard = is.jcbCardNumber;
|
|
1645
|
+
|
|
1646
|
+
/**
|
|
1647
|
+
* Test if card number is a Laser card number
|
|
1648
|
+
* @param {String} the credit card number string to test.
|
|
1649
|
+
* @return true if the string is the correct format, false otherwise
|
|
1650
|
+
*/
|
|
1651
|
+
is.laserCardNumber = function(str) {
|
|
1652
|
+
if (!is.str(str) || (str.length < 16 && str.length > 19))
|
|
1653
|
+
return false;
|
|
1654
|
+
|
|
1655
|
+
var prefix = Math.floor(str.slice(0,4));
|
|
1656
|
+
var valid = [ 6304, 6706, 6771, 6709 ];
|
|
1657
|
+
if (valid.indexOf(prefix) === -1)
|
|
1658
|
+
return false;
|
|
1659
|
+
|
|
1660
|
+
if (!is.creditCardNumber(str))
|
|
1661
|
+
return false;
|
|
1662
|
+
|
|
1663
|
+
return true;
|
|
1664
|
+
};
|
|
1665
|
+
is.laser = is.laserCard = is.laserCardNumber;
|
|
1666
|
+
|
|
1667
|
+
/**
|
|
1668
|
+
* Test if card number is a Maestro card number
|
|
1669
|
+
* @param {String} the credit card number string to test.
|
|
1670
|
+
* @return true if the string is the correct format, false otherwise
|
|
1671
|
+
*/
|
|
1672
|
+
is.maestroCardNumber = function(str) {
|
|
1673
|
+
if (!is.str(str) || str.length < 12 || str.length > 19)
|
|
1674
|
+
return false;
|
|
1675
|
+
|
|
1676
|
+
var prefix = str.slice(0,4);
|
|
1677
|
+
var valid = [ '5018', '5020', '5038', '5612', '5893', '6304', '6759',
|
|
1678
|
+
'6761', '6762', '6763', '0604', '6390' ];
|
|
1679
|
+
|
|
1680
|
+
if (valid.indexOf(prefix) === -1)
|
|
1681
|
+
return false;
|
|
1682
|
+
|
|
1683
|
+
if (!is.creditCardNumber(str))
|
|
1684
|
+
return false;
|
|
1685
|
+
|
|
1686
|
+
return true;
|
|
1687
|
+
};
|
|
1688
|
+
is.maestro = is.maestroCard = is.maestroCardNumber;
|
|
1689
|
+
|
|
1690
|
+
/**
|
|
1691
|
+
* Test if card number is a Dankort card number
|
|
1692
|
+
* @param {String} the credit card number string to test.
|
|
1693
|
+
* @return true if the string is the correct format, false otherwise
|
|
1694
|
+
*/
|
|
1695
|
+
is.dankortCardNumber = function(str) {
|
|
1696
|
+
if (!is.str(str) || str.length !== 16)
|
|
1697
|
+
return false;
|
|
1698
|
+
|
|
1699
|
+
if (str.slice(0,4) !== '5019')
|
|
1700
|
+
return false;
|
|
1701
|
+
|
|
1702
|
+
if (!is.creditCardNumber(str))
|
|
1703
|
+
return false;
|
|
1704
|
+
|
|
1705
|
+
return true;
|
|
1706
|
+
};
|
|
1707
|
+
is.dankort = is.dankortCard = is.dankortCardNumber;
|
|
1708
|
+
|
|
1709
|
+
/**
|
|
1710
|
+
* Test if card number is a MasterCard card number
|
|
1711
|
+
* @param {String} the credit card number string to test.
|
|
1712
|
+
* @return true if the string is the correct format, false otherwise
|
|
1713
|
+
*/
|
|
1714
|
+
is.masterCardCardNumber = function(str) {
|
|
1715
|
+
if (!is.str(str) || str.length !== 16)
|
|
1716
|
+
return false;
|
|
1717
|
+
|
|
1718
|
+
var prefix = Math.floor(str.slice(0,2));
|
|
1719
|
+
if (prefix < 50 || prefix > 55)
|
|
1720
|
+
return false;
|
|
1721
|
+
|
|
1722
|
+
if (!is.creditCardNumber(str))
|
|
1723
|
+
return false;
|
|
1724
|
+
|
|
1725
|
+
return true;
|
|
1726
|
+
};
|
|
1727
|
+
is.masterCard = is.masterCardCard = is.masterCardCardNumber;
|
|
1728
|
+
|
|
1729
|
+
/**
|
|
1730
|
+
* Test if card number is a Visa card number
|
|
1731
|
+
* @param {String} the credit card number string to test.
|
|
1732
|
+
* @return true if the string is the correct format, false otherwise
|
|
1733
|
+
*/
|
|
1734
|
+
is.visaCardNumber = function(str) {
|
|
1735
|
+
if (!is.str(str) || (str.length !== 13 && str.length !== 16))
|
|
1736
|
+
return false;
|
|
1737
|
+
|
|
1738
|
+
if ('4' !== str.slice(0,1))
|
|
1739
|
+
return false;
|
|
1740
|
+
|
|
1741
|
+
if (!is.creditCardNumber(str))
|
|
1742
|
+
return false;
|
|
1743
|
+
|
|
1744
|
+
return true;
|
|
1745
|
+
};
|
|
1746
|
+
|
|
1747
|
+
is.visa = is.visaCard = is.visaCardNumber;
|
|
1748
|
+
|
|
1749
|
+
/**
|
|
1750
|
+
* Test if card number is a Visa card number
|
|
1751
|
+
* @param {String} the credit card number string to test.
|
|
1752
|
+
* @return true if the string is the correct format, false otherwise
|
|
1753
|
+
*/
|
|
1754
|
+
is.visaElectronCardNumber = function(str) {
|
|
1755
|
+
if (!is.str(str) || str.length !== 16)
|
|
1756
|
+
return false;
|
|
1757
|
+
|
|
1758
|
+
var prefix = Math.floor(str.slice(0,4));
|
|
1759
|
+
var valid = [ 4026, 4405, 4508, 4844, 4913, 4917 ];
|
|
1760
|
+
if ('417500' !== str.slice(0,6) && valid.indexOf(prefix) === -1)
|
|
1761
|
+
return false;
|
|
1762
|
+
|
|
1763
|
+
if (!is.creditCardNumber(str))
|
|
1764
|
+
return false;
|
|
1765
|
+
|
|
1766
|
+
return false;
|
|
1767
|
+
};
|
|
1768
|
+
|
|
1769
|
+
is.visaElectron = is.visaElectronCard = is.visaElectronCardNumber;
|
|
1770
|
+
|
|
1771
|
+
/**
|
|
1772
|
+
* Test if the input is a valid MongoDB id.
|
|
1773
|
+
* @param {String|Object} Either a mongodb object id or a string representation.
|
|
1774
|
+
* @return true if the string is the correct format, false otherwise
|
|
1775
|
+
* Thanks to Jason Denizac (https://github.com/jden) for pointing this out.
|
|
1776
|
+
* https://github.com/jden/objectid/blob/master/index.js#L7-L10
|
|
1777
|
+
*/
|
|
1778
|
+
var objIdPattern = /^[0-9a-fA-F]{24}$/;
|
|
1779
|
+
is.mongoId = is.objectId = is.objId = function(id) {
|
|
1780
|
+
return (Boolean(id) && !Array.isArray(id) && objIdPattern.test(String(id)));
|
|
1781
|
+
};
|
|
1782
|
+
|
|
1783
|
+
/**
|
|
1784
|
+
* Test is the first argument is structly equal to any of the subsequent args.
|
|
1785
|
+
* @param Value to test against subsequent arguments.
|
|
1786
|
+
* @return true if the first value matches any of subsequent values.
|
|
1787
|
+
*/
|
|
1788
|
+
is.matching = is.match = is.inArgs = function(val) {
|
|
1789
|
+
if (arguments.length < 2)
|
|
1790
|
+
return false;
|
|
1791
|
+
var result = false;
|
|
1792
|
+
for (var i=1; i<arguments.length; i++) {
|
|
1793
|
+
var eq = is.equal(val, arguments[i]);
|
|
1794
|
+
result = result || eq;
|
|
1795
|
+
}
|
|
1796
|
+
return result;
|
|
1797
|
+
};
|
|
1798
|
+
|
|
1799
|
+
|
|
1800
|
+
|
|
1801
|
+
// US Address components
|
|
1802
|
+
/**********************************
|
|
1803
|
+
***Definitely a work in progress***
|
|
1804
|
+
**********************************/
|
|
1805
|
+
/**
|
|
1806
|
+
* Test if a string contains a US street address
|
|
1807
|
+
* @param {String} the string to search
|
|
1808
|
+
* @return true if an address is present, false otherwise
|
|
1809
|
+
*/
|
|
1810
|
+
is.streetAddress = function(str) {
|
|
1811
|
+
if (!is.str(str))
|
|
1812
|
+
return false;
|
|
1813
|
+
|
|
1814
|
+
var regex = /\b\d+[\s](?:[A-Za-z0-9.-]+[\s]+)+\b(ALLEY|ALY|AVENUE|AVE|BEND|BND|BLUFFS?|BLFS?|BOULEVARD|BLVD|BRANCH|BR|CENTERS?|CTRS?|CIRCLES?|CIRS?|CLIFFS?|CLFS?|COURTS?|CTS?|COVES?|CVS?|CREEK|CRK|CRESCENT|CRES|CREST|CRST|CROSSING|XING|DRIVES?|DRS?|EXPRESSWAY|EXPY|FREEWAY|FWY|HEIGHTS|HTS|HIGHWAY|HWY|HILLS?|HLS?|LANE|LN|LOOP|MANORS?|MNRS?|MOTORWAY|MTWY|MOUNT|MT|PARKS?|PARKWAYS?|PKWY|PASS|PLACE|PL|PLAZA|PLZ|POINTS?|PTS?|RIDGES?|RDGS?|ROADS?|RDS?|ROUTE|RTE?|SHOALS?|SHLS?|SHORES?|SHRS?|SPRINGS?|SPGS?|SPURS?|STREETS?|STS?|SUMMIT|SMT|TERRACE|TER|THROUGHWAY|TRWY|TRAFFICWAY|TRFY|TRAIL|TRL|TURNPIKE|TPKE|VALLEYS?|VLYS?|WAYS?)+(?:[\.\-\s\,]?)*((APARTMENT|APT|APPT|#|NUMBER|NUM|FLOOR|FL|\s)?(\d)*)\b/ig;
|
|
1815
|
+
|
|
1816
|
+
return regex.test(str);
|
|
1817
|
+
};
|
|
1818
|
+
is.street = is.address = is.streetAddress;
|
|
1819
|
+
|
|
1820
|
+
/**
|
|
1821
|
+
* Test if a string resembles a US Zip code,
|
|
1822
|
+
* no regular expression will be perfect for this,
|
|
1823
|
+
* as there are many numbers that aren't valid zip codes
|
|
1824
|
+
* @param {String || Number} the string or number literal to test
|
|
1825
|
+
* @return true if zipcode like, false otherwise
|
|
1826
|
+
*/
|
|
1827
|
+
is.zipCode = function(str) {
|
|
1828
|
+
if (is.undefined(str) || !(is.string(str) || is.number(str)))
|
|
1829
|
+
return false;
|
|
1830
|
+
|
|
1831
|
+
var zip = /^\d{5}(?:-\d{4})?$/;
|
|
1832
|
+
return zip.test(str);
|
|
1833
|
+
};
|
|
1834
|
+
is.zip = is.zipCode;
|
|
1835
|
+
|
|
1836
|
+
/**
|
|
1837
|
+
* Test if a string contains a US phone number
|
|
1838
|
+
* @param {String} the string to search
|
|
1839
|
+
* @return true if str contains a phone number, false otherwise.
|
|
1840
|
+
*/
|
|
1841
|
+
is.phoneNumber = function(str){
|
|
1842
|
+
if (!is.string(str))
|
|
1843
|
+
return false;
|
|
1844
|
+
var nums = /(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:(\(?)(?:(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\)?)\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})/g;
|
|
1845
|
+
return nums.test(str);
|
|
1846
|
+
};
|
|
1847
|
+
is.phone = is.phoneNumber;
|
|
1848
|
+
|
|
1849
|
+
/**
|
|
1850
|
+
* Test is a string is a valid URL
|
|
1851
|
+
* @param {string} val - the possible url to check
|
|
1852
|
+
* @return true if str contains a phone number, false otherwise.
|
|
1853
|
+
*/
|
|
1854
|
+
var isUrl = requireIsUrl();
|
|
1855
|
+
is.url = function(val) {
|
|
1856
|
+
return isUrl(val);
|
|
1857
|
+
};
|
|
1858
|
+
is.uri = is.url;
|
|
1859
|
+
|
|
1860
|
+
is.enumerator = function(val, ary){
|
|
1861
|
+
var value = false;
|
|
1862
|
+
|
|
1863
|
+
if (!is.defined(val) || !is.defined(ary) || !is.arrayLike(ary))
|
|
1864
|
+
return value;
|
|
1865
|
+
|
|
1866
|
+
for (var i = 0, len = ary.length; i < len; i++) {
|
|
1867
|
+
if (is.equal(val, ary[i])) {
|
|
1868
|
+
value = true;
|
|
1869
|
+
break;
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
return value;
|
|
1873
|
+
};
|
|
1874
|
+
is.enum = is.inArray = is.enumerator;
|
|
1875
|
+
} (is2));
|
|
1876
|
+
return is2;
|
|
1877
|
+
}
|
|
1878
|
+
|
|
1879
|
+
var src = {exports: {}};
|
|
1880
|
+
|
|
1881
|
+
var browser = {exports: {}};
|
|
1882
|
+
|
|
1883
|
+
/**
|
|
1884
|
+
* Helpers.
|
|
1885
|
+
*/
|
|
1886
|
+
|
|
1887
|
+
var ms;
|
|
1888
|
+
var hasRequiredMs;
|
|
1889
|
+
|
|
1890
|
+
function requireMs () {
|
|
1891
|
+
if (hasRequiredMs) return ms;
|
|
1892
|
+
hasRequiredMs = 1;
|
|
1893
|
+
var s = 1000;
|
|
1894
|
+
var m = s * 60;
|
|
1895
|
+
var h = m * 60;
|
|
1896
|
+
var d = h * 24;
|
|
1897
|
+
var w = d * 7;
|
|
1898
|
+
var y = d * 365.25;
|
|
1899
|
+
|
|
1900
|
+
/**
|
|
1901
|
+
* Parse or format the given `val`.
|
|
1902
|
+
*
|
|
1903
|
+
* Options:
|
|
1904
|
+
*
|
|
1905
|
+
* - `long` verbose formatting [false]
|
|
1906
|
+
*
|
|
1907
|
+
* @param {String|Number} val
|
|
1908
|
+
* @param {Object} [options]
|
|
1909
|
+
* @throws {Error} throw an error if val is not a non-empty string or a number
|
|
1910
|
+
* @return {String|Number}
|
|
1911
|
+
* @api public
|
|
1912
|
+
*/
|
|
1913
|
+
|
|
1914
|
+
ms = function(val, options) {
|
|
1915
|
+
options = options || {};
|
|
1916
|
+
var type = typeof val;
|
|
1917
|
+
if (type === 'string' && val.length > 0) {
|
|
1918
|
+
return parse(val);
|
|
1919
|
+
} else if (type === 'number' && isFinite(val)) {
|
|
1920
|
+
return options.long ? fmtLong(val) : fmtShort(val);
|
|
1921
|
+
}
|
|
1922
|
+
throw new Error(
|
|
1923
|
+
'val is not a non-empty string or a valid number. val=' +
|
|
1924
|
+
JSON.stringify(val)
|
|
1925
|
+
);
|
|
1926
|
+
};
|
|
1927
|
+
|
|
1928
|
+
/**
|
|
1929
|
+
* Parse the given `str` and return milliseconds.
|
|
1930
|
+
*
|
|
1931
|
+
* @param {String} str
|
|
1932
|
+
* @return {Number}
|
|
1933
|
+
* @api private
|
|
1934
|
+
*/
|
|
1935
|
+
|
|
1936
|
+
function parse(str) {
|
|
1937
|
+
str = String(str);
|
|
1938
|
+
if (str.length > 100) {
|
|
1939
|
+
return;
|
|
1940
|
+
}
|
|
1941
|
+
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
|
1942
|
+
str
|
|
1943
|
+
);
|
|
1944
|
+
if (!match) {
|
|
1945
|
+
return;
|
|
1946
|
+
}
|
|
1947
|
+
var n = parseFloat(match[1]);
|
|
1948
|
+
var type = (match[2] || 'ms').toLowerCase();
|
|
1949
|
+
switch (type) {
|
|
1950
|
+
case 'years':
|
|
1951
|
+
case 'year':
|
|
1952
|
+
case 'yrs':
|
|
1953
|
+
case 'yr':
|
|
1954
|
+
case 'y':
|
|
1955
|
+
return n * y;
|
|
1956
|
+
case 'weeks':
|
|
1957
|
+
case 'week':
|
|
1958
|
+
case 'w':
|
|
1959
|
+
return n * w;
|
|
1960
|
+
case 'days':
|
|
1961
|
+
case 'day':
|
|
1962
|
+
case 'd':
|
|
1963
|
+
return n * d;
|
|
1964
|
+
case 'hours':
|
|
1965
|
+
case 'hour':
|
|
1966
|
+
case 'hrs':
|
|
1967
|
+
case 'hr':
|
|
1968
|
+
case 'h':
|
|
1969
|
+
return n * h;
|
|
1970
|
+
case 'minutes':
|
|
1971
|
+
case 'minute':
|
|
1972
|
+
case 'mins':
|
|
1973
|
+
case 'min':
|
|
1974
|
+
case 'm':
|
|
1975
|
+
return n * m;
|
|
1976
|
+
case 'seconds':
|
|
1977
|
+
case 'second':
|
|
1978
|
+
case 'secs':
|
|
1979
|
+
case 'sec':
|
|
1980
|
+
case 's':
|
|
1981
|
+
return n * s;
|
|
1982
|
+
case 'milliseconds':
|
|
1983
|
+
case 'millisecond':
|
|
1984
|
+
case 'msecs':
|
|
1985
|
+
case 'msec':
|
|
1986
|
+
case 'ms':
|
|
1987
|
+
return n;
|
|
1988
|
+
default:
|
|
1989
|
+
return undefined;
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
|
|
1993
|
+
/**
|
|
1994
|
+
* Short format for `ms`.
|
|
1995
|
+
*
|
|
1996
|
+
* @param {Number} ms
|
|
1997
|
+
* @return {String}
|
|
1998
|
+
* @api private
|
|
1999
|
+
*/
|
|
2000
|
+
|
|
2001
|
+
function fmtShort(ms) {
|
|
2002
|
+
var msAbs = Math.abs(ms);
|
|
2003
|
+
if (msAbs >= d) {
|
|
2004
|
+
return Math.round(ms / d) + 'd';
|
|
2005
|
+
}
|
|
2006
|
+
if (msAbs >= h) {
|
|
2007
|
+
return Math.round(ms / h) + 'h';
|
|
2008
|
+
}
|
|
2009
|
+
if (msAbs >= m) {
|
|
2010
|
+
return Math.round(ms / m) + 'm';
|
|
2011
|
+
}
|
|
2012
|
+
if (msAbs >= s) {
|
|
2013
|
+
return Math.round(ms / s) + 's';
|
|
2014
|
+
}
|
|
2015
|
+
return ms + 'ms';
|
|
2016
|
+
}
|
|
2017
|
+
|
|
2018
|
+
/**
|
|
2019
|
+
* Long format for `ms`.
|
|
2020
|
+
*
|
|
2021
|
+
* @param {Number} ms
|
|
2022
|
+
* @return {String}
|
|
2023
|
+
* @api private
|
|
2024
|
+
*/
|
|
2025
|
+
|
|
2026
|
+
function fmtLong(ms) {
|
|
2027
|
+
var msAbs = Math.abs(ms);
|
|
2028
|
+
if (msAbs >= d) {
|
|
2029
|
+
return plural(ms, msAbs, d, 'day');
|
|
2030
|
+
}
|
|
2031
|
+
if (msAbs >= h) {
|
|
2032
|
+
return plural(ms, msAbs, h, 'hour');
|
|
2033
|
+
}
|
|
2034
|
+
if (msAbs >= m) {
|
|
2035
|
+
return plural(ms, msAbs, m, 'minute');
|
|
2036
|
+
}
|
|
2037
|
+
if (msAbs >= s) {
|
|
2038
|
+
return plural(ms, msAbs, s, 'second');
|
|
2039
|
+
}
|
|
2040
|
+
return ms + ' ms';
|
|
2041
|
+
}
|
|
2042
|
+
|
|
2043
|
+
/**
|
|
2044
|
+
* Pluralization helper.
|
|
2045
|
+
*/
|
|
2046
|
+
|
|
2047
|
+
function plural(ms, msAbs, n, name) {
|
|
2048
|
+
var isPlural = msAbs >= n * 1.5;
|
|
2049
|
+
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
|
|
2050
|
+
}
|
|
2051
|
+
return ms;
|
|
2052
|
+
}
|
|
2053
|
+
|
|
2054
|
+
var common$2;
|
|
2055
|
+
var hasRequiredCommon$2;
|
|
2056
|
+
|
|
2057
|
+
function requireCommon$2 () {
|
|
2058
|
+
if (hasRequiredCommon$2) return common$2;
|
|
2059
|
+
hasRequiredCommon$2 = 1;
|
|
2060
|
+
/**
|
|
2061
|
+
* This is the common logic for both the Node.js and web browser
|
|
2062
|
+
* implementations of `debug()`.
|
|
2063
|
+
*/
|
|
2064
|
+
|
|
2065
|
+
function setup(env) {
|
|
2066
|
+
createDebug.debug = createDebug;
|
|
2067
|
+
createDebug.default = createDebug;
|
|
2068
|
+
createDebug.coerce = coerce;
|
|
2069
|
+
createDebug.disable = disable;
|
|
2070
|
+
createDebug.enable = enable;
|
|
2071
|
+
createDebug.enabled = enabled;
|
|
2072
|
+
createDebug.humanize = requireMs();
|
|
2073
|
+
createDebug.destroy = destroy;
|
|
2074
|
+
|
|
2075
|
+
Object.keys(env).forEach(key => {
|
|
2076
|
+
createDebug[key] = env[key];
|
|
2077
|
+
});
|
|
2078
|
+
|
|
2079
|
+
/**
|
|
2080
|
+
* The currently active debug mode names, and names to skip.
|
|
2081
|
+
*/
|
|
2082
|
+
|
|
2083
|
+
createDebug.names = [];
|
|
2084
|
+
createDebug.skips = [];
|
|
2085
|
+
|
|
2086
|
+
/**
|
|
2087
|
+
* Map of special "%n" handling functions, for the debug "format" argument.
|
|
2088
|
+
*
|
|
2089
|
+
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
|
2090
|
+
*/
|
|
2091
|
+
createDebug.formatters = {};
|
|
2092
|
+
|
|
2093
|
+
/**
|
|
2094
|
+
* Selects a color for a debug namespace
|
|
2095
|
+
* @param {String} namespace The namespace string for the for the debug instance to be colored
|
|
2096
|
+
* @return {Number|String} An ANSI color code for the given namespace
|
|
2097
|
+
* @api private
|
|
2098
|
+
*/
|
|
2099
|
+
function selectColor(namespace) {
|
|
2100
|
+
let hash = 0;
|
|
2101
|
+
|
|
2102
|
+
for (let i = 0; i < namespace.length; i++) {
|
|
2103
|
+
hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
|
|
2104
|
+
hash |= 0; // Convert to 32bit integer
|
|
2105
|
+
}
|
|
2106
|
+
|
|
2107
|
+
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
|
2108
|
+
}
|
|
2109
|
+
createDebug.selectColor = selectColor;
|
|
2110
|
+
|
|
2111
|
+
/**
|
|
2112
|
+
* Create a debugger with the given `namespace`.
|
|
2113
|
+
*
|
|
2114
|
+
* @param {String} namespace
|
|
2115
|
+
* @return {Function}
|
|
2116
|
+
* @api public
|
|
2117
|
+
*/
|
|
2118
|
+
function createDebug(namespace) {
|
|
2119
|
+
let prevTime;
|
|
2120
|
+
let enableOverride = null;
|
|
2121
|
+
|
|
2122
|
+
function debug(...args) {
|
|
2123
|
+
// Disabled?
|
|
2124
|
+
if (!debug.enabled) {
|
|
2125
|
+
return;
|
|
2126
|
+
}
|
|
2127
|
+
|
|
2128
|
+
const self = debug;
|
|
2129
|
+
|
|
2130
|
+
// Set `diff` timestamp
|
|
2131
|
+
const curr = Number(new Date());
|
|
2132
|
+
const ms = curr - (prevTime || curr);
|
|
2133
|
+
self.diff = ms;
|
|
2134
|
+
self.prev = prevTime;
|
|
2135
|
+
self.curr = curr;
|
|
2136
|
+
prevTime = curr;
|
|
2137
|
+
|
|
2138
|
+
args[0] = createDebug.coerce(args[0]);
|
|
2139
|
+
|
|
2140
|
+
if (typeof args[0] !== 'string') {
|
|
2141
|
+
// Anything else let's inspect with %O
|
|
2142
|
+
args.unshift('%O');
|
|
2143
|
+
}
|
|
2144
|
+
|
|
2145
|
+
// Apply any `formatters` transformations
|
|
2146
|
+
let index = 0;
|
|
2147
|
+
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
|
|
2148
|
+
// If we encounter an escaped % then don't increase the array index
|
|
2149
|
+
if (match === '%%') {
|
|
2150
|
+
return '%';
|
|
2151
|
+
}
|
|
2152
|
+
index++;
|
|
2153
|
+
const formatter = createDebug.formatters[format];
|
|
2154
|
+
if (typeof formatter === 'function') {
|
|
2155
|
+
const val = args[index];
|
|
2156
|
+
match = formatter.call(self, val);
|
|
2157
|
+
|
|
2158
|
+
// Now we need to remove `args[index]` since it's inlined in the `format`
|
|
2159
|
+
args.splice(index, 1);
|
|
2160
|
+
index--;
|
|
2161
|
+
}
|
|
2162
|
+
return match;
|
|
2163
|
+
});
|
|
2164
|
+
|
|
2165
|
+
// Apply env-specific formatting (colors, etc.)
|
|
2166
|
+
createDebug.formatArgs.call(self, args);
|
|
2167
|
+
|
|
2168
|
+
const logFn = self.log || createDebug.log;
|
|
2169
|
+
logFn.apply(self, args);
|
|
2170
|
+
}
|
|
2171
|
+
|
|
2172
|
+
debug.namespace = namespace;
|
|
2173
|
+
debug.useColors = createDebug.useColors();
|
|
2174
|
+
debug.color = createDebug.selectColor(namespace);
|
|
2175
|
+
debug.extend = extend;
|
|
2176
|
+
debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
|
|
2177
|
+
|
|
2178
|
+
Object.defineProperty(debug, 'enabled', {
|
|
2179
|
+
enumerable: true,
|
|
2180
|
+
configurable: false,
|
|
2181
|
+
get: () => enableOverride === null ? createDebug.enabled(namespace) : enableOverride,
|
|
2182
|
+
set: v => {
|
|
2183
|
+
enableOverride = v;
|
|
2184
|
+
}
|
|
2185
|
+
});
|
|
2186
|
+
|
|
2187
|
+
// Env-specific initialization logic for debug instances
|
|
2188
|
+
if (typeof createDebug.init === 'function') {
|
|
2189
|
+
createDebug.init(debug);
|
|
2190
|
+
}
|
|
2191
|
+
|
|
2192
|
+
return debug;
|
|
2193
|
+
}
|
|
2194
|
+
|
|
2195
|
+
function extend(namespace, delimiter) {
|
|
2196
|
+
const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
|
|
2197
|
+
newDebug.log = this.log;
|
|
2198
|
+
return newDebug;
|
|
2199
|
+
}
|
|
2200
|
+
|
|
2201
|
+
/**
|
|
2202
|
+
* Enables a debug mode by namespaces. This can include modes
|
|
2203
|
+
* separated by a colon and wildcards.
|
|
2204
|
+
*
|
|
2205
|
+
* @param {String} namespaces
|
|
2206
|
+
* @api public
|
|
2207
|
+
*/
|
|
2208
|
+
function enable(namespaces) {
|
|
2209
|
+
createDebug.save(namespaces);
|
|
2210
|
+
|
|
2211
|
+
createDebug.names = [];
|
|
2212
|
+
createDebug.skips = [];
|
|
2213
|
+
|
|
2214
|
+
let i;
|
|
2215
|
+
const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
|
2216
|
+
const len = split.length;
|
|
2217
|
+
|
|
2218
|
+
for (i = 0; i < len; i++) {
|
|
2219
|
+
if (!split[i]) {
|
|
2220
|
+
// ignore empty strings
|
|
2221
|
+
continue;
|
|
2222
|
+
}
|
|
2223
|
+
|
|
2224
|
+
namespaces = split[i].replace(/\*/g, '.*?');
|
|
2225
|
+
|
|
2226
|
+
if (namespaces[0] === '-') {
|
|
2227
|
+
createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
|
|
2228
|
+
} else {
|
|
2229
|
+
createDebug.names.push(new RegExp('^' + namespaces + '$'));
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
|
|
2234
|
+
/**
|
|
2235
|
+
* Disable debug output.
|
|
2236
|
+
*
|
|
2237
|
+
* @return {String} namespaces
|
|
2238
|
+
* @api public
|
|
2239
|
+
*/
|
|
2240
|
+
function disable() {
|
|
2241
|
+
const namespaces = [
|
|
2242
|
+
...createDebug.names.map(toNamespace),
|
|
2243
|
+
...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
|
|
2244
|
+
].join(',');
|
|
2245
|
+
createDebug.enable('');
|
|
2246
|
+
return namespaces;
|
|
2247
|
+
}
|
|
2248
|
+
|
|
2249
|
+
/**
|
|
2250
|
+
* Returns true if the given mode name is enabled, false otherwise.
|
|
2251
|
+
*
|
|
2252
|
+
* @param {String} name
|
|
2253
|
+
* @return {Boolean}
|
|
2254
|
+
* @api public
|
|
2255
|
+
*/
|
|
2256
|
+
function enabled(name) {
|
|
2257
|
+
if (name[name.length - 1] === '*') {
|
|
2258
|
+
return true;
|
|
2259
|
+
}
|
|
2260
|
+
|
|
2261
|
+
let i;
|
|
2262
|
+
let len;
|
|
2263
|
+
|
|
2264
|
+
for (i = 0, len = createDebug.skips.length; i < len; i++) {
|
|
2265
|
+
if (createDebug.skips[i].test(name)) {
|
|
2266
|
+
return false;
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2269
|
+
|
|
2270
|
+
for (i = 0, len = createDebug.names.length; i < len; i++) {
|
|
2271
|
+
if (createDebug.names[i].test(name)) {
|
|
2272
|
+
return true;
|
|
2273
|
+
}
|
|
2274
|
+
}
|
|
2275
|
+
|
|
2276
|
+
return false;
|
|
2277
|
+
}
|
|
2278
|
+
|
|
2279
|
+
/**
|
|
2280
|
+
* Convert regexp to namespace
|
|
2281
|
+
*
|
|
2282
|
+
* @param {RegExp} regxep
|
|
2283
|
+
* @return {String} namespace
|
|
2284
|
+
* @api private
|
|
2285
|
+
*/
|
|
2286
|
+
function toNamespace(regexp) {
|
|
2287
|
+
return regexp.toString()
|
|
2288
|
+
.substring(2, regexp.toString().length - 2)
|
|
2289
|
+
.replace(/\.\*\?$/, '*');
|
|
2290
|
+
}
|
|
2291
|
+
|
|
2292
|
+
/**
|
|
2293
|
+
* Coerce `val`.
|
|
2294
|
+
*
|
|
2295
|
+
* @param {Mixed} val
|
|
2296
|
+
* @return {Mixed}
|
|
2297
|
+
* @api private
|
|
2298
|
+
*/
|
|
2299
|
+
function coerce(val) {
|
|
2300
|
+
if (val instanceof Error) {
|
|
2301
|
+
return val.stack || val.message;
|
|
2302
|
+
}
|
|
2303
|
+
return val;
|
|
2304
|
+
}
|
|
2305
|
+
|
|
2306
|
+
/**
|
|
2307
|
+
* XXX DO NOT USE. This is a temporary stub function.
|
|
2308
|
+
* XXX It WILL be removed in the next major release.
|
|
2309
|
+
*/
|
|
2310
|
+
function destroy() {
|
|
2311
|
+
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2314
|
+
createDebug.enable(createDebug.load());
|
|
2315
|
+
|
|
2316
|
+
return createDebug;
|
|
2317
|
+
}
|
|
2318
|
+
|
|
2319
|
+
common$2 = setup;
|
|
2320
|
+
return common$2;
|
|
2321
|
+
}
|
|
2322
|
+
|
|
2323
|
+
/* eslint-env browser */
|
|
2324
|
+
|
|
2325
|
+
var hasRequiredBrowser;
|
|
2326
|
+
|
|
2327
|
+
function requireBrowser () {
|
|
2328
|
+
if (hasRequiredBrowser) return browser.exports;
|
|
2329
|
+
hasRequiredBrowser = 1;
|
|
2330
|
+
(function (module, exports) {
|
|
2331
|
+
/**
|
|
2332
|
+
* This is the web browser implementation of `debug()`.
|
|
2333
|
+
*/
|
|
2334
|
+
|
|
2335
|
+
exports.formatArgs = formatArgs;
|
|
2336
|
+
exports.save = save;
|
|
2337
|
+
exports.load = load;
|
|
2338
|
+
exports.useColors = useColors;
|
|
2339
|
+
exports.storage = localstorage();
|
|
2340
|
+
exports.destroy = (() => {
|
|
2341
|
+
let warned = false;
|
|
2342
|
+
|
|
2343
|
+
return () => {
|
|
2344
|
+
if (!warned) {
|
|
2345
|
+
warned = true;
|
|
2346
|
+
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
|
2347
|
+
}
|
|
2348
|
+
};
|
|
2349
|
+
})();
|
|
2350
|
+
|
|
2351
|
+
/**
|
|
2352
|
+
* Colors.
|
|
2353
|
+
*/
|
|
2354
|
+
|
|
2355
|
+
exports.colors = [
|
|
2356
|
+
'#0000CC',
|
|
2357
|
+
'#0000FF',
|
|
2358
|
+
'#0033CC',
|
|
2359
|
+
'#0033FF',
|
|
2360
|
+
'#0066CC',
|
|
2361
|
+
'#0066FF',
|
|
2362
|
+
'#0099CC',
|
|
2363
|
+
'#0099FF',
|
|
2364
|
+
'#00CC00',
|
|
2365
|
+
'#00CC33',
|
|
2366
|
+
'#00CC66',
|
|
2367
|
+
'#00CC99',
|
|
2368
|
+
'#00CCCC',
|
|
2369
|
+
'#00CCFF',
|
|
2370
|
+
'#3300CC',
|
|
2371
|
+
'#3300FF',
|
|
2372
|
+
'#3333CC',
|
|
2373
|
+
'#3333FF',
|
|
2374
|
+
'#3366CC',
|
|
2375
|
+
'#3366FF',
|
|
2376
|
+
'#3399CC',
|
|
2377
|
+
'#3399FF',
|
|
2378
|
+
'#33CC00',
|
|
2379
|
+
'#33CC33',
|
|
2380
|
+
'#33CC66',
|
|
2381
|
+
'#33CC99',
|
|
2382
|
+
'#33CCCC',
|
|
2383
|
+
'#33CCFF',
|
|
2384
|
+
'#6600CC',
|
|
2385
|
+
'#6600FF',
|
|
2386
|
+
'#6633CC',
|
|
2387
|
+
'#6633FF',
|
|
2388
|
+
'#66CC00',
|
|
2389
|
+
'#66CC33',
|
|
2390
|
+
'#9900CC',
|
|
2391
|
+
'#9900FF',
|
|
2392
|
+
'#9933CC',
|
|
2393
|
+
'#9933FF',
|
|
2394
|
+
'#99CC00',
|
|
2395
|
+
'#99CC33',
|
|
2396
|
+
'#CC0000',
|
|
2397
|
+
'#CC0033',
|
|
2398
|
+
'#CC0066',
|
|
2399
|
+
'#CC0099',
|
|
2400
|
+
'#CC00CC',
|
|
2401
|
+
'#CC00FF',
|
|
2402
|
+
'#CC3300',
|
|
2403
|
+
'#CC3333',
|
|
2404
|
+
'#CC3366',
|
|
2405
|
+
'#CC3399',
|
|
2406
|
+
'#CC33CC',
|
|
2407
|
+
'#CC33FF',
|
|
2408
|
+
'#CC6600',
|
|
2409
|
+
'#CC6633',
|
|
2410
|
+
'#CC9900',
|
|
2411
|
+
'#CC9933',
|
|
2412
|
+
'#CCCC00',
|
|
2413
|
+
'#CCCC33',
|
|
2414
|
+
'#FF0000',
|
|
2415
|
+
'#FF0033',
|
|
2416
|
+
'#FF0066',
|
|
2417
|
+
'#FF0099',
|
|
2418
|
+
'#FF00CC',
|
|
2419
|
+
'#FF00FF',
|
|
2420
|
+
'#FF3300',
|
|
2421
|
+
'#FF3333',
|
|
2422
|
+
'#FF3366',
|
|
2423
|
+
'#FF3399',
|
|
2424
|
+
'#FF33CC',
|
|
2425
|
+
'#FF33FF',
|
|
2426
|
+
'#FF6600',
|
|
2427
|
+
'#FF6633',
|
|
2428
|
+
'#FF9900',
|
|
2429
|
+
'#FF9933',
|
|
2430
|
+
'#FFCC00',
|
|
2431
|
+
'#FFCC33'
|
|
2432
|
+
];
|
|
2433
|
+
|
|
2434
|
+
/**
|
|
2435
|
+
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
|
2436
|
+
* and the Firebug extension (any Firefox version) are known
|
|
2437
|
+
* to support "%c" CSS customizations.
|
|
2438
|
+
*
|
|
2439
|
+
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
|
2440
|
+
*/
|
|
2441
|
+
|
|
2442
|
+
// eslint-disable-next-line complexity
|
|
2443
|
+
function useColors() {
|
|
2444
|
+
// NB: In an Electron preload script, document will be defined but not fully
|
|
2445
|
+
// initialized. Since we know we're in Chrome, we'll just detect this case
|
|
2446
|
+
// explicitly
|
|
2447
|
+
if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
|
|
2448
|
+
return true;
|
|
2449
|
+
}
|
|
2450
|
+
|
|
2451
|
+
// Internet Explorer and Edge do not support colors.
|
|
2452
|
+
if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
|
2453
|
+
return false;
|
|
2454
|
+
}
|
|
2455
|
+
|
|
2456
|
+
// Is webkit? http://stackoverflow.com/a/16459606/376773
|
|
2457
|
+
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
|
2458
|
+
return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
|
|
2459
|
+
// Is firebug? http://stackoverflow.com/a/398120/376773
|
|
2460
|
+
(typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
|
|
2461
|
+
// Is firefox >= v31?
|
|
2462
|
+
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
|
2463
|
+
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
|
|
2464
|
+
// Double check webkit in userAgent just in case we are in a worker
|
|
2465
|
+
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
|
|
2466
|
+
}
|
|
2467
|
+
|
|
2468
|
+
/**
|
|
2469
|
+
* Colorize log arguments if enabled.
|
|
2470
|
+
*
|
|
2471
|
+
* @api public
|
|
2472
|
+
*/
|
|
2473
|
+
|
|
2474
|
+
function formatArgs(args) {
|
|
2475
|
+
args[0] = (this.useColors ? '%c' : '') +
|
|
2476
|
+
this.namespace +
|
|
2477
|
+
(this.useColors ? ' %c' : ' ') +
|
|
2478
|
+
args[0] +
|
|
2479
|
+
(this.useColors ? '%c ' : ' ') +
|
|
2480
|
+
'+' + module.exports.humanize(this.diff);
|
|
2481
|
+
|
|
2482
|
+
if (!this.useColors) {
|
|
2483
|
+
return;
|
|
2484
|
+
}
|
|
2485
|
+
|
|
2486
|
+
const c = 'color: ' + this.color;
|
|
2487
|
+
args.splice(1, 0, c, 'color: inherit');
|
|
2488
|
+
|
|
2489
|
+
// The final "%c" is somewhat tricky, because there could be other
|
|
2490
|
+
// arguments passed either before or after the %c, so we need to
|
|
2491
|
+
// figure out the correct index to insert the CSS into
|
|
2492
|
+
let index = 0;
|
|
2493
|
+
let lastC = 0;
|
|
2494
|
+
args[0].replace(/%[a-zA-Z%]/g, match => {
|
|
2495
|
+
if (match === '%%') {
|
|
2496
|
+
return;
|
|
2497
|
+
}
|
|
2498
|
+
index++;
|
|
2499
|
+
if (match === '%c') {
|
|
2500
|
+
// We only are interested in the *last* %c
|
|
2501
|
+
// (the user may have provided their own)
|
|
2502
|
+
lastC = index;
|
|
2503
|
+
}
|
|
2504
|
+
});
|
|
2505
|
+
|
|
2506
|
+
args.splice(lastC, 0, c);
|
|
2507
|
+
}
|
|
2508
|
+
|
|
2509
|
+
/**
|
|
2510
|
+
* Invokes `console.debug()` when available.
|
|
2511
|
+
* No-op when `console.debug` is not a "function".
|
|
2512
|
+
* If `console.debug` is not available, falls back
|
|
2513
|
+
* to `console.log`.
|
|
2514
|
+
*
|
|
2515
|
+
* @api public
|
|
2516
|
+
*/
|
|
2517
|
+
exports.log = console.debug || console.log || (() => {});
|
|
2518
|
+
|
|
2519
|
+
/**
|
|
2520
|
+
* Save `namespaces`.
|
|
2521
|
+
*
|
|
2522
|
+
* @param {String} namespaces
|
|
2523
|
+
* @api private
|
|
2524
|
+
*/
|
|
2525
|
+
function save(namespaces) {
|
|
2526
|
+
try {
|
|
2527
|
+
if (namespaces) {
|
|
2528
|
+
exports.storage.setItem('debug', namespaces);
|
|
2529
|
+
} else {
|
|
2530
|
+
exports.storage.removeItem('debug');
|
|
2531
|
+
}
|
|
2532
|
+
} catch (error) {
|
|
2533
|
+
// Swallow
|
|
2534
|
+
// XXX (@Qix-) should we be logging these?
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
|
|
2538
|
+
/**
|
|
2539
|
+
* Load `namespaces`.
|
|
2540
|
+
*
|
|
2541
|
+
* @return {String} returns the previously persisted debug modes
|
|
2542
|
+
* @api private
|
|
2543
|
+
*/
|
|
2544
|
+
function load() {
|
|
2545
|
+
let r;
|
|
2546
|
+
try {
|
|
2547
|
+
r = exports.storage.getItem('debug');
|
|
2548
|
+
} catch (error) {
|
|
2549
|
+
// Swallow
|
|
2550
|
+
// XXX (@Qix-) should we be logging these?
|
|
2551
|
+
}
|
|
2552
|
+
|
|
2553
|
+
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
|
|
2554
|
+
if (!r && typeof process !== 'undefined' && 'env' in process) {
|
|
2555
|
+
r = process.env.DEBUG;
|
|
2556
|
+
}
|
|
2557
|
+
|
|
2558
|
+
return r;
|
|
2559
|
+
}
|
|
2560
|
+
|
|
2561
|
+
/**
|
|
2562
|
+
* Localstorage attempts to return the localstorage.
|
|
2563
|
+
*
|
|
2564
|
+
* This is necessary because safari throws
|
|
2565
|
+
* when a user disables cookies/localstorage
|
|
2566
|
+
* and you attempt to access it.
|
|
2567
|
+
*
|
|
2568
|
+
* @return {LocalStorage}
|
|
2569
|
+
* @api private
|
|
2570
|
+
*/
|
|
2571
|
+
|
|
2572
|
+
function localstorage() {
|
|
2573
|
+
try {
|
|
2574
|
+
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
|
|
2575
|
+
// The Browser also has localStorage in the global context.
|
|
2576
|
+
return localStorage;
|
|
2577
|
+
} catch (error) {
|
|
2578
|
+
// Swallow
|
|
2579
|
+
// XXX (@Qix-) should we be logging these?
|
|
2580
|
+
}
|
|
2581
|
+
}
|
|
2582
|
+
|
|
2583
|
+
module.exports = requireCommon$2()(exports);
|
|
2584
|
+
|
|
2585
|
+
const {formatters} = module.exports;
|
|
2586
|
+
|
|
2587
|
+
/**
|
|
2588
|
+
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
|
2589
|
+
*/
|
|
2590
|
+
|
|
2591
|
+
formatters.j = function (v) {
|
|
2592
|
+
try {
|
|
2593
|
+
return JSON.stringify(v);
|
|
2594
|
+
} catch (error) {
|
|
2595
|
+
return '[UnexpectedJSONParseError]: ' + error.message;
|
|
2596
|
+
}
|
|
2597
|
+
};
|
|
2598
|
+
} (browser, browser.exports));
|
|
2599
|
+
return browser.exports;
|
|
2600
|
+
}
|
|
2601
|
+
|
|
2602
|
+
var node = {exports: {}};
|
|
2603
|
+
|
|
2604
|
+
/**
|
|
2605
|
+
* Module dependencies.
|
|
2606
|
+
*/
|
|
2607
|
+
|
|
2608
|
+
var hasRequiredNode;
|
|
2609
|
+
|
|
2610
|
+
function requireNode () {
|
|
2611
|
+
if (hasRequiredNode) return node.exports;
|
|
2612
|
+
hasRequiredNode = 1;
|
|
2613
|
+
(function (module, exports) {
|
|
2614
|
+
const tty = require$$0__default$1;
|
|
2615
|
+
const util = require$$0__default;
|
|
2616
|
+
|
|
2617
|
+
/**
|
|
2618
|
+
* This is the Node.js implementation of `debug()`.
|
|
2619
|
+
*/
|
|
2620
|
+
|
|
2621
|
+
exports.init = init;
|
|
2622
|
+
exports.log = log;
|
|
2623
|
+
exports.formatArgs = formatArgs;
|
|
2624
|
+
exports.save = save;
|
|
2625
|
+
exports.load = load;
|
|
2626
|
+
exports.useColors = useColors;
|
|
2627
|
+
exports.destroy = util.deprecate(
|
|
2628
|
+
() => {},
|
|
2629
|
+
'Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'
|
|
2630
|
+
);
|
|
2631
|
+
|
|
2632
|
+
/**
|
|
2633
|
+
* Colors.
|
|
2634
|
+
*/
|
|
2635
|
+
|
|
2636
|
+
exports.colors = [6, 2, 3, 4, 5, 1];
|
|
2637
|
+
|
|
2638
|
+
try {
|
|
2639
|
+
// Optional dependency (as in, doesn't need to be installed, NOT like optionalDependencies in package.json)
|
|
2640
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2641
|
+
const supportsColor = require('supports-color');
|
|
2642
|
+
|
|
2643
|
+
if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
|
|
2644
|
+
exports.colors = [
|
|
2645
|
+
20,
|
|
2646
|
+
21,
|
|
2647
|
+
26,
|
|
2648
|
+
27,
|
|
2649
|
+
32,
|
|
2650
|
+
33,
|
|
2651
|
+
38,
|
|
2652
|
+
39,
|
|
2653
|
+
40,
|
|
2654
|
+
41,
|
|
2655
|
+
42,
|
|
2656
|
+
43,
|
|
2657
|
+
44,
|
|
2658
|
+
45,
|
|
2659
|
+
56,
|
|
2660
|
+
57,
|
|
2661
|
+
62,
|
|
2662
|
+
63,
|
|
2663
|
+
68,
|
|
2664
|
+
69,
|
|
2665
|
+
74,
|
|
2666
|
+
75,
|
|
2667
|
+
76,
|
|
2668
|
+
77,
|
|
2669
|
+
78,
|
|
2670
|
+
79,
|
|
2671
|
+
80,
|
|
2672
|
+
81,
|
|
2673
|
+
92,
|
|
2674
|
+
93,
|
|
2675
|
+
98,
|
|
2676
|
+
99,
|
|
2677
|
+
112,
|
|
2678
|
+
113,
|
|
2679
|
+
128,
|
|
2680
|
+
129,
|
|
2681
|
+
134,
|
|
2682
|
+
135,
|
|
2683
|
+
148,
|
|
2684
|
+
149,
|
|
2685
|
+
160,
|
|
2686
|
+
161,
|
|
2687
|
+
162,
|
|
2688
|
+
163,
|
|
2689
|
+
164,
|
|
2690
|
+
165,
|
|
2691
|
+
166,
|
|
2692
|
+
167,
|
|
2693
|
+
168,
|
|
2694
|
+
169,
|
|
2695
|
+
170,
|
|
2696
|
+
171,
|
|
2697
|
+
172,
|
|
2698
|
+
173,
|
|
2699
|
+
178,
|
|
2700
|
+
179,
|
|
2701
|
+
184,
|
|
2702
|
+
185,
|
|
2703
|
+
196,
|
|
2704
|
+
197,
|
|
2705
|
+
198,
|
|
2706
|
+
199,
|
|
2707
|
+
200,
|
|
2708
|
+
201,
|
|
2709
|
+
202,
|
|
2710
|
+
203,
|
|
2711
|
+
204,
|
|
2712
|
+
205,
|
|
2713
|
+
206,
|
|
2714
|
+
207,
|
|
2715
|
+
208,
|
|
2716
|
+
209,
|
|
2717
|
+
214,
|
|
2718
|
+
215,
|
|
2719
|
+
220,
|
|
2720
|
+
221
|
|
2721
|
+
];
|
|
2722
|
+
}
|
|
2723
|
+
} catch (error) {
|
|
2724
|
+
// Swallow - we only care if `supports-color` is available; it doesn't have to be.
|
|
2725
|
+
}
|
|
2726
|
+
|
|
2727
|
+
/**
|
|
2728
|
+
* Build up the default `inspectOpts` object from the environment variables.
|
|
2729
|
+
*
|
|
2730
|
+
* $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
|
|
2731
|
+
*/
|
|
2732
|
+
|
|
2733
|
+
exports.inspectOpts = Object.keys(process.env).filter(key => {
|
|
2734
|
+
return /^debug_/i.test(key);
|
|
2735
|
+
}).reduce((obj, key) => {
|
|
2736
|
+
// Camel-case
|
|
2737
|
+
const prop = key
|
|
2738
|
+
.substring(6)
|
|
2739
|
+
.toLowerCase()
|
|
2740
|
+
.replace(/_([a-z])/g, (_, k) => {
|
|
2741
|
+
return k.toUpperCase();
|
|
2742
|
+
});
|
|
2743
|
+
|
|
2744
|
+
// Coerce string value into JS value
|
|
2745
|
+
let val = process.env[key];
|
|
2746
|
+
if (/^(yes|on|true|enabled)$/i.test(val)) {
|
|
2747
|
+
val = true;
|
|
2748
|
+
} else if (/^(no|off|false|disabled)$/i.test(val)) {
|
|
2749
|
+
val = false;
|
|
2750
|
+
} else if (val === 'null') {
|
|
2751
|
+
val = null;
|
|
2752
|
+
} else {
|
|
2753
|
+
val = Number(val);
|
|
2754
|
+
}
|
|
2755
|
+
|
|
2756
|
+
obj[prop] = val;
|
|
2757
|
+
return obj;
|
|
2758
|
+
}, {});
|
|
2759
|
+
|
|
2760
|
+
/**
|
|
2761
|
+
* Is stdout a TTY? Colored output is enabled when `true`.
|
|
2762
|
+
*/
|
|
2763
|
+
|
|
2764
|
+
function useColors() {
|
|
2765
|
+
return 'colors' in exports.inspectOpts ?
|
|
2766
|
+
Boolean(exports.inspectOpts.colors) :
|
|
2767
|
+
tty.isatty(process.stderr.fd);
|
|
2768
|
+
}
|
|
2769
|
+
|
|
2770
|
+
/**
|
|
2771
|
+
* Adds ANSI color escape codes if enabled.
|
|
2772
|
+
*
|
|
2773
|
+
* @api public
|
|
2774
|
+
*/
|
|
2775
|
+
|
|
2776
|
+
function formatArgs(args) {
|
|
2777
|
+
const {namespace: name, useColors} = this;
|
|
2778
|
+
|
|
2779
|
+
if (useColors) {
|
|
2780
|
+
const c = this.color;
|
|
2781
|
+
const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
|
|
2782
|
+
const prefix = ` ${colorCode};1m${name} \u001B[0m`;
|
|
2783
|
+
|
|
2784
|
+
args[0] = prefix + args[0].split('\n').join('\n' + prefix);
|
|
2785
|
+
args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001B[0m');
|
|
2786
|
+
} else {
|
|
2787
|
+
args[0] = getDate() + name + ' ' + args[0];
|
|
2788
|
+
}
|
|
2789
|
+
}
|
|
2790
|
+
|
|
2791
|
+
function getDate() {
|
|
2792
|
+
if (exports.inspectOpts.hideDate) {
|
|
2793
|
+
return '';
|
|
2794
|
+
}
|
|
2795
|
+
return new Date().toISOString() + ' ';
|
|
2796
|
+
}
|
|
2797
|
+
|
|
2798
|
+
/**
|
|
2799
|
+
* Invokes `util.format()` with the specified arguments and writes to stderr.
|
|
2800
|
+
*/
|
|
2801
|
+
|
|
2802
|
+
function log(...args) {
|
|
2803
|
+
return process.stderr.write(util.format(...args) + '\n');
|
|
2804
|
+
}
|
|
2805
|
+
|
|
2806
|
+
/**
|
|
2807
|
+
* Save `namespaces`.
|
|
2808
|
+
*
|
|
2809
|
+
* @param {String} namespaces
|
|
2810
|
+
* @api private
|
|
2811
|
+
*/
|
|
2812
|
+
function save(namespaces) {
|
|
2813
|
+
if (namespaces) {
|
|
2814
|
+
process.env.DEBUG = namespaces;
|
|
2815
|
+
} else {
|
|
2816
|
+
// If you set a process.env field to null or undefined, it gets cast to the
|
|
2817
|
+
// string 'null' or 'undefined'. Just delete instead.
|
|
2818
|
+
delete process.env.DEBUG;
|
|
2819
|
+
}
|
|
2820
|
+
}
|
|
2821
|
+
|
|
2822
|
+
/**
|
|
2823
|
+
* Load `namespaces`.
|
|
2824
|
+
*
|
|
2825
|
+
* @return {String} returns the previously persisted debug modes
|
|
2826
|
+
* @api private
|
|
2827
|
+
*/
|
|
2828
|
+
|
|
2829
|
+
function load() {
|
|
2830
|
+
return process.env.DEBUG;
|
|
2831
|
+
}
|
|
2832
|
+
|
|
2833
|
+
/**
|
|
2834
|
+
* Init logic for `debug` instances.
|
|
2835
|
+
*
|
|
2836
|
+
* Create a new `inspectOpts` object in case `useColors` is set
|
|
2837
|
+
* differently for a particular `debug` instance.
|
|
2838
|
+
*/
|
|
2839
|
+
|
|
2840
|
+
function init(debug) {
|
|
2841
|
+
debug.inspectOpts = {};
|
|
2842
|
+
|
|
2843
|
+
const keys = Object.keys(exports.inspectOpts);
|
|
2844
|
+
for (let i = 0; i < keys.length; i++) {
|
|
2845
|
+
debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
|
|
2849
|
+
module.exports = requireCommon$2()(exports);
|
|
2850
|
+
|
|
2851
|
+
const {formatters} = module.exports;
|
|
2852
|
+
|
|
2853
|
+
/**
|
|
2854
|
+
* Map %o to `util.inspect()`, all on a single line.
|
|
2855
|
+
*/
|
|
2856
|
+
|
|
2857
|
+
formatters.o = function (v) {
|
|
2858
|
+
this.inspectOpts.colors = this.useColors;
|
|
2859
|
+
return util.inspect(v, this.inspectOpts)
|
|
2860
|
+
.split('\n')
|
|
2861
|
+
.map(str => str.trim())
|
|
2862
|
+
.join(' ');
|
|
2863
|
+
};
|
|
2864
|
+
|
|
2865
|
+
/**
|
|
2866
|
+
* Map %O to `util.inspect()`, allowing multiple lines if needed.
|
|
2867
|
+
*/
|
|
2868
|
+
|
|
2869
|
+
formatters.O = function (v) {
|
|
2870
|
+
this.inspectOpts.colors = this.useColors;
|
|
2871
|
+
return util.inspect(v, this.inspectOpts);
|
|
2872
|
+
};
|
|
2873
|
+
} (node, node.exports));
|
|
2874
|
+
return node.exports;
|
|
2875
|
+
}
|
|
2876
|
+
|
|
2877
|
+
/**
|
|
2878
|
+
* Detect Electron renderer / nwjs process, which is node, but we should
|
|
2879
|
+
* treat as a browser.
|
|
2880
|
+
*/
|
|
2881
|
+
|
|
2882
|
+
var hasRequiredSrc;
|
|
2883
|
+
|
|
2884
|
+
function requireSrc () {
|
|
2885
|
+
if (hasRequiredSrc) return src.exports;
|
|
2886
|
+
hasRequiredSrc = 1;
|
|
2887
|
+
if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) {
|
|
2888
|
+
src.exports = requireBrowser();
|
|
2889
|
+
} else {
|
|
2890
|
+
src.exports = requireNode();
|
|
2891
|
+
}
|
|
2892
|
+
return src.exports;
|
|
2893
|
+
}
|
|
2894
|
+
|
|
2895
|
+
/**
|
|
2896
|
+
* @fileOverview
|
|
2897
|
+
* A simple promises-based check to see if a TCP port is already in use.
|
|
2898
|
+
*/
|
|
2899
|
+
|
|
2900
|
+
var hasRequiredTcpPortUsed;
|
|
2901
|
+
|
|
2902
|
+
function requireTcpPortUsed () {
|
|
2903
|
+
if (hasRequiredTcpPortUsed) return tcpPortUsed$1;
|
|
2904
|
+
hasRequiredTcpPortUsed = 1;
|
|
2905
|
+
|
|
2906
|
+
// define the exports first to avoid cyclic dependencies.
|
|
2907
|
+
tcpPortUsed$1.check = check;
|
|
2908
|
+
tcpPortUsed$1.waitUntilFreeOnHost = waitUntilFreeOnHost;
|
|
2909
|
+
tcpPortUsed$1.waitUntilFree = waitUntilFree;
|
|
2910
|
+
tcpPortUsed$1.waitUntilUsedOnHost = waitUntilUsedOnHost;
|
|
2911
|
+
tcpPortUsed$1.waitUntilUsed = waitUntilUsed;
|
|
2912
|
+
tcpPortUsed$1.waitForStatus = waitForStatus;
|
|
2913
|
+
|
|
2914
|
+
var is = requireIs2();
|
|
2915
|
+
var net = require$$1__default;
|
|
2916
|
+
var util = require$$0__default;
|
|
2917
|
+
var debug = requireSrc()('tcp-port-used');
|
|
2918
|
+
|
|
2919
|
+
// Global Values
|
|
2920
|
+
var TIMEOUT = 2000;
|
|
2921
|
+
var RETRYTIME = 250;
|
|
2922
|
+
|
|
2923
|
+
function getDeferred() {
|
|
2924
|
+
var resolve, reject, promise = new Promise(function(res, rej) {
|
|
2925
|
+
resolve = res;
|
|
2926
|
+
reject = rej;
|
|
2927
|
+
});
|
|
2928
|
+
|
|
2929
|
+
return {
|
|
2930
|
+
resolve: resolve,
|
|
2931
|
+
reject: reject,
|
|
2932
|
+
promise: promise
|
|
2933
|
+
};
|
|
2934
|
+
}
|
|
2935
|
+
|
|
2936
|
+
/**
|
|
2937
|
+
* Creates an options object from all the possible arguments
|
|
2938
|
+
* @private
|
|
2939
|
+
* @param {Number} port a valid TCP port number
|
|
2940
|
+
* @param {String} host The DNS name or IP address.
|
|
2941
|
+
* @param {Boolean} status The desired in use status to wait for: false === not in use, true === in use
|
|
2942
|
+
* @param {Number} retryTimeMs the retry interval in milliseconds - defaultis is 200ms
|
|
2943
|
+
* @param {Number} timeOutMs the amount of time to wait until port is free default is 1000ms
|
|
2944
|
+
* @return {Object} An options object with all the above parameters as properties.
|
|
2945
|
+
*/
|
|
2946
|
+
function makeOptionsObj(port, host, inUse, retryTimeMs, timeOutMs) {
|
|
2947
|
+
var opts = {};
|
|
2948
|
+
opts.port = port;
|
|
2949
|
+
opts.host = host;
|
|
2950
|
+
opts.inUse = inUse;
|
|
2951
|
+
opts.retryTimeMs = retryTimeMs;
|
|
2952
|
+
opts.timeOutMs = timeOutMs;
|
|
2953
|
+
return opts;
|
|
2954
|
+
}
|
|
2955
|
+
|
|
2956
|
+
/**
|
|
2957
|
+
* Checks if a TCP port is in use by creating the socket and binding it to the
|
|
2958
|
+
* target port. Once bound, successfully, it's assume the port is availble.
|
|
2959
|
+
* After the socket is closed or in error, the promise is resolved.
|
|
2960
|
+
* Note: you have to be super user to correctly test system ports (0-1023).
|
|
2961
|
+
* @param {Number|Object} port The port you are curious to see if available. If an object, must have the parameters as properties.
|
|
2962
|
+
* @param {String} [host] May be a DNS name or IP address. Default '127.0.0.1'
|
|
2963
|
+
* @return {Object} A deferred Q promise.
|
|
2964
|
+
*
|
|
2965
|
+
* Example usage:
|
|
2966
|
+
*
|
|
2967
|
+
* var tcpPortUsed = require('tcp-port-used');
|
|
2968
|
+
* tcpPortUsed.check(22, '127.0.0.1')
|
|
2969
|
+
* .then(function(inUse) {
|
|
2970
|
+
* debug('Port 22 usage: '+inUse);
|
|
2971
|
+
* }, function(err) {
|
|
2972
|
+
* console.error('Error on check: '+util.inspect(err));
|
|
2973
|
+
* });
|
|
2974
|
+
*/
|
|
2975
|
+
function check(port, host) {
|
|
2976
|
+
|
|
2977
|
+
var deferred = getDeferred();
|
|
2978
|
+
var inUse = true;
|
|
2979
|
+
var client;
|
|
2980
|
+
|
|
2981
|
+
var opts;
|
|
2982
|
+
if (!is.obj(port)) {
|
|
2983
|
+
opts = makeOptionsObj(port, host);
|
|
2984
|
+
} else {
|
|
2985
|
+
opts = port;
|
|
2986
|
+
}
|
|
2987
|
+
|
|
2988
|
+
if (!is.port(opts.port)) {
|
|
2989
|
+
debug('Error invalid port: '+util.inspect(opts.port));
|
|
2990
|
+
deferred.reject(new Error('invalid port: '+util.inspect(opts.port)));
|
|
2991
|
+
return deferred.promise;
|
|
2992
|
+
}
|
|
2993
|
+
|
|
2994
|
+
if (is.nullOrUndefined(opts.host)) {
|
|
2995
|
+
debug('set host address to default 127.0.0.1');
|
|
2996
|
+
opts.host = '127.0.0.1';
|
|
2997
|
+
}
|
|
2998
|
+
|
|
2999
|
+
function cleanUp() {
|
|
3000
|
+
if (client) {
|
|
3001
|
+
client.removeAllListeners('connect');
|
|
3002
|
+
client.removeAllListeners('error');
|
|
3003
|
+
client.end();
|
|
3004
|
+
client.destroy();
|
|
3005
|
+
client.unref();
|
|
3006
|
+
}
|
|
3007
|
+
//debug('listeners removed from client socket');
|
|
3008
|
+
}
|
|
3009
|
+
|
|
3010
|
+
function onConnectCb() {
|
|
3011
|
+
//debug('check - promise resolved - in use');
|
|
3012
|
+
deferred.resolve(inUse);
|
|
3013
|
+
cleanUp();
|
|
3014
|
+
}
|
|
3015
|
+
|
|
3016
|
+
function onErrorCb(err) {
|
|
3017
|
+
if (err.code !== 'ECONNREFUSED') {
|
|
3018
|
+
//debug('check - promise rejected, error: '+err.message);
|
|
3019
|
+
deferred.reject(err);
|
|
3020
|
+
} else {
|
|
3021
|
+
//debug('ECONNREFUSED');
|
|
3022
|
+
inUse = false;
|
|
3023
|
+
//debug('check - promise resolved - not in use');
|
|
3024
|
+
deferred.resolve(inUse);
|
|
3025
|
+
}
|
|
3026
|
+
cleanUp();
|
|
3027
|
+
}
|
|
3028
|
+
|
|
3029
|
+
client = new net.Socket();
|
|
3030
|
+
client.once('connect', onConnectCb);
|
|
3031
|
+
client.once('error', onErrorCb);
|
|
3032
|
+
client.connect({port: opts.port, host: opts.host}, function() {});
|
|
3033
|
+
|
|
3034
|
+
return deferred.promise;
|
|
3035
|
+
}
|
|
3036
|
+
|
|
3037
|
+
/**
|
|
3038
|
+
* Creates a deferred promise and fulfills it only when the socket's usage
|
|
3039
|
+
* equals status in terms of 'in use' (false === not in use, true === in use).
|
|
3040
|
+
* Will retry on an interval specified in retryTimeMs. Note: you have to be
|
|
3041
|
+
* super user to correctly test system ports (0-1023).
|
|
3042
|
+
* @param {Number|Object} port a valid TCP port number, if an object, has all the parameters described as properties.
|
|
3043
|
+
* @param {String} host The DNS name or IP address.
|
|
3044
|
+
* @param {Boolean} status The desired in use status to wait for false === not in use, true === in use
|
|
3045
|
+
* @param {Number} [retryTimeMs] the retry interval in milliseconds - defaultis is 200ms
|
|
3046
|
+
* @param {Number} [timeOutMs] the amount of time to wait until port is free default is 1000ms
|
|
3047
|
+
* @return {Object} A deferred promise from the Q library.
|
|
3048
|
+
*
|
|
3049
|
+
* Example usage:
|
|
3050
|
+
*
|
|
3051
|
+
* var tcpPortUsed = require('tcp-port-used');
|
|
3052
|
+
* tcpPortUsed.waitForStatus(44204, 'some.host.com', true, 500, 4000)
|
|
3053
|
+
* .then(function() {
|
|
3054
|
+
* console.log('Port 44204 is now in use.');
|
|
3055
|
+
* }, function(err) {
|
|
3056
|
+
* console.log('Error: ', error.message);
|
|
3057
|
+
* });
|
|
3058
|
+
*/
|
|
3059
|
+
function waitForStatus(port, host, inUse, retryTimeMs, timeOutMs) {
|
|
3060
|
+
|
|
3061
|
+
var deferred = getDeferred();
|
|
3062
|
+
var timeoutId;
|
|
3063
|
+
var timedout = false;
|
|
3064
|
+
var retryId;
|
|
3065
|
+
|
|
3066
|
+
// the first arument may be an object, if it is not, make an object
|
|
3067
|
+
var opts;
|
|
3068
|
+
if (is.obj(port)) {
|
|
3069
|
+
opts = port;
|
|
3070
|
+
} else {
|
|
3071
|
+
opts = makeOptionsObj(port, host, inUse, retryTimeMs, timeOutMs);
|
|
3072
|
+
}
|
|
3073
|
+
|
|
3074
|
+
//debug('opts:'+util.inspect(opts);
|
|
3075
|
+
|
|
3076
|
+
if (!is.bool(opts.inUse)) {
|
|
3077
|
+
deferred.reject(new Error('inUse must be a boolean'));
|
|
3078
|
+
return deferred.promise;
|
|
3079
|
+
}
|
|
3080
|
+
|
|
3081
|
+
if (!is.positiveInt(opts.retryTimeMs)) {
|
|
3082
|
+
opts.retryTimeMs = RETRYTIME;
|
|
3083
|
+
debug('set retryTime to default '+RETRYTIME+'ms');
|
|
3084
|
+
}
|
|
3085
|
+
|
|
3086
|
+
if (!is.positiveInt(opts.timeOutMs)) {
|
|
3087
|
+
opts.timeOutMs = TIMEOUT;
|
|
3088
|
+
debug('set timeOutMs to default '+TIMEOUT+'ms');
|
|
3089
|
+
}
|
|
3090
|
+
|
|
3091
|
+
function cleanUp() {
|
|
3092
|
+
if (timeoutId) {
|
|
3093
|
+
clearTimeout(timeoutId);
|
|
3094
|
+
}
|
|
3095
|
+
if (retryId) {
|
|
3096
|
+
clearTimeout(retryId);
|
|
3097
|
+
}
|
|
3098
|
+
}
|
|
3099
|
+
|
|
3100
|
+
function timeoutFunc() {
|
|
3101
|
+
timedout = true;
|
|
3102
|
+
cleanUp();
|
|
3103
|
+
deferred.reject(new Error('timeout'));
|
|
3104
|
+
}
|
|
3105
|
+
timeoutId = setTimeout(timeoutFunc, opts.timeOutMs);
|
|
3106
|
+
|
|
3107
|
+
function doCheck() {
|
|
3108
|
+
check(opts.port, opts.host)
|
|
3109
|
+
.then(function(inUse) {
|
|
3110
|
+
if (timedout) {
|
|
3111
|
+
return;
|
|
3112
|
+
}
|
|
3113
|
+
//debug('doCheck inUse: '+inUse);
|
|
3114
|
+
//debug('doCheck opts.inUse: '+opts.inUse);
|
|
3115
|
+
if (inUse === opts.inUse) {
|
|
3116
|
+
deferred.resolve();
|
|
3117
|
+
cleanUp();
|
|
3118
|
+
return;
|
|
3119
|
+
} else {
|
|
3120
|
+
retryId = setTimeout(function() { doCheck(); }, opts.retryTimeMs);
|
|
3121
|
+
return;
|
|
3122
|
+
}
|
|
3123
|
+
}, function(err) {
|
|
3124
|
+
if (timedout) {
|
|
3125
|
+
return;
|
|
3126
|
+
}
|
|
3127
|
+
deferred.reject(err);
|
|
3128
|
+
cleanUp();
|
|
3129
|
+
});
|
|
3130
|
+
}
|
|
3131
|
+
|
|
3132
|
+
doCheck();
|
|
3133
|
+
return deferred.promise;
|
|
3134
|
+
}
|
|
3135
|
+
|
|
3136
|
+
/**
|
|
3137
|
+
* Creates a deferred promise and fulfills it only when the socket is free.
|
|
3138
|
+
* Will retry on an interval specified in retryTimeMs.
|
|
3139
|
+
* Note: you have to be super user to correctly test system ports (0-1023).
|
|
3140
|
+
* @param {Number} port a valid TCP port number
|
|
3141
|
+
* @param {String} [host] The hostname or IP address of where the socket is.
|
|
3142
|
+
* @param {Number} [retryTimeMs] the retry interval in milliseconds - defaultis is 100ms.
|
|
3143
|
+
* @param {Number} [timeOutMs] the amount of time to wait until port is free. Default 300ms.
|
|
3144
|
+
* @return {Object} A deferred promise from the q library.
|
|
3145
|
+
*
|
|
3146
|
+
* Example usage:
|
|
3147
|
+
*
|
|
3148
|
+
* var tcpPortUsed = require('tcp-port-used');
|
|
3149
|
+
* tcpPortUsed.waitUntilFreeOnHost(44203, 'some.host.com', 500, 4000)
|
|
3150
|
+
* .then(function() {
|
|
3151
|
+
* console.log('Port 44203 is now free.');
|
|
3152
|
+
* }, function(err) {
|
|
3153
|
+
* console.loh('Error: ', error.message);
|
|
3154
|
+
* });
|
|
3155
|
+
*/
|
|
3156
|
+
function waitUntilFreeOnHost(port, host, retryTimeMs, timeOutMs) {
|
|
3157
|
+
|
|
3158
|
+
// the first arument may be an object, if it is not, make an object
|
|
3159
|
+
var opts;
|
|
3160
|
+
if (is.obj(port)) {
|
|
3161
|
+
opts = port;
|
|
3162
|
+
opts.inUse = false;
|
|
3163
|
+
} else {
|
|
3164
|
+
opts = makeOptionsObj(port, host, false, retryTimeMs, timeOutMs);
|
|
3165
|
+
}
|
|
3166
|
+
|
|
3167
|
+
return waitForStatus(opts);
|
|
3168
|
+
}
|
|
107
3169
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
3170
|
+
/**
|
|
3171
|
+
* For compatibility with previous version of the module, that did not provide
|
|
3172
|
+
* arguements for hostnames. The host is set to the localhost '127.0.0.1'.
|
|
3173
|
+
* @param {Number|Object} port a valid TCP port number. If an object, must contain all the parameters as properties.
|
|
3174
|
+
* @param {Number} [retryTimeMs] the retry interval in milliseconds - defaultis is 100ms.
|
|
3175
|
+
* @param {Number} [timeOutMs] the amount of time to wait until port is free. Default 300ms.
|
|
3176
|
+
* @return {Object} A deferred promise from the q library.
|
|
3177
|
+
*
|
|
3178
|
+
* Example usage:
|
|
3179
|
+
*
|
|
3180
|
+
* var tcpPortUsed = require('tcp-port-used');
|
|
3181
|
+
* tcpPortUsed.waitUntilFree(44203, 500, 4000)
|
|
3182
|
+
* .then(function() {
|
|
3183
|
+
* console.log('Port 44203 is now free.');
|
|
3184
|
+
* }, function(err) {
|
|
3185
|
+
* console.loh('Error: ', error.message);
|
|
3186
|
+
* });
|
|
3187
|
+
*/
|
|
3188
|
+
function waitUntilFree(port, retryTimeMs, timeOutMs) {
|
|
3189
|
+
|
|
3190
|
+
// the first arument may be an object, if it is not, make an object
|
|
3191
|
+
var opts;
|
|
3192
|
+
if (is.obj(port)) {
|
|
3193
|
+
opts = port;
|
|
3194
|
+
opts.host = '127.0.0.1';
|
|
3195
|
+
opts.inUse = false;
|
|
3196
|
+
} else {
|
|
3197
|
+
opts = makeOptionsObj(port, '127.0.0.1', false, retryTimeMs, timeOutMs);
|
|
3198
|
+
}
|
|
117
3199
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
bgGreen: f("\x1b[42m", "\x1b[49m"),
|
|
121
|
-
bgYellow: f("\x1b[43m", "\x1b[49m"),
|
|
122
|
-
bgBlue: f("\x1b[44m", "\x1b[49m"),
|
|
123
|
-
bgMagenta: f("\x1b[45m", "\x1b[49m"),
|
|
124
|
-
bgCyan: f("\x1b[46m", "\x1b[49m"),
|
|
125
|
-
bgWhite: f("\x1b[47m", "\x1b[49m"),
|
|
3200
|
+
return waitForStatus(opts);
|
|
3201
|
+
}
|
|
126
3202
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
3203
|
+
/**
|
|
3204
|
+
* Creates a deferred promise and fulfills it only when the socket is used.
|
|
3205
|
+
* Will retry on an interval specified in retryTimeMs.
|
|
3206
|
+
* Note: you have to be super user to correctly test system ports (0-1023).
|
|
3207
|
+
* @param {Number|Object} port a valid TCP port number. If an object, must contain all the parameters as properties.
|
|
3208
|
+
* @param {Number} [retryTimeMs] the retry interval in milliseconds - defaultis is 500ms
|
|
3209
|
+
* @param {Number} [timeOutMs] the amount of time to wait until port is free
|
|
3210
|
+
* @return {Object} A deferred promise from the q library.
|
|
3211
|
+
*
|
|
3212
|
+
* Example usage:
|
|
3213
|
+
*
|
|
3214
|
+
* var tcpPortUsed = require('tcp-port-used');
|
|
3215
|
+
* tcpPortUsed.waitUntilUsedOnHost(44204, 'some.host.com', 500, 4000)
|
|
3216
|
+
* .then(function() {
|
|
3217
|
+
* console.log('Port 44204 is now in use.');
|
|
3218
|
+
* }, function(err) {
|
|
3219
|
+
* console.log('Error: ', error.message);
|
|
3220
|
+
* });
|
|
3221
|
+
*/
|
|
3222
|
+
function waitUntilUsedOnHost(port, host, retryTimeMs, timeOutMs) {
|
|
135
3223
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
};
|
|
3224
|
+
// the first arument may be an object, if it is not, make an object
|
|
3225
|
+
var opts;
|
|
3226
|
+
if (is.obj(port)) {
|
|
3227
|
+
opts = port;
|
|
3228
|
+
opts.inUse = true;
|
|
3229
|
+
} else {
|
|
3230
|
+
opts = makeOptionsObj(port, host, true, retryTimeMs, timeOutMs);
|
|
3231
|
+
}
|
|
146
3232
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return picocolors.exports;
|
|
150
|
-
}
|
|
3233
|
+
return waitForStatus(opts);
|
|
3234
|
+
}
|
|
151
3235
|
|
|
152
|
-
|
|
153
|
-
|
|
3236
|
+
/**
|
|
3237
|
+
* For compatibility to previous version of module which did not have support
|
|
3238
|
+
* for host addresses. This function works only for localhost.
|
|
3239
|
+
* @param {Number} port a valid TCP port number. If an Object, must contain all the parameters as properties.
|
|
3240
|
+
* @param {Number} [retryTimeMs] the retry interval in milliseconds - defaultis is 500ms
|
|
3241
|
+
* @param {Number} [timeOutMs] the amount of time to wait until port is free
|
|
3242
|
+
* @return {Object} A deferred promise from the q library.
|
|
3243
|
+
*
|
|
3244
|
+
* Example usage:
|
|
3245
|
+
*
|
|
3246
|
+
* var tcpPortUsed = require('tcp-port-used');
|
|
3247
|
+
* tcpPortUsed.waitUntilUsed(44204, 500, 4000)
|
|
3248
|
+
* .then(function() {
|
|
3249
|
+
* console.log('Port 44204 is now in use.');
|
|
3250
|
+
* }, function(err) {
|
|
3251
|
+
* console.log('Error: ', error.message);
|
|
3252
|
+
* });
|
|
3253
|
+
*/
|
|
3254
|
+
function waitUntilUsed(port, retryTimeMs, timeOutMs) {
|
|
3255
|
+
|
|
3256
|
+
// the first arument may be an object, if it is not, make an object
|
|
3257
|
+
var opts;
|
|
3258
|
+
if (is.obj(port)) {
|
|
3259
|
+
opts = port;
|
|
3260
|
+
opts.host = '127.0.0.1';
|
|
3261
|
+
opts.inUse = true;
|
|
3262
|
+
} else {
|
|
3263
|
+
opts = makeOptionsObj(port, '127.0.0.1', true, retryTimeMs, timeOutMs);
|
|
3264
|
+
}
|
|
154
3265
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
3266
|
+
return waitUntilUsedOnHost(opts);
|
|
3267
|
+
}
|
|
3268
|
+
return tcpPortUsed$1;
|
|
159
3269
|
}
|
|
160
3270
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
let output = "";
|
|
164
|
-
if (prefix) {
|
|
165
|
-
output += colors.bgMagenta(colors.white("\u2009php\u2009")) + " ";
|
|
166
|
-
}
|
|
167
|
-
output += message;
|
|
168
|
-
shared.viteConfig.logger[type](output, options);
|
|
169
|
-
}
|
|
170
|
-
log.error = function(json, options = {}) {
|
|
171
|
-
let output = json;
|
|
172
|
-
let type = "info";
|
|
173
|
-
try {
|
|
174
|
-
const data = JSON.parse(json);
|
|
175
|
-
output = "";
|
|
176
|
-
switch (data.code) {
|
|
177
|
-
case EPHPError.PARSE:
|
|
178
|
-
case EPHPError.ERROR:
|
|
179
|
-
case EPHPError.CORE_ERROR:
|
|
180
|
-
case EPHPError.COMPILE_ERROR:
|
|
181
|
-
case EPHPError.USER_ERROR:
|
|
182
|
-
type = "error";
|
|
183
|
-
output += colors.bgRedBright(colors.white("Fatal Error"));
|
|
184
|
-
break;
|
|
185
|
-
case EPHPError.WARNING:
|
|
186
|
-
case EPHPError.USER_WARNING:
|
|
187
|
-
case EPHPError.COMPILE_WARNING:
|
|
188
|
-
case EPHPError.RECOVERABLE_ERROR:
|
|
189
|
-
type = "warn";
|
|
190
|
-
output += colors.yellowBright("Warning");
|
|
191
|
-
break;
|
|
192
|
-
case EPHPError.NOTICE:
|
|
193
|
-
case EPHPError.USER_NOTICE:
|
|
194
|
-
type = "info";
|
|
195
|
-
output += colors.bgWhite(colors.black("Notice"));
|
|
196
|
-
break;
|
|
197
|
-
case EPHPError.STRICT:
|
|
198
|
-
type = "info";
|
|
199
|
-
output += colors.yellow("Strict");
|
|
200
|
-
break;
|
|
201
|
-
case EPHPError.DEPRECATED:
|
|
202
|
-
case EPHPError.USER_DEPRECATED:
|
|
203
|
-
type = "info";
|
|
204
|
-
output += colors.cyan("Deprecated");
|
|
205
|
-
break;
|
|
206
|
-
default:
|
|
207
|
-
break;
|
|
208
|
-
}
|
|
209
|
-
output += " " + data.message + "\r\n";
|
|
210
|
-
output += " In: " + data.file.replace(
|
|
211
|
-
node_path.resolve(shared.tempDir),
|
|
212
|
-
shared.viteConfig?.root
|
|
213
|
-
) + "\r\n";
|
|
214
|
-
output += " On line: " + data.line;
|
|
215
|
-
} catch (error) {
|
|
216
|
-
}
|
|
217
|
-
log(output, { ...options, type });
|
|
218
|
-
};
|
|
3271
|
+
var tcpPortUsedExports = requireTcpPortUsed();
|
|
3272
|
+
const tcpPortUsed = /*@__PURE__*/getDefaultExportFromCjs(tcpPortUsedExports);
|
|
219
3273
|
|
|
220
3274
|
const PHP_Server = {
|
|
221
3275
|
binary: "php",
|
|
@@ -225,11 +3279,11 @@ const PHP_Server = {
|
|
|
225
3279
|
start,
|
|
226
3280
|
stop
|
|
227
3281
|
};
|
|
228
|
-
async function start(root) {
|
|
3282
|
+
async function start(root = shared.projectRoot) {
|
|
229
3283
|
if (!PHP_Server.process?.pid) {
|
|
230
3284
|
await new Promise(async (resolve, reject) => {
|
|
231
3285
|
const routerFileUrl = new URL("./router.php", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
|
|
232
|
-
while (await
|
|
3286
|
+
while (await tcpPortUsed.check(PHP_Server.port, PHP_Server.host)) {
|
|
233
3287
|
PHP_Server.port++;
|
|
234
3288
|
}
|
|
235
3289
|
PHP_Server.process = node_child_process.spawn(PHP_Server.binary, [
|
|
@@ -237,7 +3291,7 @@ async function start(root) {
|
|
|
237
3291
|
`${PHP_Server.host}:${PHP_Server.port}`,
|
|
238
3292
|
"-t",
|
|
239
3293
|
root,
|
|
240
|
-
|
|
3294
|
+
node_url.fileURLToPath(routerFileUrl)
|
|
241
3295
|
]).once("spawn", () => {
|
|
242
3296
|
log(`Server started (PID: ${PHP_Server.process?.pid})`);
|
|
243
3297
|
resolve(PHP_Server.process?.pid);
|
|
@@ -373,8 +3427,8 @@ function requirePath () {
|
|
|
373
3427
|
hasRequiredPath = 1;
|
|
374
3428
|
Object.defineProperty(path, "__esModule", { value: true });
|
|
375
3429
|
path.convertPosixPathToPattern = path.convertWindowsPathToPattern = path.convertPathToPattern = path.escapePosixPath = path.escapeWindowsPath = path.escape = path.removeLeadingDotSegment = path.makeAbsolute = path.unixify = void 0;
|
|
376
|
-
const os = require$$0__default;
|
|
377
|
-
const path$1 = require$$0__default$
|
|
3430
|
+
const os = require$$0__default$2;
|
|
3431
|
+
const path$1 = require$$0__default$3;
|
|
378
3432
|
const IS_WINDOWS_PLATFORM = os.platform() === 'win32';
|
|
379
3433
|
const LEADING_DOT_SEGMENT_CHARACTERS_COUNT = 2; // ./ or .\\
|
|
380
3434
|
/**
|
|
@@ -639,8 +3693,8 @@ function requireGlobParent () {
|
|
|
639
3693
|
hasRequiredGlobParent = 1;
|
|
640
3694
|
|
|
641
3695
|
var isGlob = requireIsGlob();
|
|
642
|
-
var pathPosixDirname = require$$0__default$
|
|
643
|
-
var isWin32 = require$$0__default.platform() === 'win32';
|
|
3696
|
+
var pathPosixDirname = require$$0__default$3.posix.dirname;
|
|
3697
|
+
var isWin32 = require$$0__default$2.platform() === 'win32';
|
|
644
3698
|
|
|
645
3699
|
var slash = '/';
|
|
646
3700
|
var backslash = /\\/g;
|
|
@@ -1189,7 +4243,7 @@ function requireFillRange () {
|
|
|
1189
4243
|
if (hasRequiredFillRange) return fillRange;
|
|
1190
4244
|
hasRequiredFillRange = 1;
|
|
1191
4245
|
|
|
1192
|
-
const util = require$$0__default
|
|
4246
|
+
const util = require$$0__default;
|
|
1193
4247
|
const toRegexRange = requireToRegexRange();
|
|
1194
4248
|
|
|
1195
4249
|
const isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
|
|
@@ -2211,7 +5265,7 @@ function requireConstants$1 () {
|
|
|
2211
5265
|
if (hasRequiredConstants$1) return constants$1;
|
|
2212
5266
|
hasRequiredConstants$1 = 1;
|
|
2213
5267
|
|
|
2214
|
-
const path = require$$0__default$
|
|
5268
|
+
const path = require$$0__default$3;
|
|
2215
5269
|
const WIN_SLASH = '\\\\/';
|
|
2216
5270
|
const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
|
2217
5271
|
|
|
@@ -2398,7 +5452,7 @@ function requireUtils$2 () {
|
|
|
2398
5452
|
hasRequiredUtils$2 = 1;
|
|
2399
5453
|
(function (exports) {
|
|
2400
5454
|
|
|
2401
|
-
const path = require$$0__default$
|
|
5455
|
+
const path = require$$0__default$3;
|
|
2402
5456
|
const win32 = process.platform === 'win32';
|
|
2403
5457
|
const {
|
|
2404
5458
|
REGEX_BACKSLASH,
|
|
@@ -3969,7 +7023,7 @@ function requirePicomatch$1 () {
|
|
|
3969
7023
|
if (hasRequiredPicomatch$1) return picomatch_1;
|
|
3970
7024
|
hasRequiredPicomatch$1 = 1;
|
|
3971
7025
|
|
|
3972
|
-
const path = require$$0__default$
|
|
7026
|
+
const path = require$$0__default$3;
|
|
3973
7027
|
const scan = requireScan();
|
|
3974
7028
|
const parse = requireParse();
|
|
3975
7029
|
const utils = requireUtils$2();
|
|
@@ -4330,7 +7384,7 @@ function requireMicromatch () {
|
|
|
4330
7384
|
if (hasRequiredMicromatch) return micromatch_1;
|
|
4331
7385
|
hasRequiredMicromatch = 1;
|
|
4332
7386
|
|
|
4333
|
-
const util = require$$0__default
|
|
7387
|
+
const util = require$$0__default;
|
|
4334
7388
|
const braces = requireBraces();
|
|
4335
7389
|
const picomatch = requirePicomatch();
|
|
4336
7390
|
const utils = requireUtils$2();
|
|
@@ -4812,7 +7866,7 @@ function requirePattern () {
|
|
|
4812
7866
|
hasRequiredPattern = 1;
|
|
4813
7867
|
Object.defineProperty(pattern, "__esModule", { value: true });
|
|
4814
7868
|
pattern.isAbsolute = pattern.partitionAbsoluteAndRelative = pattern.removeDuplicateSlashes = pattern.matchAny = pattern.convertPatternsToRe = pattern.makeRe = pattern.getPatternParts = pattern.expandBraceExpansion = pattern.expandPatternsWithBraceExpansion = pattern.isAffectDepthOfReadingPattern = pattern.endsWithSlashGlobStar = pattern.hasGlobStar = pattern.getBaseDirectory = pattern.isPatternRelatedToParentDirectory = pattern.getPatternsOutsideCurrentDirectory = pattern.getPatternsInsideCurrentDirectory = pattern.getPositivePatterns = pattern.getNegativePatterns = pattern.isPositivePattern = pattern.isNegativePattern = pattern.convertToNegativePattern = pattern.convertToPositivePattern = pattern.isDynamicPattern = pattern.isStaticPattern = void 0;
|
|
4815
|
-
const path = require$$0__default$
|
|
7869
|
+
const path = require$$0__default$3;
|
|
4816
7870
|
const globParent = requireGlobParent();
|
|
4817
7871
|
const micromatch = requireMicromatch();
|
|
4818
7872
|
const GLOBSTAR = '**';
|
|
@@ -5033,7 +8087,7 @@ function requireMerge2 () {
|
|
|
5033
8087
|
* Copyright (c) 2014-2020 Teambition
|
|
5034
8088
|
* Licensed under the MIT license.
|
|
5035
8089
|
*/
|
|
5036
|
-
const Stream = require$$0__default$
|
|
8090
|
+
const Stream = require$$0__default$4;
|
|
5037
8091
|
const PassThrough = Stream.PassThrough;
|
|
5038
8092
|
const slice = Array.prototype.slice;
|
|
5039
8093
|
|
|
@@ -5462,7 +8516,7 @@ function requireFs$2 () {
|
|
|
5462
8516
|
(function (exports) {
|
|
5463
8517
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5464
8518
|
exports.createFileSystemAdapter = exports.FILE_SYSTEM_ADAPTER = void 0;
|
|
5465
|
-
const fs = require$$0__default$
|
|
8519
|
+
const fs = require$$0__default$5;
|
|
5466
8520
|
exports.FILE_SYSTEM_ADAPTER = {
|
|
5467
8521
|
lstat: fs.lstat,
|
|
5468
8522
|
stat: fs.stat,
|
|
@@ -5892,7 +8946,7 @@ function requireFs () {
|
|
|
5892
8946
|
(function (exports) {
|
|
5893
8947
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5894
8948
|
exports.createFileSystemAdapter = exports.FILE_SYSTEM_ADAPTER = void 0;
|
|
5895
|
-
const fs = require$$0__default$
|
|
8949
|
+
const fs = require$$0__default$5;
|
|
5896
8950
|
exports.FILE_SYSTEM_ADAPTER = {
|
|
5897
8951
|
lstat: fs.lstat,
|
|
5898
8952
|
stat: fs.stat,
|
|
@@ -5918,7 +8972,7 @@ function requireSettings$2 () {
|
|
|
5918
8972
|
if (hasRequiredSettings$2) return settings$2;
|
|
5919
8973
|
hasRequiredSettings$2 = 1;
|
|
5920
8974
|
Object.defineProperty(settings$2, "__esModule", { value: true });
|
|
5921
|
-
const path = require$$0__default$
|
|
8975
|
+
const path = require$$0__default$3;
|
|
5922
8976
|
const fsStat = requireOut$3();
|
|
5923
8977
|
const fs = requireFs();
|
|
5924
8978
|
class Settings {
|
|
@@ -6403,7 +9457,7 @@ function requireAsync$3 () {
|
|
|
6403
9457
|
if (hasRequiredAsync$3) return async$2;
|
|
6404
9458
|
hasRequiredAsync$3 = 1;
|
|
6405
9459
|
Object.defineProperty(async$2, "__esModule", { value: true });
|
|
6406
|
-
const events_1 = require$$0__default$
|
|
9460
|
+
const events_1 = require$$0__default$6;
|
|
6407
9461
|
const fsScandir = requireOut$2();
|
|
6408
9462
|
const fastq = requireQueue();
|
|
6409
9463
|
const common = requireCommon();
|
|
@@ -6546,7 +9600,7 @@ function requireStream$2 () {
|
|
|
6546
9600
|
if (hasRequiredStream$2) return stream$2;
|
|
6547
9601
|
hasRequiredStream$2 = 1;
|
|
6548
9602
|
Object.defineProperty(stream$2, "__esModule", { value: true });
|
|
6549
|
-
const stream_1 = require$$0__default$
|
|
9603
|
+
const stream_1 = require$$0__default$4;
|
|
6550
9604
|
const async_1 = requireAsync$3();
|
|
6551
9605
|
class StreamProvider {
|
|
6552
9606
|
constructor(_root, _settings) {
|
|
@@ -6680,7 +9734,7 @@ function requireSettings$1 () {
|
|
|
6680
9734
|
if (hasRequiredSettings$1) return settings$1;
|
|
6681
9735
|
hasRequiredSettings$1 = 1;
|
|
6682
9736
|
Object.defineProperty(settings$1, "__esModule", { value: true });
|
|
6683
|
-
const path = require$$0__default$
|
|
9737
|
+
const path = require$$0__default$3;
|
|
6684
9738
|
const fsScandir = requireOut$2();
|
|
6685
9739
|
class Settings {
|
|
6686
9740
|
constructor(_options = {}) {
|
|
@@ -6756,7 +9810,7 @@ function requireReader () {
|
|
|
6756
9810
|
if (hasRequiredReader) return reader;
|
|
6757
9811
|
hasRequiredReader = 1;
|
|
6758
9812
|
Object.defineProperty(reader, "__esModule", { value: true });
|
|
6759
|
-
const path = require$$0__default$
|
|
9813
|
+
const path = require$$0__default$3;
|
|
6760
9814
|
const fsStat = requireOut$3();
|
|
6761
9815
|
const utils = requireUtils$1();
|
|
6762
9816
|
class Reader {
|
|
@@ -6798,7 +9852,7 @@ function requireStream$1 () {
|
|
|
6798
9852
|
if (hasRequiredStream$1) return stream$1;
|
|
6799
9853
|
hasRequiredStream$1 = 1;
|
|
6800
9854
|
Object.defineProperty(stream$1, "__esModule", { value: true });
|
|
6801
|
-
const stream_1 = require$$0__default$
|
|
9855
|
+
const stream_1 = require$$0__default$4;
|
|
6802
9856
|
const fsStat = requireOut$3();
|
|
6803
9857
|
const fsWalk = requireOut$1();
|
|
6804
9858
|
const reader_1 = requireReader();
|
|
@@ -7229,7 +10283,7 @@ function requireProvider () {
|
|
|
7229
10283
|
if (hasRequiredProvider) return provider;
|
|
7230
10284
|
hasRequiredProvider = 1;
|
|
7231
10285
|
Object.defineProperty(provider, "__esModule", { value: true });
|
|
7232
|
-
const path = require$$0__default$
|
|
10286
|
+
const path = require$$0__default$3;
|
|
7233
10287
|
const deep_1 = requireDeep();
|
|
7234
10288
|
const entry_1 = requireEntry$1();
|
|
7235
10289
|
const error_1 = requireError();
|
|
@@ -7316,7 +10370,7 @@ function requireStream () {
|
|
|
7316
10370
|
if (hasRequiredStream) return stream;
|
|
7317
10371
|
hasRequiredStream = 1;
|
|
7318
10372
|
Object.defineProperty(stream, "__esModule", { value: true });
|
|
7319
|
-
const stream_1 = require$$0__default$
|
|
10373
|
+
const stream_1 = require$$0__default$4;
|
|
7320
10374
|
const stream_2 = requireStream$1();
|
|
7321
10375
|
const provider_1 = requireProvider();
|
|
7322
10376
|
class ProviderStream extends provider_1.default {
|
|
@@ -7442,8 +10496,8 @@ function requireSettings () {
|
|
|
7442
10496
|
(function (exports) {
|
|
7443
10497
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7444
10498
|
exports.DEFAULT_FILE_SYSTEM_ADAPTER = void 0;
|
|
7445
|
-
const fs = require$$0__default$
|
|
7446
|
-
const os = require$$0__default;
|
|
10499
|
+
const fs = require$$0__default$5;
|
|
10500
|
+
const os = require$$0__default$2;
|
|
7447
10501
|
/**
|
|
7448
10502
|
* The `os.cpus` method can return zero. We expect the number of cores to be greater than zero.
|
|
7449
10503
|
* https://github.com/nodejs/node/blob/7faeddf23a98c53896f8b574a6e66589e8fb1eb8/lib/os.js#L106-L107
|
|
@@ -7613,23 +10667,6 @@ function requireOut () {
|
|
|
7613
10667
|
var outExports = requireOut();
|
|
7614
10668
|
const fastGlob = /*@__PURE__*/getDefaultExportFromCjs(outExports);
|
|
7615
10669
|
|
|
7616
|
-
function consoleHijack() {
|
|
7617
|
-
const entries = shared.entries;
|
|
7618
|
-
["log", "info", "warn", "error"].forEach((command) => {
|
|
7619
|
-
const cx = console[command];
|
|
7620
|
-
console[command] = function(...args) {
|
|
7621
|
-
cx.apply(
|
|
7622
|
-
this,
|
|
7623
|
-
args.map(
|
|
7624
|
-
(arg) => typeof arg === "string" ? entries.reduce((acc, entry) => {
|
|
7625
|
-
return acc.replace(entry + ".html", entry);
|
|
7626
|
-
}, arg) : arg
|
|
7627
|
-
)
|
|
7628
|
-
);
|
|
7629
|
-
};
|
|
7630
|
-
});
|
|
7631
|
-
}
|
|
7632
|
-
|
|
7633
10670
|
function readFile(file) {
|
|
7634
10671
|
return node_fs.readFileSync(file, "utf-8").toString();
|
|
7635
10672
|
}
|
|
@@ -7637,6 +10674,9 @@ function writeFile(file, data) {
|
|
|
7637
10674
|
node_fs.mkdirSync(node_path.dirname(file), { recursive: true });
|
|
7638
10675
|
node_fs.writeFileSync(file, data);
|
|
7639
10676
|
}
|
|
10677
|
+
function tempName(entry) {
|
|
10678
|
+
return `${shared.tempDir}/${entry}`;
|
|
10679
|
+
}
|
|
7640
10680
|
|
|
7641
10681
|
function makeID() {
|
|
7642
10682
|
return Date.now().toString(36) + Math.random() * 100;
|
|
@@ -7795,164 +10835,106 @@ const handleExit = {
|
|
|
7795
10835
|
}
|
|
7796
10836
|
};
|
|
7797
10837
|
|
|
7798
|
-
const
|
|
7799
|
-
|
|
7800
|
-
|
|
7801
|
-
|
|
7802
|
-
|
|
7803
|
-
|
|
7804
|
-
|
|
7805
|
-
|
|
7806
|
-
|
|
7807
|
-
|
|
7808
|
-
|
|
7809
|
-
|
|
7810
|
-
|
|
7811
|
-
|
|
7812
|
-
|
|
7813
|
-
|
|
7814
|
-
|
|
7815
|
-
|
|
7816
|
-
|
|
7817
|
-
|
|
7818
|
-
|
|
7819
|
-
|
|
7820
|
-
|
|
7821
|
-
|
|
7822
|
-
return
|
|
7823
|
-
};
|
|
7824
|
-
|
|
7825
|
-
|
|
7826
|
-
|
|
7827
|
-
|
|
7828
|
-
|
|
7829
|
-
|
|
7830
|
-
|
|
7831
|
-
|
|
7832
|
-
|
|
7833
|
-
|
|
7834
|
-
|
|
7835
|
-
|
|
7836
|
-
|
|
7837
|
-
|
|
7838
|
-
|
|
7839
|
-
|
|
7840
|
-
|
|
7841
|
-
|
|
7842
|
-
|
|
7843
|
-
|
|
7844
|
-
|
|
7845
|
-
|
|
7846
|
-
|
|
7847
|
-
|
|
7848
|
-
|
|
7849
|
-
|
|
7850
|
-
|
|
7851
|
-
|
|
7852
|
-
|
|
7853
|
-
|
|
7854
|
-
|
|
7855
|
-
|
|
7856
|
-
|
|
7857
|
-
|
|
7858
|
-
|
|
7859
|
-
|
|
7860
|
-
url.searchParams.set(
|
|
7861
|
-
internalParam,
|
|
7862
|
-
new URLSearchParams({
|
|
7863
|
-
$REQUEST_URI: requestUrl,
|
|
7864
|
-
$PHP_SELF: "/" + entry,
|
|
7865
|
-
temp_dir: shared.tempDir,
|
|
7866
|
-
error_levels: shared.devConfig.errorLevels.toString()
|
|
7867
|
-
}).toString()
|
|
7868
|
-
);
|
|
7869
|
-
const body = await new Promise(
|
|
7870
|
-
(resolve2, reject) => {
|
|
7871
|
-
let data = [];
|
|
7872
|
-
req.on("data", (chunk) => {
|
|
7873
|
-
data.push(chunk);
|
|
7874
|
-
}).on("end", () => {
|
|
7875
|
-
resolve2(Buffer.concat(data));
|
|
7876
|
-
});
|
|
10838
|
+
const phpProxy = async (req, res, next) => {
|
|
10839
|
+
try {
|
|
10840
|
+
if (req.url && !["/@vite", "/@fs", "/@id/__x00__", "/node_modules"].some(
|
|
10841
|
+
(path) => req.url.startsWith(path)
|
|
10842
|
+
)) {
|
|
10843
|
+
req.on("error", (error) => {
|
|
10844
|
+
throw error;
|
|
10845
|
+
});
|
|
10846
|
+
const url = new URL(req.url, "http://localhost");
|
|
10847
|
+
if (shared.viteConfig?.server.port) {
|
|
10848
|
+
url.port = shared.viteConfig.server.port.toString();
|
|
10849
|
+
}
|
|
10850
|
+
const requestUrl = url.pathname;
|
|
10851
|
+
if (url.pathname.endsWith("/")) {
|
|
10852
|
+
url.pathname += "index.php";
|
|
10853
|
+
}
|
|
10854
|
+
const routedUrl = serve.rewriteUrl(url);
|
|
10855
|
+
if (routedUrl) {
|
|
10856
|
+
url.pathname = routedUrl.pathname;
|
|
10857
|
+
url.search = routedUrl.search;
|
|
10858
|
+
url.hash = routedUrl.hash;
|
|
10859
|
+
}
|
|
10860
|
+
const entryPathname = url.pathname.substring(1);
|
|
10861
|
+
const entry = shared.entries.find((file) => {
|
|
10862
|
+
return file === entryPathname || file.substring(0, file.lastIndexOf(".")) === entryPathname;
|
|
10863
|
+
});
|
|
10864
|
+
if (entry) {
|
|
10865
|
+
const tempFile = tempName(entry);
|
|
10866
|
+
if (node_fs.existsSync(node_path.resolve(tempFile))) {
|
|
10867
|
+
url.pathname = tempFile;
|
|
10868
|
+
url.host = PHP_Server.host;
|
|
10869
|
+
url.port = PHP_Server.port.toString();
|
|
10870
|
+
url.searchParams.set(
|
|
10871
|
+
internalParam,
|
|
10872
|
+
new URLSearchParams({
|
|
10873
|
+
$REQUEST_URI: requestUrl,
|
|
10874
|
+
$PHP_SELF: "/" + entry,
|
|
10875
|
+
temp_dir: shared.tempDir,
|
|
10876
|
+
error_levels: shared.devConfig.errorLevels.toString()
|
|
10877
|
+
}).toString()
|
|
10878
|
+
);
|
|
10879
|
+
const body = await new Promise(
|
|
10880
|
+
(resolve2, reject) => {
|
|
10881
|
+
let data = [];
|
|
10882
|
+
req.on("data", (chunk) => {
|
|
10883
|
+
data.push(chunk);
|
|
10884
|
+
}).on("end", () => {
|
|
10885
|
+
resolve2(Buffer.concat(data));
|
|
10886
|
+
});
|
|
10887
|
+
}
|
|
10888
|
+
);
|
|
10889
|
+
const phpResult = await new Promise(async (resolve2, reject) => {
|
|
10890
|
+
const chunks = [];
|
|
10891
|
+
let statusCode;
|
|
10892
|
+
let incomingHeaders = {};
|
|
10893
|
+
const request = http__default.request(
|
|
10894
|
+
url.toString(),
|
|
10895
|
+
{
|
|
10896
|
+
method: req.method,
|
|
10897
|
+
headers: {
|
|
10898
|
+
...req.headers,
|
|
10899
|
+
"content-length": Buffer.byteLength(body)
|
|
7877
10900
|
}
|
|
7878
|
-
|
|
7879
|
-
|
|
7880
|
-
|
|
7881
|
-
|
|
7882
|
-
|
|
7883
|
-
|
|
7884
|
-
url.toString(),
|
|
7885
|
-
{
|
|
7886
|
-
method: req.method,
|
|
7887
|
-
headers: {
|
|
7888
|
-
...req.headers,
|
|
7889
|
-
"content-length": Buffer.byteLength(body)
|
|
7890
|
-
}
|
|
7891
|
-
},
|
|
7892
|
-
(msg) => {
|
|
7893
|
-
statusCode = msg.statusCode;
|
|
7894
|
-
incomingHeaders = msg.headers;
|
|
7895
|
-
msg.on("data", (data) => {
|
|
7896
|
-
chunks.push(data);
|
|
7897
|
-
});
|
|
7898
|
-
}
|
|
7899
|
-
).on("error", (error) => {
|
|
7900
|
-
reject(error);
|
|
7901
|
-
}).on("close", () => {
|
|
7902
|
-
const content = Buffer.concat(chunks).toString(
|
|
7903
|
-
"utf8"
|
|
7904
|
-
);
|
|
7905
|
-
resolve2({
|
|
7906
|
-
statusCode,
|
|
7907
|
-
headers: incomingHeaders,
|
|
7908
|
-
content
|
|
7909
|
-
});
|
|
7910
|
-
});
|
|
7911
|
-
request.write(body, (error) => {
|
|
7912
|
-
if (error) {
|
|
7913
|
-
reject(error);
|
|
7914
|
-
}
|
|
10901
|
+
},
|
|
10902
|
+
(msg) => {
|
|
10903
|
+
statusCode = msg.statusCode;
|
|
10904
|
+
incomingHeaders = msg.headers;
|
|
10905
|
+
msg.on("data", (data) => {
|
|
10906
|
+
chunks.push(data);
|
|
7915
10907
|
});
|
|
7916
|
-
|
|
10908
|
+
}
|
|
10909
|
+
).on("error", (error) => {
|
|
10910
|
+
reject(error);
|
|
10911
|
+
}).on("close", () => {
|
|
10912
|
+
const content = Buffer.concat(chunks).toString("utf8");
|
|
10913
|
+
resolve2({
|
|
10914
|
+
statusCode,
|
|
10915
|
+
headers: incomingHeaders,
|
|
10916
|
+
content
|
|
7917
10917
|
});
|
|
7918
|
-
|
|
7919
|
-
|
|
7920
|
-
|
|
7921
|
-
|
|
7922
|
-
out = await server.transformIndexHtml(
|
|
7923
|
-
`/${entry}.html:${requestUrl}`,
|
|
7924
|
-
out,
|
|
7925
|
-
requestUrl
|
|
7926
|
-
);
|
|
10918
|
+
});
|
|
10919
|
+
request.write(body, (error) => {
|
|
10920
|
+
if (error) {
|
|
10921
|
+
reject(error);
|
|
7927
10922
|
}
|
|
7928
|
-
|
|
7929
|
-
|
|
7930
|
-
|
|
7931
|
-
|
|
7932
|
-
|
|
7933
|
-
|
|
7934
|
-
|
|
10923
|
+
});
|
|
10924
|
+
request.end();
|
|
10925
|
+
});
|
|
10926
|
+
res.writeHead(
|
|
10927
|
+
phpResult.statusCode || 200,
|
|
10928
|
+
phpResult.headers
|
|
10929
|
+
).end(phpResult.content);
|
|
10930
|
+
return;
|
|
7935
10931
|
}
|
|
7936
|
-
} catch (error) {
|
|
7937
|
-
console.error("Vite-PHP Error: " + error);
|
|
7938
10932
|
}
|
|
7939
|
-
next();
|
|
7940
|
-
});
|
|
7941
|
-
},
|
|
7942
|
-
handleHotUpdate({ server, file }) {
|
|
7943
|
-
const entry = shared.entries.find(
|
|
7944
|
-
(entryFile) => node_path.resolve(entryFile) === node_path.resolve(file)
|
|
7945
|
-
);
|
|
7946
|
-
if (entry) {
|
|
7947
|
-
PHP_Code.fromFile(entry).applyEnv().write(tempName(entry));
|
|
7948
|
-
server.moduleGraph.invalidateAll();
|
|
7949
|
-
}
|
|
7950
|
-
if (entry || !file.startsWith(node_path.resolve(shared.tempDir)) && file.includes(".php")) {
|
|
7951
|
-
server.ws.send({
|
|
7952
|
-
type: "full-reload"
|
|
7953
|
-
});
|
|
7954
10933
|
}
|
|
10934
|
+
} catch (error) {
|
|
10935
|
+
console.error("Vite-PHP Error: " + error);
|
|
7955
10936
|
}
|
|
10937
|
+
next();
|
|
7956
10938
|
};
|
|
7957
10939
|
|
|
7958
10940
|
const assetsPattern = new RegExp(
|
|
@@ -7991,69 +10973,295 @@ function fixAssetsInjection(input) {
|
|
|
7991
10973
|
return out;
|
|
7992
10974
|
}
|
|
7993
10975
|
|
|
7994
|
-
const
|
|
7995
|
-
|
|
7996
|
-
|
|
7997
|
-
|
|
7998
|
-
|
|
7999
|
-
|
|
8000
|
-
|
|
8001
|
-
|
|
8002
|
-
|
|
8003
|
-
|
|
8004
|
-
|
|
8005
|
-
|
|
10976
|
+
const serve = {
|
|
10977
|
+
rewriteUrl: (url) => url
|
|
10978
|
+
};
|
|
10979
|
+
let devServer = void 0;
|
|
10980
|
+
let entryMatcher = new RegExp(``, "gs");
|
|
10981
|
+
const codeMap$1 = /* @__PURE__ */ new Map();
|
|
10982
|
+
const servePlugin = [
|
|
10983
|
+
{
|
|
10984
|
+
name: "php:serve-load",
|
|
10985
|
+
apply: "serve",
|
|
10986
|
+
configResolved: {
|
|
10987
|
+
handler(config) {
|
|
10988
|
+
handleExit.register();
|
|
10989
|
+
const gitIgnoreFile = node_path.resolve(`${shared.tempDir}/.gitignore`);
|
|
10990
|
+
if (!node_fs.existsSync(gitIgnoreFile)) {
|
|
10991
|
+
writeFile(gitIgnoreFile, "*\r\n**/*");
|
|
10992
|
+
}
|
|
10993
|
+
entryMatcher = new RegExp(
|
|
10994
|
+
`(${shared.entries.join("|")}).html`,
|
|
10995
|
+
"gs"
|
|
10996
|
+
);
|
|
10997
|
+
}
|
|
10998
|
+
},
|
|
10999
|
+
configureServer: {
|
|
11000
|
+
async handler(server) {
|
|
11001
|
+
devServer = server;
|
|
11002
|
+
server.restart = /* @__PURE__ */ ((originalRestart) => {
|
|
11003
|
+
return async function(...args) {
|
|
11004
|
+
handleExit.unregister();
|
|
11005
|
+
return originalRestart.apply(null, args);
|
|
11006
|
+
};
|
|
11007
|
+
})(server.restart);
|
|
11008
|
+
if (!PHP_Server.process) {
|
|
11009
|
+
await PHP_Server.start(server.config.root);
|
|
11010
|
+
}
|
|
11011
|
+
server.middlewares.use(phpProxy);
|
|
11012
|
+
}
|
|
11013
|
+
},
|
|
11014
|
+
// `rollupOptions.input` entries not arriving in `resolveId(source, importer, options)` -> force file loading with buildStart
|
|
11015
|
+
buildStart: {
|
|
11016
|
+
async handler(options) {
|
|
11017
|
+
await Promise.allSettled(
|
|
11018
|
+
shared.entries.map(async (entry) => {
|
|
11019
|
+
await this.load({
|
|
11020
|
+
id: entry
|
|
11021
|
+
});
|
|
11022
|
+
})
|
|
11023
|
+
);
|
|
11024
|
+
}
|
|
11025
|
+
},
|
|
11026
|
+
load: {
|
|
11027
|
+
handler(id, options) {
|
|
11028
|
+
if (shared.entries.includes(id)) {
|
|
11029
|
+
const php = PHP_Code.fromFile(id);
|
|
11030
|
+
return {
|
|
11031
|
+
code: php.code
|
|
11032
|
+
};
|
|
11033
|
+
}
|
|
11034
|
+
}
|
|
11035
|
+
}
|
|
11036
|
+
},
|
|
11037
|
+
{
|
|
11038
|
+
name: "php:serve-escape",
|
|
11039
|
+
apply: "serve",
|
|
11040
|
+
transform: {
|
|
11041
|
+
async handler(code, id, options) {
|
|
11042
|
+
if (shared.entries.includes(id) && devServer) {
|
|
11043
|
+
let ogWarnLogger = () => {
|
|
11044
|
+
};
|
|
11045
|
+
if (shared.viteConfig) {
|
|
11046
|
+
const warnings = /* @__PURE__ */ new Set();
|
|
11047
|
+
ogWarnLogger = shared.viteConfig.logger.warn;
|
|
11048
|
+
shared.viteConfig.logger.warn = /* @__PURE__ */ ((fn) => function(...args) {
|
|
11049
|
+
const ser = args.toString().replace(entryMatcher, (match, p1) => p1);
|
|
11050
|
+
if (warnings.has(ser)) {
|
|
11051
|
+
return;
|
|
11052
|
+
}
|
|
11053
|
+
warnings.add(ser);
|
|
11054
|
+
return fn.apply(null, args);
|
|
11055
|
+
})(shared.viteConfig.logger.warn);
|
|
11056
|
+
}
|
|
11057
|
+
const res = {
|
|
11058
|
+
code: await devServer.transformIndexHtml(
|
|
11059
|
+
// Rename ids because Vite transforms only .html files: https://github.com/vitejs/vite/blob/0cde495ebeb48bcfb5961784a30bfaed997790a0/packages/vite/src/node/plugins/html.ts#L330
|
|
11060
|
+
`/${id}.html`,
|
|
11061
|
+
code
|
|
11062
|
+
)
|
|
11063
|
+
};
|
|
11064
|
+
if (shared.viteConfig) {
|
|
11065
|
+
shared.viteConfig.logger.warn = ogWarnLogger;
|
|
11066
|
+
}
|
|
11067
|
+
return res;
|
|
11068
|
+
}
|
|
11069
|
+
}
|
|
11070
|
+
},
|
|
11071
|
+
transformIndexHtml: {
|
|
11072
|
+
order: "pre",
|
|
11073
|
+
handler(html, ctx) {
|
|
11074
|
+
const entry = ctx.path.substring(
|
|
11075
|
+
1,
|
|
11076
|
+
ctx.path.length - ".html".length
|
|
11077
|
+
);
|
|
11078
|
+
if (shared.entries.includes(entry)) {
|
|
11079
|
+
const php = new PHP_Code(html);
|
|
11080
|
+
php.file = entry;
|
|
11081
|
+
php.applyEnv();
|
|
11082
|
+
php.escape();
|
|
11083
|
+
codeMap$1.set(entry, php.mapping);
|
|
11084
|
+
return php.code;
|
|
11085
|
+
}
|
|
11086
|
+
}
|
|
11087
|
+
}
|
|
11088
|
+
},
|
|
11089
|
+
{
|
|
11090
|
+
name: "php:serve-unescape",
|
|
11091
|
+
apply: "serve",
|
|
11092
|
+
enforce: "post",
|
|
11093
|
+
transform: {
|
|
11094
|
+
order: "post",
|
|
11095
|
+
handler(code, id, options) {
|
|
11096
|
+
let entry = "";
|
|
11097
|
+
if (id.includes("html-proxy") && shared.entries.some((entryItem) => {
|
|
11098
|
+
const res = id.startsWith(`\0/${entryItem}.html?`);
|
|
11099
|
+
if (res) {
|
|
11100
|
+
entry = entryItem;
|
|
11101
|
+
return true;
|
|
11102
|
+
}
|
|
11103
|
+
})) {
|
|
11104
|
+
const escapes = codeMap$1.get(entry);
|
|
11105
|
+
if (escapes) {
|
|
11106
|
+
return {
|
|
11107
|
+
code: PHP_Code.unescape(code, escapes)
|
|
11108
|
+
};
|
|
11109
|
+
}
|
|
11110
|
+
}
|
|
11111
|
+
}
|
|
11112
|
+
},
|
|
11113
|
+
transformIndexHtml: {
|
|
11114
|
+
order: "post",
|
|
11115
|
+
handler(html, ctx) {
|
|
11116
|
+
const entry = ctx.path.substring(
|
|
11117
|
+
1,
|
|
11118
|
+
ctx.path.length - ".html".length
|
|
11119
|
+
);
|
|
11120
|
+
if (shared.entries.includes(entry)) {
|
|
11121
|
+
const escapes = codeMap$1.get(entry);
|
|
11122
|
+
let php = new PHP_Code(html);
|
|
11123
|
+
php.file = entry;
|
|
11124
|
+
if (escapes) {
|
|
11125
|
+
php.code = PHP_Code.unescape(php.code, escapes);
|
|
11126
|
+
}
|
|
11127
|
+
php.code = fixAssetsInjection(php.code);
|
|
11128
|
+
php.write(tempName(entry));
|
|
11129
|
+
return php.code;
|
|
11130
|
+
}
|
|
11131
|
+
}
|
|
11132
|
+
}
|
|
11133
|
+
},
|
|
11134
|
+
{
|
|
11135
|
+
name: "php:serve-watch",
|
|
11136
|
+
apply: "serve",
|
|
11137
|
+
async watchChange(id, change) {
|
|
11138
|
+
const entry = shared.entries.find(
|
|
11139
|
+
(entryFile) => node_path.resolve(entryFile) === node_path.resolve(id)
|
|
11140
|
+
);
|
|
11141
|
+
if (entry) {
|
|
11142
|
+
try {
|
|
11143
|
+
await this.load({
|
|
11144
|
+
id: entry
|
|
11145
|
+
});
|
|
11146
|
+
} catch (error) {
|
|
11147
|
+
}
|
|
11148
|
+
}
|
|
11149
|
+
},
|
|
11150
|
+
handleHotUpdate({ server, file }) {
|
|
11151
|
+
const entry = shared.entries.find(
|
|
11152
|
+
(entryFile) => node_path.resolve(entryFile) === node_path.resolve(file)
|
|
11153
|
+
);
|
|
11154
|
+
if (entry || !file.startsWith(node_path.resolve(shared.tempDir)) && file.includes(".php")) {
|
|
11155
|
+
server.ws.send({
|
|
11156
|
+
type: "full-reload"
|
|
11157
|
+
});
|
|
11158
|
+
}
|
|
11159
|
+
if (entry) {
|
|
11160
|
+
server.moduleGraph.invalidateAll();
|
|
11161
|
+
}
|
|
11162
|
+
}
|
|
11163
|
+
}
|
|
11164
|
+
];
|
|
11165
|
+
|
|
11166
|
+
const entryMap = /* @__PURE__ */ new Map();
|
|
11167
|
+
const codeMap = /* @__PURE__ */ new Map();
|
|
11168
|
+
const buildPlugin = [
|
|
11169
|
+
{
|
|
11170
|
+
name: "php:build-load",
|
|
11171
|
+
apply: "build",
|
|
11172
|
+
enforce: "pre",
|
|
11173
|
+
resolveId: {
|
|
11174
|
+
handler(source, importer, options) {
|
|
11175
|
+
if (shared.entries.includes(source)) {
|
|
11176
|
+
const id = `${source}.html`;
|
|
11177
|
+
entryMap.set(id, source);
|
|
11178
|
+
return {
|
|
11179
|
+
id,
|
|
11180
|
+
resolvedBy: "vite-plugin-php"
|
|
11181
|
+
};
|
|
11182
|
+
}
|
|
11183
|
+
}
|
|
11184
|
+
},
|
|
11185
|
+
load: {
|
|
11186
|
+
handler(id, options) {
|
|
11187
|
+
const entry = entryMap.get(id);
|
|
11188
|
+
if (entry) {
|
|
11189
|
+
const php = PHP_Code.fromFile(entry);
|
|
11190
|
+
return {
|
|
11191
|
+
code: php.code
|
|
11192
|
+
};
|
|
8006
11193
|
}
|
|
8007
|
-
}
|
|
11194
|
+
}
|
|
8008
11195
|
}
|
|
8009
11196
|
},
|
|
8010
|
-
|
|
8011
|
-
|
|
8012
|
-
|
|
8013
|
-
|
|
8014
|
-
|
|
8015
|
-
|
|
8016
|
-
|
|
8017
|
-
|
|
8018
|
-
|
|
11197
|
+
{
|
|
11198
|
+
name: "php:build-escape",
|
|
11199
|
+
apply: "build",
|
|
11200
|
+
transformIndexHtml: {
|
|
11201
|
+
order: "pre",
|
|
11202
|
+
handler(html, ctx) {
|
|
11203
|
+
const entry = entryMap.get(ctx.filename);
|
|
11204
|
+
if (entry) {
|
|
11205
|
+
ctx.filename = entry;
|
|
11206
|
+
const php = new PHP_Code(html);
|
|
11207
|
+
php.file = entry;
|
|
11208
|
+
php.applyEnv();
|
|
11209
|
+
php.escape();
|
|
11210
|
+
codeMap.set(entry, php.mapping);
|
|
11211
|
+
return php.code;
|
|
11212
|
+
}
|
|
11213
|
+
}
|
|
8019
11214
|
}
|
|
8020
11215
|
},
|
|
8021
|
-
|
|
8022
|
-
|
|
8023
|
-
|
|
8024
|
-
|
|
8025
|
-
|
|
8026
|
-
|
|
8027
|
-
|
|
8028
|
-
|
|
8029
|
-
|
|
8030
|
-
|
|
8031
|
-
|
|
8032
|
-
|
|
8033
|
-
|
|
8034
|
-
|
|
8035
|
-
}
|
|
8036
|
-
item.source = fixAssetsInjection(
|
|
8037
|
-
item.source.toString()
|
|
8038
|
-
);
|
|
11216
|
+
{
|
|
11217
|
+
name: "php:build-unescape",
|
|
11218
|
+
apply: "build",
|
|
11219
|
+
enforce: "post",
|
|
11220
|
+
transformIndexHtml: {
|
|
11221
|
+
order: "post",
|
|
11222
|
+
handler(html, ctx) {
|
|
11223
|
+
const entry = entryMap.get(ctx.filename);
|
|
11224
|
+
if (entry) {
|
|
11225
|
+
const escapes = codeMap.get(entry);
|
|
11226
|
+
if (escapes) {
|
|
11227
|
+
let php = PHP_Code.unescape(html, escapes);
|
|
11228
|
+
php = fixAssetsInjection(php);
|
|
11229
|
+
return php;
|
|
8039
11230
|
}
|
|
8040
|
-
}
|
|
8041
|
-
|
|
8042
|
-
|
|
8043
|
-
|
|
8044
|
-
|
|
8045
|
-
|
|
8046
|
-
|
|
8047
|
-
|
|
8048
|
-
|
|
11231
|
+
}
|
|
11232
|
+
}
|
|
11233
|
+
}
|
|
11234
|
+
},
|
|
11235
|
+
{
|
|
11236
|
+
name: "php:build-bundle",
|
|
11237
|
+
apply: "build",
|
|
11238
|
+
enforce: "post",
|
|
11239
|
+
generateBundle: {
|
|
11240
|
+
order: "post",
|
|
11241
|
+
handler(options, bundle, isWrite) {
|
|
11242
|
+
Object.entries(bundle).forEach(([key, item]) => {
|
|
11243
|
+
if (item.type === "asset") {
|
|
11244
|
+
const entry = entryMap.get(item.fileName);
|
|
11245
|
+
if (entry) {
|
|
11246
|
+
item.fileName = entry;
|
|
11247
|
+
}
|
|
11248
|
+
} else if (item.type === "chunk" && item.facadeModuleId) {
|
|
11249
|
+
const entry = entryMap.get(item.facadeModuleId);
|
|
11250
|
+
if (entry) {
|
|
11251
|
+
const escapes = codeMap.get(entry);
|
|
11252
|
+
if (escapes) {
|
|
11253
|
+
item.code = PHP_Code.unescape(
|
|
11254
|
+
item.code,
|
|
11255
|
+
escapes
|
|
11256
|
+
);
|
|
11257
|
+
}
|
|
8049
11258
|
}
|
|
8050
|
-
item.code = fixAssetsInjection(item.code);
|
|
8051
11259
|
}
|
|
8052
|
-
}
|
|
8053
|
-
}
|
|
11260
|
+
});
|
|
11261
|
+
}
|
|
8054
11262
|
}
|
|
8055
11263
|
}
|
|
8056
|
-
|
|
11264
|
+
];
|
|
8057
11265
|
|
|
8058
11266
|
function usePHP(cfg = {}) {
|
|
8059
11267
|
const { entry = "index.php" } = cfg;
|
|
@@ -8068,7 +11276,7 @@ function usePHP(cfg = {}) {
|
|
|
8068
11276
|
};
|
|
8069
11277
|
return [
|
|
8070
11278
|
{
|
|
8071
|
-
name: "init
|
|
11279
|
+
name: "php:init",
|
|
8072
11280
|
enforce: "post",
|
|
8073
11281
|
config(config, env) {
|
|
8074
11282
|
shared.entries = [
|
|
@@ -8086,7 +11294,6 @@ function usePHP(cfg = {}) {
|
|
|
8086
11294
|
)
|
|
8087
11295
|
)
|
|
8088
11296
|
];
|
|
8089
|
-
consoleHijack();
|
|
8090
11297
|
return {
|
|
8091
11298
|
server: {
|
|
8092
11299
|
watch: {
|
|
@@ -8094,17 +11301,21 @@ function usePHP(cfg = {}) {
|
|
|
8094
11301
|
}
|
|
8095
11302
|
},
|
|
8096
11303
|
build: {
|
|
8097
|
-
rollupOptions: {
|
|
11304
|
+
rollupOptions: {
|
|
11305
|
+
input: shared.entries
|
|
11306
|
+
}
|
|
8098
11307
|
},
|
|
8099
|
-
optimizeDeps: {
|
|
11308
|
+
optimizeDeps: {
|
|
11309
|
+
entries: shared.entries
|
|
11310
|
+
}
|
|
8100
11311
|
};
|
|
8101
11312
|
},
|
|
8102
11313
|
configResolved(_config) {
|
|
8103
11314
|
shared.viteConfig = _config;
|
|
8104
11315
|
}
|
|
8105
11316
|
},
|
|
8106
|
-
servePlugin,
|
|
8107
|
-
buildPlugin
|
|
11317
|
+
...servePlugin,
|
|
11318
|
+
...buildPlugin
|
|
8108
11319
|
];
|
|
8109
11320
|
}
|
|
8110
11321
|
|