string-left-right 4.1.0 → 5.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.
@@ -1,2600 +0,0 @@
1
- /**
2
- * @name string-left-right
3
- * @fileoverview Looks up the first non-whitespace character to the left/right of a given index
4
- * @version 4.1.0
5
- * @author Roy Revelt, Codsen Ltd
6
- * @license MIT
7
- * {@link https://codsen.com/os/string-left-right/}
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.stringLeftRight = {}));
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
- /**
19
- * lodash (Custom Build) <https://lodash.com/>
20
- * Build: `lodash modularize exports="npm" -o ./`
21
- * Copyright jQuery Foundation and other contributors <https://jquery.org/>
22
- * Released under MIT license <https://lodash.com/license>
23
- * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
24
- * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
25
- */
26
-
27
- /** `Object#toString` result references. */
28
- var objectTag = '[object Object]';
29
-
30
- /**
31
- * Checks if `value` is a host object in IE < 9.
32
- *
33
- * @private
34
- * @param {*} value The value to check.
35
- * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
36
- */
37
- function isHostObject(value) {
38
- // Many host objects are `Object` objects that can coerce to strings
39
- // despite having improperly defined `toString` methods.
40
- var result = false;
41
- if (value != null && typeof value.toString != 'function') {
42
- try {
43
- result = !!(value + '');
44
- } catch (e) {}
45
- }
46
- return result;
47
- }
48
-
49
- /**
50
- * Creates a unary function that invokes `func` with its argument transformed.
51
- *
52
- * @private
53
- * @param {Function} func The function to wrap.
54
- * @param {Function} transform The argument transform.
55
- * @returns {Function} Returns the new function.
56
- */
57
- function overArg(func, transform) {
58
- return function(arg) {
59
- return func(transform(arg));
60
- };
61
- }
62
-
63
- /** Used for built-in method references. */
64
- var funcProto = Function.prototype,
65
- objectProto = Object.prototype;
66
-
67
- /** Used to resolve the decompiled source of functions. */
68
- var funcToString = funcProto.toString;
69
-
70
- /** Used to check objects for own properties. */
71
- var hasOwnProperty = objectProto.hasOwnProperty;
72
-
73
- /** Used to infer the `Object` constructor. */
74
- var objectCtorString = funcToString.call(Object);
75
-
76
- /**
77
- * Used to resolve the
78
- * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
79
- * of values.
80
- */
81
- var objectToString = objectProto.toString;
82
-
83
- /** Built-in value references. */
84
- var getPrototype = overArg(Object.getPrototypeOf, Object);
85
-
86
- /**
87
- * Checks if `value` is object-like. A value is object-like if it's not `null`
88
- * and has a `typeof` result of "object".
89
- *
90
- * @static
91
- * @memberOf _
92
- * @since 4.0.0
93
- * @category Lang
94
- * @param {*} value The value to check.
95
- * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
96
- * @example
97
- *
98
- * _.isObjectLike({});
99
- * // => true
100
- *
101
- * _.isObjectLike([1, 2, 3]);
102
- * // => true
103
- *
104
- * _.isObjectLike(_.noop);
105
- * // => false
106
- *
107
- * _.isObjectLike(null);
108
- * // => false
109
- */
110
- function isObjectLike(value) {
111
- return !!value && typeof value == 'object';
112
- }
113
-
114
- /**
115
- * Checks if `value` is a plain object, that is, an object created by the
116
- * `Object` constructor or one with a `[[Prototype]]` of `null`.
117
- *
118
- * @static
119
- * @memberOf _
120
- * @since 0.8.0
121
- * @category Lang
122
- * @param {*} value The value to check.
123
- * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
124
- * @example
125
- *
126
- * function Foo() {
127
- * this.a = 1;
128
- * }
129
- *
130
- * _.isPlainObject(new Foo);
131
- * // => false
132
- *
133
- * _.isPlainObject([1, 2, 3]);
134
- * // => false
135
- *
136
- * _.isPlainObject({ 'x': 0, 'y': 0 });
137
- * // => true
138
- *
139
- * _.isPlainObject(Object.create(null));
140
- * // => true
141
- */
142
- function isPlainObject(value) {
143
- if (!isObjectLike(value) ||
144
- objectToString.call(value) != objectTag || isHostObject(value)) {
145
- return false;
146
- }
147
- var proto = getPrototype(value);
148
- if (proto === null) {
149
- return true;
150
- }
151
- var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
152
- return (typeof Ctor == 'function' &&
153
- Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString);
154
- }
155
-
156
- var lodash_isplainobject = isPlainObject;
157
-
158
- var lodash_clonedeep = {exports: {}};
159
-
160
- /**
161
- * lodash (Custom Build) <https://lodash.com/>
162
- * Build: `lodash modularize exports="npm" -o ./`
163
- * Copyright jQuery Foundation and other contributors <https://jquery.org/>
164
- * Released under MIT license <https://lodash.com/license>
165
- * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
166
- * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
167
- */
168
-
169
- (function (module, exports) {
170
- /** Used as the size to enable large array optimizations. */
171
- var LARGE_ARRAY_SIZE = 200;
172
-
173
- /** Used to stand-in for `undefined` hash values. */
174
- var HASH_UNDEFINED = '__lodash_hash_undefined__';
175
-
176
- /** Used as references for various `Number` constants. */
177
- var MAX_SAFE_INTEGER = 9007199254740991;
178
-
179
- /** `Object#toString` result references. */
180
- var argsTag = '[object Arguments]',
181
- arrayTag = '[object Array]',
182
- boolTag = '[object Boolean]',
183
- dateTag = '[object Date]',
184
- errorTag = '[object Error]',
185
- funcTag = '[object Function]',
186
- genTag = '[object GeneratorFunction]',
187
- mapTag = '[object Map]',
188
- numberTag = '[object Number]',
189
- objectTag = '[object Object]',
190
- promiseTag = '[object Promise]',
191
- regexpTag = '[object RegExp]',
192
- setTag = '[object Set]',
193
- stringTag = '[object String]',
194
- symbolTag = '[object Symbol]',
195
- weakMapTag = '[object WeakMap]';
196
-
197
- var arrayBufferTag = '[object ArrayBuffer]',
198
- dataViewTag = '[object DataView]',
199
- float32Tag = '[object Float32Array]',
200
- float64Tag = '[object Float64Array]',
201
- int8Tag = '[object Int8Array]',
202
- int16Tag = '[object Int16Array]',
203
- int32Tag = '[object Int32Array]',
204
- uint8Tag = '[object Uint8Array]',
205
- uint8ClampedTag = '[object Uint8ClampedArray]',
206
- uint16Tag = '[object Uint16Array]',
207
- uint32Tag = '[object Uint32Array]';
208
-
209
- /**
210
- * Used to match `RegExp`
211
- * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
212
- */
213
- var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
214
-
215
- /** Used to match `RegExp` flags from their coerced string values. */
216
- var reFlags = /\w*$/;
217
-
218
- /** Used to detect host constructors (Safari). */
219
- var reIsHostCtor = /^\[object .+?Constructor\]$/;
220
-
221
- /** Used to detect unsigned integer values. */
222
- var reIsUint = /^(?:0|[1-9]\d*)$/;
223
-
224
- /** Used to identify `toStringTag` values supported by `_.clone`. */
225
- var cloneableTags = {};
226
- cloneableTags[argsTag] = cloneableTags[arrayTag] =
227
- cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
228
- cloneableTags[boolTag] = cloneableTags[dateTag] =
229
- cloneableTags[float32Tag] = cloneableTags[float64Tag] =
230
- cloneableTags[int8Tag] = cloneableTags[int16Tag] =
231
- cloneableTags[int32Tag] = cloneableTags[mapTag] =
232
- cloneableTags[numberTag] = cloneableTags[objectTag] =
233
- cloneableTags[regexpTag] = cloneableTags[setTag] =
234
- cloneableTags[stringTag] = cloneableTags[symbolTag] =
235
- cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
236
- cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
237
- cloneableTags[errorTag] = cloneableTags[funcTag] =
238
- cloneableTags[weakMapTag] = false;
239
-
240
- /** Detect free variable `global` from Node.js. */
241
- var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
242
-
243
- /** Detect free variable `self`. */
244
- var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
245
-
246
- /** Used as a reference to the global object. */
247
- var root = freeGlobal || freeSelf || Function('return this')();
248
-
249
- /** Detect free variable `exports`. */
250
- var freeExports = exports && !exports.nodeType && exports;
251
-
252
- /** Detect free variable `module`. */
253
- var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
254
-
255
- /** Detect the popular CommonJS extension `module.exports`. */
256
- var moduleExports = freeModule && freeModule.exports === freeExports;
257
-
258
- /**
259
- * Adds the key-value `pair` to `map`.
260
- *
261
- * @private
262
- * @param {Object} map The map to modify.
263
- * @param {Array} pair The key-value pair to add.
264
- * @returns {Object} Returns `map`.
265
- */
266
- function addMapEntry(map, pair) {
267
- // Don't return `map.set` because it's not chainable in IE 11.
268
- map.set(pair[0], pair[1]);
269
- return map;
270
- }
271
-
272
- /**
273
- * Adds `value` to `set`.
274
- *
275
- * @private
276
- * @param {Object} set The set to modify.
277
- * @param {*} value The value to add.
278
- * @returns {Object} Returns `set`.
279
- */
280
- function addSetEntry(set, value) {
281
- // Don't return `set.add` because it's not chainable in IE 11.
282
- set.add(value);
283
- return set;
284
- }
285
-
286
- /**
287
- * A specialized version of `_.forEach` for arrays without support for
288
- * iteratee shorthands.
289
- *
290
- * @private
291
- * @param {Array} [array] The array to iterate over.
292
- * @param {Function} iteratee The function invoked per iteration.
293
- * @returns {Array} Returns `array`.
294
- */
295
- function arrayEach(array, iteratee) {
296
- var index = -1,
297
- length = array ? array.length : 0;
298
-
299
- while (++index < length) {
300
- if (iteratee(array[index], index, array) === false) {
301
- break;
302
- }
303
- }
304
- return array;
305
- }
306
-
307
- /**
308
- * Appends the elements of `values` to `array`.
309
- *
310
- * @private
311
- * @param {Array} array The array to modify.
312
- * @param {Array} values The values to append.
313
- * @returns {Array} Returns `array`.
314
- */
315
- function arrayPush(array, values) {
316
- var index = -1,
317
- length = values.length,
318
- offset = array.length;
319
-
320
- while (++index < length) {
321
- array[offset + index] = values[index];
322
- }
323
- return array;
324
- }
325
-
326
- /**
327
- * A specialized version of `_.reduce` for arrays without support for
328
- * iteratee shorthands.
329
- *
330
- * @private
331
- * @param {Array} [array] The array to iterate over.
332
- * @param {Function} iteratee The function invoked per iteration.
333
- * @param {*} [accumulator] The initial value.
334
- * @param {boolean} [initAccum] Specify using the first element of `array` as
335
- * the initial value.
336
- * @returns {*} Returns the accumulated value.
337
- */
338
- function arrayReduce(array, iteratee, accumulator, initAccum) {
339
- var index = -1,
340
- length = array ? array.length : 0;
341
-
342
- if (initAccum && length) {
343
- accumulator = array[++index];
344
- }
345
- while (++index < length) {
346
- accumulator = iteratee(accumulator, array[index], index, array);
347
- }
348
- return accumulator;
349
- }
350
-
351
- /**
352
- * The base implementation of `_.times` without support for iteratee shorthands
353
- * or max array length checks.
354
- *
355
- * @private
356
- * @param {number} n The number of times to invoke `iteratee`.
357
- * @param {Function} iteratee The function invoked per iteration.
358
- * @returns {Array} Returns the array of results.
359
- */
360
- function baseTimes(n, iteratee) {
361
- var index = -1,
362
- result = Array(n);
363
-
364
- while (++index < n) {
365
- result[index] = iteratee(index);
366
- }
367
- return result;
368
- }
369
-
370
- /**
371
- * Gets the value at `key` of `object`.
372
- *
373
- * @private
374
- * @param {Object} [object] The object to query.
375
- * @param {string} key The key of the property to get.
376
- * @returns {*} Returns the property value.
377
- */
378
- function getValue(object, key) {
379
- return object == null ? undefined : object[key];
380
- }
381
-
382
- /**
383
- * Checks if `value` is a host object in IE < 9.
384
- *
385
- * @private
386
- * @param {*} value The value to check.
387
- * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
388
- */
389
- function isHostObject(value) {
390
- // Many host objects are `Object` objects that can coerce to strings
391
- // despite having improperly defined `toString` methods.
392
- var result = false;
393
- if (value != null && typeof value.toString != 'function') {
394
- try {
395
- result = !!(value + '');
396
- } catch (e) {}
397
- }
398
- return result;
399
- }
400
-
401
- /**
402
- * Converts `map` to its key-value pairs.
403
- *
404
- * @private
405
- * @param {Object} map The map to convert.
406
- * @returns {Array} Returns the key-value pairs.
407
- */
408
- function mapToArray(map) {
409
- var index = -1,
410
- result = Array(map.size);
411
-
412
- map.forEach(function(value, key) {
413
- result[++index] = [key, value];
414
- });
415
- return result;
416
- }
417
-
418
- /**
419
- * Creates a unary function that invokes `func` with its argument transformed.
420
- *
421
- * @private
422
- * @param {Function} func The function to wrap.
423
- * @param {Function} transform The argument transform.
424
- * @returns {Function} Returns the new function.
425
- */
426
- function overArg(func, transform) {
427
- return function(arg) {
428
- return func(transform(arg));
429
- };
430
- }
431
-
432
- /**
433
- * Converts `set` to an array of its values.
434
- *
435
- * @private
436
- * @param {Object} set The set to convert.
437
- * @returns {Array} Returns the values.
438
- */
439
- function setToArray(set) {
440
- var index = -1,
441
- result = Array(set.size);
442
-
443
- set.forEach(function(value) {
444
- result[++index] = value;
445
- });
446
- return result;
447
- }
448
-
449
- /** Used for built-in method references. */
450
- var arrayProto = Array.prototype,
451
- funcProto = Function.prototype,
452
- objectProto = Object.prototype;
453
-
454
- /** Used to detect overreaching core-js shims. */
455
- var coreJsData = root['__core-js_shared__'];
456
-
457
- /** Used to detect methods masquerading as native. */
458
- var maskSrcKey = (function() {
459
- var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
460
- return uid ? ('Symbol(src)_1.' + uid) : '';
461
- }());
462
-
463
- /** Used to resolve the decompiled source of functions. */
464
- var funcToString = funcProto.toString;
465
-
466
- /** Used to check objects for own properties. */
467
- var hasOwnProperty = objectProto.hasOwnProperty;
468
-
469
- /**
470
- * Used to resolve the
471
- * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
472
- * of values.
473
- */
474
- var objectToString = objectProto.toString;
475
-
476
- /** Used to detect if a method is native. */
477
- var reIsNative = RegExp('^' +
478
- funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
479
- .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
480
- );
481
-
482
- /** Built-in value references. */
483
- var Buffer = moduleExports ? root.Buffer : undefined,
484
- Symbol = root.Symbol,
485
- Uint8Array = root.Uint8Array,
486
- getPrototype = overArg(Object.getPrototypeOf, Object),
487
- objectCreate = Object.create,
488
- propertyIsEnumerable = objectProto.propertyIsEnumerable,
489
- splice = arrayProto.splice;
490
-
491
- /* Built-in method references for those with the same name as other `lodash` methods. */
492
- var nativeGetSymbols = Object.getOwnPropertySymbols,
493
- nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
494
- nativeKeys = overArg(Object.keys, Object);
495
-
496
- /* Built-in method references that are verified to be native. */
497
- var DataView = getNative(root, 'DataView'),
498
- Map = getNative(root, 'Map'),
499
- Promise = getNative(root, 'Promise'),
500
- Set = getNative(root, 'Set'),
501
- WeakMap = getNative(root, 'WeakMap'),
502
- nativeCreate = getNative(Object, 'create');
503
-
504
- /** Used to detect maps, sets, and weakmaps. */
505
- var dataViewCtorString = toSource(DataView),
506
- mapCtorString = toSource(Map),
507
- promiseCtorString = toSource(Promise),
508
- setCtorString = toSource(Set),
509
- weakMapCtorString = toSource(WeakMap);
510
-
511
- /** Used to convert symbols to primitives and strings. */
512
- var symbolProto = Symbol ? Symbol.prototype : undefined,
513
- symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
514
-
515
- /**
516
- * Creates a hash object.
517
- *
518
- * @private
519
- * @constructor
520
- * @param {Array} [entries] The key-value pairs to cache.
521
- */
522
- function Hash(entries) {
523
- var index = -1,
524
- length = entries ? entries.length : 0;
525
-
526
- this.clear();
527
- while (++index < length) {
528
- var entry = entries[index];
529
- this.set(entry[0], entry[1]);
530
- }
531
- }
532
-
533
- /**
534
- * Removes all key-value entries from the hash.
535
- *
536
- * @private
537
- * @name clear
538
- * @memberOf Hash
539
- */
540
- function hashClear() {
541
- this.__data__ = nativeCreate ? nativeCreate(null) : {};
542
- }
543
-
544
- /**
545
- * Removes `key` and its value from the hash.
546
- *
547
- * @private
548
- * @name delete
549
- * @memberOf Hash
550
- * @param {Object} hash The hash to modify.
551
- * @param {string} key The key of the value to remove.
552
- * @returns {boolean} Returns `true` if the entry was removed, else `false`.
553
- */
554
- function hashDelete(key) {
555
- return this.has(key) && delete this.__data__[key];
556
- }
557
-
558
- /**
559
- * Gets the hash value for `key`.
560
- *
561
- * @private
562
- * @name get
563
- * @memberOf Hash
564
- * @param {string} key The key of the value to get.
565
- * @returns {*} Returns the entry value.
566
- */
567
- function hashGet(key) {
568
- var data = this.__data__;
569
- if (nativeCreate) {
570
- var result = data[key];
571
- return result === HASH_UNDEFINED ? undefined : result;
572
- }
573
- return hasOwnProperty.call(data, key) ? data[key] : undefined;
574
- }
575
-
576
- /**
577
- * Checks if a hash value for `key` exists.
578
- *
579
- * @private
580
- * @name has
581
- * @memberOf Hash
582
- * @param {string} key The key of the entry to check.
583
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
584
- */
585
- function hashHas(key) {
586
- var data = this.__data__;
587
- return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
588
- }
589
-
590
- /**
591
- * Sets the hash `key` to `value`.
592
- *
593
- * @private
594
- * @name set
595
- * @memberOf Hash
596
- * @param {string} key The key of the value to set.
597
- * @param {*} value The value to set.
598
- * @returns {Object} Returns the hash instance.
599
- */
600
- function hashSet(key, value) {
601
- var data = this.__data__;
602
- data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
603
- return this;
604
- }
605
-
606
- // Add methods to `Hash`.
607
- Hash.prototype.clear = hashClear;
608
- Hash.prototype['delete'] = hashDelete;
609
- Hash.prototype.get = hashGet;
610
- Hash.prototype.has = hashHas;
611
- Hash.prototype.set = hashSet;
612
-
613
- /**
614
- * Creates an list cache object.
615
- *
616
- * @private
617
- * @constructor
618
- * @param {Array} [entries] The key-value pairs to cache.
619
- */
620
- function ListCache(entries) {
621
- var index = -1,
622
- length = entries ? entries.length : 0;
623
-
624
- this.clear();
625
- while (++index < length) {
626
- var entry = entries[index];
627
- this.set(entry[0], entry[1]);
628
- }
629
- }
630
-
631
- /**
632
- * Removes all key-value entries from the list cache.
633
- *
634
- * @private
635
- * @name clear
636
- * @memberOf ListCache
637
- */
638
- function listCacheClear() {
639
- this.__data__ = [];
640
- }
641
-
642
- /**
643
- * Removes `key` and its value from the list cache.
644
- *
645
- * @private
646
- * @name delete
647
- * @memberOf ListCache
648
- * @param {string} key The key of the value to remove.
649
- * @returns {boolean} Returns `true` if the entry was removed, else `false`.
650
- */
651
- function listCacheDelete(key) {
652
- var data = this.__data__,
653
- index = assocIndexOf(data, key);
654
-
655
- if (index < 0) {
656
- return false;
657
- }
658
- var lastIndex = data.length - 1;
659
- if (index == lastIndex) {
660
- data.pop();
661
- } else {
662
- splice.call(data, index, 1);
663
- }
664
- return true;
665
- }
666
-
667
- /**
668
- * Gets the list cache value for `key`.
669
- *
670
- * @private
671
- * @name get
672
- * @memberOf ListCache
673
- * @param {string} key The key of the value to get.
674
- * @returns {*} Returns the entry value.
675
- */
676
- function listCacheGet(key) {
677
- var data = this.__data__,
678
- index = assocIndexOf(data, key);
679
-
680
- return index < 0 ? undefined : data[index][1];
681
- }
682
-
683
- /**
684
- * Checks if a list cache value for `key` exists.
685
- *
686
- * @private
687
- * @name has
688
- * @memberOf ListCache
689
- * @param {string} key The key of the entry to check.
690
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
691
- */
692
- function listCacheHas(key) {
693
- return assocIndexOf(this.__data__, key) > -1;
694
- }
695
-
696
- /**
697
- * Sets the list cache `key` to `value`.
698
- *
699
- * @private
700
- * @name set
701
- * @memberOf ListCache
702
- * @param {string} key The key of the value to set.
703
- * @param {*} value The value to set.
704
- * @returns {Object} Returns the list cache instance.
705
- */
706
- function listCacheSet(key, value) {
707
- var data = this.__data__,
708
- index = assocIndexOf(data, key);
709
-
710
- if (index < 0) {
711
- data.push([key, value]);
712
- } else {
713
- data[index][1] = value;
714
- }
715
- return this;
716
- }
717
-
718
- // Add methods to `ListCache`.
719
- ListCache.prototype.clear = listCacheClear;
720
- ListCache.prototype['delete'] = listCacheDelete;
721
- ListCache.prototype.get = listCacheGet;
722
- ListCache.prototype.has = listCacheHas;
723
- ListCache.prototype.set = listCacheSet;
724
-
725
- /**
726
- * Creates a map cache object to store key-value pairs.
727
- *
728
- * @private
729
- * @constructor
730
- * @param {Array} [entries] The key-value pairs to cache.
731
- */
732
- function MapCache(entries) {
733
- var index = -1,
734
- length = entries ? entries.length : 0;
735
-
736
- this.clear();
737
- while (++index < length) {
738
- var entry = entries[index];
739
- this.set(entry[0], entry[1]);
740
- }
741
- }
742
-
743
- /**
744
- * Removes all key-value entries from the map.
745
- *
746
- * @private
747
- * @name clear
748
- * @memberOf MapCache
749
- */
750
- function mapCacheClear() {
751
- this.__data__ = {
752
- 'hash': new Hash,
753
- 'map': new (Map || ListCache),
754
- 'string': new Hash
755
- };
756
- }
757
-
758
- /**
759
- * Removes `key` and its value from the map.
760
- *
761
- * @private
762
- * @name delete
763
- * @memberOf MapCache
764
- * @param {string} key The key of the value to remove.
765
- * @returns {boolean} Returns `true` if the entry was removed, else `false`.
766
- */
767
- function mapCacheDelete(key) {
768
- return getMapData(this, key)['delete'](key);
769
- }
770
-
771
- /**
772
- * Gets the map value for `key`.
773
- *
774
- * @private
775
- * @name get
776
- * @memberOf MapCache
777
- * @param {string} key The key of the value to get.
778
- * @returns {*} Returns the entry value.
779
- */
780
- function mapCacheGet(key) {
781
- return getMapData(this, key).get(key);
782
- }
783
-
784
- /**
785
- * Checks if a map value for `key` exists.
786
- *
787
- * @private
788
- * @name has
789
- * @memberOf MapCache
790
- * @param {string} key The key of the entry to check.
791
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
792
- */
793
- function mapCacheHas(key) {
794
- return getMapData(this, key).has(key);
795
- }
796
-
797
- /**
798
- * Sets the map `key` to `value`.
799
- *
800
- * @private
801
- * @name set
802
- * @memberOf MapCache
803
- * @param {string} key The key of the value to set.
804
- * @param {*} value The value to set.
805
- * @returns {Object} Returns the map cache instance.
806
- */
807
- function mapCacheSet(key, value) {
808
- getMapData(this, key).set(key, value);
809
- return this;
810
- }
811
-
812
- // Add methods to `MapCache`.
813
- MapCache.prototype.clear = mapCacheClear;
814
- MapCache.prototype['delete'] = mapCacheDelete;
815
- MapCache.prototype.get = mapCacheGet;
816
- MapCache.prototype.has = mapCacheHas;
817
- MapCache.prototype.set = mapCacheSet;
818
-
819
- /**
820
- * Creates a stack cache object to store key-value pairs.
821
- *
822
- * @private
823
- * @constructor
824
- * @param {Array} [entries] The key-value pairs to cache.
825
- */
826
- function Stack(entries) {
827
- this.__data__ = new ListCache(entries);
828
- }
829
-
830
- /**
831
- * Removes all key-value entries from the stack.
832
- *
833
- * @private
834
- * @name clear
835
- * @memberOf Stack
836
- */
837
- function stackClear() {
838
- this.__data__ = new ListCache;
839
- }
840
-
841
- /**
842
- * Removes `key` and its value from the stack.
843
- *
844
- * @private
845
- * @name delete
846
- * @memberOf Stack
847
- * @param {string} key The key of the value to remove.
848
- * @returns {boolean} Returns `true` if the entry was removed, else `false`.
849
- */
850
- function stackDelete(key) {
851
- return this.__data__['delete'](key);
852
- }
853
-
854
- /**
855
- * Gets the stack value for `key`.
856
- *
857
- * @private
858
- * @name get
859
- * @memberOf Stack
860
- * @param {string} key The key of the value to get.
861
- * @returns {*} Returns the entry value.
862
- */
863
- function stackGet(key) {
864
- return this.__data__.get(key);
865
- }
866
-
867
- /**
868
- * Checks if a stack value for `key` exists.
869
- *
870
- * @private
871
- * @name has
872
- * @memberOf Stack
873
- * @param {string} key The key of the entry to check.
874
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
875
- */
876
- function stackHas(key) {
877
- return this.__data__.has(key);
878
- }
879
-
880
- /**
881
- * Sets the stack `key` to `value`.
882
- *
883
- * @private
884
- * @name set
885
- * @memberOf Stack
886
- * @param {string} key The key of the value to set.
887
- * @param {*} value The value to set.
888
- * @returns {Object} Returns the stack cache instance.
889
- */
890
- function stackSet(key, value) {
891
- var cache = this.__data__;
892
- if (cache instanceof ListCache) {
893
- var pairs = cache.__data__;
894
- if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
895
- pairs.push([key, value]);
896
- return this;
897
- }
898
- cache = this.__data__ = new MapCache(pairs);
899
- }
900
- cache.set(key, value);
901
- return this;
902
- }
903
-
904
- // Add methods to `Stack`.
905
- Stack.prototype.clear = stackClear;
906
- Stack.prototype['delete'] = stackDelete;
907
- Stack.prototype.get = stackGet;
908
- Stack.prototype.has = stackHas;
909
- Stack.prototype.set = stackSet;
910
-
911
- /**
912
- * Creates an array of the enumerable property names of the array-like `value`.
913
- *
914
- * @private
915
- * @param {*} value The value to query.
916
- * @param {boolean} inherited Specify returning inherited property names.
917
- * @returns {Array} Returns the array of property names.
918
- */
919
- function arrayLikeKeys(value, inherited) {
920
- // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
921
- // Safari 9 makes `arguments.length` enumerable in strict mode.
922
- var result = (isArray(value) || isArguments(value))
923
- ? baseTimes(value.length, String)
924
- : [];
925
-
926
- var length = result.length,
927
- skipIndexes = !!length;
928
-
929
- for (var key in value) {
930
- if ((inherited || hasOwnProperty.call(value, key)) &&
931
- !(skipIndexes && (key == 'length' || isIndex(key, length)))) {
932
- result.push(key);
933
- }
934
- }
935
- return result;
936
- }
937
-
938
- /**
939
- * Assigns `value` to `key` of `object` if the existing value is not equivalent
940
- * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
941
- * for equality comparisons.
942
- *
943
- * @private
944
- * @param {Object} object The object to modify.
945
- * @param {string} key The key of the property to assign.
946
- * @param {*} value The value to assign.
947
- */
948
- function assignValue(object, key, value) {
949
- var objValue = object[key];
950
- if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
951
- (value === undefined && !(key in object))) {
952
- object[key] = value;
953
- }
954
- }
955
-
956
- /**
957
- * Gets the index at which the `key` is found in `array` of key-value pairs.
958
- *
959
- * @private
960
- * @param {Array} array The array to inspect.
961
- * @param {*} key The key to search for.
962
- * @returns {number} Returns the index of the matched value, else `-1`.
963
- */
964
- function assocIndexOf(array, key) {
965
- var length = array.length;
966
- while (length--) {
967
- if (eq(array[length][0], key)) {
968
- return length;
969
- }
970
- }
971
- return -1;
972
- }
973
-
974
- /**
975
- * The base implementation of `_.assign` without support for multiple sources
976
- * or `customizer` functions.
977
- *
978
- * @private
979
- * @param {Object} object The destination object.
980
- * @param {Object} source The source object.
981
- * @returns {Object} Returns `object`.
982
- */
983
- function baseAssign(object, source) {
984
- return object && copyObject(source, keys(source), object);
985
- }
986
-
987
- /**
988
- * The base implementation of `_.clone` and `_.cloneDeep` which tracks
989
- * traversed objects.
990
- *
991
- * @private
992
- * @param {*} value The value to clone.
993
- * @param {boolean} [isDeep] Specify a deep clone.
994
- * @param {boolean} [isFull] Specify a clone including symbols.
995
- * @param {Function} [customizer] The function to customize cloning.
996
- * @param {string} [key] The key of `value`.
997
- * @param {Object} [object] The parent object of `value`.
998
- * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
999
- * @returns {*} Returns the cloned value.
1000
- */
1001
- function baseClone(value, isDeep, isFull, customizer, key, object, stack) {
1002
- var result;
1003
- if (customizer) {
1004
- result = object ? customizer(value, key, object, stack) : customizer(value);
1005
- }
1006
- if (result !== undefined) {
1007
- return result;
1008
- }
1009
- if (!isObject(value)) {
1010
- return value;
1011
- }
1012
- var isArr = isArray(value);
1013
- if (isArr) {
1014
- result = initCloneArray(value);
1015
- if (!isDeep) {
1016
- return copyArray(value, result);
1017
- }
1018
- } else {
1019
- var tag = getTag(value),
1020
- isFunc = tag == funcTag || tag == genTag;
1021
-
1022
- if (isBuffer(value)) {
1023
- return cloneBuffer(value, isDeep);
1024
- }
1025
- if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
1026
- if (isHostObject(value)) {
1027
- return object ? value : {};
1028
- }
1029
- result = initCloneObject(isFunc ? {} : value);
1030
- if (!isDeep) {
1031
- return copySymbols(value, baseAssign(result, value));
1032
- }
1033
- } else {
1034
- if (!cloneableTags[tag]) {
1035
- return object ? value : {};
1036
- }
1037
- result = initCloneByTag(value, tag, baseClone, isDeep);
1038
- }
1039
- }
1040
- // Check for circular references and return its corresponding clone.
1041
- stack || (stack = new Stack);
1042
- var stacked = stack.get(value);
1043
- if (stacked) {
1044
- return stacked;
1045
- }
1046
- stack.set(value, result);
1047
-
1048
- if (!isArr) {
1049
- var props = isFull ? getAllKeys(value) : keys(value);
1050
- }
1051
- arrayEach(props || value, function(subValue, key) {
1052
- if (props) {
1053
- key = subValue;
1054
- subValue = value[key];
1055
- }
1056
- // Recursively populate clone (susceptible to call stack limits).
1057
- assignValue(result, key, baseClone(subValue, isDeep, isFull, customizer, key, value, stack));
1058
- });
1059
- return result;
1060
- }
1061
-
1062
- /**
1063
- * The base implementation of `_.create` without support for assigning
1064
- * properties to the created object.
1065
- *
1066
- * @private
1067
- * @param {Object} prototype The object to inherit from.
1068
- * @returns {Object} Returns the new object.
1069
- */
1070
- function baseCreate(proto) {
1071
- return isObject(proto) ? objectCreate(proto) : {};
1072
- }
1073
-
1074
- /**
1075
- * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
1076
- * `keysFunc` and `symbolsFunc` to get the enumerable property names and
1077
- * symbols of `object`.
1078
- *
1079
- * @private
1080
- * @param {Object} object The object to query.
1081
- * @param {Function} keysFunc The function to get the keys of `object`.
1082
- * @param {Function} symbolsFunc The function to get the symbols of `object`.
1083
- * @returns {Array} Returns the array of property names and symbols.
1084
- */
1085
- function baseGetAllKeys(object, keysFunc, symbolsFunc) {
1086
- var result = keysFunc(object);
1087
- return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
1088
- }
1089
-
1090
- /**
1091
- * The base implementation of `getTag`.
1092
- *
1093
- * @private
1094
- * @param {*} value The value to query.
1095
- * @returns {string} Returns the `toStringTag`.
1096
- */
1097
- function baseGetTag(value) {
1098
- return objectToString.call(value);
1099
- }
1100
-
1101
- /**
1102
- * The base implementation of `_.isNative` without bad shim checks.
1103
- *
1104
- * @private
1105
- * @param {*} value The value to check.
1106
- * @returns {boolean} Returns `true` if `value` is a native function,
1107
- * else `false`.
1108
- */
1109
- function baseIsNative(value) {
1110
- if (!isObject(value) || isMasked(value)) {
1111
- return false;
1112
- }
1113
- var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor;
1114
- return pattern.test(toSource(value));
1115
- }
1116
-
1117
- /**
1118
- * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
1119
- *
1120
- * @private
1121
- * @param {Object} object The object to query.
1122
- * @returns {Array} Returns the array of property names.
1123
- */
1124
- function baseKeys(object) {
1125
- if (!isPrototype(object)) {
1126
- return nativeKeys(object);
1127
- }
1128
- var result = [];
1129
- for (var key in Object(object)) {
1130
- if (hasOwnProperty.call(object, key) && key != 'constructor') {
1131
- result.push(key);
1132
- }
1133
- }
1134
- return result;
1135
- }
1136
-
1137
- /**
1138
- * Creates a clone of `buffer`.
1139
- *
1140
- * @private
1141
- * @param {Buffer} buffer The buffer to clone.
1142
- * @param {boolean} [isDeep] Specify a deep clone.
1143
- * @returns {Buffer} Returns the cloned buffer.
1144
- */
1145
- function cloneBuffer(buffer, isDeep) {
1146
- if (isDeep) {
1147
- return buffer.slice();
1148
- }
1149
- var result = new buffer.constructor(buffer.length);
1150
- buffer.copy(result);
1151
- return result;
1152
- }
1153
-
1154
- /**
1155
- * Creates a clone of `arrayBuffer`.
1156
- *
1157
- * @private
1158
- * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
1159
- * @returns {ArrayBuffer} Returns the cloned array buffer.
1160
- */
1161
- function cloneArrayBuffer(arrayBuffer) {
1162
- var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
1163
- new Uint8Array(result).set(new Uint8Array(arrayBuffer));
1164
- return result;
1165
- }
1166
-
1167
- /**
1168
- * Creates a clone of `dataView`.
1169
- *
1170
- * @private
1171
- * @param {Object} dataView The data view to clone.
1172
- * @param {boolean} [isDeep] Specify a deep clone.
1173
- * @returns {Object} Returns the cloned data view.
1174
- */
1175
- function cloneDataView(dataView, isDeep) {
1176
- var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
1177
- return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
1178
- }
1179
-
1180
- /**
1181
- * Creates a clone of `map`.
1182
- *
1183
- * @private
1184
- * @param {Object} map The map to clone.
1185
- * @param {Function} cloneFunc The function to clone values.
1186
- * @param {boolean} [isDeep] Specify a deep clone.
1187
- * @returns {Object} Returns the cloned map.
1188
- */
1189
- function cloneMap(map, isDeep, cloneFunc) {
1190
- var array = isDeep ? cloneFunc(mapToArray(map), true) : mapToArray(map);
1191
- return arrayReduce(array, addMapEntry, new map.constructor);
1192
- }
1193
-
1194
- /**
1195
- * Creates a clone of `regexp`.
1196
- *
1197
- * @private
1198
- * @param {Object} regexp The regexp to clone.
1199
- * @returns {Object} Returns the cloned regexp.
1200
- */
1201
- function cloneRegExp(regexp) {
1202
- var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
1203
- result.lastIndex = regexp.lastIndex;
1204
- return result;
1205
- }
1206
-
1207
- /**
1208
- * Creates a clone of `set`.
1209
- *
1210
- * @private
1211
- * @param {Object} set The set to clone.
1212
- * @param {Function} cloneFunc The function to clone values.
1213
- * @param {boolean} [isDeep] Specify a deep clone.
1214
- * @returns {Object} Returns the cloned set.
1215
- */
1216
- function cloneSet(set, isDeep, cloneFunc) {
1217
- var array = isDeep ? cloneFunc(setToArray(set), true) : setToArray(set);
1218
- return arrayReduce(array, addSetEntry, new set.constructor);
1219
- }
1220
-
1221
- /**
1222
- * Creates a clone of the `symbol` object.
1223
- *
1224
- * @private
1225
- * @param {Object} symbol The symbol object to clone.
1226
- * @returns {Object} Returns the cloned symbol object.
1227
- */
1228
- function cloneSymbol(symbol) {
1229
- return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
1230
- }
1231
-
1232
- /**
1233
- * Creates a clone of `typedArray`.
1234
- *
1235
- * @private
1236
- * @param {Object} typedArray The typed array to clone.
1237
- * @param {boolean} [isDeep] Specify a deep clone.
1238
- * @returns {Object} Returns the cloned typed array.
1239
- */
1240
- function cloneTypedArray(typedArray, isDeep) {
1241
- var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
1242
- return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
1243
- }
1244
-
1245
- /**
1246
- * Copies the values of `source` to `array`.
1247
- *
1248
- * @private
1249
- * @param {Array} source The array to copy values from.
1250
- * @param {Array} [array=[]] The array to copy values to.
1251
- * @returns {Array} Returns `array`.
1252
- */
1253
- function copyArray(source, array) {
1254
- var index = -1,
1255
- length = source.length;
1256
-
1257
- array || (array = Array(length));
1258
- while (++index < length) {
1259
- array[index] = source[index];
1260
- }
1261
- return array;
1262
- }
1263
-
1264
- /**
1265
- * Copies properties of `source` to `object`.
1266
- *
1267
- * @private
1268
- * @param {Object} source The object to copy properties from.
1269
- * @param {Array} props The property identifiers to copy.
1270
- * @param {Object} [object={}] The object to copy properties to.
1271
- * @param {Function} [customizer] The function to customize copied values.
1272
- * @returns {Object} Returns `object`.
1273
- */
1274
- function copyObject(source, props, object, customizer) {
1275
- object || (object = {});
1276
-
1277
- var index = -1,
1278
- length = props.length;
1279
-
1280
- while (++index < length) {
1281
- var key = props[index];
1282
-
1283
- var newValue = customizer
1284
- ? customizer(object[key], source[key], key, object, source)
1285
- : undefined;
1286
-
1287
- assignValue(object, key, newValue === undefined ? source[key] : newValue);
1288
- }
1289
- return object;
1290
- }
1291
-
1292
- /**
1293
- * Copies own symbol properties of `source` to `object`.
1294
- *
1295
- * @private
1296
- * @param {Object} source The object to copy symbols from.
1297
- * @param {Object} [object={}] The object to copy symbols to.
1298
- * @returns {Object} Returns `object`.
1299
- */
1300
- function copySymbols(source, object) {
1301
- return copyObject(source, getSymbols(source), object);
1302
- }
1303
-
1304
- /**
1305
- * Creates an array of own enumerable property names and symbols of `object`.
1306
- *
1307
- * @private
1308
- * @param {Object} object The object to query.
1309
- * @returns {Array} Returns the array of property names and symbols.
1310
- */
1311
- function getAllKeys(object) {
1312
- return baseGetAllKeys(object, keys, getSymbols);
1313
- }
1314
-
1315
- /**
1316
- * Gets the data for `map`.
1317
- *
1318
- * @private
1319
- * @param {Object} map The map to query.
1320
- * @param {string} key The reference key.
1321
- * @returns {*} Returns the map data.
1322
- */
1323
- function getMapData(map, key) {
1324
- var data = map.__data__;
1325
- return isKeyable(key)
1326
- ? data[typeof key == 'string' ? 'string' : 'hash']
1327
- : data.map;
1328
- }
1329
-
1330
- /**
1331
- * Gets the native function at `key` of `object`.
1332
- *
1333
- * @private
1334
- * @param {Object} object The object to query.
1335
- * @param {string} key The key of the method to get.
1336
- * @returns {*} Returns the function if it's native, else `undefined`.
1337
- */
1338
- function getNative(object, key) {
1339
- var value = getValue(object, key);
1340
- return baseIsNative(value) ? value : undefined;
1341
- }
1342
-
1343
- /**
1344
- * Creates an array of the own enumerable symbol properties of `object`.
1345
- *
1346
- * @private
1347
- * @param {Object} object The object to query.
1348
- * @returns {Array} Returns the array of symbols.
1349
- */
1350
- var getSymbols = nativeGetSymbols ? overArg(nativeGetSymbols, Object) : stubArray;
1351
-
1352
- /**
1353
- * Gets the `toStringTag` of `value`.
1354
- *
1355
- * @private
1356
- * @param {*} value The value to query.
1357
- * @returns {string} Returns the `toStringTag`.
1358
- */
1359
- var getTag = baseGetTag;
1360
-
1361
- // Fallback for data views, maps, sets, and weak maps in IE 11,
1362
- // for data views in Edge < 14, and promises in Node.js.
1363
- if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
1364
- (Map && getTag(new Map) != mapTag) ||
1365
- (Promise && getTag(Promise.resolve()) != promiseTag) ||
1366
- (Set && getTag(new Set) != setTag) ||
1367
- (WeakMap && getTag(new WeakMap) != weakMapTag)) {
1368
- getTag = function(value) {
1369
- var result = objectToString.call(value),
1370
- Ctor = result == objectTag ? value.constructor : undefined,
1371
- ctorString = Ctor ? toSource(Ctor) : undefined;
1372
-
1373
- if (ctorString) {
1374
- switch (ctorString) {
1375
- case dataViewCtorString: return dataViewTag;
1376
- case mapCtorString: return mapTag;
1377
- case promiseCtorString: return promiseTag;
1378
- case setCtorString: return setTag;
1379
- case weakMapCtorString: return weakMapTag;
1380
- }
1381
- }
1382
- return result;
1383
- };
1384
- }
1385
-
1386
- /**
1387
- * Initializes an array clone.
1388
- *
1389
- * @private
1390
- * @param {Array} array The array to clone.
1391
- * @returns {Array} Returns the initialized clone.
1392
- */
1393
- function initCloneArray(array) {
1394
- var length = array.length,
1395
- result = array.constructor(length);
1396
-
1397
- // Add properties assigned by `RegExp#exec`.
1398
- if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
1399
- result.index = array.index;
1400
- result.input = array.input;
1401
- }
1402
- return result;
1403
- }
1404
-
1405
- /**
1406
- * Initializes an object clone.
1407
- *
1408
- * @private
1409
- * @param {Object} object The object to clone.
1410
- * @returns {Object} Returns the initialized clone.
1411
- */
1412
- function initCloneObject(object) {
1413
- return (typeof object.constructor == 'function' && !isPrototype(object))
1414
- ? baseCreate(getPrototype(object))
1415
- : {};
1416
- }
1417
-
1418
- /**
1419
- * Initializes an object clone based on its `toStringTag`.
1420
- *
1421
- * **Note:** This function only supports cloning values with tags of
1422
- * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
1423
- *
1424
- * @private
1425
- * @param {Object} object The object to clone.
1426
- * @param {string} tag The `toStringTag` of the object to clone.
1427
- * @param {Function} cloneFunc The function to clone values.
1428
- * @param {boolean} [isDeep] Specify a deep clone.
1429
- * @returns {Object} Returns the initialized clone.
1430
- */
1431
- function initCloneByTag(object, tag, cloneFunc, isDeep) {
1432
- var Ctor = object.constructor;
1433
- switch (tag) {
1434
- case arrayBufferTag:
1435
- return cloneArrayBuffer(object);
1436
-
1437
- case boolTag:
1438
- case dateTag:
1439
- return new Ctor(+object);
1440
-
1441
- case dataViewTag:
1442
- return cloneDataView(object, isDeep);
1443
-
1444
- case float32Tag: case float64Tag:
1445
- case int8Tag: case int16Tag: case int32Tag:
1446
- case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
1447
- return cloneTypedArray(object, isDeep);
1448
-
1449
- case mapTag:
1450
- return cloneMap(object, isDeep, cloneFunc);
1451
-
1452
- case numberTag:
1453
- case stringTag:
1454
- return new Ctor(object);
1455
-
1456
- case regexpTag:
1457
- return cloneRegExp(object);
1458
-
1459
- case setTag:
1460
- return cloneSet(object, isDeep, cloneFunc);
1461
-
1462
- case symbolTag:
1463
- return cloneSymbol(object);
1464
- }
1465
- }
1466
-
1467
- /**
1468
- * Checks if `value` is a valid array-like index.
1469
- *
1470
- * @private
1471
- * @param {*} value The value to check.
1472
- * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
1473
- * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
1474
- */
1475
- function isIndex(value, length) {
1476
- length = length == null ? MAX_SAFE_INTEGER : length;
1477
- return !!length &&
1478
- (typeof value == 'number' || reIsUint.test(value)) &&
1479
- (value > -1 && value % 1 == 0 && value < length);
1480
- }
1481
-
1482
- /**
1483
- * Checks if `value` is suitable for use as unique object key.
1484
- *
1485
- * @private
1486
- * @param {*} value The value to check.
1487
- * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
1488
- */
1489
- function isKeyable(value) {
1490
- var type = typeof value;
1491
- return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
1492
- ? (value !== '__proto__')
1493
- : (value === null);
1494
- }
1495
-
1496
- /**
1497
- * Checks if `func` has its source masked.
1498
- *
1499
- * @private
1500
- * @param {Function} func The function to check.
1501
- * @returns {boolean} Returns `true` if `func` is masked, else `false`.
1502
- */
1503
- function isMasked(func) {
1504
- return !!maskSrcKey && (maskSrcKey in func);
1505
- }
1506
-
1507
- /**
1508
- * Checks if `value` is likely a prototype object.
1509
- *
1510
- * @private
1511
- * @param {*} value The value to check.
1512
- * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
1513
- */
1514
- function isPrototype(value) {
1515
- var Ctor = value && value.constructor,
1516
- proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
1517
-
1518
- return value === proto;
1519
- }
1520
-
1521
- /**
1522
- * Converts `func` to its source code.
1523
- *
1524
- * @private
1525
- * @param {Function} func The function to process.
1526
- * @returns {string} Returns the source code.
1527
- */
1528
- function toSource(func) {
1529
- if (func != null) {
1530
- try {
1531
- return funcToString.call(func);
1532
- } catch (e) {}
1533
- try {
1534
- return (func + '');
1535
- } catch (e) {}
1536
- }
1537
- return '';
1538
- }
1539
-
1540
- /**
1541
- * This method is like `_.clone` except that it recursively clones `value`.
1542
- *
1543
- * @static
1544
- * @memberOf _
1545
- * @since 1.0.0
1546
- * @category Lang
1547
- * @param {*} value The value to recursively clone.
1548
- * @returns {*} Returns the deep cloned value.
1549
- * @see _.clone
1550
- * @example
1551
- *
1552
- * var objects = [{ 'a': 1 }, { 'b': 2 }];
1553
- *
1554
- * var deep = _.cloneDeep(objects);
1555
- * console.log(deep[0] === objects[0]);
1556
- * // => false
1557
- */
1558
- function cloneDeep(value) {
1559
- return baseClone(value, true, true);
1560
- }
1561
-
1562
- /**
1563
- * Performs a
1564
- * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
1565
- * comparison between two values to determine if they are equivalent.
1566
- *
1567
- * @static
1568
- * @memberOf _
1569
- * @since 4.0.0
1570
- * @category Lang
1571
- * @param {*} value The value to compare.
1572
- * @param {*} other The other value to compare.
1573
- * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
1574
- * @example
1575
- *
1576
- * var object = { 'a': 1 };
1577
- * var other = { 'a': 1 };
1578
- *
1579
- * _.eq(object, object);
1580
- * // => true
1581
- *
1582
- * _.eq(object, other);
1583
- * // => false
1584
- *
1585
- * _.eq('a', 'a');
1586
- * // => true
1587
- *
1588
- * _.eq('a', Object('a'));
1589
- * // => false
1590
- *
1591
- * _.eq(NaN, NaN);
1592
- * // => true
1593
- */
1594
- function eq(value, other) {
1595
- return value === other || (value !== value && other !== other);
1596
- }
1597
-
1598
- /**
1599
- * Checks if `value` is likely an `arguments` object.
1600
- *
1601
- * @static
1602
- * @memberOf _
1603
- * @since 0.1.0
1604
- * @category Lang
1605
- * @param {*} value The value to check.
1606
- * @returns {boolean} Returns `true` if `value` is an `arguments` object,
1607
- * else `false`.
1608
- * @example
1609
- *
1610
- * _.isArguments(function() { return arguments; }());
1611
- * // => true
1612
- *
1613
- * _.isArguments([1, 2, 3]);
1614
- * // => false
1615
- */
1616
- function isArguments(value) {
1617
- // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
1618
- return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
1619
- (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
1620
- }
1621
-
1622
- /**
1623
- * Checks if `value` is classified as an `Array` object.
1624
- *
1625
- * @static
1626
- * @memberOf _
1627
- * @since 0.1.0
1628
- * @category Lang
1629
- * @param {*} value The value to check.
1630
- * @returns {boolean} Returns `true` if `value` is an array, else `false`.
1631
- * @example
1632
- *
1633
- * _.isArray([1, 2, 3]);
1634
- * // => true
1635
- *
1636
- * _.isArray(document.body.children);
1637
- * // => false
1638
- *
1639
- * _.isArray('abc');
1640
- * // => false
1641
- *
1642
- * _.isArray(_.noop);
1643
- * // => false
1644
- */
1645
- var isArray = Array.isArray;
1646
-
1647
- /**
1648
- * Checks if `value` is array-like. A value is considered array-like if it's
1649
- * not a function and has a `value.length` that's an integer greater than or
1650
- * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
1651
- *
1652
- * @static
1653
- * @memberOf _
1654
- * @since 4.0.0
1655
- * @category Lang
1656
- * @param {*} value The value to check.
1657
- * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
1658
- * @example
1659
- *
1660
- * _.isArrayLike([1, 2, 3]);
1661
- * // => true
1662
- *
1663
- * _.isArrayLike(document.body.children);
1664
- * // => true
1665
- *
1666
- * _.isArrayLike('abc');
1667
- * // => true
1668
- *
1669
- * _.isArrayLike(_.noop);
1670
- * // => false
1671
- */
1672
- function isArrayLike(value) {
1673
- return value != null && isLength(value.length) && !isFunction(value);
1674
- }
1675
-
1676
- /**
1677
- * This method is like `_.isArrayLike` except that it also checks if `value`
1678
- * is an object.
1679
- *
1680
- * @static
1681
- * @memberOf _
1682
- * @since 4.0.0
1683
- * @category Lang
1684
- * @param {*} value The value to check.
1685
- * @returns {boolean} Returns `true` if `value` is an array-like object,
1686
- * else `false`.
1687
- * @example
1688
- *
1689
- * _.isArrayLikeObject([1, 2, 3]);
1690
- * // => true
1691
- *
1692
- * _.isArrayLikeObject(document.body.children);
1693
- * // => true
1694
- *
1695
- * _.isArrayLikeObject('abc');
1696
- * // => false
1697
- *
1698
- * _.isArrayLikeObject(_.noop);
1699
- * // => false
1700
- */
1701
- function isArrayLikeObject(value) {
1702
- return isObjectLike(value) && isArrayLike(value);
1703
- }
1704
-
1705
- /**
1706
- * Checks if `value` is a buffer.
1707
- *
1708
- * @static
1709
- * @memberOf _
1710
- * @since 4.3.0
1711
- * @category Lang
1712
- * @param {*} value The value to check.
1713
- * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
1714
- * @example
1715
- *
1716
- * _.isBuffer(new Buffer(2));
1717
- * // => true
1718
- *
1719
- * _.isBuffer(new Uint8Array(2));
1720
- * // => false
1721
- */
1722
- var isBuffer = nativeIsBuffer || stubFalse;
1723
-
1724
- /**
1725
- * Checks if `value` is classified as a `Function` object.
1726
- *
1727
- * @static
1728
- * @memberOf _
1729
- * @since 0.1.0
1730
- * @category Lang
1731
- * @param {*} value The value to check.
1732
- * @returns {boolean} Returns `true` if `value` is a function, else `false`.
1733
- * @example
1734
- *
1735
- * _.isFunction(_);
1736
- * // => true
1737
- *
1738
- * _.isFunction(/abc/);
1739
- * // => false
1740
- */
1741
- function isFunction(value) {
1742
- // The use of `Object#toString` avoids issues with the `typeof` operator
1743
- // in Safari 8-9 which returns 'object' for typed array and other constructors.
1744
- var tag = isObject(value) ? objectToString.call(value) : '';
1745
- return tag == funcTag || tag == genTag;
1746
- }
1747
-
1748
- /**
1749
- * Checks if `value` is a valid array-like length.
1750
- *
1751
- * **Note:** This method is loosely based on
1752
- * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
1753
- *
1754
- * @static
1755
- * @memberOf _
1756
- * @since 4.0.0
1757
- * @category Lang
1758
- * @param {*} value The value to check.
1759
- * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
1760
- * @example
1761
- *
1762
- * _.isLength(3);
1763
- * // => true
1764
- *
1765
- * _.isLength(Number.MIN_VALUE);
1766
- * // => false
1767
- *
1768
- * _.isLength(Infinity);
1769
- * // => false
1770
- *
1771
- * _.isLength('3');
1772
- * // => false
1773
- */
1774
- function isLength(value) {
1775
- return typeof value == 'number' &&
1776
- value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
1777
- }
1778
-
1779
- /**
1780
- * Checks if `value` is the
1781
- * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
1782
- * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
1783
- *
1784
- * @static
1785
- * @memberOf _
1786
- * @since 0.1.0
1787
- * @category Lang
1788
- * @param {*} value The value to check.
1789
- * @returns {boolean} Returns `true` if `value` is an object, else `false`.
1790
- * @example
1791
- *
1792
- * _.isObject({});
1793
- * // => true
1794
- *
1795
- * _.isObject([1, 2, 3]);
1796
- * // => true
1797
- *
1798
- * _.isObject(_.noop);
1799
- * // => true
1800
- *
1801
- * _.isObject(null);
1802
- * // => false
1803
- */
1804
- function isObject(value) {
1805
- var type = typeof value;
1806
- return !!value && (type == 'object' || type == 'function');
1807
- }
1808
-
1809
- /**
1810
- * Checks if `value` is object-like. A value is object-like if it's not `null`
1811
- * and has a `typeof` result of "object".
1812
- *
1813
- * @static
1814
- * @memberOf _
1815
- * @since 4.0.0
1816
- * @category Lang
1817
- * @param {*} value The value to check.
1818
- * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
1819
- * @example
1820
- *
1821
- * _.isObjectLike({});
1822
- * // => true
1823
- *
1824
- * _.isObjectLike([1, 2, 3]);
1825
- * // => true
1826
- *
1827
- * _.isObjectLike(_.noop);
1828
- * // => false
1829
- *
1830
- * _.isObjectLike(null);
1831
- * // => false
1832
- */
1833
- function isObjectLike(value) {
1834
- return !!value && typeof value == 'object';
1835
- }
1836
-
1837
- /**
1838
- * Creates an array of the own enumerable property names of `object`.
1839
- *
1840
- * **Note:** Non-object values are coerced to objects. See the
1841
- * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
1842
- * for more details.
1843
- *
1844
- * @static
1845
- * @since 0.1.0
1846
- * @memberOf _
1847
- * @category Object
1848
- * @param {Object} object The object to query.
1849
- * @returns {Array} Returns the array of property names.
1850
- * @example
1851
- *
1852
- * function Foo() {
1853
- * this.a = 1;
1854
- * this.b = 2;
1855
- * }
1856
- *
1857
- * Foo.prototype.c = 3;
1858
- *
1859
- * _.keys(new Foo);
1860
- * // => ['a', 'b'] (iteration order is not guaranteed)
1861
- *
1862
- * _.keys('hi');
1863
- * // => ['0', '1']
1864
- */
1865
- function keys(object) {
1866
- return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
1867
- }
1868
-
1869
- /**
1870
- * This method returns a new empty array.
1871
- *
1872
- * @static
1873
- * @memberOf _
1874
- * @since 4.13.0
1875
- * @category Util
1876
- * @returns {Array} Returns the new empty array.
1877
- * @example
1878
- *
1879
- * var arrays = _.times(2, _.stubArray);
1880
- *
1881
- * console.log(arrays);
1882
- * // => [[], []]
1883
- *
1884
- * console.log(arrays[0] === arrays[1]);
1885
- * // => false
1886
- */
1887
- function stubArray() {
1888
- return [];
1889
- }
1890
-
1891
- /**
1892
- * This method returns `false`.
1893
- *
1894
- * @static
1895
- * @memberOf _
1896
- * @since 4.13.0
1897
- * @category Util
1898
- * @returns {boolean} Returns `false`.
1899
- * @example
1900
- *
1901
- * _.times(2, _.stubFalse);
1902
- * // => [false, false]
1903
- */
1904
- function stubFalse() {
1905
- return false;
1906
- }
1907
-
1908
- module.exports = cloneDeep;
1909
- }(lodash_clonedeep, lodash_clonedeep.exports));
1910
-
1911
- var clone = lodash_clonedeep.exports;
1912
-
1913
- var version$1 = "4.1.0";
1914
-
1915
- const version = version$1;
1916
- const RAWNBSP = "\u00A0";
1917
- // separates the value from flags
1918
- function x(something) {
1919
- // console.log(
1920
- // `007 ${`\u001b[${35}m${`x() incoming "${something}"`}\u001b[${39}m`}`
1921
- // );
1922
- const res = {
1923
- value: something,
1924
- hungry: false,
1925
- optional: false,
1926
- };
1927
- if ((res.value.endsWith("?*") || res.value.endsWith("*?")) &&
1928
- res.value.length > 2) {
1929
- res.value = res.value.slice(0, res.value.length - 2);
1930
- res.optional = true;
1931
- res.hungry = true;
1932
- }
1933
- else if (res.value.endsWith("?") && res.value.length > 1) {
1934
- res.value = res.value.slice(0, ~-res.value.length);
1935
- res.optional = true;
1936
- }
1937
- else if (res.value.endsWith("*") && res.value.length > 1) {
1938
- res.value = res.value.slice(0, ~-res.value.length);
1939
- res.hungry = true;
1940
- }
1941
- // console.log(
1942
- // `036 ${`\u001b[${35}m${`x() returning ${JSON.stringify(
1943
- // res,
1944
- // null,
1945
- // 0
1946
- // )}`}\u001b[${39}m`}`
1947
- // );
1948
- return res;
1949
- }
1950
- function isNum(something) {
1951
- return typeof something === "number";
1952
- }
1953
- function isStr(something) {
1954
- return typeof something === "string";
1955
- }
1956
- function rightMain({ str, idx = 0, stopAtNewlines = false, stopAtRawNbsp = false, }) {
1957
- if (typeof str !== "string" || !str.length) {
1958
- return null;
1959
- }
1960
- if (!idx || typeof idx !== "number") {
1961
- idx = 0;
1962
- }
1963
- if (!str[idx + 1]) {
1964
- return null;
1965
- }
1966
- if (
1967
- // next character exists
1968
- str[idx + 1] &&
1969
- // and...
1970
- // it's solid
1971
- (str[idx + 1].trim() ||
1972
- // or it's a whitespace character, but...
1973
- // stop at newlines is on
1974
- (stopAtNewlines &&
1975
- // and it's a newline
1976
- "\n\r".includes(str[idx + 1])) ||
1977
- // stop at raw nbsp is on
1978
- (stopAtRawNbsp &&
1979
- // and it's a raw nbsp
1980
- str[idx + 1] === RAWNBSP))) {
1981
- // best case scenario - next character is non-whitespace:
1982
- return idx + 1;
1983
- }
1984
- if (
1985
- // second next character exists
1986
- str[idx + 2] &&
1987
- // and...
1988
- // it's solid
1989
- (str[idx + 2].trim() ||
1990
- // it's a whitespace character and...
1991
- // stop at newlines is on
1992
- (stopAtNewlines &&
1993
- // and it's a newline
1994
- "\n\r".includes(str[idx + 2])) ||
1995
- // stop at raw nbsp is on
1996
- (stopAtRawNbsp &&
1997
- // and it's a raw nbsp
1998
- str[idx + 2] === RAWNBSP))) {
1999
- // second best case scenario - second next character is non-whitespace:
2000
- return idx + 2;
2001
- }
2002
- // worst case scenario - traverse forwards
2003
- for (let i = idx + 1, len = str.length; i < len; i++) {
2004
- if (
2005
- // it's solid
2006
- str[i].trim() ||
2007
- // it's a whitespace character and...
2008
- // stop at newlines is on
2009
- (stopAtNewlines &&
2010
- // and it's a newline
2011
- "\n\r".includes(str[i])) ||
2012
- // stop at raw nbsp is on
2013
- (stopAtRawNbsp &&
2014
- // and it's a raw nbsp
2015
- str[i] === RAWNBSP)) {
2016
- return i;
2017
- }
2018
- }
2019
- return null;
2020
- }
2021
- function right(str, idx = 0) {
2022
- return rightMain({ str, idx, stopAtNewlines: false, stopAtRawNbsp: false });
2023
- }
2024
- function rightStopAtNewLines(str, idx) {
2025
- return rightMain({ str, idx, stopAtNewlines: true, stopAtRawNbsp: false });
2026
- }
2027
- function rightStopAtRawNbsp(str, idx) {
2028
- return rightMain({ str, idx, stopAtNewlines: false, stopAtRawNbsp: true });
2029
- }
2030
- //
2031
- //
2032
- // lllllll ffffffffffffffff tttt (((((( ))))))
2033
- // l:::::l f::::::::::::::::f ttt:::t ((::::::( )::::::))
2034
- // l:::::l f::::::::::::::::::f t:::::t ((:::::::( ):::::::))
2035
- // l:::::l f::::::fffffff:::::f t:::::t (:::::::(( )):::::::)
2036
- // l::::l eeeeeeeeeeee f:::::f ffffffttttttt:::::ttttttt (::::::( )::::::)
2037
- // l::::l ee::::::::::::ee f:::::f t:::::::::::::::::t (:::::( ):::::)
2038
- // l::::l e::::::eeeee:::::eef:::::::ffffff t:::::::::::::::::t (:::::( ):::::)
2039
- // l::::l e::::::e e:::::ef::::::::::::f tttttt:::::::tttttt (:::::( ):::::)
2040
- // l::::l e:::::::eeeee::::::ef::::::::::::f t:::::t (:::::( ):::::)
2041
- // l::::l e:::::::::::::::::e f:::::::ffffff t:::::t (:::::( ):::::)
2042
- // l::::l e::::::eeeeeeeeeee f:::::f t:::::t (:::::( ):::::)
2043
- // l::::l e:::::::e f:::::f t:::::t tttttt (::::::( )::::::)
2044
- // l::::::le::::::::e f:::::::f t::::::tttt:::::t (:::::::(( )):::::::)
2045
- // l::::::l e::::::::eeeeeeee f:::::::f tt::::::::::::::t ((:::::::( ):::::::))
2046
- // l::::::l ee:::::::::::::e f:::::::f tt:::::::::::tt ((::::::( )::::::)
2047
- // llllllll eeeeeeeeeeeeee fffffffff ttttttttttt (((((( ))))))
2048
- //
2049
- //
2050
- // Finds the index of the first non-whitespace character on the left
2051
- function leftMain({ str, idx, stopAtNewlines, stopAtRawNbsp }) {
2052
- if (typeof str !== "string" || !str.length) {
2053
- return null;
2054
- }
2055
- if (!idx || typeof idx !== "number") {
2056
- idx = 0;
2057
- }
2058
- if (idx < 1) {
2059
- return null;
2060
- }
2061
- if (
2062
- // ~- means minus one, in bitwise
2063
- str[~-idx] &&
2064
- // either it's not a whitespace
2065
- (str[~-idx].trim() ||
2066
- // or it is whitespace, but...
2067
- // stop at newlines is on
2068
- (stopAtNewlines &&
2069
- // and it's a newline
2070
- "\n\r".includes(str[~-idx])) ||
2071
- // stop at raw nbsp is on
2072
- (stopAtRawNbsp &&
2073
- // and it's a raw nbsp
2074
- str[~-idx] === RAWNBSP))) {
2075
- // best case scenario - next character is non-whitespace:
2076
- return ~-idx;
2077
- }
2078
- // if we reached this point, this means character on the left is whitespace -
2079
- // fine - check the next character on the left, str[idx - 2]
2080
- if (
2081
- // second character exists
2082
- str[idx - 2] &&
2083
- // either it's not whitespace so Bob's your uncle here's non-whitespace character
2084
- (str[idx - 2].trim() ||
2085
- // it is whitespace, but...
2086
- // stop at newlines is on
2087
- (stopAtNewlines &&
2088
- // it's some sort of a newline
2089
- "\n\r".includes(str[idx - 2])) ||
2090
- // stop at raw nbsp is on
2091
- (stopAtRawNbsp &&
2092
- // and it's a raw nbsp
2093
- str[idx - 2] === RAWNBSP))) {
2094
- // second best case scenario - second next character is non-whitespace:
2095
- return idx - 2;
2096
- }
2097
- // worst case scenario - traverse backwards
2098
- for (let i = idx; i--;) {
2099
- if (str[i] &&
2100
- // it's non-whitespace character
2101
- (str[i].trim() ||
2102
- // or it is whitespace character, but...
2103
- // stop at newlines is on
2104
- (stopAtNewlines &&
2105
- // it's some sort of a newline
2106
- "\n\r".includes(str[i])) ||
2107
- // stop at raw nbsp is on
2108
- (stopAtRawNbsp &&
2109
- // and it's a raw nbsp
2110
- str[i] === RAWNBSP))) {
2111
- return i;
2112
- }
2113
- }
2114
- return null;
2115
- }
2116
- function left(str, idx = 0) {
2117
- return leftMain({ str, idx, stopAtNewlines: false, stopAtRawNbsp: false });
2118
- }
2119
- function leftStopAtNewLines(str, idx) {
2120
- return leftMain({ str, idx, stopAtNewlines: true, stopAtRawNbsp: false });
2121
- }
2122
- function leftStopAtRawNbsp(str, idx) {
2123
- return leftMain({ str, idx, stopAtNewlines: false, stopAtRawNbsp: true });
2124
- }
2125
- function seq(direction, str, idx, opts, args) {
2126
- if (typeof str !== "string" || !str.length) {
2127
- return null;
2128
- }
2129
- if (typeof idx !== "number") {
2130
- idx = 0;
2131
- }
2132
- if ((direction === "right" && !str[idx + 1]) ||
2133
- (direction === "left" && !str[~-idx])) {
2134
- // if next character on the particular side doesn't even exist, that's a quick end
2135
- return null;
2136
- }
2137
- // we start to look on the particular side from index "idx".
2138
- // From there on, each finding sets its index to "lastFinding" so that we
2139
- // know where to start looking on from next. Any failed finding
2140
- // in a sequence is instant return "null".
2141
- let lastFinding = idx;
2142
- const gaps = [];
2143
- let leftmostChar;
2144
- let rightmostChar;
2145
- let satiated; // used to prevent mismatching action kicking in when that
2146
- // mismatching is after multiple hungry findings.
2147
- // go through all arguments
2148
- let i = 0;
2149
- // we use while loop because for loop would not do in hungry matching cases,
2150
- // where we need to repeat same step (hungrily matched character) few times.
2151
- while (i < args.length) {
2152
- if (!isStr(args[i]) || !args[i].length) {
2153
- i += 1;
2154
- continue;
2155
- }
2156
- const { value, optional, hungry } = x(args[i]);
2157
- const whattsOnTheSide = direction === "right" ? right(str, lastFinding) : left(str, lastFinding);
2158
- if ((opts.i &&
2159
- str[whattsOnTheSide].toLowerCase() === value.toLowerCase()) ||
2160
- (!opts.i && str[whattsOnTheSide] === value)) {
2161
- // OK, one was matched, we're in the right clauses (otherwise we'd skip
2162
- // if it was optional or break the matching)
2163
- // Now, it depends, is it a hungry match, because if so, we need to look
2164
- // for more of these.
2165
- const temp = direction === "right"
2166
- ? right(str, whattsOnTheSide)
2167
- : left(str, whattsOnTheSide);
2168
- if (hungry &&
2169
- ((opts.i &&
2170
- str[temp].toLowerCase() === value.toLowerCase()) ||
2171
- (!opts.i && str[temp] === value))) {
2172
- // satiated means next iteration is allowed not to match anything
2173
- satiated = true;
2174
- }
2175
- else {
2176
- // move on
2177
- i += 1;
2178
- }
2179
- // 1. first, tackle gaps
2180
- // if there was a gap, push it to gaps array:
2181
- if (typeof whattsOnTheSide === "number" &&
2182
- direction === "right" &&
2183
- whattsOnTheSide > lastFinding + 1) {
2184
- gaps.push([lastFinding + 1, whattsOnTheSide]);
2185
- }
2186
- else if (direction === "left" &&
2187
- typeof whattsOnTheSide === "number" &&
2188
- whattsOnTheSide < ~-lastFinding) {
2189
- gaps.unshift([whattsOnTheSide + 1, lastFinding]);
2190
- }
2191
- // 2. second, tackle the matching
2192
- lastFinding = whattsOnTheSide;
2193
- if (direction === "right") {
2194
- if (leftmostChar === undefined) {
2195
- leftmostChar = whattsOnTheSide;
2196
- }
2197
- rightmostChar = whattsOnTheSide;
2198
- }
2199
- else {
2200
- if (rightmostChar === undefined) {
2201
- rightmostChar = whattsOnTheSide;
2202
- }
2203
- leftmostChar = whattsOnTheSide;
2204
- }
2205
- }
2206
- else if (optional) {
2207
- i += 1;
2208
- continue;
2209
- }
2210
- else if (satiated) {
2211
- i += 1;
2212
- satiated = undefined;
2213
- continue;
2214
- }
2215
- else {
2216
- return null;
2217
- }
2218
- }
2219
- // if all arguments in sequence were empty strings, we return falsey null:
2220
- if (leftmostChar === undefined || rightmostChar === undefined) {
2221
- return null;
2222
- }
2223
- return { gaps, leftmostChar, rightmostChar };
2224
- }
2225
- //
2226
- //
2227
- // lllllll
2228
- // l:::::l
2229
- // l:::::l
2230
- // l:::::l
2231
- // l::::l rrrrr rrrrrrrrr ssssssssss eeeeeeeeeeee qqqqqqqqq qqqqq
2232
- // l::::l r::::rrr:::::::::r ss::::::::::s ee::::::::::::ee q:::::::::qqq::::q
2233
- // l::::l r:::::::::::::::::r ss:::::::::::::s e::::::eeeee:::::ee q:::::::::::::::::q
2234
- // l::::l --------------- rr::::::rrrrr::::::r s::::::ssss:::::se::::::e e:::::eq::::::qqqqq::::::qq
2235
- // l::::l -:::::::::::::- r:::::r r:::::r s:::::s ssssss e:::::::eeeee::::::eq:::::q q:::::q
2236
- // l::::l --------------- r:::::r rrrrrrr s::::::s e:::::::::::::::::e q:::::q q:::::q
2237
- // l::::l r:::::r s::::::s e::::::eeeeeeeeeee q:::::q q:::::q
2238
- // l::::l r:::::r ssssss s:::::s e:::::::e q::::::q q:::::q
2239
- // l::::::l r:::::r s:::::ssss::::::se::::::::e q:::::::qqqqq:::::q
2240
- // l::::::l r:::::r s::::::::::::::s e::::::::eeeeeeee q::::::::::::::::q
2241
- // l::::::l r:::::r s:::::::::::ss ee:::::::::::::e qq::::::::::::::q
2242
- // llllllll rrrrrrr sssssssssss eeeeeeeeeeeeee qqqqqqqq::::::q
2243
- // q:::::q
2244
- // q:::::q
2245
- // q:::::::q
2246
- // q:::::::q
2247
- // q:::::::q
2248
- // qqqqqqqqq
2249
- const seqDefaults = {
2250
- i: false,
2251
- };
2252
- function leftSeq(str, idx, ...args) {
2253
- // if there are no arguments, it becomes left()
2254
- if (!args || !args.length) {
2255
- // console.log(`493 leftSeq() calling left()`);
2256
- // return left(str, idx);
2257
- throw new Error(`string-left-right/leftSeq(): only two input arguments were passed! Did you intend to use left() method instead?`);
2258
- }
2259
- let opts;
2260
- if (lodash_isplainobject(args[0])) {
2261
- opts = { ...seqDefaults, ...args.shift() };
2262
- }
2263
- else {
2264
- opts = seqDefaults;
2265
- }
2266
- return seq("left", str, idx, opts, Array.from(args).reverse());
2267
- }
2268
- function rightSeq(str, idx, ...args) {
2269
- // if there are no arguments, it becomes right()
2270
- if (!args || !args.length) {
2271
- // console.log(`520 rightSeq() calling right()`);
2272
- // return right(str, idx);
2273
- throw new Error(`string-left-right/rightSeq(): only two input arguments were passed! Did you intend to use right() method instead?`);
2274
- }
2275
- let opts;
2276
- if (lodash_isplainobject(args[0])) {
2277
- opts = { ...seqDefaults, ...args.shift() };
2278
- }
2279
- else {
2280
- opts = seqDefaults;
2281
- }
2282
- return seq("right", str, idx, opts, args);
2283
- }
2284
- // chomp() lets you match sequences of characters with zero or more whitespace characters in between each,
2285
- // on left or right of a given string index, with optional granular control over surrounding
2286
- // whitespace-munching. Yes, that's a technical term.
2287
- function chomp(direction, str, idx, opts, args = []) {
2288
- //
2289
- // INSURANCE.
2290
- //
2291
- if (typeof str !== "string" || !str.length) {
2292
- return null;
2293
- }
2294
- if (!idx || typeof idx !== "number") {
2295
- idx = 0;
2296
- }
2297
- if ((direction === "right" && !str[idx + 1]) ||
2298
- (direction === "left" && +idx === 0)) {
2299
- return null;
2300
- }
2301
- //
2302
- // ACTION.
2303
- //
2304
- let lastRes = null;
2305
- let lastIdx = null;
2306
- do {
2307
- lastRes =
2308
- direction === "right"
2309
- ? rightSeq(str, typeof lastIdx === "number" ? lastIdx : idx, ...args)
2310
- : leftSeq(str, typeof lastIdx === "number" ? lastIdx : idx, ...args);
2311
- if (lastRes !== null) {
2312
- lastIdx =
2313
- direction === "right" ? lastRes.rightmostChar : lastRes.leftmostChar;
2314
- }
2315
- } while (lastRes);
2316
- if (lastIdx != null && direction === "right") {
2317
- lastIdx += 1;
2318
- }
2319
- if (lastIdx === null) {
2320
- // if nothing was matched
2321
- return null;
2322
- }
2323
- // the last thing what's left to do is tackle the whitespace on the right.
2324
- // Depending on opts.mode, there can be different ways.
2325
- if (direction === "right") {
2326
- //
2327
- //
2328
- //
2329
- // R I G H T
2330
- //
2331
- //
2332
- //
2333
- // quick ending - no whitespace on the right at all:
2334
- if (str[lastIdx] && str[lastIdx].trim()) {
2335
- // if the character follows tightly right after,
2336
- return lastIdx;
2337
- }
2338
- // Default, 0 is leave single space if possible or chomp up to nearest line
2339
- // break character or chomp up to EOL
2340
- const whatsOnTheRight = right(str, lastIdx);
2341
- if (!opts || opts.mode === 0) {
2342
- if (whatsOnTheRight === lastIdx + 1) {
2343
- // if there's one whitespace character, Bob's your uncle here's
2344
- // the final result
2345
- return lastIdx;
2346
- }
2347
- if (str.slice(lastIdx, whatsOnTheRight || str.length).trim() ||
2348
- str.slice(lastIdx, whatsOnTheRight || str.length).includes("\n") ||
2349
- str.slice(lastIdx, whatsOnTheRight || str.length).includes("\r")) {
2350
- // if there are line break characters between current "lastIdx" we're on
2351
- // and the first non-whitespace character on the right
2352
- for (let y = lastIdx, len = str.length; y < len; y++) {
2353
- if (`\n\r`.includes(str[y])) {
2354
- return y;
2355
- }
2356
- }
2357
- }
2358
- else {
2359
- return whatsOnTheRight ? ~-whatsOnTheRight : str.length;
2360
- }
2361
- }
2362
- else if (opts.mode === 1) {
2363
- // mode 1 doesn't touch the whitespace, so it's quick:
2364
- return lastIdx;
2365
- }
2366
- else if (opts.mode === 2) {
2367
- // mode 2 hungrily chomps all whitespace except newlines
2368
- const remainderString = str.slice(lastIdx);
2369
- if (remainderString.trim() ||
2370
- remainderString.includes("\n") ||
2371
- remainderString.includes("\r")) {
2372
- // if there are line breaks, we need to loop to chomp up to them but not further
2373
- for (let y = lastIdx, len = str.length; y < len; y++) {
2374
- if (str[y].trim() || `\n\r`.includes(str[y])) {
2375
- return y;
2376
- }
2377
- }
2378
- }
2379
- // ELSE, last but not least, chomp to the end:
2380
- return str.length;
2381
- }
2382
- // ELSE - mode 3
2383
- // mode 3 is an aggro chomp - will chump all whitespace
2384
- return whatsOnTheRight || str.length;
2385
- //
2386
- //
2387
- //
2388
- // R I G H T E N D S
2389
- //
2390
- //
2391
- //
2392
- }
2393
- //
2394
- //
2395
- //
2396
- // L E F T
2397
- //
2398
- //
2399
- //
2400
- // quick ending - no whitespace on the left at all:
2401
- if (str[lastIdx] && str[~-lastIdx] && str[~-lastIdx].trim()) {
2402
- // if the non-whitespace character is on the left
2403
- return lastIdx;
2404
- }
2405
- // Default, 0 is leave single space if possible or chomp up to nearest line
2406
- // break character or chomp up to index zero, start of the string
2407
- const whatsOnTheLeft = left(str, lastIdx);
2408
- if (!opts || opts.mode === 0) {
2409
- if (whatsOnTheLeft === lastIdx - 2) {
2410
- // if there's one whitespace character between here and next real character, Bob's your uncle here's
2411
- // the final result
2412
- return lastIdx;
2413
- }
2414
- if (str.slice(0, lastIdx).trim() ||
2415
- str.slice(0, lastIdx).includes("\n") ||
2416
- str.slice(0, lastIdx).includes("\r")) {
2417
- // if there are line break characters between current "lastIdx" we're on
2418
- // and the first non-whitespace character on the right
2419
- for (let y = lastIdx; y--;) {
2420
- if (`\n\r`.includes(str[y]) || str[y].trim()) {
2421
- return y + 1 + (str[y].trim() ? 1 : 0);
2422
- }
2423
- }
2424
- }
2425
- // ELSE
2426
- return 0;
2427
- }
2428
- if (opts.mode === 1) {
2429
- // mode 1 doesn't touch the whitespace, so it's quick:
2430
- return lastIdx;
2431
- }
2432
- if (opts.mode === 2) {
2433
- // mode 2 hungrily chomps all whitespace except newlines
2434
- const remainderString = str.slice(0, lastIdx);
2435
- if (remainderString.trim() ||
2436
- remainderString.includes("\n") ||
2437
- remainderString.includes("\r")) {
2438
- // if there are line breaks, we need to loop to chomp up to them but not further
2439
- for (let y = lastIdx; y--;) {
2440
- if (str[y].trim() || `\n\r`.includes(str[y])) {
2441
- return y + 1;
2442
- }
2443
- }
2444
- }
2445
- // ELSE, last but not least, chomp to the end:
2446
- return 0;
2447
- }
2448
- // ELSE - mode 3
2449
- // mode 3 is an aggro chomp - will chump all whitespace
2450
- return whatsOnTheLeft !== null ? whatsOnTheLeft + 1 : 0;
2451
- //
2452
- //
2453
- //
2454
- // L E F T E N D S
2455
- //
2456
- //
2457
- //
2458
- }
2459
- //
2460
- //
2461
- // hhhhhhh LLLLLLLLLLL
2462
- // h:::::h L:::::::::L
2463
- // h:::::h L:::::::::L
2464
- // h:::::h LL:::::::LL
2465
- // cccccccccccccccch::::h hhhhh mmmmmmm mmmmmmm ppppp ppppppppp L:::::L
2466
- // cc:::::::::::::::ch::::hh:::::hhh mm:::::::m m:::::::mm p::::ppp:::::::::p L:::::L
2467
- // c:::::::::::::::::ch::::::::::::::hh m::::::::::mm::::::::::mp:::::::::::::::::p L:::::L
2468
- // c:::::::cccccc:::::ch:::::::hhh::::::h m::::::::::::::::::::::mpp::::::ppppp::::::p L:::::L
2469
- // c::::::c ccccccch::::::h h::::::hm:::::mmm::::::mmm:::::m p:::::p p:::::p L:::::L
2470
- // c:::::c h:::::h h:::::hm::::m m::::m m::::m p:::::p p:::::p L:::::L
2471
- // c:::::c h:::::h h:::::hm::::m m::::m m::::m p:::::p p:::::p L:::::L
2472
- // c::::::c ccccccch:::::h h:::::hm::::m m::::m m::::m p:::::p p::::::p L:::::L LLLLLL
2473
- // c:::::::cccccc:::::ch:::::h h:::::hm::::m m::::m m::::m p:::::ppppp:::::::pLL:::::::LLLLLLLLL:::::L
2474
- // c:::::::::::::::::ch:::::h h:::::hm::::m m::::m m::::m p::::::::::::::::p L::::::::::::::::::::::L
2475
- // cc:::::::::::::::ch:::::h h:::::hm::::m m::::m m::::m p::::::::::::::pp L::::::::::::::::::::::L
2476
- // cccccccccccccccchhhhhhh hhhhhhhmmmmmm mmmmmm mmmmmm p::::::pppppppp LLLLLLLLLLLLLLLLLLLLLLLL
2477
- // p:::::p
2478
- // p:::::p
2479
- // p:::::::p
2480
- // p:::::::p
2481
- // p:::::::p
2482
- // ppppppppp
2483
- //
2484
- function chompLeft(str, idx, ...args) {
2485
- // if there are no arguments, null
2486
- if (!args.length || (args.length === 1 && lodash_isplainobject(args[0]))) {
2487
- return null;
2488
- }
2489
- //
2490
- // OPTS.
2491
- //
2492
- // modes:
2493
- // 0 - leave single space if possible
2494
- // 1 - stop at first space, leave whitespace alone
2495
- // 2 - aggressively chomp all whitespace except newlines
2496
- // 3 - aggressively chomp all whitespace including newlines
2497
- const defaults = {
2498
- mode: 0,
2499
- };
2500
- // now, the first element within args can be opts.
2501
- // It's a plain object so it's easy to distinguish
2502
- if (lodash_isplainobject(args[0])) {
2503
- const opts = { ...defaults, ...clone(args[0]) };
2504
- if (!opts.mode) {
2505
- opts.mode = 0;
2506
- }
2507
- else if (isStr(opts.mode) && `0123`.includes(opts.mode)) {
2508
- opts.mode = Number.parseInt(opts.mode, 10);
2509
- }
2510
- else if (!isNum(opts.mode)) {
2511
- throw new Error(`string-left-right/chompLeft(): [THROW_ID_01] the opts.mode is wrong! It should be 0, 1, 2 or 3. It was given as ${opts.mode} (type ${typeof opts.mode})`);
2512
- }
2513
- return chomp("left", str, idx, opts, clone(args).slice(1));
2514
- }
2515
- if (!isStr(args[0])) {
2516
- return chomp("left", str, idx, defaults, clone(args).slice(1));
2517
- }
2518
- // ELSE
2519
- // all arguments are values to match, first element is not options object
2520
- return chomp("left", str, idx, defaults, clone(args));
2521
- }
2522
- //
2523
- //
2524
- // hhhhhhh RRRRRRRRRRRRRRRRR
2525
- // h:::::h R::::::::::::::::R
2526
- // h:::::h R::::::RRRRRR:::::R
2527
- // h:::::h RR:::::R R:::::R
2528
- // cccccccccccccccch::::h hhhhh mmmmmmm mmmmmmm ppppp ppppppppp R::::R R:::::R
2529
- // cc:::::::::::::::ch::::hh:::::hhh mm:::::::m m:::::::mm p::::ppp:::::::::p R::::R R:::::R
2530
- // c:::::::::::::::::ch::::::::::::::hh m::::::::::mm::::::::::mp:::::::::::::::::p R::::RRRRRR:::::R
2531
- // c:::::::cccccc:::::ch:::::::hhh::::::h m::::::::::::::::::::::mpp::::::ppppp::::::p R:::::::::::::RR
2532
- // c::::::c ccccccch::::::h h::::::hm:::::mmm::::::mmm:::::m p:::::p p:::::p R::::RRRRRR:::::R
2533
- // c:::::c h:::::h h:::::hm::::m m::::m m::::m p:::::p p:::::p R::::R R:::::R
2534
- // c:::::c h:::::h h:::::hm::::m m::::m m::::m p:::::p p:::::p R::::R R:::::R
2535
- // c::::::c ccccccch:::::h h:::::hm::::m m::::m m::::m p:::::p p::::::p R::::R R:::::R
2536
- // c:::::::cccccc:::::ch:::::h h:::::hm::::m m::::m m::::m p:::::ppppp:::::::pRR:::::R R:::::R
2537
- // c:::::::::::::::::ch:::::h h:::::hm::::m m::::m m::::m p::::::::::::::::p R::::::R R:::::R
2538
- // cc:::::::::::::::ch:::::h h:::::hm::::m m::::m m::::m p::::::::::::::pp R::::::R R:::::R
2539
- // cccccccccccccccchhhhhhh hhhhhhhmmmmmm mmmmmm mmmmmm p::::::pppppppp RRRRRRRR RRRRRRR
2540
- // p:::::p
2541
- // p:::::p
2542
- // p:::::::p
2543
- // p:::::::p
2544
- // p:::::::p
2545
- // ppppppppp
2546
- //
2547
- function chompRight(str, idx, ...args) {
2548
- // if there are no arguments, null
2549
- if (!args.length || (args.length === 1 && lodash_isplainobject(args[0]))) {
2550
- return null;
2551
- }
2552
- //
2553
- // OPTS.
2554
- //
2555
- // modes:
2556
- // 0 - leave single space if possible
2557
- // 1 - stop at first space, leave whitespace alone
2558
- // 2 - aggressively chomp all whitespace except newlines
2559
- // 3 - aggressively chomp all whitespace including newlines
2560
- const defaults = {
2561
- mode: 0,
2562
- };
2563
- // now, the first element within args can be opts.
2564
- // It's a plain object so it's easy to distinguish
2565
- if (lodash_isplainobject(args[0])) {
2566
- const opts = { ...defaults, ...clone(args[0]) };
2567
- if (!opts.mode) {
2568
- opts.mode = 0;
2569
- }
2570
- else if (isStr(opts.mode) && `0123`.includes(opts.mode)) {
2571
- opts.mode = Number.parseInt(opts.mode, 10);
2572
- }
2573
- else if (!isNum(opts.mode)) {
2574
- throw new Error(`string-left-right/chompRight(): [THROW_ID_02] the opts.mode is wrong! It should be 0, 1, 2 or 3. It was given as ${opts.mode} (type ${typeof opts.mode})`);
2575
- }
2576
- return chomp("right", str, idx, opts, clone(args).slice(1));
2577
- }
2578
- if (!isStr(args[0])) {
2579
- return chomp("right", str, idx, defaults, clone(args).slice(1));
2580
- }
2581
- // ELSE
2582
- // all arguments are values to match, first element is not options object
2583
- return chomp("right", str, idx, defaults, clone(args));
2584
- }
2585
-
2586
- exports.chompLeft = chompLeft;
2587
- exports.chompRight = chompRight;
2588
- exports.left = left;
2589
- exports.leftSeq = leftSeq;
2590
- exports.leftStopAtNewLines = leftStopAtNewLines;
2591
- exports.leftStopAtRawNbsp = leftStopAtRawNbsp;
2592
- exports.right = right;
2593
- exports.rightSeq = rightSeq;
2594
- exports.rightStopAtNewLines = rightStopAtNewLines;
2595
- exports.rightStopAtRawNbsp = rightStopAtRawNbsp;
2596
- exports.version = version;
2597
-
2598
- Object.defineProperty(exports, '__esModule', { value: true });
2599
-
2600
- })));