json-variables 10.1.0 → 11.0.3
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/CHANGELOG.md +30 -0
- package/README.md +4 -0
- package/dist/json-variables.esm.js +4 -4
- package/dist/json-variables.umd.js +34 -34
- package/package.json +60 -52
- package/dist/json-variables.cjs.js +0 -463
- package/dist/json-variables.dev.umd.js +0 -4376
|
@@ -1,4376 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @name json-variables
|
|
3
|
-
* @fileoverview Resolves custom-marked, cross-referenced paths in parsed JSON
|
|
4
|
-
* @version 10.1.0
|
|
5
|
-
* @author Roy Revelt, Codsen Ltd
|
|
6
|
-
* @license MIT
|
|
7
|
-
* {@link https://codsen.com/os/json-variables/}
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
(function (global, factory) {
|
|
11
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
12
|
-
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
13
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.jsonVariables = {}));
|
|
14
|
-
}(this, (function (exports) { 'use strict';
|
|
15
|
-
|
|
16
|
-
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
17
|
-
|
|
18
|
-
var lodash_clonedeep = {exports: {}};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* lodash (Custom Build) <https://lodash.com/>
|
|
22
|
-
* Build: `lodash modularize exports="npm" -o ./`
|
|
23
|
-
* Copyright jQuery Foundation and other contributors <https://jquery.org/>
|
|
24
|
-
* Released under MIT license <https://lodash.com/license>
|
|
25
|
-
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
26
|
-
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
(function (module, exports) {
|
|
30
|
-
/** Used as the size to enable large array optimizations. */
|
|
31
|
-
var LARGE_ARRAY_SIZE = 200;
|
|
32
|
-
|
|
33
|
-
/** Used to stand-in for `undefined` hash values. */
|
|
34
|
-
var HASH_UNDEFINED = '__lodash_hash_undefined__';
|
|
35
|
-
|
|
36
|
-
/** Used as references for various `Number` constants. */
|
|
37
|
-
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
38
|
-
|
|
39
|
-
/** `Object#toString` result references. */
|
|
40
|
-
var argsTag = '[object Arguments]',
|
|
41
|
-
arrayTag = '[object Array]',
|
|
42
|
-
boolTag = '[object Boolean]',
|
|
43
|
-
dateTag = '[object Date]',
|
|
44
|
-
errorTag = '[object Error]',
|
|
45
|
-
funcTag = '[object Function]',
|
|
46
|
-
genTag = '[object GeneratorFunction]',
|
|
47
|
-
mapTag = '[object Map]',
|
|
48
|
-
numberTag = '[object Number]',
|
|
49
|
-
objectTag = '[object Object]',
|
|
50
|
-
promiseTag = '[object Promise]',
|
|
51
|
-
regexpTag = '[object RegExp]',
|
|
52
|
-
setTag = '[object Set]',
|
|
53
|
-
stringTag = '[object String]',
|
|
54
|
-
symbolTag = '[object Symbol]',
|
|
55
|
-
weakMapTag = '[object WeakMap]';
|
|
56
|
-
|
|
57
|
-
var arrayBufferTag = '[object ArrayBuffer]',
|
|
58
|
-
dataViewTag = '[object DataView]',
|
|
59
|
-
float32Tag = '[object Float32Array]',
|
|
60
|
-
float64Tag = '[object Float64Array]',
|
|
61
|
-
int8Tag = '[object Int8Array]',
|
|
62
|
-
int16Tag = '[object Int16Array]',
|
|
63
|
-
int32Tag = '[object Int32Array]',
|
|
64
|
-
uint8Tag = '[object Uint8Array]',
|
|
65
|
-
uint8ClampedTag = '[object Uint8ClampedArray]',
|
|
66
|
-
uint16Tag = '[object Uint16Array]',
|
|
67
|
-
uint32Tag = '[object Uint32Array]';
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Used to match `RegExp`
|
|
71
|
-
* [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
|
|
72
|
-
*/
|
|
73
|
-
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
|
|
74
|
-
|
|
75
|
-
/** Used to match `RegExp` flags from their coerced string values. */
|
|
76
|
-
var reFlags = /\w*$/;
|
|
77
|
-
|
|
78
|
-
/** Used to detect host constructors (Safari). */
|
|
79
|
-
var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
|
80
|
-
|
|
81
|
-
/** Used to detect unsigned integer values. */
|
|
82
|
-
var reIsUint = /^(?:0|[1-9]\d*)$/;
|
|
83
|
-
|
|
84
|
-
/** Used to identify `toStringTag` values supported by `_.clone`. */
|
|
85
|
-
var cloneableTags = {};
|
|
86
|
-
cloneableTags[argsTag] = cloneableTags[arrayTag] =
|
|
87
|
-
cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
|
|
88
|
-
cloneableTags[boolTag] = cloneableTags[dateTag] =
|
|
89
|
-
cloneableTags[float32Tag] = cloneableTags[float64Tag] =
|
|
90
|
-
cloneableTags[int8Tag] = cloneableTags[int16Tag] =
|
|
91
|
-
cloneableTags[int32Tag] = cloneableTags[mapTag] =
|
|
92
|
-
cloneableTags[numberTag] = cloneableTags[objectTag] =
|
|
93
|
-
cloneableTags[regexpTag] = cloneableTags[setTag] =
|
|
94
|
-
cloneableTags[stringTag] = cloneableTags[symbolTag] =
|
|
95
|
-
cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
|
|
96
|
-
cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
|
|
97
|
-
cloneableTags[errorTag] = cloneableTags[funcTag] =
|
|
98
|
-
cloneableTags[weakMapTag] = false;
|
|
99
|
-
|
|
100
|
-
/** Detect free variable `global` from Node.js. */
|
|
101
|
-
var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
|
|
102
|
-
|
|
103
|
-
/** Detect free variable `self`. */
|
|
104
|
-
var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
|
|
105
|
-
|
|
106
|
-
/** Used as a reference to the global object. */
|
|
107
|
-
var root = freeGlobal || freeSelf || Function('return this')();
|
|
108
|
-
|
|
109
|
-
/** Detect free variable `exports`. */
|
|
110
|
-
var freeExports = exports && !exports.nodeType && exports;
|
|
111
|
-
|
|
112
|
-
/** Detect free variable `module`. */
|
|
113
|
-
var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
|
|
114
|
-
|
|
115
|
-
/** Detect the popular CommonJS extension `module.exports`. */
|
|
116
|
-
var moduleExports = freeModule && freeModule.exports === freeExports;
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Adds the key-value `pair` to `map`.
|
|
120
|
-
*
|
|
121
|
-
* @private
|
|
122
|
-
* @param {Object} map The map to modify.
|
|
123
|
-
* @param {Array} pair The key-value pair to add.
|
|
124
|
-
* @returns {Object} Returns `map`.
|
|
125
|
-
*/
|
|
126
|
-
function addMapEntry(map, pair) {
|
|
127
|
-
// Don't return `map.set` because it's not chainable in IE 11.
|
|
128
|
-
map.set(pair[0], pair[1]);
|
|
129
|
-
return map;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Adds `value` to `set`.
|
|
134
|
-
*
|
|
135
|
-
* @private
|
|
136
|
-
* @param {Object} set The set to modify.
|
|
137
|
-
* @param {*} value The value to add.
|
|
138
|
-
* @returns {Object} Returns `set`.
|
|
139
|
-
*/
|
|
140
|
-
function addSetEntry(set, value) {
|
|
141
|
-
// Don't return `set.add` because it's not chainable in IE 11.
|
|
142
|
-
set.add(value);
|
|
143
|
-
return set;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* A specialized version of `_.forEach` for arrays without support for
|
|
148
|
-
* iteratee shorthands.
|
|
149
|
-
*
|
|
150
|
-
* @private
|
|
151
|
-
* @param {Array} [array] The array to iterate over.
|
|
152
|
-
* @param {Function} iteratee The function invoked per iteration.
|
|
153
|
-
* @returns {Array} Returns `array`.
|
|
154
|
-
*/
|
|
155
|
-
function arrayEach(array, iteratee) {
|
|
156
|
-
var index = -1,
|
|
157
|
-
length = array ? array.length : 0;
|
|
158
|
-
|
|
159
|
-
while (++index < length) {
|
|
160
|
-
if (iteratee(array[index], index, array) === false) {
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return array;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Appends the elements of `values` to `array`.
|
|
169
|
-
*
|
|
170
|
-
* @private
|
|
171
|
-
* @param {Array} array The array to modify.
|
|
172
|
-
* @param {Array} values The values to append.
|
|
173
|
-
* @returns {Array} Returns `array`.
|
|
174
|
-
*/
|
|
175
|
-
function arrayPush(array, values) {
|
|
176
|
-
var index = -1,
|
|
177
|
-
length = values.length,
|
|
178
|
-
offset = array.length;
|
|
179
|
-
|
|
180
|
-
while (++index < length) {
|
|
181
|
-
array[offset + index] = values[index];
|
|
182
|
-
}
|
|
183
|
-
return array;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* A specialized version of `_.reduce` for arrays without support for
|
|
188
|
-
* iteratee shorthands.
|
|
189
|
-
*
|
|
190
|
-
* @private
|
|
191
|
-
* @param {Array} [array] The array to iterate over.
|
|
192
|
-
* @param {Function} iteratee The function invoked per iteration.
|
|
193
|
-
* @param {*} [accumulator] The initial value.
|
|
194
|
-
* @param {boolean} [initAccum] Specify using the first element of `array` as
|
|
195
|
-
* the initial value.
|
|
196
|
-
* @returns {*} Returns the accumulated value.
|
|
197
|
-
*/
|
|
198
|
-
function arrayReduce(array, iteratee, accumulator, initAccum) {
|
|
199
|
-
var index = -1,
|
|
200
|
-
length = array ? array.length : 0;
|
|
201
|
-
|
|
202
|
-
if (initAccum && length) {
|
|
203
|
-
accumulator = array[++index];
|
|
204
|
-
}
|
|
205
|
-
while (++index < length) {
|
|
206
|
-
accumulator = iteratee(accumulator, array[index], index, array);
|
|
207
|
-
}
|
|
208
|
-
return accumulator;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* The base implementation of `_.times` without support for iteratee shorthands
|
|
213
|
-
* or max array length checks.
|
|
214
|
-
*
|
|
215
|
-
* @private
|
|
216
|
-
* @param {number} n The number of times to invoke `iteratee`.
|
|
217
|
-
* @param {Function} iteratee The function invoked per iteration.
|
|
218
|
-
* @returns {Array} Returns the array of results.
|
|
219
|
-
*/
|
|
220
|
-
function baseTimes(n, iteratee) {
|
|
221
|
-
var index = -1,
|
|
222
|
-
result = Array(n);
|
|
223
|
-
|
|
224
|
-
while (++index < n) {
|
|
225
|
-
result[index] = iteratee(index);
|
|
226
|
-
}
|
|
227
|
-
return result;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Gets the value at `key` of `object`.
|
|
232
|
-
*
|
|
233
|
-
* @private
|
|
234
|
-
* @param {Object} [object] The object to query.
|
|
235
|
-
* @param {string} key The key of the property to get.
|
|
236
|
-
* @returns {*} Returns the property value.
|
|
237
|
-
*/
|
|
238
|
-
function getValue(object, key) {
|
|
239
|
-
return object == null ? undefined : object[key];
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Checks if `value` is a host object in IE < 9.
|
|
244
|
-
*
|
|
245
|
-
* @private
|
|
246
|
-
* @param {*} value The value to check.
|
|
247
|
-
* @returns {boolean} Returns `true` if `value` is a host object, else `false`.
|
|
248
|
-
*/
|
|
249
|
-
function isHostObject(value) {
|
|
250
|
-
// Many host objects are `Object` objects that can coerce to strings
|
|
251
|
-
// despite having improperly defined `toString` methods.
|
|
252
|
-
var result = false;
|
|
253
|
-
if (value != null && typeof value.toString != 'function') {
|
|
254
|
-
try {
|
|
255
|
-
result = !!(value + '');
|
|
256
|
-
} catch (e) {}
|
|
257
|
-
}
|
|
258
|
-
return result;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Converts `map` to its key-value pairs.
|
|
263
|
-
*
|
|
264
|
-
* @private
|
|
265
|
-
* @param {Object} map The map to convert.
|
|
266
|
-
* @returns {Array} Returns the key-value pairs.
|
|
267
|
-
*/
|
|
268
|
-
function mapToArray(map) {
|
|
269
|
-
var index = -1,
|
|
270
|
-
result = Array(map.size);
|
|
271
|
-
|
|
272
|
-
map.forEach(function(value, key) {
|
|
273
|
-
result[++index] = [key, value];
|
|
274
|
-
});
|
|
275
|
-
return result;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Creates a unary function that invokes `func` with its argument transformed.
|
|
280
|
-
*
|
|
281
|
-
* @private
|
|
282
|
-
* @param {Function} func The function to wrap.
|
|
283
|
-
* @param {Function} transform The argument transform.
|
|
284
|
-
* @returns {Function} Returns the new function.
|
|
285
|
-
*/
|
|
286
|
-
function overArg(func, transform) {
|
|
287
|
-
return function(arg) {
|
|
288
|
-
return func(transform(arg));
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Converts `set` to an array of its values.
|
|
294
|
-
*
|
|
295
|
-
* @private
|
|
296
|
-
* @param {Object} set The set to convert.
|
|
297
|
-
* @returns {Array} Returns the values.
|
|
298
|
-
*/
|
|
299
|
-
function setToArray(set) {
|
|
300
|
-
var index = -1,
|
|
301
|
-
result = Array(set.size);
|
|
302
|
-
|
|
303
|
-
set.forEach(function(value) {
|
|
304
|
-
result[++index] = value;
|
|
305
|
-
});
|
|
306
|
-
return result;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/** Used for built-in method references. */
|
|
310
|
-
var arrayProto = Array.prototype,
|
|
311
|
-
funcProto = Function.prototype,
|
|
312
|
-
objectProto = Object.prototype;
|
|
313
|
-
|
|
314
|
-
/** Used to detect overreaching core-js shims. */
|
|
315
|
-
var coreJsData = root['__core-js_shared__'];
|
|
316
|
-
|
|
317
|
-
/** Used to detect methods masquerading as native. */
|
|
318
|
-
var maskSrcKey = (function() {
|
|
319
|
-
var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
|
|
320
|
-
return uid ? ('Symbol(src)_1.' + uid) : '';
|
|
321
|
-
}());
|
|
322
|
-
|
|
323
|
-
/** Used to resolve the decompiled source of functions. */
|
|
324
|
-
var funcToString = funcProto.toString;
|
|
325
|
-
|
|
326
|
-
/** Used to check objects for own properties. */
|
|
327
|
-
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* Used to resolve the
|
|
331
|
-
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
|
|
332
|
-
* of values.
|
|
333
|
-
*/
|
|
334
|
-
var objectToString = objectProto.toString;
|
|
335
|
-
|
|
336
|
-
/** Used to detect if a method is native. */
|
|
337
|
-
var reIsNative = RegExp('^' +
|
|
338
|
-
funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
|
|
339
|
-
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
|
340
|
-
);
|
|
341
|
-
|
|
342
|
-
/** Built-in value references. */
|
|
343
|
-
var Buffer = moduleExports ? root.Buffer : undefined,
|
|
344
|
-
Symbol = root.Symbol,
|
|
345
|
-
Uint8Array = root.Uint8Array,
|
|
346
|
-
getPrototype = overArg(Object.getPrototypeOf, Object),
|
|
347
|
-
objectCreate = Object.create,
|
|
348
|
-
propertyIsEnumerable = objectProto.propertyIsEnumerable,
|
|
349
|
-
splice = arrayProto.splice;
|
|
350
|
-
|
|
351
|
-
/* Built-in method references for those with the same name as other `lodash` methods. */
|
|
352
|
-
var nativeGetSymbols = Object.getOwnPropertySymbols,
|
|
353
|
-
nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
|
|
354
|
-
nativeKeys = overArg(Object.keys, Object);
|
|
355
|
-
|
|
356
|
-
/* Built-in method references that are verified to be native. */
|
|
357
|
-
var DataView = getNative(root, 'DataView'),
|
|
358
|
-
Map = getNative(root, 'Map'),
|
|
359
|
-
Promise = getNative(root, 'Promise'),
|
|
360
|
-
Set = getNative(root, 'Set'),
|
|
361
|
-
WeakMap = getNative(root, 'WeakMap'),
|
|
362
|
-
nativeCreate = getNative(Object, 'create');
|
|
363
|
-
|
|
364
|
-
/** Used to detect maps, sets, and weakmaps. */
|
|
365
|
-
var dataViewCtorString = toSource(DataView),
|
|
366
|
-
mapCtorString = toSource(Map),
|
|
367
|
-
promiseCtorString = toSource(Promise),
|
|
368
|
-
setCtorString = toSource(Set),
|
|
369
|
-
weakMapCtorString = toSource(WeakMap);
|
|
370
|
-
|
|
371
|
-
/** Used to convert symbols to primitives and strings. */
|
|
372
|
-
var symbolProto = Symbol ? Symbol.prototype : undefined,
|
|
373
|
-
symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* Creates a hash object.
|
|
377
|
-
*
|
|
378
|
-
* @private
|
|
379
|
-
* @constructor
|
|
380
|
-
* @param {Array} [entries] The key-value pairs to cache.
|
|
381
|
-
*/
|
|
382
|
-
function Hash(entries) {
|
|
383
|
-
var index = -1,
|
|
384
|
-
length = entries ? entries.length : 0;
|
|
385
|
-
|
|
386
|
-
this.clear();
|
|
387
|
-
while (++index < length) {
|
|
388
|
-
var entry = entries[index];
|
|
389
|
-
this.set(entry[0], entry[1]);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
/**
|
|
394
|
-
* Removes all key-value entries from the hash.
|
|
395
|
-
*
|
|
396
|
-
* @private
|
|
397
|
-
* @name clear
|
|
398
|
-
* @memberOf Hash
|
|
399
|
-
*/
|
|
400
|
-
function hashClear() {
|
|
401
|
-
this.__data__ = nativeCreate ? nativeCreate(null) : {};
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* Removes `key` and its value from the hash.
|
|
406
|
-
*
|
|
407
|
-
* @private
|
|
408
|
-
* @name delete
|
|
409
|
-
* @memberOf Hash
|
|
410
|
-
* @param {Object} hash The hash to modify.
|
|
411
|
-
* @param {string} key The key of the value to remove.
|
|
412
|
-
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
|
413
|
-
*/
|
|
414
|
-
function hashDelete(key) {
|
|
415
|
-
return this.has(key) && delete this.__data__[key];
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
/**
|
|
419
|
-
* Gets the hash value for `key`.
|
|
420
|
-
*
|
|
421
|
-
* @private
|
|
422
|
-
* @name get
|
|
423
|
-
* @memberOf Hash
|
|
424
|
-
* @param {string} key The key of the value to get.
|
|
425
|
-
* @returns {*} Returns the entry value.
|
|
426
|
-
*/
|
|
427
|
-
function hashGet(key) {
|
|
428
|
-
var data = this.__data__;
|
|
429
|
-
if (nativeCreate) {
|
|
430
|
-
var result = data[key];
|
|
431
|
-
return result === HASH_UNDEFINED ? undefined : result;
|
|
432
|
-
}
|
|
433
|
-
return hasOwnProperty.call(data, key) ? data[key] : undefined;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
/**
|
|
437
|
-
* Checks if a hash value for `key` exists.
|
|
438
|
-
*
|
|
439
|
-
* @private
|
|
440
|
-
* @name has
|
|
441
|
-
* @memberOf Hash
|
|
442
|
-
* @param {string} key The key of the entry to check.
|
|
443
|
-
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
|
444
|
-
*/
|
|
445
|
-
function hashHas(key) {
|
|
446
|
-
var data = this.__data__;
|
|
447
|
-
return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
/**
|
|
451
|
-
* Sets the hash `key` to `value`.
|
|
452
|
-
*
|
|
453
|
-
* @private
|
|
454
|
-
* @name set
|
|
455
|
-
* @memberOf Hash
|
|
456
|
-
* @param {string} key The key of the value to set.
|
|
457
|
-
* @param {*} value The value to set.
|
|
458
|
-
* @returns {Object} Returns the hash instance.
|
|
459
|
-
*/
|
|
460
|
-
function hashSet(key, value) {
|
|
461
|
-
var data = this.__data__;
|
|
462
|
-
data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
|
|
463
|
-
return this;
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
// Add methods to `Hash`.
|
|
467
|
-
Hash.prototype.clear = hashClear;
|
|
468
|
-
Hash.prototype['delete'] = hashDelete;
|
|
469
|
-
Hash.prototype.get = hashGet;
|
|
470
|
-
Hash.prototype.has = hashHas;
|
|
471
|
-
Hash.prototype.set = hashSet;
|
|
472
|
-
|
|
473
|
-
/**
|
|
474
|
-
* Creates an list cache object.
|
|
475
|
-
*
|
|
476
|
-
* @private
|
|
477
|
-
* @constructor
|
|
478
|
-
* @param {Array} [entries] The key-value pairs to cache.
|
|
479
|
-
*/
|
|
480
|
-
function ListCache(entries) {
|
|
481
|
-
var index = -1,
|
|
482
|
-
length = entries ? entries.length : 0;
|
|
483
|
-
|
|
484
|
-
this.clear();
|
|
485
|
-
while (++index < length) {
|
|
486
|
-
var entry = entries[index];
|
|
487
|
-
this.set(entry[0], entry[1]);
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
/**
|
|
492
|
-
* Removes all key-value entries from the list cache.
|
|
493
|
-
*
|
|
494
|
-
* @private
|
|
495
|
-
* @name clear
|
|
496
|
-
* @memberOf ListCache
|
|
497
|
-
*/
|
|
498
|
-
function listCacheClear() {
|
|
499
|
-
this.__data__ = [];
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
/**
|
|
503
|
-
* Removes `key` and its value from the list cache.
|
|
504
|
-
*
|
|
505
|
-
* @private
|
|
506
|
-
* @name delete
|
|
507
|
-
* @memberOf ListCache
|
|
508
|
-
* @param {string} key The key of the value to remove.
|
|
509
|
-
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
|
510
|
-
*/
|
|
511
|
-
function listCacheDelete(key) {
|
|
512
|
-
var data = this.__data__,
|
|
513
|
-
index = assocIndexOf(data, key);
|
|
514
|
-
|
|
515
|
-
if (index < 0) {
|
|
516
|
-
return false;
|
|
517
|
-
}
|
|
518
|
-
var lastIndex = data.length - 1;
|
|
519
|
-
if (index == lastIndex) {
|
|
520
|
-
data.pop();
|
|
521
|
-
} else {
|
|
522
|
-
splice.call(data, index, 1);
|
|
523
|
-
}
|
|
524
|
-
return true;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
/**
|
|
528
|
-
* Gets the list cache value for `key`.
|
|
529
|
-
*
|
|
530
|
-
* @private
|
|
531
|
-
* @name get
|
|
532
|
-
* @memberOf ListCache
|
|
533
|
-
* @param {string} key The key of the value to get.
|
|
534
|
-
* @returns {*} Returns the entry value.
|
|
535
|
-
*/
|
|
536
|
-
function listCacheGet(key) {
|
|
537
|
-
var data = this.__data__,
|
|
538
|
-
index = assocIndexOf(data, key);
|
|
539
|
-
|
|
540
|
-
return index < 0 ? undefined : data[index][1];
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
/**
|
|
544
|
-
* Checks if a list cache value for `key` exists.
|
|
545
|
-
*
|
|
546
|
-
* @private
|
|
547
|
-
* @name has
|
|
548
|
-
* @memberOf ListCache
|
|
549
|
-
* @param {string} key The key of the entry to check.
|
|
550
|
-
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
|
551
|
-
*/
|
|
552
|
-
function listCacheHas(key) {
|
|
553
|
-
return assocIndexOf(this.__data__, key) > -1;
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
/**
|
|
557
|
-
* Sets the list cache `key` to `value`.
|
|
558
|
-
*
|
|
559
|
-
* @private
|
|
560
|
-
* @name set
|
|
561
|
-
* @memberOf ListCache
|
|
562
|
-
* @param {string} key The key of the value to set.
|
|
563
|
-
* @param {*} value The value to set.
|
|
564
|
-
* @returns {Object} Returns the list cache instance.
|
|
565
|
-
*/
|
|
566
|
-
function listCacheSet(key, value) {
|
|
567
|
-
var data = this.__data__,
|
|
568
|
-
index = assocIndexOf(data, key);
|
|
569
|
-
|
|
570
|
-
if (index < 0) {
|
|
571
|
-
data.push([key, value]);
|
|
572
|
-
} else {
|
|
573
|
-
data[index][1] = value;
|
|
574
|
-
}
|
|
575
|
-
return this;
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
// Add methods to `ListCache`.
|
|
579
|
-
ListCache.prototype.clear = listCacheClear;
|
|
580
|
-
ListCache.prototype['delete'] = listCacheDelete;
|
|
581
|
-
ListCache.prototype.get = listCacheGet;
|
|
582
|
-
ListCache.prototype.has = listCacheHas;
|
|
583
|
-
ListCache.prototype.set = listCacheSet;
|
|
584
|
-
|
|
585
|
-
/**
|
|
586
|
-
* Creates a map cache object to store key-value pairs.
|
|
587
|
-
*
|
|
588
|
-
* @private
|
|
589
|
-
* @constructor
|
|
590
|
-
* @param {Array} [entries] The key-value pairs to cache.
|
|
591
|
-
*/
|
|
592
|
-
function MapCache(entries) {
|
|
593
|
-
var index = -1,
|
|
594
|
-
length = entries ? entries.length : 0;
|
|
595
|
-
|
|
596
|
-
this.clear();
|
|
597
|
-
while (++index < length) {
|
|
598
|
-
var entry = entries[index];
|
|
599
|
-
this.set(entry[0], entry[1]);
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
/**
|
|
604
|
-
* Removes all key-value entries from the map.
|
|
605
|
-
*
|
|
606
|
-
* @private
|
|
607
|
-
* @name clear
|
|
608
|
-
* @memberOf MapCache
|
|
609
|
-
*/
|
|
610
|
-
function mapCacheClear() {
|
|
611
|
-
this.__data__ = {
|
|
612
|
-
'hash': new Hash,
|
|
613
|
-
'map': new (Map || ListCache),
|
|
614
|
-
'string': new Hash
|
|
615
|
-
};
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
/**
|
|
619
|
-
* Removes `key` and its value from the map.
|
|
620
|
-
*
|
|
621
|
-
* @private
|
|
622
|
-
* @name delete
|
|
623
|
-
* @memberOf MapCache
|
|
624
|
-
* @param {string} key The key of the value to remove.
|
|
625
|
-
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
|
626
|
-
*/
|
|
627
|
-
function mapCacheDelete(key) {
|
|
628
|
-
return getMapData(this, key)['delete'](key);
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
/**
|
|
632
|
-
* Gets the map value for `key`.
|
|
633
|
-
*
|
|
634
|
-
* @private
|
|
635
|
-
* @name get
|
|
636
|
-
* @memberOf MapCache
|
|
637
|
-
* @param {string} key The key of the value to get.
|
|
638
|
-
* @returns {*} Returns the entry value.
|
|
639
|
-
*/
|
|
640
|
-
function mapCacheGet(key) {
|
|
641
|
-
return getMapData(this, key).get(key);
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
/**
|
|
645
|
-
* Checks if a map value for `key` exists.
|
|
646
|
-
*
|
|
647
|
-
* @private
|
|
648
|
-
* @name has
|
|
649
|
-
* @memberOf MapCache
|
|
650
|
-
* @param {string} key The key of the entry to check.
|
|
651
|
-
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
|
652
|
-
*/
|
|
653
|
-
function mapCacheHas(key) {
|
|
654
|
-
return getMapData(this, key).has(key);
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
/**
|
|
658
|
-
* Sets the map `key` to `value`.
|
|
659
|
-
*
|
|
660
|
-
* @private
|
|
661
|
-
* @name set
|
|
662
|
-
* @memberOf MapCache
|
|
663
|
-
* @param {string} key The key of the value to set.
|
|
664
|
-
* @param {*} value The value to set.
|
|
665
|
-
* @returns {Object} Returns the map cache instance.
|
|
666
|
-
*/
|
|
667
|
-
function mapCacheSet(key, value) {
|
|
668
|
-
getMapData(this, key).set(key, value);
|
|
669
|
-
return this;
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
// Add methods to `MapCache`.
|
|
673
|
-
MapCache.prototype.clear = mapCacheClear;
|
|
674
|
-
MapCache.prototype['delete'] = mapCacheDelete;
|
|
675
|
-
MapCache.prototype.get = mapCacheGet;
|
|
676
|
-
MapCache.prototype.has = mapCacheHas;
|
|
677
|
-
MapCache.prototype.set = mapCacheSet;
|
|
678
|
-
|
|
679
|
-
/**
|
|
680
|
-
* Creates a stack cache object to store key-value pairs.
|
|
681
|
-
*
|
|
682
|
-
* @private
|
|
683
|
-
* @constructor
|
|
684
|
-
* @param {Array} [entries] The key-value pairs to cache.
|
|
685
|
-
*/
|
|
686
|
-
function Stack(entries) {
|
|
687
|
-
this.__data__ = new ListCache(entries);
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
/**
|
|
691
|
-
* Removes all key-value entries from the stack.
|
|
692
|
-
*
|
|
693
|
-
* @private
|
|
694
|
-
* @name clear
|
|
695
|
-
* @memberOf Stack
|
|
696
|
-
*/
|
|
697
|
-
function stackClear() {
|
|
698
|
-
this.__data__ = new ListCache;
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
/**
|
|
702
|
-
* Removes `key` and its value from the stack.
|
|
703
|
-
*
|
|
704
|
-
* @private
|
|
705
|
-
* @name delete
|
|
706
|
-
* @memberOf Stack
|
|
707
|
-
* @param {string} key The key of the value to remove.
|
|
708
|
-
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
|
709
|
-
*/
|
|
710
|
-
function stackDelete(key) {
|
|
711
|
-
return this.__data__['delete'](key);
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
/**
|
|
715
|
-
* Gets the stack value for `key`.
|
|
716
|
-
*
|
|
717
|
-
* @private
|
|
718
|
-
* @name get
|
|
719
|
-
* @memberOf Stack
|
|
720
|
-
* @param {string} key The key of the value to get.
|
|
721
|
-
* @returns {*} Returns the entry value.
|
|
722
|
-
*/
|
|
723
|
-
function stackGet(key) {
|
|
724
|
-
return this.__data__.get(key);
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
/**
|
|
728
|
-
* Checks if a stack value for `key` exists.
|
|
729
|
-
*
|
|
730
|
-
* @private
|
|
731
|
-
* @name has
|
|
732
|
-
* @memberOf Stack
|
|
733
|
-
* @param {string} key The key of the entry to check.
|
|
734
|
-
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
|
735
|
-
*/
|
|
736
|
-
function stackHas(key) {
|
|
737
|
-
return this.__data__.has(key);
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
/**
|
|
741
|
-
* Sets the stack `key` to `value`.
|
|
742
|
-
*
|
|
743
|
-
* @private
|
|
744
|
-
* @name set
|
|
745
|
-
* @memberOf Stack
|
|
746
|
-
* @param {string} key The key of the value to set.
|
|
747
|
-
* @param {*} value The value to set.
|
|
748
|
-
* @returns {Object} Returns the stack cache instance.
|
|
749
|
-
*/
|
|
750
|
-
function stackSet(key, value) {
|
|
751
|
-
var cache = this.__data__;
|
|
752
|
-
if (cache instanceof ListCache) {
|
|
753
|
-
var pairs = cache.__data__;
|
|
754
|
-
if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
|
|
755
|
-
pairs.push([key, value]);
|
|
756
|
-
return this;
|
|
757
|
-
}
|
|
758
|
-
cache = this.__data__ = new MapCache(pairs);
|
|
759
|
-
}
|
|
760
|
-
cache.set(key, value);
|
|
761
|
-
return this;
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
// Add methods to `Stack`.
|
|
765
|
-
Stack.prototype.clear = stackClear;
|
|
766
|
-
Stack.prototype['delete'] = stackDelete;
|
|
767
|
-
Stack.prototype.get = stackGet;
|
|
768
|
-
Stack.prototype.has = stackHas;
|
|
769
|
-
Stack.prototype.set = stackSet;
|
|
770
|
-
|
|
771
|
-
/**
|
|
772
|
-
* Creates an array of the enumerable property names of the array-like `value`.
|
|
773
|
-
*
|
|
774
|
-
* @private
|
|
775
|
-
* @param {*} value The value to query.
|
|
776
|
-
* @param {boolean} inherited Specify returning inherited property names.
|
|
777
|
-
* @returns {Array} Returns the array of property names.
|
|
778
|
-
*/
|
|
779
|
-
function arrayLikeKeys(value, inherited) {
|
|
780
|
-
// Safari 8.1 makes `arguments.callee` enumerable in strict mode.
|
|
781
|
-
// Safari 9 makes `arguments.length` enumerable in strict mode.
|
|
782
|
-
var result = (isArray(value) || isArguments(value))
|
|
783
|
-
? baseTimes(value.length, String)
|
|
784
|
-
: [];
|
|
785
|
-
|
|
786
|
-
var length = result.length,
|
|
787
|
-
skipIndexes = !!length;
|
|
788
|
-
|
|
789
|
-
for (var key in value) {
|
|
790
|
-
if ((inherited || hasOwnProperty.call(value, key)) &&
|
|
791
|
-
!(skipIndexes && (key == 'length' || isIndex(key, length)))) {
|
|
792
|
-
result.push(key);
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
return result;
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
/**
|
|
799
|
-
* Assigns `value` to `key` of `object` if the existing value is not equivalent
|
|
800
|
-
* using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
|
801
|
-
* for equality comparisons.
|
|
802
|
-
*
|
|
803
|
-
* @private
|
|
804
|
-
* @param {Object} object The object to modify.
|
|
805
|
-
* @param {string} key The key of the property to assign.
|
|
806
|
-
* @param {*} value The value to assign.
|
|
807
|
-
*/
|
|
808
|
-
function assignValue(object, key, value) {
|
|
809
|
-
var objValue = object[key];
|
|
810
|
-
if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
|
|
811
|
-
(value === undefined && !(key in object))) {
|
|
812
|
-
object[key] = value;
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
/**
|
|
817
|
-
* Gets the index at which the `key` is found in `array` of key-value pairs.
|
|
818
|
-
*
|
|
819
|
-
* @private
|
|
820
|
-
* @param {Array} array The array to inspect.
|
|
821
|
-
* @param {*} key The key to search for.
|
|
822
|
-
* @returns {number} Returns the index of the matched value, else `-1`.
|
|
823
|
-
*/
|
|
824
|
-
function assocIndexOf(array, key) {
|
|
825
|
-
var length = array.length;
|
|
826
|
-
while (length--) {
|
|
827
|
-
if (eq(array[length][0], key)) {
|
|
828
|
-
return length;
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
return -1;
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
/**
|
|
835
|
-
* The base implementation of `_.assign` without support for multiple sources
|
|
836
|
-
* or `customizer` functions.
|
|
837
|
-
*
|
|
838
|
-
* @private
|
|
839
|
-
* @param {Object} object The destination object.
|
|
840
|
-
* @param {Object} source The source object.
|
|
841
|
-
* @returns {Object} Returns `object`.
|
|
842
|
-
*/
|
|
843
|
-
function baseAssign(object, source) {
|
|
844
|
-
return object && copyObject(source, keys(source), object);
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
/**
|
|
848
|
-
* The base implementation of `_.clone` and `_.cloneDeep` which tracks
|
|
849
|
-
* traversed objects.
|
|
850
|
-
*
|
|
851
|
-
* @private
|
|
852
|
-
* @param {*} value The value to clone.
|
|
853
|
-
* @param {boolean} [isDeep] Specify a deep clone.
|
|
854
|
-
* @param {boolean} [isFull] Specify a clone including symbols.
|
|
855
|
-
* @param {Function} [customizer] The function to customize cloning.
|
|
856
|
-
* @param {string} [key] The key of `value`.
|
|
857
|
-
* @param {Object} [object] The parent object of `value`.
|
|
858
|
-
* @param {Object} [stack] Tracks traversed objects and their clone counterparts.
|
|
859
|
-
* @returns {*} Returns the cloned value.
|
|
860
|
-
*/
|
|
861
|
-
function baseClone(value, isDeep, isFull, customizer, key, object, stack) {
|
|
862
|
-
var result;
|
|
863
|
-
if (customizer) {
|
|
864
|
-
result = object ? customizer(value, key, object, stack) : customizer(value);
|
|
865
|
-
}
|
|
866
|
-
if (result !== undefined) {
|
|
867
|
-
return result;
|
|
868
|
-
}
|
|
869
|
-
if (!isObject(value)) {
|
|
870
|
-
return value;
|
|
871
|
-
}
|
|
872
|
-
var isArr = isArray(value);
|
|
873
|
-
if (isArr) {
|
|
874
|
-
result = initCloneArray(value);
|
|
875
|
-
if (!isDeep) {
|
|
876
|
-
return copyArray(value, result);
|
|
877
|
-
}
|
|
878
|
-
} else {
|
|
879
|
-
var tag = getTag(value),
|
|
880
|
-
isFunc = tag == funcTag || tag == genTag;
|
|
881
|
-
|
|
882
|
-
if (isBuffer(value)) {
|
|
883
|
-
return cloneBuffer(value, isDeep);
|
|
884
|
-
}
|
|
885
|
-
if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
|
|
886
|
-
if (isHostObject(value)) {
|
|
887
|
-
return object ? value : {};
|
|
888
|
-
}
|
|
889
|
-
result = initCloneObject(isFunc ? {} : value);
|
|
890
|
-
if (!isDeep) {
|
|
891
|
-
return copySymbols(value, baseAssign(result, value));
|
|
892
|
-
}
|
|
893
|
-
} else {
|
|
894
|
-
if (!cloneableTags[tag]) {
|
|
895
|
-
return object ? value : {};
|
|
896
|
-
}
|
|
897
|
-
result = initCloneByTag(value, tag, baseClone, isDeep);
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
// Check for circular references and return its corresponding clone.
|
|
901
|
-
stack || (stack = new Stack);
|
|
902
|
-
var stacked = stack.get(value);
|
|
903
|
-
if (stacked) {
|
|
904
|
-
return stacked;
|
|
905
|
-
}
|
|
906
|
-
stack.set(value, result);
|
|
907
|
-
|
|
908
|
-
if (!isArr) {
|
|
909
|
-
var props = isFull ? getAllKeys(value) : keys(value);
|
|
910
|
-
}
|
|
911
|
-
arrayEach(props || value, function(subValue, key) {
|
|
912
|
-
if (props) {
|
|
913
|
-
key = subValue;
|
|
914
|
-
subValue = value[key];
|
|
915
|
-
}
|
|
916
|
-
// Recursively populate clone (susceptible to call stack limits).
|
|
917
|
-
assignValue(result, key, baseClone(subValue, isDeep, isFull, customizer, key, value, stack));
|
|
918
|
-
});
|
|
919
|
-
return result;
|
|
920
|
-
}
|
|
921
|
-
|
|
922
|
-
/**
|
|
923
|
-
* The base implementation of `_.create` without support for assigning
|
|
924
|
-
* properties to the created object.
|
|
925
|
-
*
|
|
926
|
-
* @private
|
|
927
|
-
* @param {Object} prototype The object to inherit from.
|
|
928
|
-
* @returns {Object} Returns the new object.
|
|
929
|
-
*/
|
|
930
|
-
function baseCreate(proto) {
|
|
931
|
-
return isObject(proto) ? objectCreate(proto) : {};
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
/**
|
|
935
|
-
* The base implementation of `getAllKeys` and `getAllKeysIn` which uses
|
|
936
|
-
* `keysFunc` and `symbolsFunc` to get the enumerable property names and
|
|
937
|
-
* symbols of `object`.
|
|
938
|
-
*
|
|
939
|
-
* @private
|
|
940
|
-
* @param {Object} object The object to query.
|
|
941
|
-
* @param {Function} keysFunc The function to get the keys of `object`.
|
|
942
|
-
* @param {Function} symbolsFunc The function to get the symbols of `object`.
|
|
943
|
-
* @returns {Array} Returns the array of property names and symbols.
|
|
944
|
-
*/
|
|
945
|
-
function baseGetAllKeys(object, keysFunc, symbolsFunc) {
|
|
946
|
-
var result = keysFunc(object);
|
|
947
|
-
return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
/**
|
|
951
|
-
* The base implementation of `getTag`.
|
|
952
|
-
*
|
|
953
|
-
* @private
|
|
954
|
-
* @param {*} value The value to query.
|
|
955
|
-
* @returns {string} Returns the `toStringTag`.
|
|
956
|
-
*/
|
|
957
|
-
function baseGetTag(value) {
|
|
958
|
-
return objectToString.call(value);
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
/**
|
|
962
|
-
* The base implementation of `_.isNative` without bad shim checks.
|
|
963
|
-
*
|
|
964
|
-
* @private
|
|
965
|
-
* @param {*} value The value to check.
|
|
966
|
-
* @returns {boolean} Returns `true` if `value` is a native function,
|
|
967
|
-
* else `false`.
|
|
968
|
-
*/
|
|
969
|
-
function baseIsNative(value) {
|
|
970
|
-
if (!isObject(value) || isMasked(value)) {
|
|
971
|
-
return false;
|
|
972
|
-
}
|
|
973
|
-
var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor;
|
|
974
|
-
return pattern.test(toSource(value));
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
/**
|
|
978
|
-
* The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
|
|
979
|
-
*
|
|
980
|
-
* @private
|
|
981
|
-
* @param {Object} object The object to query.
|
|
982
|
-
* @returns {Array} Returns the array of property names.
|
|
983
|
-
*/
|
|
984
|
-
function baseKeys(object) {
|
|
985
|
-
if (!isPrototype(object)) {
|
|
986
|
-
return nativeKeys(object);
|
|
987
|
-
}
|
|
988
|
-
var result = [];
|
|
989
|
-
for (var key in Object(object)) {
|
|
990
|
-
if (hasOwnProperty.call(object, key) && key != 'constructor') {
|
|
991
|
-
result.push(key);
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
return result;
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
/**
|
|
998
|
-
* Creates a clone of `buffer`.
|
|
999
|
-
*
|
|
1000
|
-
* @private
|
|
1001
|
-
* @param {Buffer} buffer The buffer to clone.
|
|
1002
|
-
* @param {boolean} [isDeep] Specify a deep clone.
|
|
1003
|
-
* @returns {Buffer} Returns the cloned buffer.
|
|
1004
|
-
*/
|
|
1005
|
-
function cloneBuffer(buffer, isDeep) {
|
|
1006
|
-
if (isDeep) {
|
|
1007
|
-
return buffer.slice();
|
|
1008
|
-
}
|
|
1009
|
-
var result = new buffer.constructor(buffer.length);
|
|
1010
|
-
buffer.copy(result);
|
|
1011
|
-
return result;
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
/**
|
|
1015
|
-
* Creates a clone of `arrayBuffer`.
|
|
1016
|
-
*
|
|
1017
|
-
* @private
|
|
1018
|
-
* @param {ArrayBuffer} arrayBuffer The array buffer to clone.
|
|
1019
|
-
* @returns {ArrayBuffer} Returns the cloned array buffer.
|
|
1020
|
-
*/
|
|
1021
|
-
function cloneArrayBuffer(arrayBuffer) {
|
|
1022
|
-
var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
|
|
1023
|
-
new Uint8Array(result).set(new Uint8Array(arrayBuffer));
|
|
1024
|
-
return result;
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
/**
|
|
1028
|
-
* Creates a clone of `dataView`.
|
|
1029
|
-
*
|
|
1030
|
-
* @private
|
|
1031
|
-
* @param {Object} dataView The data view to clone.
|
|
1032
|
-
* @param {boolean} [isDeep] Specify a deep clone.
|
|
1033
|
-
* @returns {Object} Returns the cloned data view.
|
|
1034
|
-
*/
|
|
1035
|
-
function cloneDataView(dataView, isDeep) {
|
|
1036
|
-
var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
|
|
1037
|
-
return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
/**
|
|
1041
|
-
* Creates a clone of `map`.
|
|
1042
|
-
*
|
|
1043
|
-
* @private
|
|
1044
|
-
* @param {Object} map The map to clone.
|
|
1045
|
-
* @param {Function} cloneFunc The function to clone values.
|
|
1046
|
-
* @param {boolean} [isDeep] Specify a deep clone.
|
|
1047
|
-
* @returns {Object} Returns the cloned map.
|
|
1048
|
-
*/
|
|
1049
|
-
function cloneMap(map, isDeep, cloneFunc) {
|
|
1050
|
-
var array = isDeep ? cloneFunc(mapToArray(map), true) : mapToArray(map);
|
|
1051
|
-
return arrayReduce(array, addMapEntry, new map.constructor);
|
|
1052
|
-
}
|
|
1053
|
-
|
|
1054
|
-
/**
|
|
1055
|
-
* Creates a clone of `regexp`.
|
|
1056
|
-
*
|
|
1057
|
-
* @private
|
|
1058
|
-
* @param {Object} regexp The regexp to clone.
|
|
1059
|
-
* @returns {Object} Returns the cloned regexp.
|
|
1060
|
-
*/
|
|
1061
|
-
function cloneRegExp(regexp) {
|
|
1062
|
-
var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
|
|
1063
|
-
result.lastIndex = regexp.lastIndex;
|
|
1064
|
-
return result;
|
|
1065
|
-
}
|
|
1066
|
-
|
|
1067
|
-
/**
|
|
1068
|
-
* Creates a clone of `set`.
|
|
1069
|
-
*
|
|
1070
|
-
* @private
|
|
1071
|
-
* @param {Object} set The set to clone.
|
|
1072
|
-
* @param {Function} cloneFunc The function to clone values.
|
|
1073
|
-
* @param {boolean} [isDeep] Specify a deep clone.
|
|
1074
|
-
* @returns {Object} Returns the cloned set.
|
|
1075
|
-
*/
|
|
1076
|
-
function cloneSet(set, isDeep, cloneFunc) {
|
|
1077
|
-
var array = isDeep ? cloneFunc(setToArray(set), true) : setToArray(set);
|
|
1078
|
-
return arrayReduce(array, addSetEntry, new set.constructor);
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1081
|
-
/**
|
|
1082
|
-
* Creates a clone of the `symbol` object.
|
|
1083
|
-
*
|
|
1084
|
-
* @private
|
|
1085
|
-
* @param {Object} symbol The symbol object to clone.
|
|
1086
|
-
* @returns {Object} Returns the cloned symbol object.
|
|
1087
|
-
*/
|
|
1088
|
-
function cloneSymbol(symbol) {
|
|
1089
|
-
return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
|
|
1090
|
-
}
|
|
1091
|
-
|
|
1092
|
-
/**
|
|
1093
|
-
* Creates a clone of `typedArray`.
|
|
1094
|
-
*
|
|
1095
|
-
* @private
|
|
1096
|
-
* @param {Object} typedArray The typed array to clone.
|
|
1097
|
-
* @param {boolean} [isDeep] Specify a deep clone.
|
|
1098
|
-
* @returns {Object} Returns the cloned typed array.
|
|
1099
|
-
*/
|
|
1100
|
-
function cloneTypedArray(typedArray, isDeep) {
|
|
1101
|
-
var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
|
|
1102
|
-
return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
|
|
1103
|
-
}
|
|
1104
|
-
|
|
1105
|
-
/**
|
|
1106
|
-
* Copies the values of `source` to `array`.
|
|
1107
|
-
*
|
|
1108
|
-
* @private
|
|
1109
|
-
* @param {Array} source The array to copy values from.
|
|
1110
|
-
* @param {Array} [array=[]] The array to copy values to.
|
|
1111
|
-
* @returns {Array} Returns `array`.
|
|
1112
|
-
*/
|
|
1113
|
-
function copyArray(source, array) {
|
|
1114
|
-
var index = -1,
|
|
1115
|
-
length = source.length;
|
|
1116
|
-
|
|
1117
|
-
array || (array = Array(length));
|
|
1118
|
-
while (++index < length) {
|
|
1119
|
-
array[index] = source[index];
|
|
1120
|
-
}
|
|
1121
|
-
return array;
|
|
1122
|
-
}
|
|
1123
|
-
|
|
1124
|
-
/**
|
|
1125
|
-
* Copies properties of `source` to `object`.
|
|
1126
|
-
*
|
|
1127
|
-
* @private
|
|
1128
|
-
* @param {Object} source The object to copy properties from.
|
|
1129
|
-
* @param {Array} props The property identifiers to copy.
|
|
1130
|
-
* @param {Object} [object={}] The object to copy properties to.
|
|
1131
|
-
* @param {Function} [customizer] The function to customize copied values.
|
|
1132
|
-
* @returns {Object} Returns `object`.
|
|
1133
|
-
*/
|
|
1134
|
-
function copyObject(source, props, object, customizer) {
|
|
1135
|
-
object || (object = {});
|
|
1136
|
-
|
|
1137
|
-
var index = -1,
|
|
1138
|
-
length = props.length;
|
|
1139
|
-
|
|
1140
|
-
while (++index < length) {
|
|
1141
|
-
var key = props[index];
|
|
1142
|
-
|
|
1143
|
-
var newValue = customizer
|
|
1144
|
-
? customizer(object[key], source[key], key, object, source)
|
|
1145
|
-
: undefined;
|
|
1146
|
-
|
|
1147
|
-
assignValue(object, key, newValue === undefined ? source[key] : newValue);
|
|
1148
|
-
}
|
|
1149
|
-
return object;
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
/**
|
|
1153
|
-
* Copies own symbol properties of `source` to `object`.
|
|
1154
|
-
*
|
|
1155
|
-
* @private
|
|
1156
|
-
* @param {Object} source The object to copy symbols from.
|
|
1157
|
-
* @param {Object} [object={}] The object to copy symbols to.
|
|
1158
|
-
* @returns {Object} Returns `object`.
|
|
1159
|
-
*/
|
|
1160
|
-
function copySymbols(source, object) {
|
|
1161
|
-
return copyObject(source, getSymbols(source), object);
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
|
-
/**
|
|
1165
|
-
* Creates an array of own enumerable property names and symbols of `object`.
|
|
1166
|
-
*
|
|
1167
|
-
* @private
|
|
1168
|
-
* @param {Object} object The object to query.
|
|
1169
|
-
* @returns {Array} Returns the array of property names and symbols.
|
|
1170
|
-
*/
|
|
1171
|
-
function getAllKeys(object) {
|
|
1172
|
-
return baseGetAllKeys(object, keys, getSymbols);
|
|
1173
|
-
}
|
|
1174
|
-
|
|
1175
|
-
/**
|
|
1176
|
-
* Gets the data for `map`.
|
|
1177
|
-
*
|
|
1178
|
-
* @private
|
|
1179
|
-
* @param {Object} map The map to query.
|
|
1180
|
-
* @param {string} key The reference key.
|
|
1181
|
-
* @returns {*} Returns the map data.
|
|
1182
|
-
*/
|
|
1183
|
-
function getMapData(map, key) {
|
|
1184
|
-
var data = map.__data__;
|
|
1185
|
-
return isKeyable(key)
|
|
1186
|
-
? data[typeof key == 'string' ? 'string' : 'hash']
|
|
1187
|
-
: data.map;
|
|
1188
|
-
}
|
|
1189
|
-
|
|
1190
|
-
/**
|
|
1191
|
-
* Gets the native function at `key` of `object`.
|
|
1192
|
-
*
|
|
1193
|
-
* @private
|
|
1194
|
-
* @param {Object} object The object to query.
|
|
1195
|
-
* @param {string} key The key of the method to get.
|
|
1196
|
-
* @returns {*} Returns the function if it's native, else `undefined`.
|
|
1197
|
-
*/
|
|
1198
|
-
function getNative(object, key) {
|
|
1199
|
-
var value = getValue(object, key);
|
|
1200
|
-
return baseIsNative(value) ? value : undefined;
|
|
1201
|
-
}
|
|
1202
|
-
|
|
1203
|
-
/**
|
|
1204
|
-
* Creates an array of the own enumerable symbol properties of `object`.
|
|
1205
|
-
*
|
|
1206
|
-
* @private
|
|
1207
|
-
* @param {Object} object The object to query.
|
|
1208
|
-
* @returns {Array} Returns the array of symbols.
|
|
1209
|
-
*/
|
|
1210
|
-
var getSymbols = nativeGetSymbols ? overArg(nativeGetSymbols, Object) : stubArray;
|
|
1211
|
-
|
|
1212
|
-
/**
|
|
1213
|
-
* Gets the `toStringTag` of `value`.
|
|
1214
|
-
*
|
|
1215
|
-
* @private
|
|
1216
|
-
* @param {*} value The value to query.
|
|
1217
|
-
* @returns {string} Returns the `toStringTag`.
|
|
1218
|
-
*/
|
|
1219
|
-
var getTag = baseGetTag;
|
|
1220
|
-
|
|
1221
|
-
// Fallback for data views, maps, sets, and weak maps in IE 11,
|
|
1222
|
-
// for data views in Edge < 14, and promises in Node.js.
|
|
1223
|
-
if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
|
|
1224
|
-
(Map && getTag(new Map) != mapTag) ||
|
|
1225
|
-
(Promise && getTag(Promise.resolve()) != promiseTag) ||
|
|
1226
|
-
(Set && getTag(new Set) != setTag) ||
|
|
1227
|
-
(WeakMap && getTag(new WeakMap) != weakMapTag)) {
|
|
1228
|
-
getTag = function(value) {
|
|
1229
|
-
var result = objectToString.call(value),
|
|
1230
|
-
Ctor = result == objectTag ? value.constructor : undefined,
|
|
1231
|
-
ctorString = Ctor ? toSource(Ctor) : undefined;
|
|
1232
|
-
|
|
1233
|
-
if (ctorString) {
|
|
1234
|
-
switch (ctorString) {
|
|
1235
|
-
case dataViewCtorString: return dataViewTag;
|
|
1236
|
-
case mapCtorString: return mapTag;
|
|
1237
|
-
case promiseCtorString: return promiseTag;
|
|
1238
|
-
case setCtorString: return setTag;
|
|
1239
|
-
case weakMapCtorString: return weakMapTag;
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
return result;
|
|
1243
|
-
};
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1246
|
-
/**
|
|
1247
|
-
* Initializes an array clone.
|
|
1248
|
-
*
|
|
1249
|
-
* @private
|
|
1250
|
-
* @param {Array} array The array to clone.
|
|
1251
|
-
* @returns {Array} Returns the initialized clone.
|
|
1252
|
-
*/
|
|
1253
|
-
function initCloneArray(array) {
|
|
1254
|
-
var length = array.length,
|
|
1255
|
-
result = array.constructor(length);
|
|
1256
|
-
|
|
1257
|
-
// Add properties assigned by `RegExp#exec`.
|
|
1258
|
-
if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
|
|
1259
|
-
result.index = array.index;
|
|
1260
|
-
result.input = array.input;
|
|
1261
|
-
}
|
|
1262
|
-
return result;
|
|
1263
|
-
}
|
|
1264
|
-
|
|
1265
|
-
/**
|
|
1266
|
-
* Initializes an object clone.
|
|
1267
|
-
*
|
|
1268
|
-
* @private
|
|
1269
|
-
* @param {Object} object The object to clone.
|
|
1270
|
-
* @returns {Object} Returns the initialized clone.
|
|
1271
|
-
*/
|
|
1272
|
-
function initCloneObject(object) {
|
|
1273
|
-
return (typeof object.constructor == 'function' && !isPrototype(object))
|
|
1274
|
-
? baseCreate(getPrototype(object))
|
|
1275
|
-
: {};
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
|
-
/**
|
|
1279
|
-
* Initializes an object clone based on its `toStringTag`.
|
|
1280
|
-
*
|
|
1281
|
-
* **Note:** This function only supports cloning values with tags of
|
|
1282
|
-
* `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
|
|
1283
|
-
*
|
|
1284
|
-
* @private
|
|
1285
|
-
* @param {Object} object The object to clone.
|
|
1286
|
-
* @param {string} tag The `toStringTag` of the object to clone.
|
|
1287
|
-
* @param {Function} cloneFunc The function to clone values.
|
|
1288
|
-
* @param {boolean} [isDeep] Specify a deep clone.
|
|
1289
|
-
* @returns {Object} Returns the initialized clone.
|
|
1290
|
-
*/
|
|
1291
|
-
function initCloneByTag(object, tag, cloneFunc, isDeep) {
|
|
1292
|
-
var Ctor = object.constructor;
|
|
1293
|
-
switch (tag) {
|
|
1294
|
-
case arrayBufferTag:
|
|
1295
|
-
return cloneArrayBuffer(object);
|
|
1296
|
-
|
|
1297
|
-
case boolTag:
|
|
1298
|
-
case dateTag:
|
|
1299
|
-
return new Ctor(+object);
|
|
1300
|
-
|
|
1301
|
-
case dataViewTag:
|
|
1302
|
-
return cloneDataView(object, isDeep);
|
|
1303
|
-
|
|
1304
|
-
case float32Tag: case float64Tag:
|
|
1305
|
-
case int8Tag: case int16Tag: case int32Tag:
|
|
1306
|
-
case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
|
|
1307
|
-
return cloneTypedArray(object, isDeep);
|
|
1308
|
-
|
|
1309
|
-
case mapTag:
|
|
1310
|
-
return cloneMap(object, isDeep, cloneFunc);
|
|
1311
|
-
|
|
1312
|
-
case numberTag:
|
|
1313
|
-
case stringTag:
|
|
1314
|
-
return new Ctor(object);
|
|
1315
|
-
|
|
1316
|
-
case regexpTag:
|
|
1317
|
-
return cloneRegExp(object);
|
|
1318
|
-
|
|
1319
|
-
case setTag:
|
|
1320
|
-
return cloneSet(object, isDeep, cloneFunc);
|
|
1321
|
-
|
|
1322
|
-
case symbolTag:
|
|
1323
|
-
return cloneSymbol(object);
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
|
|
1327
|
-
/**
|
|
1328
|
-
* Checks if `value` is a valid array-like index.
|
|
1329
|
-
*
|
|
1330
|
-
* @private
|
|
1331
|
-
* @param {*} value The value to check.
|
|
1332
|
-
* @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
|
|
1333
|
-
* @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
|
|
1334
|
-
*/
|
|
1335
|
-
function isIndex(value, length) {
|
|
1336
|
-
length = length == null ? MAX_SAFE_INTEGER : length;
|
|
1337
|
-
return !!length &&
|
|
1338
|
-
(typeof value == 'number' || reIsUint.test(value)) &&
|
|
1339
|
-
(value > -1 && value % 1 == 0 && value < length);
|
|
1340
|
-
}
|
|
1341
|
-
|
|
1342
|
-
/**
|
|
1343
|
-
* Checks if `value` is suitable for use as unique object key.
|
|
1344
|
-
*
|
|
1345
|
-
* @private
|
|
1346
|
-
* @param {*} value The value to check.
|
|
1347
|
-
* @returns {boolean} Returns `true` if `value` is suitable, else `false`.
|
|
1348
|
-
*/
|
|
1349
|
-
function isKeyable(value) {
|
|
1350
|
-
var type = typeof value;
|
|
1351
|
-
return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
|
|
1352
|
-
? (value !== '__proto__')
|
|
1353
|
-
: (value === null);
|
|
1354
|
-
}
|
|
1355
|
-
|
|
1356
|
-
/**
|
|
1357
|
-
* Checks if `func` has its source masked.
|
|
1358
|
-
*
|
|
1359
|
-
* @private
|
|
1360
|
-
* @param {Function} func The function to check.
|
|
1361
|
-
* @returns {boolean} Returns `true` if `func` is masked, else `false`.
|
|
1362
|
-
*/
|
|
1363
|
-
function isMasked(func) {
|
|
1364
|
-
return !!maskSrcKey && (maskSrcKey in func);
|
|
1365
|
-
}
|
|
1366
|
-
|
|
1367
|
-
/**
|
|
1368
|
-
* Checks if `value` is likely a prototype object.
|
|
1369
|
-
*
|
|
1370
|
-
* @private
|
|
1371
|
-
* @param {*} value The value to check.
|
|
1372
|
-
* @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
|
|
1373
|
-
*/
|
|
1374
|
-
function isPrototype(value) {
|
|
1375
|
-
var Ctor = value && value.constructor,
|
|
1376
|
-
proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
|
|
1377
|
-
|
|
1378
|
-
return value === proto;
|
|
1379
|
-
}
|
|
1380
|
-
|
|
1381
|
-
/**
|
|
1382
|
-
* Converts `func` to its source code.
|
|
1383
|
-
*
|
|
1384
|
-
* @private
|
|
1385
|
-
* @param {Function} func The function to process.
|
|
1386
|
-
* @returns {string} Returns the source code.
|
|
1387
|
-
*/
|
|
1388
|
-
function toSource(func) {
|
|
1389
|
-
if (func != null) {
|
|
1390
|
-
try {
|
|
1391
|
-
return funcToString.call(func);
|
|
1392
|
-
} catch (e) {}
|
|
1393
|
-
try {
|
|
1394
|
-
return (func + '');
|
|
1395
|
-
} catch (e) {}
|
|
1396
|
-
}
|
|
1397
|
-
return '';
|
|
1398
|
-
}
|
|
1399
|
-
|
|
1400
|
-
/**
|
|
1401
|
-
* This method is like `_.clone` except that it recursively clones `value`.
|
|
1402
|
-
*
|
|
1403
|
-
* @static
|
|
1404
|
-
* @memberOf _
|
|
1405
|
-
* @since 1.0.0
|
|
1406
|
-
* @category Lang
|
|
1407
|
-
* @param {*} value The value to recursively clone.
|
|
1408
|
-
* @returns {*} Returns the deep cloned value.
|
|
1409
|
-
* @see _.clone
|
|
1410
|
-
* @example
|
|
1411
|
-
*
|
|
1412
|
-
* var objects = [{ 'a': 1 }, { 'b': 2 }];
|
|
1413
|
-
*
|
|
1414
|
-
* var deep = _.cloneDeep(objects);
|
|
1415
|
-
* console.log(deep[0] === objects[0]);
|
|
1416
|
-
* // => false
|
|
1417
|
-
*/
|
|
1418
|
-
function cloneDeep(value) {
|
|
1419
|
-
return baseClone(value, true, true);
|
|
1420
|
-
}
|
|
1421
|
-
|
|
1422
|
-
/**
|
|
1423
|
-
* Performs a
|
|
1424
|
-
* [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
|
1425
|
-
* comparison between two values to determine if they are equivalent.
|
|
1426
|
-
*
|
|
1427
|
-
* @static
|
|
1428
|
-
* @memberOf _
|
|
1429
|
-
* @since 4.0.0
|
|
1430
|
-
* @category Lang
|
|
1431
|
-
* @param {*} value The value to compare.
|
|
1432
|
-
* @param {*} other The other value to compare.
|
|
1433
|
-
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
|
1434
|
-
* @example
|
|
1435
|
-
*
|
|
1436
|
-
* var object = { 'a': 1 };
|
|
1437
|
-
* var other = { 'a': 1 };
|
|
1438
|
-
*
|
|
1439
|
-
* _.eq(object, object);
|
|
1440
|
-
* // => true
|
|
1441
|
-
*
|
|
1442
|
-
* _.eq(object, other);
|
|
1443
|
-
* // => false
|
|
1444
|
-
*
|
|
1445
|
-
* _.eq('a', 'a');
|
|
1446
|
-
* // => true
|
|
1447
|
-
*
|
|
1448
|
-
* _.eq('a', Object('a'));
|
|
1449
|
-
* // => false
|
|
1450
|
-
*
|
|
1451
|
-
* _.eq(NaN, NaN);
|
|
1452
|
-
* // => true
|
|
1453
|
-
*/
|
|
1454
|
-
function eq(value, other) {
|
|
1455
|
-
return value === other || (value !== value && other !== other);
|
|
1456
|
-
}
|
|
1457
|
-
|
|
1458
|
-
/**
|
|
1459
|
-
* Checks if `value` is likely an `arguments` object.
|
|
1460
|
-
*
|
|
1461
|
-
* @static
|
|
1462
|
-
* @memberOf _
|
|
1463
|
-
* @since 0.1.0
|
|
1464
|
-
* @category Lang
|
|
1465
|
-
* @param {*} value The value to check.
|
|
1466
|
-
* @returns {boolean} Returns `true` if `value` is an `arguments` object,
|
|
1467
|
-
* else `false`.
|
|
1468
|
-
* @example
|
|
1469
|
-
*
|
|
1470
|
-
* _.isArguments(function() { return arguments; }());
|
|
1471
|
-
* // => true
|
|
1472
|
-
*
|
|
1473
|
-
* _.isArguments([1, 2, 3]);
|
|
1474
|
-
* // => false
|
|
1475
|
-
*/
|
|
1476
|
-
function isArguments(value) {
|
|
1477
|
-
// Safari 8.1 makes `arguments.callee` enumerable in strict mode.
|
|
1478
|
-
return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
|
|
1479
|
-
(!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
|
|
1480
|
-
}
|
|
1481
|
-
|
|
1482
|
-
/**
|
|
1483
|
-
* Checks if `value` is classified as an `Array` object.
|
|
1484
|
-
*
|
|
1485
|
-
* @static
|
|
1486
|
-
* @memberOf _
|
|
1487
|
-
* @since 0.1.0
|
|
1488
|
-
* @category Lang
|
|
1489
|
-
* @param {*} value The value to check.
|
|
1490
|
-
* @returns {boolean} Returns `true` if `value` is an array, else `false`.
|
|
1491
|
-
* @example
|
|
1492
|
-
*
|
|
1493
|
-
* _.isArray([1, 2, 3]);
|
|
1494
|
-
* // => true
|
|
1495
|
-
*
|
|
1496
|
-
* _.isArray(document.body.children);
|
|
1497
|
-
* // => false
|
|
1498
|
-
*
|
|
1499
|
-
* _.isArray('abc');
|
|
1500
|
-
* // => false
|
|
1501
|
-
*
|
|
1502
|
-
* _.isArray(_.noop);
|
|
1503
|
-
* // => false
|
|
1504
|
-
*/
|
|
1505
|
-
var isArray = Array.isArray;
|
|
1506
|
-
|
|
1507
|
-
/**
|
|
1508
|
-
* Checks if `value` is array-like. A value is considered array-like if it's
|
|
1509
|
-
* not a function and has a `value.length` that's an integer greater than or
|
|
1510
|
-
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
|
|
1511
|
-
*
|
|
1512
|
-
* @static
|
|
1513
|
-
* @memberOf _
|
|
1514
|
-
* @since 4.0.0
|
|
1515
|
-
* @category Lang
|
|
1516
|
-
* @param {*} value The value to check.
|
|
1517
|
-
* @returns {boolean} Returns `true` if `value` is array-like, else `false`.
|
|
1518
|
-
* @example
|
|
1519
|
-
*
|
|
1520
|
-
* _.isArrayLike([1, 2, 3]);
|
|
1521
|
-
* // => true
|
|
1522
|
-
*
|
|
1523
|
-
* _.isArrayLike(document.body.children);
|
|
1524
|
-
* // => true
|
|
1525
|
-
*
|
|
1526
|
-
* _.isArrayLike('abc');
|
|
1527
|
-
* // => true
|
|
1528
|
-
*
|
|
1529
|
-
* _.isArrayLike(_.noop);
|
|
1530
|
-
* // => false
|
|
1531
|
-
*/
|
|
1532
|
-
function isArrayLike(value) {
|
|
1533
|
-
return value != null && isLength(value.length) && !isFunction(value);
|
|
1534
|
-
}
|
|
1535
|
-
|
|
1536
|
-
/**
|
|
1537
|
-
* This method is like `_.isArrayLike` except that it also checks if `value`
|
|
1538
|
-
* is an object.
|
|
1539
|
-
*
|
|
1540
|
-
* @static
|
|
1541
|
-
* @memberOf _
|
|
1542
|
-
* @since 4.0.0
|
|
1543
|
-
* @category Lang
|
|
1544
|
-
* @param {*} value The value to check.
|
|
1545
|
-
* @returns {boolean} Returns `true` if `value` is an array-like object,
|
|
1546
|
-
* else `false`.
|
|
1547
|
-
* @example
|
|
1548
|
-
*
|
|
1549
|
-
* _.isArrayLikeObject([1, 2, 3]);
|
|
1550
|
-
* // => true
|
|
1551
|
-
*
|
|
1552
|
-
* _.isArrayLikeObject(document.body.children);
|
|
1553
|
-
* // => true
|
|
1554
|
-
*
|
|
1555
|
-
* _.isArrayLikeObject('abc');
|
|
1556
|
-
* // => false
|
|
1557
|
-
*
|
|
1558
|
-
* _.isArrayLikeObject(_.noop);
|
|
1559
|
-
* // => false
|
|
1560
|
-
*/
|
|
1561
|
-
function isArrayLikeObject(value) {
|
|
1562
|
-
return isObjectLike(value) && isArrayLike(value);
|
|
1563
|
-
}
|
|
1564
|
-
|
|
1565
|
-
/**
|
|
1566
|
-
* Checks if `value` is a buffer.
|
|
1567
|
-
*
|
|
1568
|
-
* @static
|
|
1569
|
-
* @memberOf _
|
|
1570
|
-
* @since 4.3.0
|
|
1571
|
-
* @category Lang
|
|
1572
|
-
* @param {*} value The value to check.
|
|
1573
|
-
* @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
|
|
1574
|
-
* @example
|
|
1575
|
-
*
|
|
1576
|
-
* _.isBuffer(new Buffer(2));
|
|
1577
|
-
* // => true
|
|
1578
|
-
*
|
|
1579
|
-
* _.isBuffer(new Uint8Array(2));
|
|
1580
|
-
* // => false
|
|
1581
|
-
*/
|
|
1582
|
-
var isBuffer = nativeIsBuffer || stubFalse;
|
|
1583
|
-
|
|
1584
|
-
/**
|
|
1585
|
-
* Checks if `value` is classified as a `Function` object.
|
|
1586
|
-
*
|
|
1587
|
-
* @static
|
|
1588
|
-
* @memberOf _
|
|
1589
|
-
* @since 0.1.0
|
|
1590
|
-
* @category Lang
|
|
1591
|
-
* @param {*} value The value to check.
|
|
1592
|
-
* @returns {boolean} Returns `true` if `value` is a function, else `false`.
|
|
1593
|
-
* @example
|
|
1594
|
-
*
|
|
1595
|
-
* _.isFunction(_);
|
|
1596
|
-
* // => true
|
|
1597
|
-
*
|
|
1598
|
-
* _.isFunction(/abc/);
|
|
1599
|
-
* // => false
|
|
1600
|
-
*/
|
|
1601
|
-
function isFunction(value) {
|
|
1602
|
-
// The use of `Object#toString` avoids issues with the `typeof` operator
|
|
1603
|
-
// in Safari 8-9 which returns 'object' for typed array and other constructors.
|
|
1604
|
-
var tag = isObject(value) ? objectToString.call(value) : '';
|
|
1605
|
-
return tag == funcTag || tag == genTag;
|
|
1606
|
-
}
|
|
1607
|
-
|
|
1608
|
-
/**
|
|
1609
|
-
* Checks if `value` is a valid array-like length.
|
|
1610
|
-
*
|
|
1611
|
-
* **Note:** This method is loosely based on
|
|
1612
|
-
* [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
|
|
1613
|
-
*
|
|
1614
|
-
* @static
|
|
1615
|
-
* @memberOf _
|
|
1616
|
-
* @since 4.0.0
|
|
1617
|
-
* @category Lang
|
|
1618
|
-
* @param {*} value The value to check.
|
|
1619
|
-
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
|
1620
|
-
* @example
|
|
1621
|
-
*
|
|
1622
|
-
* _.isLength(3);
|
|
1623
|
-
* // => true
|
|
1624
|
-
*
|
|
1625
|
-
* _.isLength(Number.MIN_VALUE);
|
|
1626
|
-
* // => false
|
|
1627
|
-
*
|
|
1628
|
-
* _.isLength(Infinity);
|
|
1629
|
-
* // => false
|
|
1630
|
-
*
|
|
1631
|
-
* _.isLength('3');
|
|
1632
|
-
* // => false
|
|
1633
|
-
*/
|
|
1634
|
-
function isLength(value) {
|
|
1635
|
-
return typeof value == 'number' &&
|
|
1636
|
-
value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
|
1637
|
-
}
|
|
1638
|
-
|
|
1639
|
-
/**
|
|
1640
|
-
* Checks if `value` is the
|
|
1641
|
-
* [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
|
|
1642
|
-
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|
1643
|
-
*
|
|
1644
|
-
* @static
|
|
1645
|
-
* @memberOf _
|
|
1646
|
-
* @since 0.1.0
|
|
1647
|
-
* @category Lang
|
|
1648
|
-
* @param {*} value The value to check.
|
|
1649
|
-
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|
1650
|
-
* @example
|
|
1651
|
-
*
|
|
1652
|
-
* _.isObject({});
|
|
1653
|
-
* // => true
|
|
1654
|
-
*
|
|
1655
|
-
* _.isObject([1, 2, 3]);
|
|
1656
|
-
* // => true
|
|
1657
|
-
*
|
|
1658
|
-
* _.isObject(_.noop);
|
|
1659
|
-
* // => true
|
|
1660
|
-
*
|
|
1661
|
-
* _.isObject(null);
|
|
1662
|
-
* // => false
|
|
1663
|
-
*/
|
|
1664
|
-
function isObject(value) {
|
|
1665
|
-
var type = typeof value;
|
|
1666
|
-
return !!value && (type == 'object' || type == 'function');
|
|
1667
|
-
}
|
|
1668
|
-
|
|
1669
|
-
/**
|
|
1670
|
-
* Checks if `value` is object-like. A value is object-like if it's not `null`
|
|
1671
|
-
* and has a `typeof` result of "object".
|
|
1672
|
-
*
|
|
1673
|
-
* @static
|
|
1674
|
-
* @memberOf _
|
|
1675
|
-
* @since 4.0.0
|
|
1676
|
-
* @category Lang
|
|
1677
|
-
* @param {*} value The value to check.
|
|
1678
|
-
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
|
1679
|
-
* @example
|
|
1680
|
-
*
|
|
1681
|
-
* _.isObjectLike({});
|
|
1682
|
-
* // => true
|
|
1683
|
-
*
|
|
1684
|
-
* _.isObjectLike([1, 2, 3]);
|
|
1685
|
-
* // => true
|
|
1686
|
-
*
|
|
1687
|
-
* _.isObjectLike(_.noop);
|
|
1688
|
-
* // => false
|
|
1689
|
-
*
|
|
1690
|
-
* _.isObjectLike(null);
|
|
1691
|
-
* // => false
|
|
1692
|
-
*/
|
|
1693
|
-
function isObjectLike(value) {
|
|
1694
|
-
return !!value && typeof value == 'object';
|
|
1695
|
-
}
|
|
1696
|
-
|
|
1697
|
-
/**
|
|
1698
|
-
* Creates an array of the own enumerable property names of `object`.
|
|
1699
|
-
*
|
|
1700
|
-
* **Note:** Non-object values are coerced to objects. See the
|
|
1701
|
-
* [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
|
|
1702
|
-
* for more details.
|
|
1703
|
-
*
|
|
1704
|
-
* @static
|
|
1705
|
-
* @since 0.1.0
|
|
1706
|
-
* @memberOf _
|
|
1707
|
-
* @category Object
|
|
1708
|
-
* @param {Object} object The object to query.
|
|
1709
|
-
* @returns {Array} Returns the array of property names.
|
|
1710
|
-
* @example
|
|
1711
|
-
*
|
|
1712
|
-
* function Foo() {
|
|
1713
|
-
* this.a = 1;
|
|
1714
|
-
* this.b = 2;
|
|
1715
|
-
* }
|
|
1716
|
-
*
|
|
1717
|
-
* Foo.prototype.c = 3;
|
|
1718
|
-
*
|
|
1719
|
-
* _.keys(new Foo);
|
|
1720
|
-
* // => ['a', 'b'] (iteration order is not guaranteed)
|
|
1721
|
-
*
|
|
1722
|
-
* _.keys('hi');
|
|
1723
|
-
* // => ['0', '1']
|
|
1724
|
-
*/
|
|
1725
|
-
function keys(object) {
|
|
1726
|
-
return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
|
|
1727
|
-
}
|
|
1728
|
-
|
|
1729
|
-
/**
|
|
1730
|
-
* This method returns a new empty array.
|
|
1731
|
-
*
|
|
1732
|
-
* @static
|
|
1733
|
-
* @memberOf _
|
|
1734
|
-
* @since 4.13.0
|
|
1735
|
-
* @category Util
|
|
1736
|
-
* @returns {Array} Returns the new empty array.
|
|
1737
|
-
* @example
|
|
1738
|
-
*
|
|
1739
|
-
* var arrays = _.times(2, _.stubArray);
|
|
1740
|
-
*
|
|
1741
|
-
* console.log(arrays);
|
|
1742
|
-
* // => [[], []]
|
|
1743
|
-
*
|
|
1744
|
-
* console.log(arrays[0] === arrays[1]);
|
|
1745
|
-
* // => false
|
|
1746
|
-
*/
|
|
1747
|
-
function stubArray() {
|
|
1748
|
-
return [];
|
|
1749
|
-
}
|
|
1750
|
-
|
|
1751
|
-
/**
|
|
1752
|
-
* This method returns `false`.
|
|
1753
|
-
*
|
|
1754
|
-
* @static
|
|
1755
|
-
* @memberOf _
|
|
1756
|
-
* @since 4.13.0
|
|
1757
|
-
* @category Util
|
|
1758
|
-
* @returns {boolean} Returns `false`.
|
|
1759
|
-
* @example
|
|
1760
|
-
*
|
|
1761
|
-
* _.times(2, _.stubFalse);
|
|
1762
|
-
* // => [false, false]
|
|
1763
|
-
*/
|
|
1764
|
-
function stubFalse() {
|
|
1765
|
-
return false;
|
|
1766
|
-
}
|
|
1767
|
-
|
|
1768
|
-
module.exports = cloneDeep;
|
|
1769
|
-
}(lodash_clonedeep, lodash_clonedeep.exports));
|
|
1770
|
-
|
|
1771
|
-
var clone = lodash_clonedeep.exports;
|
|
1772
|
-
|
|
1773
|
-
/**
|
|
1774
|
-
* lodash (Custom Build) <https://lodash.com/>
|
|
1775
|
-
* Build: `lodash modularize exports="npm" -o ./`
|
|
1776
|
-
* Copyright jQuery Foundation and other contributors <https://jquery.org/>
|
|
1777
|
-
* Released under MIT license <https://lodash.com/license>
|
|
1778
|
-
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
1779
|
-
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
1780
|
-
*/
|
|
1781
|
-
|
|
1782
|
-
/** `Object#toString` result references. */
|
|
1783
|
-
var objectTag = '[object Object]';
|
|
1784
|
-
|
|
1785
|
-
/**
|
|
1786
|
-
* Checks if `value` is a host object in IE < 9.
|
|
1787
|
-
*
|
|
1788
|
-
* @private
|
|
1789
|
-
* @param {*} value The value to check.
|
|
1790
|
-
* @returns {boolean} Returns `true` if `value` is a host object, else `false`.
|
|
1791
|
-
*/
|
|
1792
|
-
function isHostObject(value) {
|
|
1793
|
-
// Many host objects are `Object` objects that can coerce to strings
|
|
1794
|
-
// despite having improperly defined `toString` methods.
|
|
1795
|
-
var result = false;
|
|
1796
|
-
if (value != null && typeof value.toString != 'function') {
|
|
1797
|
-
try {
|
|
1798
|
-
result = !!(value + '');
|
|
1799
|
-
} catch (e) {}
|
|
1800
|
-
}
|
|
1801
|
-
return result;
|
|
1802
|
-
}
|
|
1803
|
-
|
|
1804
|
-
/**
|
|
1805
|
-
* Creates a unary function that invokes `func` with its argument transformed.
|
|
1806
|
-
*
|
|
1807
|
-
* @private
|
|
1808
|
-
* @param {Function} func The function to wrap.
|
|
1809
|
-
* @param {Function} transform The argument transform.
|
|
1810
|
-
* @returns {Function} Returns the new function.
|
|
1811
|
-
*/
|
|
1812
|
-
function overArg(func, transform) {
|
|
1813
|
-
return function(arg) {
|
|
1814
|
-
return func(transform(arg));
|
|
1815
|
-
};
|
|
1816
|
-
}
|
|
1817
|
-
|
|
1818
|
-
/** Used for built-in method references. */
|
|
1819
|
-
var funcProto = Function.prototype,
|
|
1820
|
-
objectProto = Object.prototype;
|
|
1821
|
-
|
|
1822
|
-
/** Used to resolve the decompiled source of functions. */
|
|
1823
|
-
var funcToString = funcProto.toString;
|
|
1824
|
-
|
|
1825
|
-
/** Used to check objects for own properties. */
|
|
1826
|
-
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
1827
|
-
|
|
1828
|
-
/** Used to infer the `Object` constructor. */
|
|
1829
|
-
var objectCtorString = funcToString.call(Object);
|
|
1830
|
-
|
|
1831
|
-
/**
|
|
1832
|
-
* Used to resolve the
|
|
1833
|
-
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
|
|
1834
|
-
* of values.
|
|
1835
|
-
*/
|
|
1836
|
-
var objectToString = objectProto.toString;
|
|
1837
|
-
|
|
1838
|
-
/** Built-in value references. */
|
|
1839
|
-
var getPrototype = overArg(Object.getPrototypeOf, Object);
|
|
1840
|
-
|
|
1841
|
-
/**
|
|
1842
|
-
* Checks if `value` is object-like. A value is object-like if it's not `null`
|
|
1843
|
-
* and has a `typeof` result of "object".
|
|
1844
|
-
*
|
|
1845
|
-
* @static
|
|
1846
|
-
* @memberOf _
|
|
1847
|
-
* @since 4.0.0
|
|
1848
|
-
* @category Lang
|
|
1849
|
-
* @param {*} value The value to check.
|
|
1850
|
-
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
|
1851
|
-
* @example
|
|
1852
|
-
*
|
|
1853
|
-
* _.isObjectLike({});
|
|
1854
|
-
* // => true
|
|
1855
|
-
*
|
|
1856
|
-
* _.isObjectLike([1, 2, 3]);
|
|
1857
|
-
* // => true
|
|
1858
|
-
*
|
|
1859
|
-
* _.isObjectLike(_.noop);
|
|
1860
|
-
* // => false
|
|
1861
|
-
*
|
|
1862
|
-
* _.isObjectLike(null);
|
|
1863
|
-
* // => false
|
|
1864
|
-
*/
|
|
1865
|
-
function isObjectLike(value) {
|
|
1866
|
-
return !!value && typeof value == 'object';
|
|
1867
|
-
}
|
|
1868
|
-
|
|
1869
|
-
/**
|
|
1870
|
-
* Checks if `value` is a plain object, that is, an object created by the
|
|
1871
|
-
* `Object` constructor or one with a `[[Prototype]]` of `null`.
|
|
1872
|
-
*
|
|
1873
|
-
* @static
|
|
1874
|
-
* @memberOf _
|
|
1875
|
-
* @since 0.8.0
|
|
1876
|
-
* @category Lang
|
|
1877
|
-
* @param {*} value The value to check.
|
|
1878
|
-
* @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
|
|
1879
|
-
* @example
|
|
1880
|
-
*
|
|
1881
|
-
* function Foo() {
|
|
1882
|
-
* this.a = 1;
|
|
1883
|
-
* }
|
|
1884
|
-
*
|
|
1885
|
-
* _.isPlainObject(new Foo);
|
|
1886
|
-
* // => false
|
|
1887
|
-
*
|
|
1888
|
-
* _.isPlainObject([1, 2, 3]);
|
|
1889
|
-
* // => false
|
|
1890
|
-
*
|
|
1891
|
-
* _.isPlainObject({ 'x': 0, 'y': 0 });
|
|
1892
|
-
* // => true
|
|
1893
|
-
*
|
|
1894
|
-
* _.isPlainObject(Object.create(null));
|
|
1895
|
-
* // => true
|
|
1896
|
-
*/
|
|
1897
|
-
function isPlainObject(value) {
|
|
1898
|
-
if (!isObjectLike(value) ||
|
|
1899
|
-
objectToString.call(value) != objectTag || isHostObject(value)) {
|
|
1900
|
-
return false;
|
|
1901
|
-
}
|
|
1902
|
-
var proto = getPrototype(value);
|
|
1903
|
-
if (proto === null) {
|
|
1904
|
-
return true;
|
|
1905
|
-
}
|
|
1906
|
-
var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
|
|
1907
|
-
return (typeof Ctor == 'function' &&
|
|
1908
|
-
Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString);
|
|
1909
|
-
}
|
|
1910
|
-
|
|
1911
|
-
var lodash_isplainobject = isPlainObject;
|
|
1912
|
-
|
|
1913
|
-
/**
|
|
1914
|
-
* @name ast-monkey-util
|
|
1915
|
-
* @fileoverview Utility library of AST helper functions
|
|
1916
|
-
* @version 1.4.0
|
|
1917
|
-
* @author Roy Revelt, Codsen Ltd
|
|
1918
|
-
* @license MIT
|
|
1919
|
-
* {@link https://codsen.com/os/ast-monkey-util/}
|
|
1920
|
-
*/
|
|
1921
|
-
|
|
1922
|
-
function parent(str) {
|
|
1923
|
-
if (str.includes(".")) {
|
|
1924
|
-
const lastDotAt = str.lastIndexOf(".");
|
|
1925
|
-
if (!str.slice(0, lastDotAt).includes(".")) {
|
|
1926
|
-
return str.slice(0, lastDotAt);
|
|
1927
|
-
}
|
|
1928
|
-
for (let i = lastDotAt - 1; i--;) {
|
|
1929
|
-
if (str[i] === ".") {
|
|
1930
|
-
return str.slice(i + 1, lastDotAt);
|
|
1931
|
-
}
|
|
1932
|
-
}
|
|
1933
|
-
}
|
|
1934
|
-
return null;
|
|
1935
|
-
}
|
|
1936
|
-
|
|
1937
|
-
/**
|
|
1938
|
-
* @name ast-monkey-traverse
|
|
1939
|
-
* @fileoverview Utility library to traverse AST
|
|
1940
|
-
* @version 2.1.0
|
|
1941
|
-
* @author Roy Revelt, Codsen Ltd
|
|
1942
|
-
* @license MIT
|
|
1943
|
-
* {@link https://codsen.com/os/ast-monkey-traverse/}
|
|
1944
|
-
*/
|
|
1945
|
-
function traverse(tree1, cb1) {
|
|
1946
|
-
const stop2 = {
|
|
1947
|
-
now: false
|
|
1948
|
-
};
|
|
1949
|
-
function traverseInner(treeOriginal, callback, originalInnerObj, stop) {
|
|
1950
|
-
const tree = clone(treeOriginal);
|
|
1951
|
-
let res;
|
|
1952
|
-
const innerObj = {
|
|
1953
|
-
depth: -1,
|
|
1954
|
-
path: "",
|
|
1955
|
-
...originalInnerObj
|
|
1956
|
-
};
|
|
1957
|
-
innerObj.depth += 1;
|
|
1958
|
-
if (Array.isArray(tree)) {
|
|
1959
|
-
for (let i = 0, len = tree.length; i < len; i++) {
|
|
1960
|
-
if (stop.now) {
|
|
1961
|
-
break;
|
|
1962
|
-
}
|
|
1963
|
-
const path = innerObj.path ? `${innerObj.path}.${i}` : `${i}`;
|
|
1964
|
-
if (tree[i] !== undefined) {
|
|
1965
|
-
innerObj.parent = clone(tree);
|
|
1966
|
-
innerObj.parentType = "array";
|
|
1967
|
-
innerObj.parentKey = parent(path);
|
|
1968
|
-
res = traverseInner(callback(tree[i], undefined, { ...innerObj,
|
|
1969
|
-
path
|
|
1970
|
-
}, stop), callback, { ...innerObj,
|
|
1971
|
-
path
|
|
1972
|
-
}, stop);
|
|
1973
|
-
if (Number.isNaN(res) && i < tree.length) {
|
|
1974
|
-
tree.splice(i, 1);
|
|
1975
|
-
i -= 1;
|
|
1976
|
-
} else {
|
|
1977
|
-
tree[i] = res;
|
|
1978
|
-
}
|
|
1979
|
-
} else {
|
|
1980
|
-
tree.splice(i, 1);
|
|
1981
|
-
}
|
|
1982
|
-
}
|
|
1983
|
-
} else if (lodash_isplainobject(tree)) {
|
|
1984
|
-
for (const key in tree) {
|
|
1985
|
-
if (stop.now && key != null) {
|
|
1986
|
-
break;
|
|
1987
|
-
}
|
|
1988
|
-
const path = innerObj.path ? `${innerObj.path}.${key}` : key;
|
|
1989
|
-
if (innerObj.depth === 0 && key != null) {
|
|
1990
|
-
innerObj.topmostKey = key;
|
|
1991
|
-
}
|
|
1992
|
-
innerObj.parent = clone(tree);
|
|
1993
|
-
innerObj.parentType = "object";
|
|
1994
|
-
innerObj.parentKey = parent(path);
|
|
1995
|
-
res = traverseInner(callback(key, tree[key], { ...innerObj,
|
|
1996
|
-
path
|
|
1997
|
-
}, stop), callback, { ...innerObj,
|
|
1998
|
-
path
|
|
1999
|
-
}, stop);
|
|
2000
|
-
if (Number.isNaN(res)) {
|
|
2001
|
-
delete tree[key];
|
|
2002
|
-
} else {
|
|
2003
|
-
tree[key] = res;
|
|
2004
|
-
}
|
|
2005
|
-
}
|
|
2006
|
-
}
|
|
2007
|
-
return tree;
|
|
2008
|
-
}
|
|
2009
|
-
return traverseInner(tree1, cb1, {}, stop2);
|
|
2010
|
-
}
|
|
2011
|
-
|
|
2012
|
-
var matcher$1 = {exports: {}};
|
|
2013
|
-
|
|
2014
|
-
var escapeStringRegexp$1 = string => {
|
|
2015
|
-
if (typeof string !== 'string') {
|
|
2016
|
-
throw new TypeError('Expected a string');
|
|
2017
|
-
}
|
|
2018
|
-
|
|
2019
|
-
// Escape characters with special meaning either inside or outside character sets.
|
|
2020
|
-
// Use a simple backslash escape when it’s always valid, and a \unnnn escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar.
|
|
2021
|
-
return string
|
|
2022
|
-
.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')
|
|
2023
|
-
.replace(/-/g, '\\x2d');
|
|
2024
|
-
};
|
|
2025
|
-
|
|
2026
|
-
const escapeStringRegexp = escapeStringRegexp$1;
|
|
2027
|
-
|
|
2028
|
-
const regexpCache = new Map();
|
|
2029
|
-
|
|
2030
|
-
function sanitizeArray(input, inputName) {
|
|
2031
|
-
if (!Array.isArray(input)) {
|
|
2032
|
-
switch (typeof input) {
|
|
2033
|
-
case 'string':
|
|
2034
|
-
input = [input];
|
|
2035
|
-
break;
|
|
2036
|
-
case 'undefined':
|
|
2037
|
-
input = [];
|
|
2038
|
-
break;
|
|
2039
|
-
default:
|
|
2040
|
-
throw new TypeError(`Expected '${inputName}' to be a string or an array, but got a type of '${typeof input}'`);
|
|
2041
|
-
}
|
|
2042
|
-
}
|
|
2043
|
-
|
|
2044
|
-
return input.filter(string => {
|
|
2045
|
-
if (typeof string !== 'string') {
|
|
2046
|
-
if (typeof string === 'undefined') {
|
|
2047
|
-
return false;
|
|
2048
|
-
}
|
|
2049
|
-
|
|
2050
|
-
throw new TypeError(`Expected '${inputName}' to be an array of strings, but found a type of '${typeof string}' in the array`);
|
|
2051
|
-
}
|
|
2052
|
-
|
|
2053
|
-
return true;
|
|
2054
|
-
});
|
|
2055
|
-
}
|
|
2056
|
-
|
|
2057
|
-
function makeRegexp(pattern, options) {
|
|
2058
|
-
options = {
|
|
2059
|
-
caseSensitive: false,
|
|
2060
|
-
...options
|
|
2061
|
-
};
|
|
2062
|
-
|
|
2063
|
-
const cacheKey = pattern + JSON.stringify(options);
|
|
2064
|
-
|
|
2065
|
-
if (regexpCache.has(cacheKey)) {
|
|
2066
|
-
return regexpCache.get(cacheKey);
|
|
2067
|
-
}
|
|
2068
|
-
|
|
2069
|
-
const negated = pattern[0] === '!';
|
|
2070
|
-
|
|
2071
|
-
if (negated) {
|
|
2072
|
-
pattern = pattern.slice(1);
|
|
2073
|
-
}
|
|
2074
|
-
|
|
2075
|
-
pattern = escapeStringRegexp(pattern).replace(/\\\*/g, '[\\s\\S]*');
|
|
2076
|
-
|
|
2077
|
-
const regexp = new RegExp(`^${pattern}$`, options.caseSensitive ? '' : 'i');
|
|
2078
|
-
regexp.negated = negated;
|
|
2079
|
-
regexpCache.set(cacheKey, regexp);
|
|
2080
|
-
|
|
2081
|
-
return regexp;
|
|
2082
|
-
}
|
|
2083
|
-
|
|
2084
|
-
matcher$1.exports = (inputs, patterns, options) => {
|
|
2085
|
-
inputs = sanitizeArray(inputs, 'inputs');
|
|
2086
|
-
patterns = sanitizeArray(patterns, 'patterns');
|
|
2087
|
-
|
|
2088
|
-
if (patterns.length === 0) {
|
|
2089
|
-
return [];
|
|
2090
|
-
}
|
|
2091
|
-
|
|
2092
|
-
const isFirstPatternNegated = patterns[0][0] === '!';
|
|
2093
|
-
|
|
2094
|
-
patterns = patterns.map(pattern => makeRegexp(pattern, options));
|
|
2095
|
-
|
|
2096
|
-
const result = [];
|
|
2097
|
-
|
|
2098
|
-
for (const input of inputs) {
|
|
2099
|
-
// If first pattern is negated we include everything to match user expectation.
|
|
2100
|
-
let matches = isFirstPatternNegated;
|
|
2101
|
-
|
|
2102
|
-
for (const pattern of patterns) {
|
|
2103
|
-
if (pattern.test(input)) {
|
|
2104
|
-
matches = !pattern.negated;
|
|
2105
|
-
}
|
|
2106
|
-
}
|
|
2107
|
-
|
|
2108
|
-
if (matches) {
|
|
2109
|
-
result.push(input);
|
|
2110
|
-
}
|
|
2111
|
-
}
|
|
2112
|
-
|
|
2113
|
-
return result;
|
|
2114
|
-
};
|
|
2115
|
-
|
|
2116
|
-
matcher$1.exports.isMatch = (inputs, patterns, options) => {
|
|
2117
|
-
inputs = sanitizeArray(inputs, 'inputs');
|
|
2118
|
-
patterns = sanitizeArray(patterns, 'patterns');
|
|
2119
|
-
|
|
2120
|
-
if (patterns.length === 0) {
|
|
2121
|
-
return false;
|
|
2122
|
-
}
|
|
2123
|
-
|
|
2124
|
-
return inputs.some(input => {
|
|
2125
|
-
return patterns.every(pattern => {
|
|
2126
|
-
const regexp = makeRegexp(pattern, options);
|
|
2127
|
-
const matches = regexp.test(input);
|
|
2128
|
-
return regexp.negated ? !matches : matches;
|
|
2129
|
-
});
|
|
2130
|
-
});
|
|
2131
|
-
};
|
|
2132
|
-
|
|
2133
|
-
var matcher = matcher$1.exports;
|
|
2134
|
-
|
|
2135
|
-
var objectPath$1 = {exports: {}};
|
|
2136
|
-
|
|
2137
|
-
(function (module) {
|
|
2138
|
-
(function (root, factory){
|
|
2139
|
-
|
|
2140
|
-
/*istanbul ignore next:cant test*/
|
|
2141
|
-
{
|
|
2142
|
-
module.exports = factory();
|
|
2143
|
-
}
|
|
2144
|
-
})(commonjsGlobal, function(){
|
|
2145
|
-
|
|
2146
|
-
var toStr = Object.prototype.toString;
|
|
2147
|
-
function hasOwnProperty(obj, prop) {
|
|
2148
|
-
if(obj == null) {
|
|
2149
|
-
return false
|
|
2150
|
-
}
|
|
2151
|
-
//to handle objects with null prototypes (too edge case?)
|
|
2152
|
-
return Object.prototype.hasOwnProperty.call(obj, prop)
|
|
2153
|
-
}
|
|
2154
|
-
|
|
2155
|
-
function isEmpty(value){
|
|
2156
|
-
if (!value) {
|
|
2157
|
-
return true;
|
|
2158
|
-
}
|
|
2159
|
-
if (isArray(value) && value.length === 0) {
|
|
2160
|
-
return true;
|
|
2161
|
-
} else if (typeof value !== 'string') {
|
|
2162
|
-
for (var i in value) {
|
|
2163
|
-
if (hasOwnProperty(value, i)) {
|
|
2164
|
-
return false;
|
|
2165
|
-
}
|
|
2166
|
-
}
|
|
2167
|
-
return true;
|
|
2168
|
-
}
|
|
2169
|
-
return false;
|
|
2170
|
-
}
|
|
2171
|
-
|
|
2172
|
-
function toString(type){
|
|
2173
|
-
return toStr.call(type);
|
|
2174
|
-
}
|
|
2175
|
-
|
|
2176
|
-
function isObject(obj){
|
|
2177
|
-
return typeof obj === 'object' && toString(obj) === "[object Object]";
|
|
2178
|
-
}
|
|
2179
|
-
|
|
2180
|
-
var isArray = Array.isArray || function(obj){
|
|
2181
|
-
/*istanbul ignore next:cant test*/
|
|
2182
|
-
return toStr.call(obj) === '[object Array]';
|
|
2183
|
-
};
|
|
2184
|
-
|
|
2185
|
-
function isBoolean(obj){
|
|
2186
|
-
return typeof obj === 'boolean' || toString(obj) === '[object Boolean]';
|
|
2187
|
-
}
|
|
2188
|
-
|
|
2189
|
-
function getKey(key){
|
|
2190
|
-
var intKey = parseInt(key);
|
|
2191
|
-
if (intKey.toString() === key) {
|
|
2192
|
-
return intKey;
|
|
2193
|
-
}
|
|
2194
|
-
return key;
|
|
2195
|
-
}
|
|
2196
|
-
|
|
2197
|
-
function factory(options) {
|
|
2198
|
-
options = options || {};
|
|
2199
|
-
|
|
2200
|
-
var objectPath = function(obj) {
|
|
2201
|
-
return Object.keys(objectPath).reduce(function(proxy, prop) {
|
|
2202
|
-
if(prop === 'create') {
|
|
2203
|
-
return proxy;
|
|
2204
|
-
}
|
|
2205
|
-
|
|
2206
|
-
/*istanbul ignore else*/
|
|
2207
|
-
if (typeof objectPath[prop] === 'function') {
|
|
2208
|
-
proxy[prop] = objectPath[prop].bind(objectPath, obj);
|
|
2209
|
-
}
|
|
2210
|
-
|
|
2211
|
-
return proxy;
|
|
2212
|
-
}, {});
|
|
2213
|
-
};
|
|
2214
|
-
|
|
2215
|
-
var hasShallowProperty;
|
|
2216
|
-
if (options.includeInheritedProps) {
|
|
2217
|
-
hasShallowProperty = function () {
|
|
2218
|
-
return true
|
|
2219
|
-
};
|
|
2220
|
-
} else {
|
|
2221
|
-
hasShallowProperty = function (obj, prop) {
|
|
2222
|
-
return (typeof prop === 'number' && Array.isArray(obj)) || hasOwnProperty(obj, prop)
|
|
2223
|
-
};
|
|
2224
|
-
}
|
|
2225
|
-
|
|
2226
|
-
function getShallowProperty(obj, prop) {
|
|
2227
|
-
if (hasShallowProperty(obj, prop)) {
|
|
2228
|
-
return obj[prop];
|
|
2229
|
-
}
|
|
2230
|
-
}
|
|
2231
|
-
|
|
2232
|
-
function set(obj, path, value, doNotReplace){
|
|
2233
|
-
if (typeof path === 'number') {
|
|
2234
|
-
path = [path];
|
|
2235
|
-
}
|
|
2236
|
-
if (!path || path.length === 0) {
|
|
2237
|
-
return obj;
|
|
2238
|
-
}
|
|
2239
|
-
if (typeof path === 'string') {
|
|
2240
|
-
return set(obj, path.split('.').map(getKey), value, doNotReplace);
|
|
2241
|
-
}
|
|
2242
|
-
var currentPath = path[0];
|
|
2243
|
-
var currentValue = getShallowProperty(obj, currentPath);
|
|
2244
|
-
if (options.includeInheritedProps && (currentPath === '__proto__' ||
|
|
2245
|
-
(currentPath === 'constructor' && typeof currentValue === 'function'))) {
|
|
2246
|
-
throw new Error('For security reasons, object\'s magic properties cannot be set')
|
|
2247
|
-
}
|
|
2248
|
-
if (path.length === 1) {
|
|
2249
|
-
if (currentValue === void 0 || !doNotReplace) {
|
|
2250
|
-
obj[currentPath] = value;
|
|
2251
|
-
}
|
|
2252
|
-
return currentValue;
|
|
2253
|
-
}
|
|
2254
|
-
|
|
2255
|
-
if (currentValue === void 0) {
|
|
2256
|
-
//check if we assume an array
|
|
2257
|
-
if(typeof path[1] === 'number') {
|
|
2258
|
-
obj[currentPath] = [];
|
|
2259
|
-
} else {
|
|
2260
|
-
obj[currentPath] = {};
|
|
2261
|
-
}
|
|
2262
|
-
}
|
|
2263
|
-
|
|
2264
|
-
return set(obj[currentPath], path.slice(1), value, doNotReplace);
|
|
2265
|
-
}
|
|
2266
|
-
|
|
2267
|
-
objectPath.has = function (obj, path) {
|
|
2268
|
-
if (typeof path === 'number') {
|
|
2269
|
-
path = [path];
|
|
2270
|
-
} else if (typeof path === 'string') {
|
|
2271
|
-
path = path.split('.');
|
|
2272
|
-
}
|
|
2273
|
-
|
|
2274
|
-
if (!path || path.length === 0) {
|
|
2275
|
-
return !!obj;
|
|
2276
|
-
}
|
|
2277
|
-
|
|
2278
|
-
for (var i = 0; i < path.length; i++) {
|
|
2279
|
-
var j = getKey(path[i]);
|
|
2280
|
-
|
|
2281
|
-
if((typeof j === 'number' && isArray(obj) && j < obj.length) ||
|
|
2282
|
-
(options.includeInheritedProps ? (j in Object(obj)) : hasOwnProperty(obj, j))) {
|
|
2283
|
-
obj = obj[j];
|
|
2284
|
-
} else {
|
|
2285
|
-
return false;
|
|
2286
|
-
}
|
|
2287
|
-
}
|
|
2288
|
-
|
|
2289
|
-
return true;
|
|
2290
|
-
};
|
|
2291
|
-
|
|
2292
|
-
objectPath.ensureExists = function (obj, path, value){
|
|
2293
|
-
return set(obj, path, value, true);
|
|
2294
|
-
};
|
|
2295
|
-
|
|
2296
|
-
objectPath.set = function (obj, path, value, doNotReplace){
|
|
2297
|
-
return set(obj, path, value, doNotReplace);
|
|
2298
|
-
};
|
|
2299
|
-
|
|
2300
|
-
objectPath.insert = function (obj, path, value, at){
|
|
2301
|
-
var arr = objectPath.get(obj, path);
|
|
2302
|
-
at = ~~at;
|
|
2303
|
-
if (!isArray(arr)) {
|
|
2304
|
-
arr = [];
|
|
2305
|
-
objectPath.set(obj, path, arr);
|
|
2306
|
-
}
|
|
2307
|
-
arr.splice(at, 0, value);
|
|
2308
|
-
};
|
|
2309
|
-
|
|
2310
|
-
objectPath.empty = function(obj, path) {
|
|
2311
|
-
if (isEmpty(path)) {
|
|
2312
|
-
return void 0;
|
|
2313
|
-
}
|
|
2314
|
-
if (obj == null) {
|
|
2315
|
-
return void 0;
|
|
2316
|
-
}
|
|
2317
|
-
|
|
2318
|
-
var value, i;
|
|
2319
|
-
if (!(value = objectPath.get(obj, path))) {
|
|
2320
|
-
return void 0;
|
|
2321
|
-
}
|
|
2322
|
-
|
|
2323
|
-
if (typeof value === 'string') {
|
|
2324
|
-
return objectPath.set(obj, path, '');
|
|
2325
|
-
} else if (isBoolean(value)) {
|
|
2326
|
-
return objectPath.set(obj, path, false);
|
|
2327
|
-
} else if (typeof value === 'number') {
|
|
2328
|
-
return objectPath.set(obj, path, 0);
|
|
2329
|
-
} else if (isArray(value)) {
|
|
2330
|
-
value.length = 0;
|
|
2331
|
-
} else if (isObject(value)) {
|
|
2332
|
-
for (i in value) {
|
|
2333
|
-
if (hasShallowProperty(value, i)) {
|
|
2334
|
-
delete value[i];
|
|
2335
|
-
}
|
|
2336
|
-
}
|
|
2337
|
-
} else {
|
|
2338
|
-
return objectPath.set(obj, path, null);
|
|
2339
|
-
}
|
|
2340
|
-
};
|
|
2341
|
-
|
|
2342
|
-
objectPath.push = function (obj, path /*, values */){
|
|
2343
|
-
var arr = objectPath.get(obj, path);
|
|
2344
|
-
if (!isArray(arr)) {
|
|
2345
|
-
arr = [];
|
|
2346
|
-
objectPath.set(obj, path, arr);
|
|
2347
|
-
}
|
|
2348
|
-
|
|
2349
|
-
arr.push.apply(arr, Array.prototype.slice.call(arguments, 2));
|
|
2350
|
-
};
|
|
2351
|
-
|
|
2352
|
-
objectPath.coalesce = function (obj, paths, defaultValue) {
|
|
2353
|
-
var value;
|
|
2354
|
-
|
|
2355
|
-
for (var i = 0, len = paths.length; i < len; i++) {
|
|
2356
|
-
if ((value = objectPath.get(obj, paths[i])) !== void 0) {
|
|
2357
|
-
return value;
|
|
2358
|
-
}
|
|
2359
|
-
}
|
|
2360
|
-
|
|
2361
|
-
return defaultValue;
|
|
2362
|
-
};
|
|
2363
|
-
|
|
2364
|
-
objectPath.get = function (obj, path, defaultValue){
|
|
2365
|
-
if (typeof path === 'number') {
|
|
2366
|
-
path = [path];
|
|
2367
|
-
}
|
|
2368
|
-
if (!path || path.length === 0) {
|
|
2369
|
-
return obj;
|
|
2370
|
-
}
|
|
2371
|
-
if (obj == null) {
|
|
2372
|
-
return defaultValue;
|
|
2373
|
-
}
|
|
2374
|
-
if (typeof path === 'string') {
|
|
2375
|
-
return objectPath.get(obj, path.split('.'), defaultValue);
|
|
2376
|
-
}
|
|
2377
|
-
|
|
2378
|
-
var currentPath = getKey(path[0]);
|
|
2379
|
-
var nextObj = getShallowProperty(obj, currentPath);
|
|
2380
|
-
if (nextObj === void 0) {
|
|
2381
|
-
return defaultValue;
|
|
2382
|
-
}
|
|
2383
|
-
|
|
2384
|
-
if (path.length === 1) {
|
|
2385
|
-
return nextObj;
|
|
2386
|
-
}
|
|
2387
|
-
|
|
2388
|
-
return objectPath.get(obj[currentPath], path.slice(1), defaultValue);
|
|
2389
|
-
};
|
|
2390
|
-
|
|
2391
|
-
objectPath.del = function del(obj, path) {
|
|
2392
|
-
if (typeof path === 'number') {
|
|
2393
|
-
path = [path];
|
|
2394
|
-
}
|
|
2395
|
-
|
|
2396
|
-
if (obj == null) {
|
|
2397
|
-
return obj;
|
|
2398
|
-
}
|
|
2399
|
-
|
|
2400
|
-
if (isEmpty(path)) {
|
|
2401
|
-
return obj;
|
|
2402
|
-
}
|
|
2403
|
-
if(typeof path === 'string') {
|
|
2404
|
-
return objectPath.del(obj, path.split('.'));
|
|
2405
|
-
}
|
|
2406
|
-
|
|
2407
|
-
var currentPath = getKey(path[0]);
|
|
2408
|
-
if (!hasShallowProperty(obj, currentPath)) {
|
|
2409
|
-
return obj;
|
|
2410
|
-
}
|
|
2411
|
-
|
|
2412
|
-
if(path.length === 1) {
|
|
2413
|
-
if (isArray(obj)) {
|
|
2414
|
-
obj.splice(currentPath, 1);
|
|
2415
|
-
} else {
|
|
2416
|
-
delete obj[currentPath];
|
|
2417
|
-
}
|
|
2418
|
-
} else {
|
|
2419
|
-
return objectPath.del(obj[currentPath], path.slice(1));
|
|
2420
|
-
}
|
|
2421
|
-
|
|
2422
|
-
return obj;
|
|
2423
|
-
};
|
|
2424
|
-
|
|
2425
|
-
return objectPath;
|
|
2426
|
-
}
|
|
2427
|
-
|
|
2428
|
-
var mod = factory();
|
|
2429
|
-
mod.create = factory;
|
|
2430
|
-
mod.withInheritedProps = factory({includeInheritedProps: true});
|
|
2431
|
-
return mod;
|
|
2432
|
-
});
|
|
2433
|
-
}(objectPath$1));
|
|
2434
|
-
|
|
2435
|
-
var objectPath = objectPath$1.exports;
|
|
2436
|
-
|
|
2437
|
-
/**
|
|
2438
|
-
* @name arrayiffy-if-string
|
|
2439
|
-
* @fileoverview Put non-empty strings into arrays, turn empty-ones into empty arrays. Bypass everything else.
|
|
2440
|
-
* @version 3.14.0
|
|
2441
|
-
* @author Roy Revelt, Codsen Ltd
|
|
2442
|
-
* @license MIT
|
|
2443
|
-
* {@link https://codsen.com/os/arrayiffy-if-string/}
|
|
2444
|
-
*/
|
|
2445
|
-
|
|
2446
|
-
function arrayiffy(something) {
|
|
2447
|
-
if (typeof something === "string") {
|
|
2448
|
-
if (something.length) {
|
|
2449
|
-
return [something];
|
|
2450
|
-
}
|
|
2451
|
-
return [];
|
|
2452
|
-
}
|
|
2453
|
-
return something;
|
|
2454
|
-
}
|
|
2455
|
-
|
|
2456
|
-
/**
|
|
2457
|
-
* @name string-match-left-right
|
|
2458
|
-
* @fileoverview Match substrings on the left or right of a given index, ignoring whitespace
|
|
2459
|
-
* @version 7.1.0
|
|
2460
|
-
* @author Roy Revelt, Codsen Ltd
|
|
2461
|
-
* @license MIT
|
|
2462
|
-
* {@link https://codsen.com/os/string-match-left-right/}
|
|
2463
|
-
*/
|
|
2464
|
-
|
|
2465
|
-
function isObj$2(something) {
|
|
2466
|
-
return something && typeof something === "object" && !Array.isArray(something);
|
|
2467
|
-
}
|
|
2468
|
-
function isStr$3(something) {
|
|
2469
|
-
return typeof something === "string";
|
|
2470
|
-
}
|
|
2471
|
-
const defaults$6 = {
|
|
2472
|
-
cb: undefined,
|
|
2473
|
-
i: false,
|
|
2474
|
-
trimBeforeMatching: false,
|
|
2475
|
-
trimCharsBeforeMatching: [],
|
|
2476
|
-
maxMismatches: 0,
|
|
2477
|
-
firstMustMatch: false,
|
|
2478
|
-
lastMustMatch: false,
|
|
2479
|
-
hungry: false
|
|
2480
|
-
};
|
|
2481
|
-
const defaultGetNextIdx = index => index + 1;
|
|
2482
|
-
function march(str, position, whatToMatchVal, originalOpts, special = false, getNextIdx = defaultGetNextIdx) {
|
|
2483
|
-
const whatToMatchValVal = typeof whatToMatchVal === "function" ? whatToMatchVal() : whatToMatchVal;
|
|
2484
|
-
if (+position < 0 && special && whatToMatchValVal === "EOL") {
|
|
2485
|
-
return whatToMatchValVal;
|
|
2486
|
-
}
|
|
2487
|
-
const opts = { ...defaults$6,
|
|
2488
|
-
...originalOpts
|
|
2489
|
-
};
|
|
2490
|
-
if (position >= str.length && !special) {
|
|
2491
|
-
return false;
|
|
2492
|
-
}
|
|
2493
|
-
let charsToCheckCount = special ? 1 : whatToMatchVal.length;
|
|
2494
|
-
let charsMatchedTotal = 0;
|
|
2495
|
-
let patienceReducedBeforeFirstMatch = false;
|
|
2496
|
-
let lastWasMismatched = false;
|
|
2497
|
-
let atLeastSomethingWasMatched = false;
|
|
2498
|
-
let patience = opts.maxMismatches;
|
|
2499
|
-
let i = position;
|
|
2500
|
-
let somethingFound = false;
|
|
2501
|
-
let firstCharacterMatched = false;
|
|
2502
|
-
let lastCharacterMatched = false;
|
|
2503
|
-
function whitespaceInFrontOfFirstChar() {
|
|
2504
|
-
return (
|
|
2505
|
-
charsMatchedTotal === 1 &&
|
|
2506
|
-
patience < opts.maxMismatches - 1
|
|
2507
|
-
);
|
|
2508
|
-
}
|
|
2509
|
-
while (str[i]) {
|
|
2510
|
-
const nextIdx = getNextIdx(i);
|
|
2511
|
-
if (opts.trimBeforeMatching && str[i].trim() === "") {
|
|
2512
|
-
if (!str[nextIdx] && special && whatToMatchVal === "EOL") {
|
|
2513
|
-
return true;
|
|
2514
|
-
}
|
|
2515
|
-
i = getNextIdx(i);
|
|
2516
|
-
continue;
|
|
2517
|
-
}
|
|
2518
|
-
if (opts && !opts.i && opts.trimCharsBeforeMatching && opts.trimCharsBeforeMatching.includes(str[i]) || opts && opts.i && opts.trimCharsBeforeMatching && opts.trimCharsBeforeMatching.map(val => val.toLowerCase()).includes(str[i].toLowerCase())) {
|
|
2519
|
-
if (special && whatToMatchVal === "EOL" && !str[nextIdx]) {
|
|
2520
|
-
return true;
|
|
2521
|
-
}
|
|
2522
|
-
i = getNextIdx(i);
|
|
2523
|
-
continue;
|
|
2524
|
-
}
|
|
2525
|
-
const charToCompareAgainst = nextIdx > i ? whatToMatchVal[whatToMatchVal.length - charsToCheckCount] : whatToMatchVal[charsToCheckCount - 1];
|
|
2526
|
-
if (!opts.i && str[i] === charToCompareAgainst || opts.i && str[i].toLowerCase() === charToCompareAgainst.toLowerCase()) {
|
|
2527
|
-
if (!somethingFound) {
|
|
2528
|
-
somethingFound = true;
|
|
2529
|
-
}
|
|
2530
|
-
if (!atLeastSomethingWasMatched) {
|
|
2531
|
-
atLeastSomethingWasMatched = true;
|
|
2532
|
-
}
|
|
2533
|
-
if (charsToCheckCount === whatToMatchVal.length) {
|
|
2534
|
-
firstCharacterMatched = true;
|
|
2535
|
-
if (patience !== opts.maxMismatches) {
|
|
2536
|
-
return false;
|
|
2537
|
-
}
|
|
2538
|
-
} else if (charsToCheckCount === 1) {
|
|
2539
|
-
lastCharacterMatched = true;
|
|
2540
|
-
}
|
|
2541
|
-
charsToCheckCount -= 1;
|
|
2542
|
-
charsMatchedTotal++;
|
|
2543
|
-
if (whitespaceInFrontOfFirstChar()) {
|
|
2544
|
-
return false;
|
|
2545
|
-
}
|
|
2546
|
-
if (!charsToCheckCount) {
|
|
2547
|
-
return (
|
|
2548
|
-
charsMatchedTotal !== whatToMatchVal.length ||
|
|
2549
|
-
patience === opts.maxMismatches ||
|
|
2550
|
-
!patienceReducedBeforeFirstMatch ? i : false
|
|
2551
|
-
);
|
|
2552
|
-
}
|
|
2553
|
-
} else {
|
|
2554
|
-
if (!patienceReducedBeforeFirstMatch && !charsMatchedTotal) {
|
|
2555
|
-
patienceReducedBeforeFirstMatch = true;
|
|
2556
|
-
}
|
|
2557
|
-
if (opts.maxMismatches && patience && i) {
|
|
2558
|
-
patience -= 1;
|
|
2559
|
-
for (let y = 0; y <= patience; y++) {
|
|
2560
|
-
const nextCharToCompareAgainst = nextIdx > i ? whatToMatchVal[whatToMatchVal.length - charsToCheckCount + 1 + y] : whatToMatchVal[charsToCheckCount - 2 - y];
|
|
2561
|
-
const nextCharInSource = str[getNextIdx(i)];
|
|
2562
|
-
if (nextCharToCompareAgainst && (!opts.i && str[i] === nextCharToCompareAgainst || opts.i && str[i].toLowerCase() === nextCharToCompareAgainst.toLowerCase()) && (
|
|
2563
|
-
!opts.firstMustMatch || charsToCheckCount !== whatToMatchVal.length)) {
|
|
2564
|
-
charsMatchedTotal++;
|
|
2565
|
-
if (whitespaceInFrontOfFirstChar()) {
|
|
2566
|
-
return false;
|
|
2567
|
-
}
|
|
2568
|
-
charsToCheckCount -= 2;
|
|
2569
|
-
somethingFound = true;
|
|
2570
|
-
break;
|
|
2571
|
-
} else if (nextCharInSource && nextCharToCompareAgainst && (!opts.i && nextCharInSource === nextCharToCompareAgainst || opts.i && nextCharInSource.toLowerCase() === nextCharToCompareAgainst.toLowerCase()) && (
|
|
2572
|
-
!opts.firstMustMatch || charsToCheckCount !== whatToMatchVal.length)) {
|
|
2573
|
-
if (!charsMatchedTotal && !opts.hungry) {
|
|
2574
|
-
return false;
|
|
2575
|
-
}
|
|
2576
|
-
charsToCheckCount -= 1;
|
|
2577
|
-
somethingFound = true;
|
|
2578
|
-
break;
|
|
2579
|
-
} else if (nextCharToCompareAgainst === undefined && patience >= 0 && somethingFound && (!opts.firstMustMatch || firstCharacterMatched) && (!opts.lastMustMatch || lastCharacterMatched)) {
|
|
2580
|
-
return i;
|
|
2581
|
-
}
|
|
2582
|
-
}
|
|
2583
|
-
if (!somethingFound) {
|
|
2584
|
-
lastWasMismatched = i;
|
|
2585
|
-
}
|
|
2586
|
-
} else if (i === 0 && charsToCheckCount === 1 && !opts.lastMustMatch && atLeastSomethingWasMatched) {
|
|
2587
|
-
return 0;
|
|
2588
|
-
} else {
|
|
2589
|
-
return false;
|
|
2590
|
-
}
|
|
2591
|
-
}
|
|
2592
|
-
if (lastWasMismatched !== false && lastWasMismatched !== i) {
|
|
2593
|
-
lastWasMismatched = false;
|
|
2594
|
-
}
|
|
2595
|
-
if (charsToCheckCount < 1) {
|
|
2596
|
-
return i;
|
|
2597
|
-
}
|
|
2598
|
-
i = getNextIdx(i);
|
|
2599
|
-
}
|
|
2600
|
-
if (charsToCheckCount > 0) {
|
|
2601
|
-
if (special && whatToMatchValVal === "EOL") {
|
|
2602
|
-
return true;
|
|
2603
|
-
}
|
|
2604
|
-
if (opts && opts.maxMismatches >= charsToCheckCount && atLeastSomethingWasMatched) {
|
|
2605
|
-
return lastWasMismatched || 0;
|
|
2606
|
-
}
|
|
2607
|
-
return false;
|
|
2608
|
-
}
|
|
2609
|
-
}
|
|
2610
|
-
function main(mode, str, position, originalWhatToMatch, originalOpts) {
|
|
2611
|
-
if (isObj$2(originalOpts) && Object.prototype.hasOwnProperty.call(originalOpts, "trimBeforeMatching") && typeof originalOpts.trimBeforeMatching !== "boolean") {
|
|
2612
|
-
throw new Error(`string-match-left-right/${mode}(): [THROW_ID_09] opts.trimBeforeMatching should be boolean!${Array.isArray(originalOpts.trimBeforeMatching) ? ` Did you mean to use opts.trimCharsBeforeMatching?` : ""}`);
|
|
2613
|
-
}
|
|
2614
|
-
const opts = { ...defaults$6,
|
|
2615
|
-
...originalOpts
|
|
2616
|
-
};
|
|
2617
|
-
if (typeof opts.trimCharsBeforeMatching === "string") {
|
|
2618
|
-
opts.trimCharsBeforeMatching = arrayiffy(opts.trimCharsBeforeMatching);
|
|
2619
|
-
}
|
|
2620
|
-
opts.trimCharsBeforeMatching = opts.trimCharsBeforeMatching.map(el => isStr$3(el) ? el : String(el));
|
|
2621
|
-
if (!isStr$3(str)) {
|
|
2622
|
-
return false;
|
|
2623
|
-
}
|
|
2624
|
-
if (!str.length) {
|
|
2625
|
-
return false;
|
|
2626
|
-
}
|
|
2627
|
-
if (!Number.isInteger(position) || position < 0) {
|
|
2628
|
-
throw new Error(`string-match-left-right/${mode}(): [THROW_ID_03] the second argument should be a natural number. Currently it's of a type: ${typeof position}, equal to:\n${JSON.stringify(position, null, 4)}`);
|
|
2629
|
-
}
|
|
2630
|
-
let whatToMatch;
|
|
2631
|
-
let special;
|
|
2632
|
-
if (isStr$3(originalWhatToMatch)) {
|
|
2633
|
-
whatToMatch = [originalWhatToMatch];
|
|
2634
|
-
} else if (Array.isArray(originalWhatToMatch)) {
|
|
2635
|
-
whatToMatch = originalWhatToMatch;
|
|
2636
|
-
} else if (!originalWhatToMatch) {
|
|
2637
|
-
whatToMatch = originalWhatToMatch;
|
|
2638
|
-
} else if (typeof originalWhatToMatch === "function") {
|
|
2639
|
-
whatToMatch = [];
|
|
2640
|
-
whatToMatch.push(originalWhatToMatch);
|
|
2641
|
-
} else {
|
|
2642
|
-
throw new Error(`string-match-left-right/${mode}(): [THROW_ID_05] the third argument, whatToMatch, is neither string nor array of strings! It's ${typeof originalWhatToMatch}, equal to:\n${JSON.stringify(originalWhatToMatch, null, 4)}`);
|
|
2643
|
-
}
|
|
2644
|
-
if (originalOpts && !isObj$2(originalOpts)) {
|
|
2645
|
-
throw new Error(`string-match-left-right/${mode}(): [THROW_ID_06] the fourth argument, options object, should be a plain object. Currently it's of a type "${typeof originalOpts}", and equal to:\n${JSON.stringify(originalOpts, null, 4)}`);
|
|
2646
|
-
}
|
|
2647
|
-
let culpritsIndex = 0;
|
|
2648
|
-
let culpritsVal = "";
|
|
2649
|
-
if (opts && opts.trimCharsBeforeMatching && opts.trimCharsBeforeMatching.some((el, i) => {
|
|
2650
|
-
if (el.length > 1) {
|
|
2651
|
-
culpritsIndex = i;
|
|
2652
|
-
culpritsVal = el;
|
|
2653
|
-
return true;
|
|
2654
|
-
}
|
|
2655
|
-
return false;
|
|
2656
|
-
})) {
|
|
2657
|
-
throw new Error(`string-match-left-right/${mode}(): [THROW_ID_07] the fourth argument, options object contains trimCharsBeforeMatching. It was meant to list the single characters but one of the entries at index ${culpritsIndex} is longer than 1 character, ${culpritsVal.length} (equals to ${culpritsVal}). Please split it into separate characters and put into array as separate elements.`);
|
|
2658
|
-
}
|
|
2659
|
-
if (!whatToMatch || !Array.isArray(whatToMatch) ||
|
|
2660
|
-
Array.isArray(whatToMatch) && !whatToMatch.length ||
|
|
2661
|
-
Array.isArray(whatToMatch) && whatToMatch.length === 1 && isStr$3(whatToMatch[0]) && !whatToMatch[0].trim()
|
|
2662
|
-
) {
|
|
2663
|
-
if (typeof opts.cb === "function") {
|
|
2664
|
-
let firstCharOutsideIndex;
|
|
2665
|
-
let startingPosition = position;
|
|
2666
|
-
if (mode === "matchLeftIncl" || mode === "matchRight") {
|
|
2667
|
-
startingPosition += 1;
|
|
2668
|
-
}
|
|
2669
|
-
if (mode[5] === "L") {
|
|
2670
|
-
for (let y = startingPosition; y--;) {
|
|
2671
|
-
const currentChar = str[y];
|
|
2672
|
-
if ((!opts.trimBeforeMatching || opts.trimBeforeMatching && currentChar !== undefined && currentChar.trim()) && (!opts.trimCharsBeforeMatching || !opts.trimCharsBeforeMatching.length || currentChar !== undefined && !opts.trimCharsBeforeMatching.includes(currentChar))) {
|
|
2673
|
-
firstCharOutsideIndex = y;
|
|
2674
|
-
break;
|
|
2675
|
-
}
|
|
2676
|
-
}
|
|
2677
|
-
} else if (mode.startsWith("matchRight")) {
|
|
2678
|
-
for (let y = startingPosition; y < str.length; y++) {
|
|
2679
|
-
const currentChar = str[y];
|
|
2680
|
-
if ((!opts.trimBeforeMatching || opts.trimBeforeMatching && currentChar.trim()) && (!opts.trimCharsBeforeMatching || !opts.trimCharsBeforeMatching.length || !opts.trimCharsBeforeMatching.includes(currentChar))) {
|
|
2681
|
-
firstCharOutsideIndex = y;
|
|
2682
|
-
break;
|
|
2683
|
-
}
|
|
2684
|
-
}
|
|
2685
|
-
}
|
|
2686
|
-
if (firstCharOutsideIndex === undefined) {
|
|
2687
|
-
return false;
|
|
2688
|
-
}
|
|
2689
|
-
const wholeCharacterOutside = str[firstCharOutsideIndex];
|
|
2690
|
-
const indexOfTheCharacterAfter = firstCharOutsideIndex + 1;
|
|
2691
|
-
let theRemainderOfTheString = "";
|
|
2692
|
-
if (indexOfTheCharacterAfter && indexOfTheCharacterAfter > 0) {
|
|
2693
|
-
theRemainderOfTheString = str.slice(0, indexOfTheCharacterAfter);
|
|
2694
|
-
}
|
|
2695
|
-
if (mode[5] === "L") {
|
|
2696
|
-
return opts.cb(wholeCharacterOutside, theRemainderOfTheString, firstCharOutsideIndex);
|
|
2697
|
-
}
|
|
2698
|
-
if (firstCharOutsideIndex && firstCharOutsideIndex > 0) {
|
|
2699
|
-
theRemainderOfTheString = str.slice(firstCharOutsideIndex);
|
|
2700
|
-
}
|
|
2701
|
-
return opts.cb(wholeCharacterOutside, theRemainderOfTheString, firstCharOutsideIndex);
|
|
2702
|
-
}
|
|
2703
|
-
let extraNote = "";
|
|
2704
|
-
if (!originalOpts) {
|
|
2705
|
-
extraNote = " More so, the whole options object, the fourth input argument, is missing!";
|
|
2706
|
-
}
|
|
2707
|
-
throw new Error(`string-match-left-right/${mode}(): [THROW_ID_08] the third argument, "whatToMatch", was given as an empty string. This means, you intend to match purely by a callback. The callback was not set though, the opts key "cb" is not set!${extraNote}`);
|
|
2708
|
-
}
|
|
2709
|
-
for (let i = 0, len = whatToMatch.length; i < len; i++) {
|
|
2710
|
-
special = typeof whatToMatch[i] === "function";
|
|
2711
|
-
const whatToMatchVal = whatToMatch[i];
|
|
2712
|
-
let fullCharacterInFront;
|
|
2713
|
-
let indexOfTheCharacterInFront;
|
|
2714
|
-
let restOfStringInFront = "";
|
|
2715
|
-
let startingPosition = position;
|
|
2716
|
-
if (mode === "matchRight") {
|
|
2717
|
-
startingPosition += 1;
|
|
2718
|
-
} else if (mode === "matchLeft") {
|
|
2719
|
-
startingPosition -= 1;
|
|
2720
|
-
}
|
|
2721
|
-
const found = march(str, startingPosition, whatToMatchVal, opts, special, i2 => mode[5] === "L" ? i2 - 1 : i2 + 1);
|
|
2722
|
-
if (found && special && typeof whatToMatchVal === "function" && whatToMatchVal() === "EOL") {
|
|
2723
|
-
return whatToMatchVal() && (opts.cb ? opts.cb(fullCharacterInFront, restOfStringInFront, indexOfTheCharacterInFront) : true) ? whatToMatchVal() : false;
|
|
2724
|
-
}
|
|
2725
|
-
if (Number.isInteger(found)) {
|
|
2726
|
-
indexOfTheCharacterInFront = mode.startsWith("matchLeft") ? found - 1 : found + 1;
|
|
2727
|
-
if (mode[5] === "L") {
|
|
2728
|
-
restOfStringInFront = str.slice(0, found);
|
|
2729
|
-
} else {
|
|
2730
|
-
restOfStringInFront = str.slice(indexOfTheCharacterInFront);
|
|
2731
|
-
}
|
|
2732
|
-
}
|
|
2733
|
-
if (indexOfTheCharacterInFront < 0) {
|
|
2734
|
-
indexOfTheCharacterInFront = undefined;
|
|
2735
|
-
}
|
|
2736
|
-
if (str[indexOfTheCharacterInFront]) {
|
|
2737
|
-
fullCharacterInFront = str[indexOfTheCharacterInFront];
|
|
2738
|
-
}
|
|
2739
|
-
if (Number.isInteger(found) && (opts.cb ? opts.cb(fullCharacterInFront, restOfStringInFront, indexOfTheCharacterInFront) : true)) {
|
|
2740
|
-
return whatToMatchVal;
|
|
2741
|
-
}
|
|
2742
|
-
}
|
|
2743
|
-
return false;
|
|
2744
|
-
}
|
|
2745
|
-
function matchLeftIncl(str, position, whatToMatch, opts) {
|
|
2746
|
-
return main("matchLeftIncl", str, position, whatToMatch, opts);
|
|
2747
|
-
}
|
|
2748
|
-
function matchRightIncl(str, position, whatToMatch, opts) {
|
|
2749
|
-
return main("matchRightIncl", str, position, whatToMatch, opts);
|
|
2750
|
-
}
|
|
2751
|
-
|
|
2752
|
-
/**
|
|
2753
|
-
* @name string-find-heads-tails
|
|
2754
|
-
* @fileoverview Finds where are arbitrary templating marker heads and tails located
|
|
2755
|
-
* @version 4.1.0
|
|
2756
|
-
* @author Roy Revelt, Codsen Ltd
|
|
2757
|
-
* @license MIT
|
|
2758
|
-
* {@link https://codsen.com/os/string-find-heads-tails/}
|
|
2759
|
-
*/
|
|
2760
|
-
function isObj$1(something) {
|
|
2761
|
-
return something && typeof something === "object" && !Array.isArray(something);
|
|
2762
|
-
}
|
|
2763
|
-
function isStr$2(something) {
|
|
2764
|
-
return typeof something === "string";
|
|
2765
|
-
}
|
|
2766
|
-
const defaults$5 = {
|
|
2767
|
-
fromIndex: 0,
|
|
2768
|
-
throwWhenSomethingWrongIsDetected: true,
|
|
2769
|
-
allowWholeValueToBeOnlyHeadsOrTails: true,
|
|
2770
|
-
source: "string-find-heads-tails",
|
|
2771
|
-
matchHeadsAndTailsStrictlyInPairsByTheirOrder: false,
|
|
2772
|
-
relaxedAPI: false
|
|
2773
|
-
};
|
|
2774
|
-
function strFindHeadsTails(str, heads, tails, originalOpts) {
|
|
2775
|
-
if (originalOpts && !isObj$1(originalOpts)) {
|
|
2776
|
-
throw new TypeError(`string-find-heads-tails: [THROW_ID_01] the fourth input argument, an Optional Options Object, must be a plain object! Currently it's equal to: ${originalOpts} (type: ${typeof originalOpts})`);
|
|
2777
|
-
}
|
|
2778
|
-
const opts = { ...defaults$5,
|
|
2779
|
-
...originalOpts
|
|
2780
|
-
};
|
|
2781
|
-
if (typeof opts.fromIndex === "string" && /^\d*$/.test(opts.fromIndex)) {
|
|
2782
|
-
opts.fromIndex = Number(opts.fromIndex);
|
|
2783
|
-
} else if (!Number.isInteger(opts.fromIndex) || opts.fromIndex < 0) {
|
|
2784
|
-
throw new TypeError(`${opts.source} [THROW_ID_18] the fourth input argument must be a natural number or zero! Currently it's: ${opts.fromIndex}`);
|
|
2785
|
-
}
|
|
2786
|
-
if (!isStr$2(str) || str.length === 0) {
|
|
2787
|
-
if (opts.relaxedAPI) {
|
|
2788
|
-
return [];
|
|
2789
|
-
}
|
|
2790
|
-
throw new TypeError(`string-find-heads-tails: [THROW_ID_02] the first input argument, input string, must be a non-zero-length string! Currently it's: ${typeof str}, equal to: ${str}`);
|
|
2791
|
-
}
|
|
2792
|
-
let culpritsVal;
|
|
2793
|
-
let culpritsIndex;
|
|
2794
|
-
if (typeof heads !== "string" && !Array.isArray(heads)) {
|
|
2795
|
-
if (opts.relaxedAPI) {
|
|
2796
|
-
return [];
|
|
2797
|
-
}
|
|
2798
|
-
throw new TypeError(`string-find-heads-tails: [THROW_ID_03] the second input argument, heads, must be either a string or an array of strings! Currently it's: ${typeof heads}, equal to:\n${JSON.stringify(heads, null, 4)}`);
|
|
2799
|
-
} else if (typeof heads === "string") {
|
|
2800
|
-
if (heads.length === 0) {
|
|
2801
|
-
if (opts.relaxedAPI) {
|
|
2802
|
-
return [];
|
|
2803
|
-
}
|
|
2804
|
-
throw new TypeError("string-find-heads-tails: [THROW_ID_04] the second input argument, heads, must be a non-empty string! Currently it's empty.");
|
|
2805
|
-
} else {
|
|
2806
|
-
heads = arrayiffy(heads);
|
|
2807
|
-
}
|
|
2808
|
-
} else if (Array.isArray(heads)) {
|
|
2809
|
-
if (heads.length === 0) {
|
|
2810
|
-
if (opts.relaxedAPI) {
|
|
2811
|
-
return [];
|
|
2812
|
-
}
|
|
2813
|
-
throw new TypeError("string-find-heads-tails: [THROW_ID_05] the second input argument, heads, must be a non-empty array and contain at least one string! Currently it's empty.");
|
|
2814
|
-
} else if (!heads.every((val, index) => {
|
|
2815
|
-
culpritsVal = val;
|
|
2816
|
-
culpritsIndex = index;
|
|
2817
|
-
return isStr$2(val);
|
|
2818
|
-
})) {
|
|
2819
|
-
if (opts.relaxedAPI) {
|
|
2820
|
-
heads = heads.filter(el => isStr$2(el) && el.length > 0);
|
|
2821
|
-
if (heads.length === 0) {
|
|
2822
|
-
return [];
|
|
2823
|
-
}
|
|
2824
|
-
} else {
|
|
2825
|
-
throw new TypeError(`string-find-heads-tails: [THROW_ID_06] the second input argument, heads, contains non-string elements! For example, element at ${culpritsIndex}th index is ${typeof culpritsVal}, equal to:\n${JSON.stringify(culpritsVal, null, 4)}. Whole heads array looks like:\n${JSON.stringify(heads, null, 4)}`);
|
|
2826
|
-
}
|
|
2827
|
-
} else if (!heads.every((val, index) => {
|
|
2828
|
-
culpritsIndex = index;
|
|
2829
|
-
return isStr$2(val) && val.length > 0 && val.trim() !== "";
|
|
2830
|
-
})) {
|
|
2831
|
-
if (opts.relaxedAPI) {
|
|
2832
|
-
heads = heads.filter(el => isStr$2(el) && el.length > 0);
|
|
2833
|
-
if (heads.length === 0) {
|
|
2834
|
-
return [];
|
|
2835
|
-
}
|
|
2836
|
-
} else {
|
|
2837
|
-
throw new TypeError(`string-find-heads-tails: [THROW_ID_07] the second input argument, heads, should not contain empty strings! For example, there's one detected at index ${culpritsIndex} of heads array:\n${JSON.stringify(heads, null, 4)}.`);
|
|
2838
|
-
}
|
|
2839
|
-
}
|
|
2840
|
-
}
|
|
2841
|
-
if (!isStr$2(tails) && !Array.isArray(tails)) {
|
|
2842
|
-
if (opts.relaxedAPI) {
|
|
2843
|
-
return [];
|
|
2844
|
-
}
|
|
2845
|
-
throw new TypeError(`string-find-heads-tails: [THROW_ID_08] the third input argument, tails, must be either a string or an array of strings! Currently it's: ${typeof tails}, equal to:\n${JSON.stringify(tails, null, 4)}`);
|
|
2846
|
-
} else if (isStr$2(tails)) {
|
|
2847
|
-
if (tails.length === 0) {
|
|
2848
|
-
if (opts.relaxedAPI) {
|
|
2849
|
-
return [];
|
|
2850
|
-
}
|
|
2851
|
-
throw new TypeError("string-find-heads-tails: [THROW_ID_09] the third input argument, tails, must be a non-empty string! Currently it's empty.");
|
|
2852
|
-
} else {
|
|
2853
|
-
tails = arrayiffy(tails);
|
|
2854
|
-
}
|
|
2855
|
-
} else if (Array.isArray(tails)) {
|
|
2856
|
-
if (tails.length === 0) {
|
|
2857
|
-
if (opts.relaxedAPI) {
|
|
2858
|
-
return [];
|
|
2859
|
-
}
|
|
2860
|
-
throw new TypeError("string-find-heads-tails: [THROW_ID_10] the third input argument, tails, must be a non-empty array and contain at least one string! Currently it's empty.");
|
|
2861
|
-
} else if (!tails.every((val, index) => {
|
|
2862
|
-
culpritsVal = val;
|
|
2863
|
-
culpritsIndex = index;
|
|
2864
|
-
return isStr$2(val);
|
|
2865
|
-
})) {
|
|
2866
|
-
if (opts.relaxedAPI) {
|
|
2867
|
-
tails = tails.filter(el => isStr$2(el) && el.length > 0);
|
|
2868
|
-
if (tails.length === 0) {
|
|
2869
|
-
return [];
|
|
2870
|
-
}
|
|
2871
|
-
} else {
|
|
2872
|
-
throw new TypeError(`string-find-heads-tails: [THROW_ID_11] the third input argument, tails, contains non-string elements! For example, element at ${culpritsIndex}th index is ${typeof culpritsVal}, equal to:\n${JSON.stringify(culpritsVal, null, 4)}. Whole tails array is equal to:\n${JSON.stringify(tails, null, 4)}`);
|
|
2873
|
-
}
|
|
2874
|
-
} else if (!tails.every((val, index) => {
|
|
2875
|
-
culpritsIndex = index;
|
|
2876
|
-
return isStr$2(val) && val.length > 0 && val.trim() !== "";
|
|
2877
|
-
})) {
|
|
2878
|
-
if (opts.relaxedAPI) {
|
|
2879
|
-
tails = tails.filter(el => isStr$2(el) && el.length > 0);
|
|
2880
|
-
if (tails.length === 0) {
|
|
2881
|
-
return [];
|
|
2882
|
-
}
|
|
2883
|
-
} else {
|
|
2884
|
-
throw new TypeError(`string-find-heads-tails: [THROW_ID_12] the third input argument, tails, should not contain empty strings! For example, there's one detected at index ${culpritsIndex}. Whole tails array is equal to:\n${JSON.stringify(tails, null, 4)}`);
|
|
2885
|
-
}
|
|
2886
|
-
}
|
|
2887
|
-
}
|
|
2888
|
-
const s = opts.source === defaults$5.source;
|
|
2889
|
-
if (opts.throwWhenSomethingWrongIsDetected && !opts.allowWholeValueToBeOnlyHeadsOrTails) {
|
|
2890
|
-
if (arrayiffy(heads).includes(str)) {
|
|
2891
|
-
throw new Error(`${opts.source}${s ? ": [THROW_ID_16]" : ""} the whole input string can't be equal to ${isStr$2(heads) ? "" : "one of "}heads (${str})!`);
|
|
2892
|
-
} else if (arrayiffy(tails).includes(str)) {
|
|
2893
|
-
throw new Error(`${opts.source}${s ? ": [THROW_ID_17]" : ""} the whole input string can't be equal to ${isStr$2(tails) ? "" : "one of "}tails (${str})!`);
|
|
2894
|
-
}
|
|
2895
|
-
}
|
|
2896
|
-
const headsAndTailsFirstCharIndexesRange = heads.concat(tails).map(value => value.charAt(0))
|
|
2897
|
-
.reduce((res, val) => {
|
|
2898
|
-
if (val.charCodeAt(0) > res[1]) {
|
|
2899
|
-
return [res[0], val.charCodeAt(0)];
|
|
2900
|
-
}
|
|
2901
|
-
if (val.charCodeAt(0) < res[0]) {
|
|
2902
|
-
return [val.charCodeAt(0), res[1]];
|
|
2903
|
-
}
|
|
2904
|
-
return res;
|
|
2905
|
-
}, [heads[0].charCodeAt(0), heads[0].charCodeAt(0)]);
|
|
2906
|
-
const res = [];
|
|
2907
|
-
let oneHeadFound = false;
|
|
2908
|
-
let tempResObj = {};
|
|
2909
|
-
let tailSuspicionRaised = "";
|
|
2910
|
-
let strictMatchingIndex;
|
|
2911
|
-
for (let i = opts.fromIndex, len = str.length; i < len; i++) {
|
|
2912
|
-
const firstCharsIndex = str[i].charCodeAt(0);
|
|
2913
|
-
if (firstCharsIndex <= headsAndTailsFirstCharIndexesRange[1] && firstCharsIndex >= headsAndTailsFirstCharIndexesRange[0]) {
|
|
2914
|
-
const matchedHeads = matchRightIncl(str, i, heads);
|
|
2915
|
-
if (matchedHeads && opts.matchHeadsAndTailsStrictlyInPairsByTheirOrder) {
|
|
2916
|
-
for (let z = heads.length; z--;) {
|
|
2917
|
-
if (heads[z] === matchedHeads) {
|
|
2918
|
-
strictMatchingIndex = z;
|
|
2919
|
-
break;
|
|
2920
|
-
}
|
|
2921
|
-
}
|
|
2922
|
-
}
|
|
2923
|
-
if (typeof matchedHeads === "string") {
|
|
2924
|
-
if (!oneHeadFound) {
|
|
2925
|
-
tempResObj = {};
|
|
2926
|
-
tempResObj.headsStartAt = i;
|
|
2927
|
-
tempResObj.headsEndAt = i + matchedHeads.length;
|
|
2928
|
-
oneHeadFound = true;
|
|
2929
|
-
i += matchedHeads.length - 1;
|
|
2930
|
-
if (tailSuspicionRaised) {
|
|
2931
|
-
tailSuspicionRaised = "";
|
|
2932
|
-
}
|
|
2933
|
-
continue;
|
|
2934
|
-
} else if (opts.throwWhenSomethingWrongIsDetected) {
|
|
2935
|
-
throw new TypeError(`${opts.source}${s ? ": [THROW_ID_19]" : ""} When processing "${str}", we found heads (${str.slice(i, i + matchedHeads.length)}) starting at character with index number "${i}" and there was another set of heads before it! Generally speaking, there should be "heads-tails-heads-tails", not "heads-heads-tails"!\nWe're talking about the area of the code:\n\n\n--------------------------------------starts\n${str.slice(Math.max(i - 200, 0), i)}\n ${`\u001b[${33}m------->\u001b[${39}m`} ${`\u001b[${31}m${str.slice(i, i + matchedHeads.length)}\u001b[${39}m`} \u001b[${33}m${"<-------"}\u001b[${39}m\n${str.slice(i + matchedHeads.length, Math.min(len, i + 200))}\n--------------------------------------ends\n\n\nTo turn off this error being thrown, set opts.throwWhenSomethingWrongIsDetected to Boolean false.`);
|
|
2936
|
-
}
|
|
2937
|
-
}
|
|
2938
|
-
const matchedTails = matchRightIncl(str, i, tails);
|
|
2939
|
-
if (oneHeadFound && matchedTails && opts.matchHeadsAndTailsStrictlyInPairsByTheirOrder && strictMatchingIndex !== undefined && tails[strictMatchingIndex] !== undefined && tails[strictMatchingIndex] !== matchedTails) {
|
|
2940
|
-
let temp;
|
|
2941
|
-
for (let z = tails.length; z--;) {
|
|
2942
|
-
if (tails[z] === matchedTails) {
|
|
2943
|
-
temp = z;
|
|
2944
|
-
break;
|
|
2945
|
-
}
|
|
2946
|
-
}
|
|
2947
|
-
throw new TypeError(`${opts.source}${s ? ": [THROW_ID_20]" : ""} When processing "${str}", we had "opts.matchHeadsAndTailsStrictlyInPairsByTheirOrder" on. We found heads (${heads[strictMatchingIndex]}) but the tails the followed it were not of the same index, ${strictMatchingIndex} (${tails[strictMatchingIndex]}) but ${temp} (${matchedTails}).`);
|
|
2948
|
-
}
|
|
2949
|
-
if (typeof matchedTails === "string") {
|
|
2950
|
-
if (oneHeadFound) {
|
|
2951
|
-
tempResObj.tailsStartAt = i;
|
|
2952
|
-
tempResObj.tailsEndAt = i + matchedTails.length;
|
|
2953
|
-
res.push(tempResObj);
|
|
2954
|
-
tempResObj = {};
|
|
2955
|
-
oneHeadFound = false;
|
|
2956
|
-
i += matchedTails.length - 1;
|
|
2957
|
-
continue;
|
|
2958
|
-
} else if (opts.throwWhenSomethingWrongIsDetected) {
|
|
2959
|
-
tailSuspicionRaised = `${opts.source}${s ? ": [THROW_ID_21]" : ""} When processing "${str}", we found tails (${str.slice(i, i + matchedTails.length)}) starting at character with index number "${i}" but there were no heads preceding it. That's very naughty!`;
|
|
2960
|
-
}
|
|
2961
|
-
}
|
|
2962
|
-
}
|
|
2963
|
-
if (opts.throwWhenSomethingWrongIsDetected && i === len - 1) {
|
|
2964
|
-
if (Object.keys(tempResObj).length !== 0) {
|
|
2965
|
-
throw new TypeError(`${opts.source}${s ? ": [THROW_ID_22]" : ""} When processing "${str}", we reached the end of the string and yet didn't find any tails (${JSON.stringify(tails, null, 4)}) to match the last detected heads (${str.slice(tempResObj.headsStartAt, tempResObj.headsEndAt)})!`);
|
|
2966
|
-
} else if (tailSuspicionRaised) {
|
|
2967
|
-
throw new Error(tailSuspicionRaised);
|
|
2968
|
-
}
|
|
2969
|
-
}
|
|
2970
|
-
}
|
|
2971
|
-
return res;
|
|
2972
|
-
}
|
|
2973
|
-
|
|
2974
|
-
/**
|
|
2975
|
-
* @name ast-get-values-by-key
|
|
2976
|
-
* @fileoverview Extract values and paths from AST by keys OR set them by keys
|
|
2977
|
-
* @version 3.1.0
|
|
2978
|
-
* @author Roy Revelt, Codsen Ltd
|
|
2979
|
-
* @license MIT
|
|
2980
|
-
* {@link https://codsen.com/os/ast-get-values-by-key/}
|
|
2981
|
-
*/
|
|
2982
|
-
function getByKey(originalInput, whatToFind, originalReplacement) {
|
|
2983
|
-
let replacement;
|
|
2984
|
-
if (originalReplacement !== undefined) {
|
|
2985
|
-
replacement = Array.isArray(originalReplacement) ? clone(originalReplacement) : [clone(originalReplacement)];
|
|
2986
|
-
}
|
|
2987
|
-
const findings = [];
|
|
2988
|
-
const amended = traverse(originalInput, (key, val, innerObj) => {
|
|
2989
|
-
const current = val !== undefined ? val : key;
|
|
2990
|
-
if (val !== undefined && matcher.isMatch(key, whatToFind, {
|
|
2991
|
-
caseSensitive: true
|
|
2992
|
-
})) {
|
|
2993
|
-
if (replacement === undefined) {
|
|
2994
|
-
findings.push({
|
|
2995
|
-
val,
|
|
2996
|
-
path: innerObj.path
|
|
2997
|
-
});
|
|
2998
|
-
} else if (replacement.length) {
|
|
2999
|
-
return replacement.shift();
|
|
3000
|
-
}
|
|
3001
|
-
}
|
|
3002
|
-
return current;
|
|
3003
|
-
});
|
|
3004
|
-
return replacement === undefined ? findings : amended;
|
|
3005
|
-
}
|
|
3006
|
-
|
|
3007
|
-
/**
|
|
3008
|
-
* @name string-collapse-leading-whitespace
|
|
3009
|
-
* @fileoverview Collapse the leading and trailing whitespace of a string
|
|
3010
|
-
* @version 5.1.0
|
|
3011
|
-
* @author Roy Revelt, Codsen Ltd
|
|
3012
|
-
* @license MIT
|
|
3013
|
-
* {@link https://codsen.com/os/string-collapse-leading-whitespace/}
|
|
3014
|
-
*/
|
|
3015
|
-
function collWhitespace(str, originallineBreakLimit = 1) {
|
|
3016
|
-
const rawNbsp = "\u00A0";
|
|
3017
|
-
function reverse(s) {
|
|
3018
|
-
return Array.from(s).reverse().join("");
|
|
3019
|
-
}
|
|
3020
|
-
function prep(whitespaceChunk, limit, trailing) {
|
|
3021
|
-
const firstBreakChar = trailing ? "\n" : "\r";
|
|
3022
|
-
const secondBreakChar = trailing ? "\r" : "\n";
|
|
3023
|
-
if (!whitespaceChunk) {
|
|
3024
|
-
return whitespaceChunk;
|
|
3025
|
-
}
|
|
3026
|
-
let crlfCount = 0;
|
|
3027
|
-
let res = "";
|
|
3028
|
-
for (let i = 0, len = whitespaceChunk.length; i < len; i++) {
|
|
3029
|
-
if (whitespaceChunk[i] === firstBreakChar || whitespaceChunk[i] === secondBreakChar && whitespaceChunk[i - 1] !== firstBreakChar) {
|
|
3030
|
-
crlfCount++;
|
|
3031
|
-
}
|
|
3032
|
-
if (`\r\n`.includes(whitespaceChunk[i]) || whitespaceChunk[i] === rawNbsp) {
|
|
3033
|
-
if (whitespaceChunk[i] === rawNbsp) {
|
|
3034
|
-
res += whitespaceChunk[i];
|
|
3035
|
-
} else if (whitespaceChunk[i] === firstBreakChar) {
|
|
3036
|
-
if (crlfCount <= limit) {
|
|
3037
|
-
res += whitespaceChunk[i];
|
|
3038
|
-
if (whitespaceChunk[i + 1] === secondBreakChar) {
|
|
3039
|
-
res += whitespaceChunk[i + 1];
|
|
3040
|
-
i++;
|
|
3041
|
-
}
|
|
3042
|
-
}
|
|
3043
|
-
} else if (whitespaceChunk[i] === secondBreakChar && (!whitespaceChunk[i - 1] || whitespaceChunk[i - 1] !== firstBreakChar) && crlfCount <= limit) {
|
|
3044
|
-
res += whitespaceChunk[i];
|
|
3045
|
-
}
|
|
3046
|
-
} else {
|
|
3047
|
-
if (!whitespaceChunk[i + 1] && !crlfCount) {
|
|
3048
|
-
res += " ";
|
|
3049
|
-
}
|
|
3050
|
-
}
|
|
3051
|
-
}
|
|
3052
|
-
return res;
|
|
3053
|
-
}
|
|
3054
|
-
if (typeof str === "string" && str.length) {
|
|
3055
|
-
let lineBreakLimit = 1;
|
|
3056
|
-
if (typeof +originallineBreakLimit === "number" && Number.isInteger(+originallineBreakLimit) && +originallineBreakLimit >= 0) {
|
|
3057
|
-
lineBreakLimit = +originallineBreakLimit;
|
|
3058
|
-
}
|
|
3059
|
-
let frontPart = "";
|
|
3060
|
-
let endPart = "";
|
|
3061
|
-
if (!str.trim()) {
|
|
3062
|
-
frontPart = str;
|
|
3063
|
-
} else if (!str[0].trim()) {
|
|
3064
|
-
for (let i = 0, len = str.length; i < len; i++) {
|
|
3065
|
-
if (str[i].trim()) {
|
|
3066
|
-
frontPart = str.slice(0, i);
|
|
3067
|
-
break;
|
|
3068
|
-
}
|
|
3069
|
-
}
|
|
3070
|
-
}
|
|
3071
|
-
if (str.trim() && (str.slice(-1).trim() === "" || str.slice(-1) === rawNbsp)) {
|
|
3072
|
-
for (let i = str.length; i--;) {
|
|
3073
|
-
if (str[i].trim()) {
|
|
3074
|
-
endPart = str.slice(i + 1);
|
|
3075
|
-
break;
|
|
3076
|
-
}
|
|
3077
|
-
}
|
|
3078
|
-
}
|
|
3079
|
-
return `${prep(frontPart, lineBreakLimit, false)}${str.trim()}${reverse(prep(reverse(endPart), lineBreakLimit, true))}`;
|
|
3080
|
-
}
|
|
3081
|
-
return str;
|
|
3082
|
-
}
|
|
3083
|
-
|
|
3084
|
-
/**
|
|
3085
|
-
* @name ranges-sort
|
|
3086
|
-
* @fileoverview Sort string index ranges
|
|
3087
|
-
* @version 4.1.0
|
|
3088
|
-
* @author Roy Revelt, Codsen Ltd
|
|
3089
|
-
* @license MIT
|
|
3090
|
-
* {@link https://codsen.com/os/ranges-sort/}
|
|
3091
|
-
*/
|
|
3092
|
-
const defaults$4 = {
|
|
3093
|
-
strictlyTwoElementsInRangeArrays: false,
|
|
3094
|
-
progressFn: null
|
|
3095
|
-
};
|
|
3096
|
-
function rSort(arrOfRanges, originalOptions) {
|
|
3097
|
-
if (!Array.isArray(arrOfRanges) || !arrOfRanges.length) {
|
|
3098
|
-
return arrOfRanges;
|
|
3099
|
-
}
|
|
3100
|
-
const opts = { ...defaults$4,
|
|
3101
|
-
...originalOptions
|
|
3102
|
-
};
|
|
3103
|
-
let culpritsIndex;
|
|
3104
|
-
let culpritsLen;
|
|
3105
|
-
if (opts.strictlyTwoElementsInRangeArrays && !arrOfRanges.filter(range => range).every((rangeArr, indx) => {
|
|
3106
|
-
if (rangeArr.length !== 2) {
|
|
3107
|
-
culpritsIndex = indx;
|
|
3108
|
-
culpritsLen = rangeArr.length;
|
|
3109
|
-
return false;
|
|
3110
|
-
}
|
|
3111
|
-
return true;
|
|
3112
|
-
})) {
|
|
3113
|
-
throw new TypeError(`ranges-sort: [THROW_ID_03] The first argument should be an array and must consist of arrays which are natural number indexes representing TWO string index ranges. However, ${culpritsIndex}th range (${JSON.stringify(arrOfRanges[culpritsIndex], null, 4)}) has not two but ${culpritsLen} elements!`);
|
|
3114
|
-
}
|
|
3115
|
-
if (!arrOfRanges.filter(range => range).every((rangeArr, indx) => {
|
|
3116
|
-
if (!Number.isInteger(rangeArr[0]) || rangeArr[0] < 0 || !Number.isInteger(rangeArr[1]) || rangeArr[1] < 0) {
|
|
3117
|
-
culpritsIndex = indx;
|
|
3118
|
-
return false;
|
|
3119
|
-
}
|
|
3120
|
-
return true;
|
|
3121
|
-
})) {
|
|
3122
|
-
throw new TypeError(`ranges-sort: [THROW_ID_04] The first argument should be an array and must consist of arrays which are natural number indexes representing string index ranges. However, ${culpritsIndex}th range (${JSON.stringify(arrOfRanges[culpritsIndex], null, 4)}) does not consist of only natural numbers!`);
|
|
3123
|
-
}
|
|
3124
|
-
const maxPossibleIterations = arrOfRanges.filter(range => range).length ** 2;
|
|
3125
|
-
let counter = 0;
|
|
3126
|
-
return Array.from(arrOfRanges).filter(range => range).sort((range1, range2) => {
|
|
3127
|
-
if (opts.progressFn) {
|
|
3128
|
-
counter += 1;
|
|
3129
|
-
opts.progressFn(Math.floor(counter * 100 / maxPossibleIterations));
|
|
3130
|
-
}
|
|
3131
|
-
if (range1[0] === range2[0]) {
|
|
3132
|
-
if (range1[1] < range2[1]) {
|
|
3133
|
-
return -1;
|
|
3134
|
-
}
|
|
3135
|
-
if (range1[1] > range2[1]) {
|
|
3136
|
-
return 1;
|
|
3137
|
-
}
|
|
3138
|
-
return 0;
|
|
3139
|
-
}
|
|
3140
|
-
if (range1[0] < range2[0]) {
|
|
3141
|
-
return -1;
|
|
3142
|
-
}
|
|
3143
|
-
return 1;
|
|
3144
|
-
});
|
|
3145
|
-
}
|
|
3146
|
-
|
|
3147
|
-
/**
|
|
3148
|
-
* @name ranges-merge
|
|
3149
|
-
* @fileoverview Merge and sort string index ranges
|
|
3150
|
-
* @version 7.1.0
|
|
3151
|
-
* @author Roy Revelt, Codsen Ltd
|
|
3152
|
-
* @license MIT
|
|
3153
|
-
* {@link https://codsen.com/os/ranges-merge/}
|
|
3154
|
-
*/
|
|
3155
|
-
const defaults$3 = {
|
|
3156
|
-
mergeType: 1,
|
|
3157
|
-
progressFn: null,
|
|
3158
|
-
joinRangesThatTouchEdges: true
|
|
3159
|
-
};
|
|
3160
|
-
function rMerge(arrOfRanges, originalOpts) {
|
|
3161
|
-
function isObj(something) {
|
|
3162
|
-
return something && typeof something === "object" && !Array.isArray(something);
|
|
3163
|
-
}
|
|
3164
|
-
if (!Array.isArray(arrOfRanges) || !arrOfRanges.length) {
|
|
3165
|
-
return null;
|
|
3166
|
-
}
|
|
3167
|
-
let opts;
|
|
3168
|
-
if (originalOpts) {
|
|
3169
|
-
if (isObj(originalOpts)) {
|
|
3170
|
-
opts = { ...defaults$3,
|
|
3171
|
-
...originalOpts
|
|
3172
|
-
};
|
|
3173
|
-
if (opts.progressFn && isObj(opts.progressFn) && !Object.keys(opts.progressFn).length) {
|
|
3174
|
-
opts.progressFn = null;
|
|
3175
|
-
} else if (opts.progressFn && typeof opts.progressFn !== "function") {
|
|
3176
|
-
throw new Error(`ranges-merge: [THROW_ID_01] opts.progressFn must be a function! It was given of a type: "${typeof opts.progressFn}", equal to ${JSON.stringify(opts.progressFn, null, 4)}`);
|
|
3177
|
-
}
|
|
3178
|
-
if (opts.mergeType && +opts.mergeType !== 1 && +opts.mergeType !== 2) {
|
|
3179
|
-
throw new Error(`ranges-merge: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof opts.mergeType}", equal to ${JSON.stringify(opts.mergeType, null, 4)}`);
|
|
3180
|
-
}
|
|
3181
|
-
if (typeof opts.joinRangesThatTouchEdges !== "boolean") {
|
|
3182
|
-
throw new Error(`ranges-merge: [THROW_ID_04] opts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "${typeof opts.joinRangesThatTouchEdges}", equal to ${JSON.stringify(opts.joinRangesThatTouchEdges, null, 4)}`);
|
|
3183
|
-
}
|
|
3184
|
-
} else {
|
|
3185
|
-
throw new Error(`emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as:\n${JSON.stringify(originalOpts, null, 4)} (type ${typeof originalOpts})`);
|
|
3186
|
-
}
|
|
3187
|
-
} else {
|
|
3188
|
-
opts = { ...defaults$3
|
|
3189
|
-
};
|
|
3190
|
-
}
|
|
3191
|
-
const filtered = arrOfRanges
|
|
3192
|
-
.filter(range => range).map(subarr => [...subarr]).filter(
|
|
3193
|
-
rangeArr => rangeArr[2] !== undefined || rangeArr[0] !== rangeArr[1]);
|
|
3194
|
-
let sortedRanges;
|
|
3195
|
-
let lastPercentageDone;
|
|
3196
|
-
let percentageDone;
|
|
3197
|
-
if (opts.progressFn) {
|
|
3198
|
-
sortedRanges = rSort(filtered, {
|
|
3199
|
-
progressFn: percentage => {
|
|
3200
|
-
percentageDone = Math.floor(percentage / 5);
|
|
3201
|
-
if (percentageDone !== lastPercentageDone) {
|
|
3202
|
-
lastPercentageDone = percentageDone;
|
|
3203
|
-
opts.progressFn(percentageDone);
|
|
3204
|
-
}
|
|
3205
|
-
}
|
|
3206
|
-
});
|
|
3207
|
-
} else {
|
|
3208
|
-
sortedRanges = rSort(filtered);
|
|
3209
|
-
}
|
|
3210
|
-
if (!sortedRanges) {
|
|
3211
|
-
return null;
|
|
3212
|
-
}
|
|
3213
|
-
const len = sortedRanges.length - 1;
|
|
3214
|
-
for (let i = len; i > 0; i--) {
|
|
3215
|
-
if (opts.progressFn) {
|
|
3216
|
-
percentageDone = Math.floor((1 - i / len) * 78) + 21;
|
|
3217
|
-
if (percentageDone !== lastPercentageDone && percentageDone > lastPercentageDone) {
|
|
3218
|
-
lastPercentageDone = percentageDone;
|
|
3219
|
-
opts.progressFn(percentageDone);
|
|
3220
|
-
}
|
|
3221
|
-
}
|
|
3222
|
-
if (sortedRanges[i][0] <= sortedRanges[i - 1][0] || !opts.joinRangesThatTouchEdges && sortedRanges[i][0] < sortedRanges[i - 1][1] || opts.joinRangesThatTouchEdges && sortedRanges[i][0] <= sortedRanges[i - 1][1]) {
|
|
3223
|
-
sortedRanges[i - 1][0] = Math.min(sortedRanges[i][0], sortedRanges[i - 1][0]);
|
|
3224
|
-
sortedRanges[i - 1][1] = Math.max(sortedRanges[i][1], sortedRanges[i - 1][1]);
|
|
3225
|
-
if (sortedRanges[i][2] !== undefined && (sortedRanges[i - 1][0] >= sortedRanges[i][0] || sortedRanges[i - 1][1] <= sortedRanges[i][1])) {
|
|
3226
|
-
if (sortedRanges[i - 1][2] !== null) {
|
|
3227
|
-
if (sortedRanges[i][2] === null && sortedRanges[i - 1][2] !== null) {
|
|
3228
|
-
sortedRanges[i - 1][2] = null;
|
|
3229
|
-
} else if (sortedRanges[i - 1][2] != null) {
|
|
3230
|
-
if (+opts.mergeType === 2 && sortedRanges[i - 1][0] === sortedRanges[i][0]) {
|
|
3231
|
-
sortedRanges[i - 1][2] = sortedRanges[i][2];
|
|
3232
|
-
} else {
|
|
3233
|
-
sortedRanges[i - 1][2] += sortedRanges[i][2];
|
|
3234
|
-
}
|
|
3235
|
-
} else {
|
|
3236
|
-
sortedRanges[i - 1][2] = sortedRanges[i][2];
|
|
3237
|
-
}
|
|
3238
|
-
}
|
|
3239
|
-
}
|
|
3240
|
-
sortedRanges.splice(i, 1);
|
|
3241
|
-
i = sortedRanges.length;
|
|
3242
|
-
}
|
|
3243
|
-
}
|
|
3244
|
-
return sortedRanges.length ? sortedRanges : null;
|
|
3245
|
-
}
|
|
3246
|
-
|
|
3247
|
-
/**
|
|
3248
|
-
* @name ranges-push
|
|
3249
|
-
* @fileoverview Gather string index ranges
|
|
3250
|
-
* @version 5.1.0
|
|
3251
|
-
* @author Roy Revelt, Codsen Ltd
|
|
3252
|
-
* @license MIT
|
|
3253
|
-
* {@link https://codsen.com/os/ranges-push/}
|
|
3254
|
-
*/
|
|
3255
|
-
function existy$1(x) {
|
|
3256
|
-
return x != null;
|
|
3257
|
-
}
|
|
3258
|
-
function isNum$1(something) {
|
|
3259
|
-
return Number.isInteger(something) && something >= 0;
|
|
3260
|
-
}
|
|
3261
|
-
function isStr$1(something) {
|
|
3262
|
-
return typeof something === "string";
|
|
3263
|
-
}
|
|
3264
|
-
const defaults$2 = {
|
|
3265
|
-
limitToBeAddedWhitespace: false,
|
|
3266
|
-
limitLinebreaksCount: 1,
|
|
3267
|
-
mergeType: 1
|
|
3268
|
-
};
|
|
3269
|
-
class Ranges {
|
|
3270
|
-
constructor(originalOpts) {
|
|
3271
|
-
const opts = { ...defaults$2,
|
|
3272
|
-
...originalOpts
|
|
3273
|
-
};
|
|
3274
|
-
if (opts.mergeType && opts.mergeType !== 1 && opts.mergeType !== 2) {
|
|
3275
|
-
if (isStr$1(opts.mergeType) && opts.mergeType.trim() === "1") {
|
|
3276
|
-
opts.mergeType = 1;
|
|
3277
|
-
} else if (isStr$1(opts.mergeType) && opts.mergeType.trim() === "2") {
|
|
3278
|
-
opts.mergeType = 2;
|
|
3279
|
-
} else {
|
|
3280
|
-
throw new Error(`ranges-push: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof opts.mergeType}", equal to ${JSON.stringify(opts.mergeType, null, 4)}`);
|
|
3281
|
-
}
|
|
3282
|
-
}
|
|
3283
|
-
this.opts = opts;
|
|
3284
|
-
this.ranges = [];
|
|
3285
|
-
}
|
|
3286
|
-
add(originalFrom, originalTo, addVal) {
|
|
3287
|
-
if (originalFrom == null && originalTo == null) {
|
|
3288
|
-
return;
|
|
3289
|
-
}
|
|
3290
|
-
if (existy$1(originalFrom) && !existy$1(originalTo)) {
|
|
3291
|
-
if (Array.isArray(originalFrom)) {
|
|
3292
|
-
if (originalFrom.length) {
|
|
3293
|
-
if (originalFrom.some(el => Array.isArray(el))) {
|
|
3294
|
-
originalFrom.forEach(thing => {
|
|
3295
|
-
if (Array.isArray(thing)) {
|
|
3296
|
-
this.add(...thing);
|
|
3297
|
-
}
|
|
3298
|
-
});
|
|
3299
|
-
return;
|
|
3300
|
-
}
|
|
3301
|
-
if (originalFrom.length && isNum$1(+originalFrom[0]) && isNum$1(+originalFrom[1])) {
|
|
3302
|
-
this.add(...originalFrom);
|
|
3303
|
-
}
|
|
3304
|
-
}
|
|
3305
|
-
return;
|
|
3306
|
-
}
|
|
3307
|
-
throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_12] the first input argument, "from" is set (${JSON.stringify(originalFrom, null, 0)}) but second-one, "to" is not (${JSON.stringify(originalTo, null, 0)})`);
|
|
3308
|
-
} else if (!existy$1(originalFrom) && existy$1(originalTo)) {
|
|
3309
|
-
throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_13] the second input argument, "to" is set (${JSON.stringify(originalTo, null, 0)}) but first-one, "from" is not (${JSON.stringify(originalFrom, null, 0)})`);
|
|
3310
|
-
}
|
|
3311
|
-
const from = +originalFrom;
|
|
3312
|
-
const to = +originalTo;
|
|
3313
|
-
if (isNum$1(addVal)) {
|
|
3314
|
-
addVal = String(addVal);
|
|
3315
|
-
}
|
|
3316
|
-
if (isNum$1(from) && isNum$1(to)) {
|
|
3317
|
-
if (existy$1(addVal) && !isStr$1(addVal) && !isNum$1(addVal)) {
|
|
3318
|
-
throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_08] The third argument, the value to add, was given not as string but ${typeof addVal}, equal to:\n${JSON.stringify(addVal, null, 4)}`);
|
|
3319
|
-
}
|
|
3320
|
-
if (existy$1(this.ranges) && Array.isArray(this.last()) && from === this.last()[1]) {
|
|
3321
|
-
this.last()[1] = to;
|
|
3322
|
-
if (this.last()[2] === null || addVal === null) ;
|
|
3323
|
-
if (this.last()[2] !== null && existy$1(addVal)) {
|
|
3324
|
-
let calculatedVal = this.last()[2] && this.last()[2].length > 0 && (!this.opts || !this.opts.mergeType || this.opts.mergeType === 1) ? this.last()[2] + addVal : addVal;
|
|
3325
|
-
if (this.opts.limitToBeAddedWhitespace) {
|
|
3326
|
-
calculatedVal = collWhitespace(calculatedVal, this.opts.limitLinebreaksCount);
|
|
3327
|
-
}
|
|
3328
|
-
if (!(isStr$1(calculatedVal) && !calculatedVal.length)) {
|
|
3329
|
-
this.last()[2] = calculatedVal;
|
|
3330
|
-
}
|
|
3331
|
-
}
|
|
3332
|
-
} else {
|
|
3333
|
-
if (!this.ranges) {
|
|
3334
|
-
this.ranges = [];
|
|
3335
|
-
}
|
|
3336
|
-
const whatToPush = addVal !== undefined && !(isStr$1(addVal) && !addVal.length) ? [from, to, addVal && this.opts.limitToBeAddedWhitespace ? collWhitespace(addVal, this.opts.limitLinebreaksCount) : addVal] : [from, to];
|
|
3337
|
-
this.ranges.push(whatToPush);
|
|
3338
|
-
}
|
|
3339
|
-
} else {
|
|
3340
|
-
if (!(isNum$1(from) && from >= 0)) {
|
|
3341
|
-
throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_09] "from" value, the first input argument, must be a natural number or zero! Currently it's of a type "${typeof from}" equal to: ${JSON.stringify(from, null, 4)}`);
|
|
3342
|
-
} else {
|
|
3343
|
-
throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_10] "to" value, the second input argument, must be a natural number or zero! Currently it's of a type "${typeof to}" equal to: ${JSON.stringify(to, null, 4)}`);
|
|
3344
|
-
}
|
|
3345
|
-
}
|
|
3346
|
-
}
|
|
3347
|
-
push(originalFrom, originalTo, addVal) {
|
|
3348
|
-
this.add(originalFrom, originalTo, addVal);
|
|
3349
|
-
}
|
|
3350
|
-
current() {
|
|
3351
|
-
if (Array.isArray(this.ranges) && this.ranges.length) {
|
|
3352
|
-
this.ranges = rMerge(this.ranges, {
|
|
3353
|
-
mergeType: this.opts.mergeType
|
|
3354
|
-
});
|
|
3355
|
-
if (this.ranges && this.opts.limitToBeAddedWhitespace) {
|
|
3356
|
-
return this.ranges.map(val => {
|
|
3357
|
-
if (existy$1(val[2])) {
|
|
3358
|
-
return [val[0], val[1], collWhitespace(val[2], this.opts.limitLinebreaksCount)];
|
|
3359
|
-
}
|
|
3360
|
-
return val;
|
|
3361
|
-
});
|
|
3362
|
-
}
|
|
3363
|
-
return this.ranges;
|
|
3364
|
-
}
|
|
3365
|
-
return null;
|
|
3366
|
-
}
|
|
3367
|
-
wipe() {
|
|
3368
|
-
this.ranges = [];
|
|
3369
|
-
}
|
|
3370
|
-
replace(givenRanges) {
|
|
3371
|
-
if (Array.isArray(givenRanges) && givenRanges.length) {
|
|
3372
|
-
if (!(Array.isArray(givenRanges[0]) && isNum$1(givenRanges[0][0]))) {
|
|
3373
|
-
throw new Error(`ranges-push/Ranges/replace(): [THROW_ID_11] Single range was given but we expected array of arrays! The first element, ${JSON.stringify(givenRanges[0], null, 4)} should be an array and its first element should be an integer, a string index.`);
|
|
3374
|
-
} else {
|
|
3375
|
-
this.ranges = Array.from(givenRanges);
|
|
3376
|
-
}
|
|
3377
|
-
} else {
|
|
3378
|
-
this.ranges = [];
|
|
3379
|
-
}
|
|
3380
|
-
}
|
|
3381
|
-
last() {
|
|
3382
|
-
if (Array.isArray(this.ranges) && this.ranges.length) {
|
|
3383
|
-
return this.ranges[this.ranges.length - 1];
|
|
3384
|
-
}
|
|
3385
|
-
return null;
|
|
3386
|
-
}
|
|
3387
|
-
}
|
|
3388
|
-
|
|
3389
|
-
/**
|
|
3390
|
-
* @name ranges-apply
|
|
3391
|
-
* @fileoverview Take an array of string index ranges, delete/replace the string according to them
|
|
3392
|
-
* @version 5.1.0
|
|
3393
|
-
* @author Roy Revelt, Codsen Ltd
|
|
3394
|
-
* @license MIT
|
|
3395
|
-
* {@link https://codsen.com/os/ranges-apply/}
|
|
3396
|
-
*/
|
|
3397
|
-
function rApply(str, originalRangesArr, progressFn) {
|
|
3398
|
-
let percentageDone = 0;
|
|
3399
|
-
let lastPercentageDone = 0;
|
|
3400
|
-
if (arguments.length === 0) {
|
|
3401
|
-
throw new Error("ranges-apply: [THROW_ID_01] inputs missing!");
|
|
3402
|
-
}
|
|
3403
|
-
if (typeof str !== "string") {
|
|
3404
|
-
throw new TypeError(`ranges-apply: [THROW_ID_02] first input argument must be a string! Currently it's: ${typeof str}, equal to: ${JSON.stringify(str, null, 4)}`);
|
|
3405
|
-
}
|
|
3406
|
-
if (originalRangesArr && !Array.isArray(originalRangesArr)) {
|
|
3407
|
-
throw new TypeError(`ranges-apply: [THROW_ID_03] second input argument must be an array (or null)! Currently it's: ${typeof originalRangesArr}, equal to: ${JSON.stringify(originalRangesArr, null, 4)}`);
|
|
3408
|
-
}
|
|
3409
|
-
if (progressFn && typeof progressFn !== "function") {
|
|
3410
|
-
throw new TypeError(`ranges-apply: [THROW_ID_04] the third input argument must be a function (or falsey)! Currently it's: ${typeof progressFn}, equal to: ${JSON.stringify(progressFn, null, 4)}`);
|
|
3411
|
-
}
|
|
3412
|
-
if (!originalRangesArr || !originalRangesArr.filter(range => range).length) {
|
|
3413
|
-
return str;
|
|
3414
|
-
}
|
|
3415
|
-
let rangesArr;
|
|
3416
|
-
if (Array.isArray(originalRangesArr) && Number.isInteger(originalRangesArr[0]) && Number.isInteger(originalRangesArr[1])) {
|
|
3417
|
-
rangesArr = [Array.from(originalRangesArr)];
|
|
3418
|
-
} else {
|
|
3419
|
-
rangesArr = Array.from(originalRangesArr);
|
|
3420
|
-
}
|
|
3421
|
-
const len = rangesArr.length;
|
|
3422
|
-
let counter = 0;
|
|
3423
|
-
rangesArr.filter(range => range).forEach((el, i) => {
|
|
3424
|
-
if (progressFn) {
|
|
3425
|
-
percentageDone = Math.floor(counter / len * 10);
|
|
3426
|
-
/* istanbul ignore else */
|
|
3427
|
-
if (percentageDone !== lastPercentageDone) {
|
|
3428
|
-
lastPercentageDone = percentageDone;
|
|
3429
|
-
progressFn(percentageDone);
|
|
3430
|
-
}
|
|
3431
|
-
}
|
|
3432
|
-
if (!Array.isArray(el)) {
|
|
3433
|
-
throw new TypeError(`ranges-apply: [THROW_ID_05] ranges array, second input arg., has ${i}th element not an array: ${JSON.stringify(el, null, 4)}, which is ${typeof el}`);
|
|
3434
|
-
}
|
|
3435
|
-
if (!Number.isInteger(el[0])) {
|
|
3436
|
-
if (!Number.isInteger(+el[0]) || +el[0] < 0) {
|
|
3437
|
-
throw new TypeError(`ranges-apply: [THROW_ID_06] ranges array, second input arg. has ${i}th element, array ${JSON.stringify(el, null, 0)}. Its first element is not an integer, string index, but ${typeof el[0]}, equal to: ${JSON.stringify(el[0], null, 4)}.`);
|
|
3438
|
-
} else {
|
|
3439
|
-
rangesArr[i][0] = +rangesArr[i][0];
|
|
3440
|
-
}
|
|
3441
|
-
}
|
|
3442
|
-
if (!Number.isInteger(el[1])) {
|
|
3443
|
-
if (!Number.isInteger(+el[1]) || +el[1] < 0) {
|
|
3444
|
-
throw new TypeError(`ranges-apply: [THROW_ID_07] ranges array, second input arg. has ${i}th element, array ${JSON.stringify(el, null, 0)}. Its second element is not an integer, string index, but ${typeof el[1]}, equal to: ${JSON.stringify(el[1], null, 4)}.`);
|
|
3445
|
-
} else {
|
|
3446
|
-
rangesArr[i][1] = +rangesArr[i][1];
|
|
3447
|
-
}
|
|
3448
|
-
}
|
|
3449
|
-
counter += 1;
|
|
3450
|
-
});
|
|
3451
|
-
const workingRanges = rMerge(rangesArr, {
|
|
3452
|
-
progressFn: perc => {
|
|
3453
|
-
if (progressFn) {
|
|
3454
|
-
percentageDone = 10 + Math.floor(perc / 10);
|
|
3455
|
-
/* istanbul ignore else */
|
|
3456
|
-
if (percentageDone !== lastPercentageDone) {
|
|
3457
|
-
lastPercentageDone = percentageDone;
|
|
3458
|
-
progressFn(percentageDone);
|
|
3459
|
-
}
|
|
3460
|
-
}
|
|
3461
|
-
}
|
|
3462
|
-
});
|
|
3463
|
-
const len2 = Array.isArray(workingRanges) ? workingRanges.length : 0;
|
|
3464
|
-
/* istanbul ignore else */
|
|
3465
|
-
if (len2 > 0) {
|
|
3466
|
-
const tails = str.slice(workingRanges[len2 - 1][1]);
|
|
3467
|
-
str = workingRanges.reduce((acc, _val, i, arr) => {
|
|
3468
|
-
if (progressFn) {
|
|
3469
|
-
percentageDone = 20 + Math.floor(i / len2 * 80);
|
|
3470
|
-
/* istanbul ignore else */
|
|
3471
|
-
if (percentageDone !== lastPercentageDone) {
|
|
3472
|
-
lastPercentageDone = percentageDone;
|
|
3473
|
-
progressFn(percentageDone);
|
|
3474
|
-
}
|
|
3475
|
-
}
|
|
3476
|
-
const beginning = i === 0 ? 0 : arr[i - 1][1];
|
|
3477
|
-
const ending = arr[i][0];
|
|
3478
|
-
return acc + str.slice(beginning, ending) + (arr[i][2] || "");
|
|
3479
|
-
}, "");
|
|
3480
|
-
str += tails;
|
|
3481
|
-
}
|
|
3482
|
-
return str;
|
|
3483
|
-
}
|
|
3484
|
-
|
|
3485
|
-
/**
|
|
3486
|
-
* @name string-trim-spaces-only
|
|
3487
|
-
* @fileoverview Like String.trim() but you can choose granularly what to trim
|
|
3488
|
-
* @version 3.1.0
|
|
3489
|
-
* @author Roy Revelt, Codsen Ltd
|
|
3490
|
-
* @license MIT
|
|
3491
|
-
* {@link https://codsen.com/os/string-trim-spaces-only/}
|
|
3492
|
-
*/
|
|
3493
|
-
const defaults$1 = {
|
|
3494
|
-
classicTrim: false,
|
|
3495
|
-
cr: false,
|
|
3496
|
-
lf: false,
|
|
3497
|
-
tab: false,
|
|
3498
|
-
space: true,
|
|
3499
|
-
nbsp: false
|
|
3500
|
-
};
|
|
3501
|
-
function trimSpaces(str, originalOpts) {
|
|
3502
|
-
if (typeof str !== "string") {
|
|
3503
|
-
throw new Error(`string-trim-spaces-only: [THROW_ID_01] input must be string! It was given as ${typeof str}, equal to:\n${JSON.stringify(str, null, 4)}`);
|
|
3504
|
-
}
|
|
3505
|
-
const opts = { ...defaults$1,
|
|
3506
|
-
...originalOpts
|
|
3507
|
-
};
|
|
3508
|
-
function check(char) {
|
|
3509
|
-
return opts.classicTrim && !char.trim() || !opts.classicTrim && (opts.space && char === " " || opts.cr && char === "\r" || opts.lf && char === "\n" || opts.tab && char === "\t" || opts.nbsp && char === "\u00a0");
|
|
3510
|
-
}
|
|
3511
|
-
let newStart;
|
|
3512
|
-
let newEnd;
|
|
3513
|
-
if (str.length) {
|
|
3514
|
-
if (check(str[0])) {
|
|
3515
|
-
for (let i = 0, len = str.length; i < len; i++) {
|
|
3516
|
-
if (!check(str[i])) {
|
|
3517
|
-
newStart = i;
|
|
3518
|
-
break;
|
|
3519
|
-
}
|
|
3520
|
-
if (i === str.length - 1) {
|
|
3521
|
-
return {
|
|
3522
|
-
res: "",
|
|
3523
|
-
ranges: [[0, str.length]]
|
|
3524
|
-
};
|
|
3525
|
-
}
|
|
3526
|
-
}
|
|
3527
|
-
}
|
|
3528
|
-
if (check(str[str.length - 1])) {
|
|
3529
|
-
for (let i = str.length; i--;) {
|
|
3530
|
-
if (!check(str[i])) {
|
|
3531
|
-
newEnd = i + 1;
|
|
3532
|
-
break;
|
|
3533
|
-
}
|
|
3534
|
-
}
|
|
3535
|
-
}
|
|
3536
|
-
if (newStart) {
|
|
3537
|
-
if (newEnd) {
|
|
3538
|
-
return {
|
|
3539
|
-
res: str.slice(newStart, newEnd),
|
|
3540
|
-
ranges: [[0, newStart], [newEnd, str.length]]
|
|
3541
|
-
};
|
|
3542
|
-
}
|
|
3543
|
-
return {
|
|
3544
|
-
res: str.slice(newStart),
|
|
3545
|
-
ranges: [[0, newStart]]
|
|
3546
|
-
};
|
|
3547
|
-
}
|
|
3548
|
-
if (newEnd) {
|
|
3549
|
-
return {
|
|
3550
|
-
res: str.slice(0, newEnd),
|
|
3551
|
-
ranges: [[newEnd, str.length]]
|
|
3552
|
-
};
|
|
3553
|
-
}
|
|
3554
|
-
return {
|
|
3555
|
-
res: str,
|
|
3556
|
-
ranges: []
|
|
3557
|
-
};
|
|
3558
|
-
}
|
|
3559
|
-
return {
|
|
3560
|
-
res: "",
|
|
3561
|
-
ranges: []
|
|
3562
|
-
};
|
|
3563
|
-
}
|
|
3564
|
-
|
|
3565
|
-
/**
|
|
3566
|
-
* @name string-remove-duplicate-heads-tails
|
|
3567
|
-
* @fileoverview Detect and (recursively) remove head and tail wrappings around the input string
|
|
3568
|
-
* @version 5.1.0
|
|
3569
|
-
* @author Roy Revelt, Codsen Ltd
|
|
3570
|
-
* @license MIT
|
|
3571
|
-
* {@link https://codsen.com/os/string-remove-duplicate-heads-tails/}
|
|
3572
|
-
*/
|
|
3573
|
-
function remDup(str, originalOpts) {
|
|
3574
|
-
const has = Object.prototype.hasOwnProperty;
|
|
3575
|
-
if (str === undefined) {
|
|
3576
|
-
throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_01] The input is missing!");
|
|
3577
|
-
}
|
|
3578
|
-
if (typeof str !== "string") {
|
|
3579
|
-
return str;
|
|
3580
|
-
}
|
|
3581
|
-
if (originalOpts && !lodash_isplainobject(originalOpts)) {
|
|
3582
|
-
throw new Error(`string-remove-duplicate-heads-tails: [THROW_ID_03] The given options are not a plain object but ${typeof originalOpts}!`);
|
|
3583
|
-
}
|
|
3584
|
-
const clonedOriginalOpts = { ...originalOpts
|
|
3585
|
-
};
|
|
3586
|
-
if (clonedOriginalOpts && has.call(clonedOriginalOpts, "heads")) {
|
|
3587
|
-
if (!arrayiffy(clonedOriginalOpts.heads).every(val => typeof val === "string" || Array.isArray(val))) {
|
|
3588
|
-
throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_04] The opts.heads contains elements which are not string-type!");
|
|
3589
|
-
} else if (typeof clonedOriginalOpts.heads === "string") {
|
|
3590
|
-
clonedOriginalOpts.heads = arrayiffy(clonedOriginalOpts.heads);
|
|
3591
|
-
}
|
|
3592
|
-
}
|
|
3593
|
-
if (clonedOriginalOpts && has.call(clonedOriginalOpts, "tails")) {
|
|
3594
|
-
if (!arrayiffy(clonedOriginalOpts.tails).every(val => typeof val === "string" || Array.isArray(val))) {
|
|
3595
|
-
throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_05] The opts.tails contains elements which are not string-type!");
|
|
3596
|
-
} else if (typeof clonedOriginalOpts.tails === "string") {
|
|
3597
|
-
clonedOriginalOpts.tails = arrayiffy(clonedOriginalOpts.tails);
|
|
3598
|
-
}
|
|
3599
|
-
}
|
|
3600
|
-
const temp = trimSpaces(str).res;
|
|
3601
|
-
if (temp.length === 0) {
|
|
3602
|
-
return str;
|
|
3603
|
-
}
|
|
3604
|
-
str = temp;
|
|
3605
|
-
const defaults = {
|
|
3606
|
-
heads: ["{{"],
|
|
3607
|
-
tails: ["}}"]
|
|
3608
|
-
};
|
|
3609
|
-
const opts = { ...defaults,
|
|
3610
|
-
...clonedOriginalOpts
|
|
3611
|
-
};
|
|
3612
|
-
opts.heads = opts.heads.map(el => el.trim());
|
|
3613
|
-
opts.tails = opts.tails.map(el => el.trim());
|
|
3614
|
-
let firstNonMarkerChunkFound = false;
|
|
3615
|
-
let secondNonMarkerChunkFound = false;
|
|
3616
|
-
const realRanges = new Ranges({
|
|
3617
|
-
limitToBeAddedWhitespace: true
|
|
3618
|
-
});
|
|
3619
|
-
const conditionalRanges = new Ranges({
|
|
3620
|
-
limitToBeAddedWhitespace: true
|
|
3621
|
-
});
|
|
3622
|
-
let itsFirstTail = true;
|
|
3623
|
-
let itsFirstLetter = true;
|
|
3624
|
-
let lastMatched = "";
|
|
3625
|
-
function delLeadingEmptyHeadTailChunks(str1, opts1) {
|
|
3626
|
-
let noteDownTheIndex;
|
|
3627
|
-
const resultOfAttemptToMatchHeads = matchRightIncl(str1, 0, opts1.heads, {
|
|
3628
|
-
trimBeforeMatching: true,
|
|
3629
|
-
cb: (_char, _theRemainderOfTheString, index) => {
|
|
3630
|
-
noteDownTheIndex = index;
|
|
3631
|
-
return true;
|
|
3632
|
-
}
|
|
3633
|
-
});
|
|
3634
|
-
if (!resultOfAttemptToMatchHeads) {
|
|
3635
|
-
return str1;
|
|
3636
|
-
}
|
|
3637
|
-
const resultOfAttemptToMatchTails = matchRightIncl(str1, noteDownTheIndex, opts1.tails, {
|
|
3638
|
-
trimBeforeMatching: true,
|
|
3639
|
-
cb: (_char, _theRemainderOfTheString, index) => {
|
|
3640
|
-
noteDownTheIndex = index;
|
|
3641
|
-
return true;
|
|
3642
|
-
}
|
|
3643
|
-
});
|
|
3644
|
-
if (resultOfAttemptToMatchTails) {
|
|
3645
|
-
return str1.slice(noteDownTheIndex);
|
|
3646
|
-
}
|
|
3647
|
-
return str1;
|
|
3648
|
-
}
|
|
3649
|
-
while (str !== delLeadingEmptyHeadTailChunks(str, opts)) {
|
|
3650
|
-
str = trimSpaces(delLeadingEmptyHeadTailChunks(str, opts)).res;
|
|
3651
|
-
}
|
|
3652
|
-
function delTrailingEmptyHeadTailChunks(str1, opts1) {
|
|
3653
|
-
let noteDownTheIndex;
|
|
3654
|
-
const resultOfAttemptToMatchTails = matchLeftIncl(str1, str1.length - 1, opts1.tails, {
|
|
3655
|
-
trimBeforeMatching: true,
|
|
3656
|
-
cb: (_char, _theRemainderOfTheString, index) => {
|
|
3657
|
-
noteDownTheIndex = index;
|
|
3658
|
-
return true;
|
|
3659
|
-
}
|
|
3660
|
-
});
|
|
3661
|
-
if (!resultOfAttemptToMatchTails || !noteDownTheIndex) {
|
|
3662
|
-
return str1;
|
|
3663
|
-
}
|
|
3664
|
-
const resultOfAttemptToMatchHeads = matchLeftIncl(str1, noteDownTheIndex, opts1.heads, {
|
|
3665
|
-
trimBeforeMatching: true,
|
|
3666
|
-
cb: (_char, _theRemainderOfTheString, index) => {
|
|
3667
|
-
noteDownTheIndex = index;
|
|
3668
|
-
return true;
|
|
3669
|
-
}
|
|
3670
|
-
});
|
|
3671
|
-
if (resultOfAttemptToMatchHeads) {
|
|
3672
|
-
return str1.slice(0, noteDownTheIndex + 1);
|
|
3673
|
-
}
|
|
3674
|
-
return str1;
|
|
3675
|
-
}
|
|
3676
|
-
while (str !== delTrailingEmptyHeadTailChunks(str, opts)) {
|
|
3677
|
-
str = trimSpaces(delTrailingEmptyHeadTailChunks(str, opts)).res;
|
|
3678
|
-
}
|
|
3679
|
-
if (!opts.heads.length || !matchRightIncl(str, 0, opts.heads, {
|
|
3680
|
-
trimBeforeMatching: true
|
|
3681
|
-
}) || !opts.tails.length || !matchLeftIncl(str, str.length - 1, opts.tails, {
|
|
3682
|
-
trimBeforeMatching: true
|
|
3683
|
-
})) {
|
|
3684
|
-
return trimSpaces(str).res;
|
|
3685
|
-
}
|
|
3686
|
-
for (let i = 0, len = str.length; i < len; i++) {
|
|
3687
|
-
if (str[i].trim() === "") ; else {
|
|
3688
|
-
let noteDownTheIndex;
|
|
3689
|
-
const resultOfAttemptToMatchHeads = matchRightIncl(str, i, opts.heads, {
|
|
3690
|
-
trimBeforeMatching: true,
|
|
3691
|
-
cb: (_char, _theRemainderOfTheString, index) => {
|
|
3692
|
-
noteDownTheIndex = index;
|
|
3693
|
-
return true;
|
|
3694
|
-
}
|
|
3695
|
-
});
|
|
3696
|
-
if (resultOfAttemptToMatchHeads && noteDownTheIndex) {
|
|
3697
|
-
itsFirstLetter = true;
|
|
3698
|
-
if (itsFirstTail) {
|
|
3699
|
-
itsFirstTail = true;
|
|
3700
|
-
}
|
|
3701
|
-
let tempIndexUpTo;
|
|
3702
|
-
const resultOfAttemptToMatchTails = matchRightIncl(str, noteDownTheIndex, opts.tails, {
|
|
3703
|
-
trimBeforeMatching: true,
|
|
3704
|
-
cb: (_char, _theRemainderOfTheString, index) => {
|
|
3705
|
-
tempIndexUpTo = index;
|
|
3706
|
-
return true;
|
|
3707
|
-
}
|
|
3708
|
-
});
|
|
3709
|
-
if (resultOfAttemptToMatchTails) {
|
|
3710
|
-
realRanges.push(i, tempIndexUpTo);
|
|
3711
|
-
}
|
|
3712
|
-
if (conditionalRanges.current() && firstNonMarkerChunkFound && lastMatched !== "tails") {
|
|
3713
|
-
realRanges.push(conditionalRanges.current());
|
|
3714
|
-
}
|
|
3715
|
-
if (!firstNonMarkerChunkFound) {
|
|
3716
|
-
if (conditionalRanges.current()) {
|
|
3717
|
-
realRanges.push(conditionalRanges.current());
|
|
3718
|
-
conditionalRanges.wipe();
|
|
3719
|
-
}
|
|
3720
|
-
conditionalRanges.push(i, noteDownTheIndex);
|
|
3721
|
-
} else {
|
|
3722
|
-
conditionalRanges.push(i, noteDownTheIndex);
|
|
3723
|
-
}
|
|
3724
|
-
lastMatched = "heads";
|
|
3725
|
-
i = noteDownTheIndex - 1;
|
|
3726
|
-
continue;
|
|
3727
|
-
}
|
|
3728
|
-
const resultOfAttemptToMatchTails = matchRightIncl(str, i, opts.tails, {
|
|
3729
|
-
trimBeforeMatching: true,
|
|
3730
|
-
cb: (_char, _theRemainderOfTheString, index) => {
|
|
3731
|
-
noteDownTheIndex = Number.isInteger(index) ? index : str.length;
|
|
3732
|
-
return true;
|
|
3733
|
-
}
|
|
3734
|
-
});
|
|
3735
|
-
if (resultOfAttemptToMatchTails && noteDownTheIndex) {
|
|
3736
|
-
itsFirstLetter = true;
|
|
3737
|
-
if (!itsFirstTail) {
|
|
3738
|
-
conditionalRanges.push(i, noteDownTheIndex);
|
|
3739
|
-
} else {
|
|
3740
|
-
if (lastMatched === "heads") {
|
|
3741
|
-
conditionalRanges.wipe();
|
|
3742
|
-
}
|
|
3743
|
-
itsFirstTail = false;
|
|
3744
|
-
}
|
|
3745
|
-
lastMatched = "tails";
|
|
3746
|
-
i = noteDownTheIndex - 1;
|
|
3747
|
-
continue;
|
|
3748
|
-
}
|
|
3749
|
-
if (itsFirstTail) {
|
|
3750
|
-
itsFirstTail = true;
|
|
3751
|
-
}
|
|
3752
|
-
if (itsFirstLetter && !firstNonMarkerChunkFound) {
|
|
3753
|
-
firstNonMarkerChunkFound = true;
|
|
3754
|
-
itsFirstLetter = false;
|
|
3755
|
-
} else if (itsFirstLetter && !secondNonMarkerChunkFound) {
|
|
3756
|
-
secondNonMarkerChunkFound = true;
|
|
3757
|
-
itsFirstTail = true;
|
|
3758
|
-
itsFirstLetter = false;
|
|
3759
|
-
if (lastMatched === "heads") {
|
|
3760
|
-
conditionalRanges.wipe();
|
|
3761
|
-
}
|
|
3762
|
-
} else if (itsFirstLetter && secondNonMarkerChunkFound) {
|
|
3763
|
-
conditionalRanges.wipe();
|
|
3764
|
-
}
|
|
3765
|
-
}
|
|
3766
|
-
}
|
|
3767
|
-
if (conditionalRanges.current()) {
|
|
3768
|
-
realRanges.push(conditionalRanges.current());
|
|
3769
|
-
}
|
|
3770
|
-
if (realRanges.current()) {
|
|
3771
|
-
return rApply(str, realRanges.current()).trim();
|
|
3772
|
-
}
|
|
3773
|
-
return str.trim();
|
|
3774
|
-
}
|
|
3775
|
-
|
|
3776
|
-
var version$1 = "10.1.0";
|
|
3777
|
-
|
|
3778
|
-
/* eslint max-len:0 */
|
|
3779
|
-
const version = version$1;
|
|
3780
|
-
const has = Object.prototype.hasOwnProperty;
|
|
3781
|
-
const defaults = {
|
|
3782
|
-
heads: "%%_",
|
|
3783
|
-
tails: "_%%",
|
|
3784
|
-
headsNoWrap: "%%-",
|
|
3785
|
-
tailsNoWrap: "-%%",
|
|
3786
|
-
lookForDataContainers: true,
|
|
3787
|
-
dataContainerIdentifierTails: "_data",
|
|
3788
|
-
wrapHeadsWith: "",
|
|
3789
|
-
wrapTailsWith: "",
|
|
3790
|
-
dontWrapVars: [],
|
|
3791
|
-
preventDoubleWrapping: true,
|
|
3792
|
-
wrapGlobalFlipSwitch: true,
|
|
3793
|
-
noSingleMarkers: false,
|
|
3794
|
-
// don't throw mismatched marker error.
|
|
3795
|
-
resolveToBoolIfAnyValuesContainBool: true,
|
|
3796
|
-
// anything that contains or is equal to Boolean false, set the whole thing to false
|
|
3797
|
-
resolveToFalseIfAnyValuesContainBool: true,
|
|
3798
|
-
// even if some values contain Boolean true. Otherwise, the whole value will
|
|
3799
|
-
// resolve to the first encountered Boolean.
|
|
3800
|
-
throwWhenNonStringInsertedInString: false,
|
|
3801
|
-
allowUnresolved: false, // Allow value to not have a resolved variable
|
|
3802
|
-
};
|
|
3803
|
-
// -----------------------------------------------------------------------------
|
|
3804
|
-
// H E L P E R F U N C T I O N S
|
|
3805
|
-
// -----------------------------------------------------------------------------
|
|
3806
|
-
function isStr(something) {
|
|
3807
|
-
return typeof something === "string";
|
|
3808
|
-
}
|
|
3809
|
-
function isNum(something) {
|
|
3810
|
-
return typeof something === "number";
|
|
3811
|
-
}
|
|
3812
|
-
function isBool(something) {
|
|
3813
|
-
return typeof something === "boolean";
|
|
3814
|
-
}
|
|
3815
|
-
function isNull(something) {
|
|
3816
|
-
return something === null;
|
|
3817
|
-
}
|
|
3818
|
-
function isObj(something) {
|
|
3819
|
-
return (something && typeof something === "object" && !Array.isArray(something));
|
|
3820
|
-
}
|
|
3821
|
-
function existy(x) {
|
|
3822
|
-
return x != null;
|
|
3823
|
-
}
|
|
3824
|
-
function trimIfString(something) {
|
|
3825
|
-
return isStr(something) ? something.trim() : something;
|
|
3826
|
-
}
|
|
3827
|
-
function getTopmostKey(str) {
|
|
3828
|
-
if (typeof str === "string" && str.length > 0 && str.indexOf(".") !== -1) {
|
|
3829
|
-
for (let i = 0, len = str.length; i < len; i++) {
|
|
3830
|
-
if (str[i] === ".") {
|
|
3831
|
-
return str.slice(0, i);
|
|
3832
|
-
}
|
|
3833
|
-
}
|
|
3834
|
-
}
|
|
3835
|
-
return str;
|
|
3836
|
-
}
|
|
3837
|
-
function withoutTopmostKey(str) {
|
|
3838
|
-
if (typeof str === "string" && str.length > 0 && str.indexOf(".") !== -1) {
|
|
3839
|
-
for (let i = 0, len = str.length; i < len; i++) {
|
|
3840
|
-
if (str[i] === ".") {
|
|
3841
|
-
return str.slice(i + 1);
|
|
3842
|
-
}
|
|
3843
|
-
}
|
|
3844
|
-
}
|
|
3845
|
-
return str;
|
|
3846
|
-
}
|
|
3847
|
-
function goLevelUp(str) {
|
|
3848
|
-
if (typeof str === "string" && str.length > 0 && str.indexOf(".") !== -1) {
|
|
3849
|
-
for (let i = str.length; i--;) {
|
|
3850
|
-
if (str[i] === ".") {
|
|
3851
|
-
return str.slice(0, i);
|
|
3852
|
-
}
|
|
3853
|
-
}
|
|
3854
|
-
}
|
|
3855
|
-
return str;
|
|
3856
|
-
}
|
|
3857
|
-
function getLastKey(str) {
|
|
3858
|
-
if (typeof str === "string" && str.length > 0 && str.indexOf(".") !== -1) {
|
|
3859
|
-
for (let i = str.length; i--;) {
|
|
3860
|
-
if (str[i] === ".") {
|
|
3861
|
-
return str.slice(i + 1);
|
|
3862
|
-
}
|
|
3863
|
-
}
|
|
3864
|
-
}
|
|
3865
|
-
return str;
|
|
3866
|
-
}
|
|
3867
|
-
function containsHeadsOrTails(str, opts) {
|
|
3868
|
-
if (typeof str !== "string" || !str.trim()) {
|
|
3869
|
-
return false;
|
|
3870
|
-
}
|
|
3871
|
-
if (str.includes(opts.heads) ||
|
|
3872
|
-
str.includes(opts.tails) ||
|
|
3873
|
-
(isStr(opts.headsNoWrap) &&
|
|
3874
|
-
opts.headsNoWrap.length > 0 &&
|
|
3875
|
-
str.includes(opts.headsNoWrap)) ||
|
|
3876
|
-
(isStr(opts.tailsNoWrap) &&
|
|
3877
|
-
opts.tailsNoWrap.length > 0 &&
|
|
3878
|
-
str.includes(opts.tailsNoWrap))) {
|
|
3879
|
-
return true;
|
|
3880
|
-
}
|
|
3881
|
-
return false;
|
|
3882
|
-
}
|
|
3883
|
-
function removeWrappingHeadsAndTails(str, heads, tails) {
|
|
3884
|
-
let tempFrom;
|
|
3885
|
-
let tempTo;
|
|
3886
|
-
if (typeof str === "string" &&
|
|
3887
|
-
str.length > 0 &&
|
|
3888
|
-
matchRightIncl(str, 0, heads, {
|
|
3889
|
-
trimBeforeMatching: true,
|
|
3890
|
-
cb: (_c, _t, index) => {
|
|
3891
|
-
tempFrom = index;
|
|
3892
|
-
return true;
|
|
3893
|
-
},
|
|
3894
|
-
}) &&
|
|
3895
|
-
matchLeftIncl(str, str.length - 1, tails, {
|
|
3896
|
-
trimBeforeMatching: true,
|
|
3897
|
-
cb: (_c, _t, index) => {
|
|
3898
|
-
tempTo = index + 1;
|
|
3899
|
-
return true;
|
|
3900
|
-
},
|
|
3901
|
-
})) {
|
|
3902
|
-
return str.slice(tempFrom, tempTo);
|
|
3903
|
-
}
|
|
3904
|
-
return str;
|
|
3905
|
-
}
|
|
3906
|
-
function wrap(placementValue, opts, dontWrapTheseVars = false, breadCrumbPath, newPath, oldVarName) {
|
|
3907
|
-
// opts validation
|
|
3908
|
-
if (!opts.wrapHeadsWith) {
|
|
3909
|
-
// eslint-disable-next-line no-param-reassign
|
|
3910
|
-
opts.wrapHeadsWith = "";
|
|
3911
|
-
}
|
|
3912
|
-
if (!opts.wrapTailsWith) {
|
|
3913
|
-
// eslint-disable-next-line no-param-reassign
|
|
3914
|
-
opts.wrapTailsWith = "";
|
|
3915
|
-
}
|
|
3916
|
-
// main opts
|
|
3917
|
-
if (isStr(placementValue) &&
|
|
3918
|
-
!dontWrapTheseVars &&
|
|
3919
|
-
opts.wrapGlobalFlipSwitch &&
|
|
3920
|
-
!opts.dontWrapVars.some((val) => matcher.isMatch(oldVarName, val)) && // considering double-wrapping prevention setting:
|
|
3921
|
-
(!opts.preventDoubleWrapping ||
|
|
3922
|
-
(opts.preventDoubleWrapping &&
|
|
3923
|
-
isStr(placementValue) &&
|
|
3924
|
-
!placementValue.includes(opts.wrapHeadsWith) &&
|
|
3925
|
-
!placementValue.includes(opts.wrapTailsWith)))) {
|
|
3926
|
-
return opts.wrapHeadsWith + placementValue + opts.wrapTailsWith;
|
|
3927
|
-
}
|
|
3928
|
-
if (dontWrapTheseVars) {
|
|
3929
|
-
if (!isStr(placementValue)) {
|
|
3930
|
-
return placementValue;
|
|
3931
|
-
}
|
|
3932
|
-
const tempValue = remDup(placementValue, {
|
|
3933
|
-
heads: opts.wrapHeadsWith,
|
|
3934
|
-
tails: opts.wrapTailsWith,
|
|
3935
|
-
});
|
|
3936
|
-
if (!isStr(tempValue)) {
|
|
3937
|
-
return tempValue;
|
|
3938
|
-
}
|
|
3939
|
-
return removeWrappingHeadsAndTails(tempValue, opts.wrapHeadsWith, opts.wrapTailsWith);
|
|
3940
|
-
}
|
|
3941
|
-
return placementValue;
|
|
3942
|
-
}
|
|
3943
|
-
function findValues(input, varName, path, opts) {
|
|
3944
|
-
let resolveValue;
|
|
3945
|
-
// 1.1. first, traverse up to root level, looking for key right at that level
|
|
3946
|
-
// or within data store, respecting the config
|
|
3947
|
-
if (path.indexOf(".") !== -1) {
|
|
3948
|
-
let currentPath = path;
|
|
3949
|
-
// traverse upwards:
|
|
3950
|
-
let handBrakeOff = true;
|
|
3951
|
-
// first, check the current level's datastore:
|
|
3952
|
-
if (opts.lookForDataContainers &&
|
|
3953
|
-
typeof opts.dataContainerIdentifierTails === "string" &&
|
|
3954
|
-
opts.dataContainerIdentifierTails.length > 0 &&
|
|
3955
|
-
!currentPath.endsWith(opts.dataContainerIdentifierTails)) {
|
|
3956
|
-
// 1.1.1. first check data store
|
|
3957
|
-
const gotPath = objectPath.get(input, currentPath + opts.dataContainerIdentifierTails);
|
|
3958
|
-
if (isObj(gotPath) && objectPath.get(gotPath, varName)) {
|
|
3959
|
-
resolveValue = objectPath.get(gotPath, varName);
|
|
3960
|
-
handBrakeOff = false;
|
|
3961
|
-
}
|
|
3962
|
-
}
|
|
3963
|
-
// then, start traversing up:
|
|
3964
|
-
while (handBrakeOff && currentPath.indexOf(".") !== -1) {
|
|
3965
|
-
currentPath = goLevelUp(currentPath);
|
|
3966
|
-
if (getLastKey(currentPath) === varName) {
|
|
3967
|
-
throw new Error(`json-variables/findValues(): [THROW_ID_20] While trying to resolve: "${varName}" at path "${path}", we encountered a closed loop. The parent key "${getLastKey(currentPath)}" is called the same as the variable "${varName}" we're looking for.`);
|
|
3968
|
-
}
|
|
3969
|
-
// first, check the current level's datastore:
|
|
3970
|
-
if (opts.lookForDataContainers &&
|
|
3971
|
-
typeof opts.dataContainerIdentifierTails === "string" &&
|
|
3972
|
-
opts.dataContainerIdentifierTails.length > 0 &&
|
|
3973
|
-
!currentPath.endsWith(opts.dataContainerIdentifierTails)) {
|
|
3974
|
-
// 1.1.1. first check data store
|
|
3975
|
-
const gotPath = objectPath.get(input, currentPath + opts.dataContainerIdentifierTails);
|
|
3976
|
-
if (isObj(gotPath) && objectPath.get(gotPath, varName)) {
|
|
3977
|
-
resolveValue = objectPath.get(gotPath, varName);
|
|
3978
|
-
handBrakeOff = false;
|
|
3979
|
-
}
|
|
3980
|
-
}
|
|
3981
|
-
if (resolveValue === undefined) {
|
|
3982
|
-
// 1.1.2. second check for key straight in parent level
|
|
3983
|
-
const gotPath = objectPath.get(input, currentPath);
|
|
3984
|
-
if (isObj(gotPath) && objectPath.get(gotPath, varName)) {
|
|
3985
|
-
resolveValue = objectPath.get(gotPath, varName);
|
|
3986
|
-
handBrakeOff = false;
|
|
3987
|
-
}
|
|
3988
|
-
}
|
|
3989
|
-
}
|
|
3990
|
-
}
|
|
3991
|
-
// 1.2. Reading this point means that maybe we were already at the root level,
|
|
3992
|
-
// maybe we traversed up to root and couldn't resolve anything.
|
|
3993
|
-
// Either way, let's check keys and data store at the root level:
|
|
3994
|
-
if (resolveValue === undefined) {
|
|
3995
|
-
const gotPath = objectPath.get(input, varName);
|
|
3996
|
-
if (gotPath !== undefined) {
|
|
3997
|
-
resolveValue = gotPath;
|
|
3998
|
-
}
|
|
3999
|
-
}
|
|
4000
|
-
// 1.3. Last resort, just look for key ANYWHERE, as long as it's named as
|
|
4001
|
-
// our variable name's topmost key (if it's a path with dots) or equal to key entirely (no dots)
|
|
4002
|
-
if (resolveValue === undefined) {
|
|
4003
|
-
// 1.3.1. It depends, does the varName we're looking for have dot or not.
|
|
4004
|
-
// - Because if it does, it's a path and we'll have to split the search into two
|
|
4005
|
-
// parts: first find topmost key, then query it's children path part via
|
|
4006
|
-
// object-path.
|
|
4007
|
-
// - If it does not have a dot, it's straightforward, pick first string
|
|
4008
|
-
// finding out of getByKey().
|
|
4009
|
-
// it's not a path (does not contain dots)
|
|
4010
|
-
if (varName.indexOf(".") === -1) {
|
|
4011
|
-
const gotPathArr = getByKey(input, varName);
|
|
4012
|
-
if (gotPathArr.length > 0) {
|
|
4013
|
-
for (let y = 0, len2 = gotPathArr.length; y < len2; y++) {
|
|
4014
|
-
if (isStr(gotPathArr[y].val) ||
|
|
4015
|
-
isBool(gotPathArr[y].val) ||
|
|
4016
|
-
isNull(gotPathArr[y].val)) {
|
|
4017
|
-
resolveValue = gotPathArr[y].val;
|
|
4018
|
-
break;
|
|
4019
|
-
}
|
|
4020
|
-
else if (isNum(gotPathArr[y].val)) {
|
|
4021
|
-
resolveValue = String(gotPathArr[y].val);
|
|
4022
|
-
break;
|
|
4023
|
-
}
|
|
4024
|
-
else if (Array.isArray(gotPathArr[y].val)) {
|
|
4025
|
-
resolveValue = gotPathArr[y].val.join("");
|
|
4026
|
-
break;
|
|
4027
|
-
}
|
|
4028
|
-
else {
|
|
4029
|
-
throw new Error(`json-variables/findValues(): [THROW_ID_21] While trying to resolve: "${varName}" at path "${path}", we actually found the key named ${varName}, but it was not equal to a string but to:\n${JSON.stringify(gotPathArr[y], null, 4)}\nWe can't resolve a string with that! It should be a string.`);
|
|
4030
|
-
}
|
|
4031
|
-
}
|
|
4032
|
-
}
|
|
4033
|
-
}
|
|
4034
|
-
else {
|
|
4035
|
-
// it's a path (contains dots)
|
|
4036
|
-
const gotPath = getByKey(input, getTopmostKey(varName));
|
|
4037
|
-
if (gotPath.length > 0) {
|
|
4038
|
-
for (let y = 0, len2 = gotPath.length; y < len2; y++) {
|
|
4039
|
-
const temp = objectPath.get(gotPath[y].val, withoutTopmostKey(varName));
|
|
4040
|
-
if (temp && isStr(temp)) {
|
|
4041
|
-
resolveValue = temp;
|
|
4042
|
-
}
|
|
4043
|
-
}
|
|
4044
|
-
}
|
|
4045
|
-
}
|
|
4046
|
-
}
|
|
4047
|
-
return resolveValue;
|
|
4048
|
-
}
|
|
4049
|
-
// Explanation of the resolveString() function's inputs.
|
|
4050
|
-
// Heads or tails were detected in the "string", which is located in the "path"
|
|
4051
|
-
// within "input" (JSON object normally, an AST). All the settings are in "opts".
|
|
4052
|
-
// Since this function will be called recursively, we have to keep a breadCrumbPath -
|
|
4053
|
-
// all keys visited so far and always check, was the current key not been
|
|
4054
|
-
// traversed already (present in breadCrumbPath). Otherwise, we might get into a
|
|
4055
|
-
// closed loop.
|
|
4056
|
-
function resolveString(input, string, path, opts, incomingBreadCrumbPath = []) {
|
|
4057
|
-
// precautions from recursion
|
|
4058
|
-
if (incomingBreadCrumbPath.includes(path)) {
|
|
4059
|
-
let extra = "";
|
|
4060
|
-
if (incomingBreadCrumbPath.length > 1) {
|
|
4061
|
-
// extra = ` Here's the path we travelled up until we hit the recursion: ${incomingBreadCrumbPath.join(' - ')}.`
|
|
4062
|
-
const separator = " →\n";
|
|
4063
|
-
extra = incomingBreadCrumbPath.reduce((accum, curr, idx) => accum +
|
|
4064
|
-
(idx === 0 ? "" : separator) +
|
|
4065
|
-
(curr === path ? "💥 " : " ") +
|
|
4066
|
-
curr, " Here's the path we travelled up until we hit the recursion:\n\n");
|
|
4067
|
-
extra += `${separator}💥 ${path}`;
|
|
4068
|
-
}
|
|
4069
|
-
throw new Error(`json-variables/resolveString(): [THROW_ID_19] While trying to resolve: "${string}" at path "${path}", we encountered a closed loop, the key is referencing itself."${extra}`);
|
|
4070
|
-
}
|
|
4071
|
-
// The Secret Data Stash, a way to cache previously resolved values and reuse the
|
|
4072
|
-
// values, saving resources. It can't be on the root because it would get retained
|
|
4073
|
-
// between different calls on the library, potentially giving wrong results (from
|
|
4074
|
-
// the previous resolved variable, from the previous function call).
|
|
4075
|
-
const secretResolvedVarsStash = {};
|
|
4076
|
-
// 0. Add current path into breadCrumbPath
|
|
4077
|
-
// =======================================
|
|
4078
|
-
const breadCrumbPath = Array.from(incomingBreadCrumbPath);
|
|
4079
|
-
breadCrumbPath.push(path);
|
|
4080
|
-
// 1. First, extract all vars
|
|
4081
|
-
// ==========================
|
|
4082
|
-
const finalRangesArr = new Ranges();
|
|
4083
|
-
function processHeadsAndTails(arr, dontWrapTheseVars, wholeValueIsVariable) {
|
|
4084
|
-
for (let i = 0, len = arr.length; i < len; i++) {
|
|
4085
|
-
const obj = arr[i];
|
|
4086
|
-
const varName = string.slice(obj.headsEndAt, obj.tailsStartAt);
|
|
4087
|
-
if (varName.length === 0) {
|
|
4088
|
-
finalRangesArr.push(obj.headsStartAt, // replace from index
|
|
4089
|
-
obj.tailsEndAt // replace upto index - no third argument, just deletion of heads/tails
|
|
4090
|
-
);
|
|
4091
|
-
}
|
|
4092
|
-
else if (has.call(secretResolvedVarsStash, varName) &&
|
|
4093
|
-
isStr(secretResolvedVarsStash[varName])) {
|
|
4094
|
-
// check, maybe the value was already resolved before and present in secret stash:
|
|
4095
|
-
finalRangesArr.push(obj.headsStartAt, // replace from index
|
|
4096
|
-
obj.tailsEndAt, // replace upto index
|
|
4097
|
-
secretResolvedVarsStash[varName] // replacement value
|
|
4098
|
-
);
|
|
4099
|
-
}
|
|
4100
|
-
else {
|
|
4101
|
-
// it's not in the stash unfortunately, so let's search for it then:
|
|
4102
|
-
let resolvedValue = findValues(input, // input
|
|
4103
|
-
varName.trim(), // varName
|
|
4104
|
-
path, // path
|
|
4105
|
-
opts // opts
|
|
4106
|
-
);
|
|
4107
|
-
if (resolvedValue === undefined) {
|
|
4108
|
-
if (opts.allowUnresolved === true) {
|
|
4109
|
-
resolvedValue = "";
|
|
4110
|
-
}
|
|
4111
|
-
else if (typeof opts.allowUnresolved === "string") {
|
|
4112
|
-
resolvedValue = opts.allowUnresolved;
|
|
4113
|
-
}
|
|
4114
|
-
else {
|
|
4115
|
-
throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_18] We couldn't find the value to resolve the variable ${string.slice(obj.headsEndAt, obj.tailsStartAt)}. We're at path: "${path}".`);
|
|
4116
|
-
}
|
|
4117
|
-
}
|
|
4118
|
-
if (!wholeValueIsVariable &&
|
|
4119
|
-
opts.throwWhenNonStringInsertedInString &&
|
|
4120
|
-
!isStr(resolvedValue)) {
|
|
4121
|
-
throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_23] While resolving the variable ${string.slice(obj.headsEndAt, obj.tailsStartAt)} at path ${path}, it resolved into a non-string value, ${JSON.stringify(resolvedValue, null, 4)}. This is happening because options setting "throwWhenNonStringInsertedInString" is active (set to "true").`);
|
|
4122
|
-
}
|
|
4123
|
-
if (isBool(resolvedValue)) {
|
|
4124
|
-
if (opts.resolveToBoolIfAnyValuesContainBool) {
|
|
4125
|
-
finalRangesArr.wipe();
|
|
4126
|
-
if (!opts.resolveToFalseIfAnyValuesContainBool) {
|
|
4127
|
-
return resolvedValue;
|
|
4128
|
-
}
|
|
4129
|
-
return false;
|
|
4130
|
-
}
|
|
4131
|
-
resolvedValue = "";
|
|
4132
|
-
}
|
|
4133
|
-
else if (isNull(resolvedValue) && wholeValueIsVariable) {
|
|
4134
|
-
finalRangesArr.wipe();
|
|
4135
|
-
return resolvedValue;
|
|
4136
|
-
}
|
|
4137
|
-
else if (Array.isArray(resolvedValue)) {
|
|
4138
|
-
resolvedValue = String(resolvedValue.join(""));
|
|
4139
|
-
}
|
|
4140
|
-
else if (isNull(resolvedValue)) {
|
|
4141
|
-
resolvedValue = "";
|
|
4142
|
-
}
|
|
4143
|
-
else {
|
|
4144
|
-
resolvedValue = String(resolvedValue);
|
|
4145
|
-
}
|
|
4146
|
-
const newPath = path.includes(".")
|
|
4147
|
-
? `${goLevelUp(path)}.${varName}`
|
|
4148
|
-
: varName;
|
|
4149
|
-
if (containsHeadsOrTails(resolvedValue, opts)) {
|
|
4150
|
-
const replacementVal = wrap(resolveString(
|
|
4151
|
-
// replacement value <--------- R E C U R S I O N
|
|
4152
|
-
input, resolvedValue, newPath, opts, breadCrumbPath), opts, dontWrapTheseVars, breadCrumbPath, newPath, varName.trim());
|
|
4153
|
-
if (isStr(replacementVal)) {
|
|
4154
|
-
finalRangesArr.push(obj.headsStartAt, // replace from index
|
|
4155
|
-
obj.tailsEndAt, // replace upto index
|
|
4156
|
-
replacementVal);
|
|
4157
|
-
}
|
|
4158
|
-
}
|
|
4159
|
-
else {
|
|
4160
|
-
// 1. store it in the stash for the future
|
|
4161
|
-
secretResolvedVarsStash[varName] = resolvedValue;
|
|
4162
|
-
const replacementVal = wrap(resolvedValue, opts, dontWrapTheseVars, breadCrumbPath, newPath, varName.trim()); // replacement value
|
|
4163
|
-
if (isStr(replacementVal)) {
|
|
4164
|
-
// 2. submit to be replaced
|
|
4165
|
-
finalRangesArr.push(obj.headsStartAt, // replace from index
|
|
4166
|
-
obj.tailsEndAt, // replace upto index
|
|
4167
|
-
replacementVal);
|
|
4168
|
-
}
|
|
4169
|
-
}
|
|
4170
|
-
}
|
|
4171
|
-
}
|
|
4172
|
-
return undefined;
|
|
4173
|
-
}
|
|
4174
|
-
let foundHeadsAndTails; // reusing same var as container for both wrapping- and non-wrapping types
|
|
4175
|
-
// 1. normal (possibly wrapping-type) heads and tails
|
|
4176
|
-
try {
|
|
4177
|
-
// strFindHeadsTails() can throw as well if there's mismatch in heads and tails,
|
|
4178
|
-
// for example, so it needs to be contained:
|
|
4179
|
-
foundHeadsAndTails = strFindHeadsTails(string, opts.heads, opts.tails, {
|
|
4180
|
-
source: "",
|
|
4181
|
-
throwWhenSomethingWrongIsDetected: false,
|
|
4182
|
-
});
|
|
4183
|
-
}
|
|
4184
|
-
catch (error) {
|
|
4185
|
-
throw new Error(`json-variables/resolveString(): [THROW_ID_17] While trying to resolve string: "${string}" at path ${path}, something wrong with heads and tails was detected! Here's the internal error message:\n${error}`);
|
|
4186
|
-
}
|
|
4187
|
-
// if heads and tails array has only one range inside and it spans whole string's
|
|
4188
|
-
// length, this means key is equal to a whole variable, like {a: '%%_b_%%'}.
|
|
4189
|
-
// In those cases, there are extra considerations when value is null, because
|
|
4190
|
-
// null among string characters is resolved to empty string, but null as a whole
|
|
4191
|
-
// value is retained as null. This means, we need to pass this as a flag to
|
|
4192
|
-
// processHeadsAndTails() so it can resolve properly...
|
|
4193
|
-
let wholeValueIsVariable = false; // we'll reuse it for non-wrap heads/tails too
|
|
4194
|
-
if (foundHeadsAndTails.length === 1 &&
|
|
4195
|
-
rApply(string, [
|
|
4196
|
-
[foundHeadsAndTails[0].headsStartAt, foundHeadsAndTails[0].tailsEndAt],
|
|
4197
|
-
]).trim() === "") {
|
|
4198
|
-
wholeValueIsVariable = true;
|
|
4199
|
-
}
|
|
4200
|
-
const temp1 = processHeadsAndTails(foundHeadsAndTails, false, wholeValueIsVariable);
|
|
4201
|
-
if (isBool(temp1)) {
|
|
4202
|
-
return temp1;
|
|
4203
|
-
}
|
|
4204
|
-
if (isNull(temp1)) {
|
|
4205
|
-
return temp1;
|
|
4206
|
-
}
|
|
4207
|
-
// 2. Process opts.headsNoWrap, opts.tailsNoWrap as well
|
|
4208
|
-
try {
|
|
4209
|
-
// strFindHeadsTails() can throw as well if there's mismatch in heads and tails,
|
|
4210
|
-
// for example, so it needs to be contained:
|
|
4211
|
-
foundHeadsAndTails = strFindHeadsTails(string, opts.headsNoWrap, opts.tailsNoWrap, {
|
|
4212
|
-
source: "",
|
|
4213
|
-
throwWhenSomethingWrongIsDetected: false,
|
|
4214
|
-
});
|
|
4215
|
-
}
|
|
4216
|
-
catch (error) {
|
|
4217
|
-
throw new Error(`json-variables/resolveString(): [THROW_ID_22] While trying to resolve string: "${string}" at path ${path}, something wrong with no-wrap heads and no-wrap tails was detected! Here's the internal error message:\n${error}`);
|
|
4218
|
-
}
|
|
4219
|
-
if (foundHeadsAndTails.length === 1 &&
|
|
4220
|
-
rApply(string, [
|
|
4221
|
-
[foundHeadsAndTails[0].headsStartAt, foundHeadsAndTails[0].tailsEndAt],
|
|
4222
|
-
]).trim() === "") {
|
|
4223
|
-
wholeValueIsVariable = true;
|
|
4224
|
-
}
|
|
4225
|
-
const temp2 = processHeadsAndTails(foundHeadsAndTails, true, wholeValueIsVariable);
|
|
4226
|
-
if (isBool(temp2)) {
|
|
4227
|
-
return temp2;
|
|
4228
|
-
}
|
|
4229
|
-
if (isNull(temp2)) {
|
|
4230
|
-
return temp2;
|
|
4231
|
-
}
|
|
4232
|
-
// 3. Then, work the finalRangesArr list
|
|
4233
|
-
// ================================
|
|
4234
|
-
if (finalRangesArr && finalRangesArr.current()) {
|
|
4235
|
-
return rApply(string, finalRangesArr.current());
|
|
4236
|
-
}
|
|
4237
|
-
return string;
|
|
4238
|
-
}
|
|
4239
|
-
// -----------------------------------------------------------------------------
|
|
4240
|
-
// M A I N F U N C T I O N
|
|
4241
|
-
// -----------------------------------------------------------------------------
|
|
4242
|
-
/**
|
|
4243
|
-
* Resolves custom-marked, cross-referenced paths in parsed JSON
|
|
4244
|
-
*/
|
|
4245
|
-
function jVar(input, originalOpts) {
|
|
4246
|
-
if (!arguments.length) {
|
|
4247
|
-
throw new Error("json-variables/jVar(): [THROW_ID_01] Alas! Inputs are missing!");
|
|
4248
|
-
}
|
|
4249
|
-
if (!isObj(input)) {
|
|
4250
|
-
throw new TypeError(`json-variables/jVar(): [THROW_ID_02] Alas! The input must be a plain object! Currently it's: ${Array.isArray(input) ? "array" : typeof input}`);
|
|
4251
|
-
}
|
|
4252
|
-
if (originalOpts && !isObj(originalOpts)) {
|
|
4253
|
-
throw new TypeError(`json-variables/jVar(): [THROW_ID_03] Alas! An Optional Options Object must be a plain object! Currently it's: ${Array.isArray(originalOpts) ? "array" : typeof originalOpts}`);
|
|
4254
|
-
}
|
|
4255
|
-
const opts = { ...defaults, ...originalOpts };
|
|
4256
|
-
if (!opts.dontWrapVars) {
|
|
4257
|
-
opts.dontWrapVars = [];
|
|
4258
|
-
}
|
|
4259
|
-
else if (!Array.isArray(opts.dontWrapVars)) {
|
|
4260
|
-
opts.dontWrapVars = arrayiffy(opts.dontWrapVars);
|
|
4261
|
-
}
|
|
4262
|
-
let culpritVal;
|
|
4263
|
-
let culpritIndex;
|
|
4264
|
-
if (opts.dontWrapVars.length > 0 &&
|
|
4265
|
-
!opts.dontWrapVars.every((el, idx) => {
|
|
4266
|
-
if (!isStr(el)) {
|
|
4267
|
-
culpritVal = el;
|
|
4268
|
-
culpritIndex = idx;
|
|
4269
|
-
return false;
|
|
4270
|
-
}
|
|
4271
|
-
return true;
|
|
4272
|
-
})) {
|
|
4273
|
-
throw new Error(`json-variables/jVar(): [THROW_ID_05] Alas! All variable names set in opts.dontWrapVars should be of a string type. Computer detected a value "${culpritVal}" at index ${culpritIndex}, which is not string but ${Array.isArray(culpritVal) ? "array" : typeof culpritVal}!`);
|
|
4274
|
-
}
|
|
4275
|
-
if (opts.heads === "") {
|
|
4276
|
-
throw new Error("json-variables/jVar(): [THROW_ID_06] Alas! opts.heads are empty!");
|
|
4277
|
-
}
|
|
4278
|
-
if (opts.tails === "") {
|
|
4279
|
-
throw new Error("json-variables/jVar(): [THROW_ID_07] Alas! opts.tails are empty!");
|
|
4280
|
-
}
|
|
4281
|
-
if (opts.lookForDataContainers && opts.dataContainerIdentifierTails === "") {
|
|
4282
|
-
throw new Error("json-variables/jVar(): [THROW_ID_08] Alas! opts.dataContainerIdentifierTails is empty!");
|
|
4283
|
-
}
|
|
4284
|
-
if (opts.heads === opts.tails) {
|
|
4285
|
-
throw new Error("json-variables/jVar(): [THROW_ID_09] Alas! opts.heads and opts.tails can't be equal!");
|
|
4286
|
-
}
|
|
4287
|
-
if (opts.heads === opts.headsNoWrap) {
|
|
4288
|
-
throw new Error("json-variables/jVar(): [THROW_ID_10] Alas! opts.heads and opts.headsNoWrap can't be equal!");
|
|
4289
|
-
}
|
|
4290
|
-
if (opts.tails === opts.tailsNoWrap) {
|
|
4291
|
-
throw new Error("json-variables/jVar(): [THROW_ID_11] Alas! opts.tails and opts.tailsNoWrap can't be equal!");
|
|
4292
|
-
}
|
|
4293
|
-
if (opts.headsNoWrap === "") {
|
|
4294
|
-
throw new Error("json-variables/jVar(): [THROW_ID_12] Alas! opts.headsNoWrap is an empty string!");
|
|
4295
|
-
}
|
|
4296
|
-
if (opts.tailsNoWrap === "") {
|
|
4297
|
-
throw new Error("json-variables/jVar(): [THROW_ID_13] Alas! opts.tailsNoWrap is an empty string!");
|
|
4298
|
-
}
|
|
4299
|
-
if (opts.headsNoWrap === opts.tailsNoWrap) {
|
|
4300
|
-
throw new Error("json-variables/jVar(): [THROW_ID_14] Alas! opts.headsNoWrap and opts.tailsNoWrap can't be equal!");
|
|
4301
|
-
}
|
|
4302
|
-
let current;
|
|
4303
|
-
//
|
|
4304
|
-
// ===============================================
|
|
4305
|
-
// 1.
|
|
4306
|
-
// Let's compile the list of all the vars to resolve
|
|
4307
|
-
// ===============================================
|
|
4308
|
-
//
|
|
4309
|
-
// we return the result of the traversal:
|
|
4310
|
-
return traverse(input, (key, val, innerObj) => {
|
|
4311
|
-
if (existy(val) && containsHeadsOrTails(key, opts)) {
|
|
4312
|
-
throw new Error(`json-variables/jVar(): [THROW_ID_15] Alas! Object keys can't contain variables!\nPlease check the following key: ${key}`);
|
|
4313
|
-
}
|
|
4314
|
-
// * * *
|
|
4315
|
-
// Get the current values which are being traversed by ast-monkey:
|
|
4316
|
-
// If it's an array, val will not exist, only key.
|
|
4317
|
-
if (val !== undefined) {
|
|
4318
|
-
// if it's object currently being traversed, we'll get both key and value
|
|
4319
|
-
current = val;
|
|
4320
|
-
}
|
|
4321
|
-
else {
|
|
4322
|
-
// if it's an array being traversed currently, we'll get only key
|
|
4323
|
-
current = key;
|
|
4324
|
-
}
|
|
4325
|
-
// * * *
|
|
4326
|
-
// In short, ast-monkey works in such way, that what we return will get written
|
|
4327
|
-
// over the current element, which is at the moment "current". If we don't want
|
|
4328
|
-
// to mutate it, we return "current". If we want to mutate it, we return a new
|
|
4329
|
-
// value (which will get written onto that node, previously equal to "current").
|
|
4330
|
-
// *
|
|
4331
|
-
// Instantly skip empty strings:
|
|
4332
|
-
if (current === "") {
|
|
4333
|
-
return current;
|
|
4334
|
-
}
|
|
4335
|
-
// *
|
|
4336
|
-
// If the "current" that monkey brought us is equal to whole heads or tails:
|
|
4337
|
-
if ((opts.heads.length !== 0 &&
|
|
4338
|
-
trimIfString(current) === trimIfString(opts.heads)) ||
|
|
4339
|
-
(opts.tails.length !== 0 &&
|
|
4340
|
-
trimIfString(current) === trimIfString(opts.tails)) ||
|
|
4341
|
-
(opts.headsNoWrap.length !== 0 &&
|
|
4342
|
-
trimIfString(current) === trimIfString(opts.headsNoWrap)) ||
|
|
4343
|
-
(opts.tailsNoWrap.length !== 0 &&
|
|
4344
|
-
trimIfString(current) === trimIfString(opts.tailsNoWrap))) {
|
|
4345
|
-
if (!opts.noSingleMarkers) {
|
|
4346
|
-
return current;
|
|
4347
|
-
}
|
|
4348
|
-
throw new Error(`json-variables/jVar(): [THROW_ID_16] Alas! While processing the input, we stumbled upon ${trimIfString(current)} which is equal to ${trimIfString(current) === trimIfString(opts.heads) ? "heads" : ""}${trimIfString(current) === trimIfString(opts.tails) ? "tails" : ""}${isStr(opts.headsNoWrap) &&
|
|
4349
|
-
trimIfString(current) === trimIfString(opts.headsNoWrap)
|
|
4350
|
-
? "headsNoWrap"
|
|
4351
|
-
: ""}${isStr(opts.tailsNoWrap) &&
|
|
4352
|
-
trimIfString(current) === trimIfString(opts.tailsNoWrap)
|
|
4353
|
-
? "tailsNoWrap"
|
|
4354
|
-
: ""}. If you wouldn't have set opts.noSingleMarkers to "true" this error would not happen and computer would have left the current element (${trimIfString(current)}) alone`);
|
|
4355
|
-
}
|
|
4356
|
-
// *
|
|
4357
|
-
// Process the current node if it's a string and it contains heads / tails /
|
|
4358
|
-
// headsNoWrap / tailsNoWrap:
|
|
4359
|
-
if (isStr(current) && containsHeadsOrTails(current, opts)) {
|
|
4360
|
-
// breadCrumbPath, the fifth argument is not passed as there're no previous paths
|
|
4361
|
-
return resolveString(input, current, innerObj.path, opts);
|
|
4362
|
-
}
|
|
4363
|
-
// otherwise, just return as it is. We're not going to touch plain objects/arrays,numbers/bools etc.
|
|
4364
|
-
return current;
|
|
4365
|
-
// END OF MONKEY'S TRAVERSE
|
|
4366
|
-
// -------------------------------------------------------------------------
|
|
4367
|
-
});
|
|
4368
|
-
}
|
|
4369
|
-
|
|
4370
|
-
exports.defaults = defaults;
|
|
4371
|
-
exports.jVar = jVar;
|
|
4372
|
-
exports.version = version;
|
|
4373
|
-
|
|
4374
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4375
|
-
|
|
4376
|
-
})));
|