string-remove-widows 2.0.16 → 3.0.2
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 +22 -0
- package/README.md +4 -0
- package/dist/string-remove-widows.esm.js +2 -2
- package/dist/string-remove-widows.umd.js +22 -22
- package/package.json +49 -42
- package/dist/string-remove-widows.cjs.js +0 -385
- package/dist/string-remove-widows.dev.umd.js +0 -3422
|
@@ -1,3422 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @name string-remove-widows
|
|
3
|
-
* @fileoverview Helps to prevent widow words in a text
|
|
4
|
-
* @version 2.0.16
|
|
5
|
-
* @author Roy Revelt, Codsen Ltd
|
|
6
|
-
* @license MIT
|
|
7
|
-
* {@link https://codsen.com/os/string-remove-widows/}
|
|
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.stringRemoveWidows = {}));
|
|
14
|
-
}(this, (function (exports) { 'use strict';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @name arrayiffy-if-string
|
|
18
|
-
* @fileoverview Put non-empty strings into arrays, turn empty-ones into empty arrays. Bypass everything else.
|
|
19
|
-
* @version 3.13.16
|
|
20
|
-
* @author Roy Revelt, Codsen Ltd
|
|
21
|
-
* @license MIT
|
|
22
|
-
* {@link https://codsen.com/os/arrayiffy-if-string/}
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
function arrayiffy(something) {
|
|
26
|
-
if (typeof something === "string") {
|
|
27
|
-
if (something.length) {
|
|
28
|
-
return [something];
|
|
29
|
-
}
|
|
30
|
-
return [];
|
|
31
|
-
}
|
|
32
|
-
return something;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @name string-match-left-right
|
|
37
|
-
* @fileoverview Match substrings on the left or right of a given index, ignoring whitespace
|
|
38
|
-
* @version 7.0.10
|
|
39
|
-
* @author Roy Revelt, Codsen Ltd
|
|
40
|
-
* @license MIT
|
|
41
|
-
* {@link https://codsen.com/os/string-match-left-right/}
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
function isObj(something) {
|
|
45
|
-
return something && typeof something === "object" && !Array.isArray(something);
|
|
46
|
-
}
|
|
47
|
-
function isStr$1(something) {
|
|
48
|
-
return typeof something === "string";
|
|
49
|
-
}
|
|
50
|
-
const defaults$4 = {
|
|
51
|
-
cb: undefined,
|
|
52
|
-
i: false,
|
|
53
|
-
trimBeforeMatching: false,
|
|
54
|
-
trimCharsBeforeMatching: [],
|
|
55
|
-
maxMismatches: 0,
|
|
56
|
-
firstMustMatch: false,
|
|
57
|
-
lastMustMatch: false,
|
|
58
|
-
hungry: false
|
|
59
|
-
};
|
|
60
|
-
const defaultGetNextIdx = index => index + 1;
|
|
61
|
-
function march(str, position, whatToMatchVal, originalOpts, special = false, getNextIdx = defaultGetNextIdx) {
|
|
62
|
-
const whatToMatchValVal = typeof whatToMatchVal === "function" ? whatToMatchVal() : whatToMatchVal;
|
|
63
|
-
if (+position < 0 && special && whatToMatchValVal === "EOL") {
|
|
64
|
-
return whatToMatchValVal;
|
|
65
|
-
}
|
|
66
|
-
const opts = { ...defaults$4,
|
|
67
|
-
...originalOpts
|
|
68
|
-
};
|
|
69
|
-
if (position >= str.length && !special) {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
let charsToCheckCount = special ? 1 : whatToMatchVal.length;
|
|
73
|
-
let charsMatchedTotal = 0;
|
|
74
|
-
let patienceReducedBeforeFirstMatch = false;
|
|
75
|
-
let lastWasMismatched = false;
|
|
76
|
-
let atLeastSomethingWasMatched = false;
|
|
77
|
-
let patience = opts.maxMismatches;
|
|
78
|
-
let i = position;
|
|
79
|
-
let somethingFound = false;
|
|
80
|
-
let firstCharacterMatched = false;
|
|
81
|
-
let lastCharacterMatched = false;
|
|
82
|
-
function whitespaceInFrontOfFirstChar() {
|
|
83
|
-
return (
|
|
84
|
-
charsMatchedTotal === 1 &&
|
|
85
|
-
patience < opts.maxMismatches - 1
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
while (str[i]) {
|
|
89
|
-
const nextIdx = getNextIdx(i);
|
|
90
|
-
if (opts.trimBeforeMatching && str[i].trim() === "") {
|
|
91
|
-
if (!str[nextIdx] && special && whatToMatchVal === "EOL") {
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
i = getNextIdx(i);
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
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())) {
|
|
98
|
-
if (special && whatToMatchVal === "EOL" && !str[nextIdx]) {
|
|
99
|
-
return true;
|
|
100
|
-
}
|
|
101
|
-
i = getNextIdx(i);
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
const charToCompareAgainst = nextIdx > i ? whatToMatchVal[whatToMatchVal.length - charsToCheckCount] : whatToMatchVal[charsToCheckCount - 1];
|
|
105
|
-
if (!opts.i && str[i] === charToCompareAgainst || opts.i && str[i].toLowerCase() === charToCompareAgainst.toLowerCase()) {
|
|
106
|
-
if (!somethingFound) {
|
|
107
|
-
somethingFound = true;
|
|
108
|
-
}
|
|
109
|
-
if (!atLeastSomethingWasMatched) {
|
|
110
|
-
atLeastSomethingWasMatched = true;
|
|
111
|
-
}
|
|
112
|
-
if (charsToCheckCount === whatToMatchVal.length) {
|
|
113
|
-
firstCharacterMatched = true;
|
|
114
|
-
if (patience !== opts.maxMismatches) {
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
} else if (charsToCheckCount === 1) {
|
|
118
|
-
lastCharacterMatched = true;
|
|
119
|
-
}
|
|
120
|
-
charsToCheckCount -= 1;
|
|
121
|
-
charsMatchedTotal++;
|
|
122
|
-
if (whitespaceInFrontOfFirstChar()) {
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
if (!charsToCheckCount) {
|
|
126
|
-
return (
|
|
127
|
-
charsMatchedTotal !== whatToMatchVal.length ||
|
|
128
|
-
patience === opts.maxMismatches ||
|
|
129
|
-
!patienceReducedBeforeFirstMatch ? i : false
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
} else {
|
|
133
|
-
if (!patienceReducedBeforeFirstMatch && !charsMatchedTotal) {
|
|
134
|
-
patienceReducedBeforeFirstMatch = true;
|
|
135
|
-
}
|
|
136
|
-
if (opts.maxMismatches && patience && i) {
|
|
137
|
-
patience -= 1;
|
|
138
|
-
for (let y = 0; y <= patience; y++) {
|
|
139
|
-
const nextCharToCompareAgainst = nextIdx > i ? whatToMatchVal[whatToMatchVal.length - charsToCheckCount + 1 + y] : whatToMatchVal[charsToCheckCount - 2 - y];
|
|
140
|
-
const nextCharInSource = str[getNextIdx(i)];
|
|
141
|
-
if (nextCharToCompareAgainst && (!opts.i && str[i] === nextCharToCompareAgainst || opts.i && str[i].toLowerCase() === nextCharToCompareAgainst.toLowerCase()) && (
|
|
142
|
-
!opts.firstMustMatch || charsToCheckCount !== whatToMatchVal.length)) {
|
|
143
|
-
charsMatchedTotal++;
|
|
144
|
-
if (whitespaceInFrontOfFirstChar()) {
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
charsToCheckCount -= 2;
|
|
148
|
-
somethingFound = true;
|
|
149
|
-
break;
|
|
150
|
-
} else if (nextCharInSource && nextCharToCompareAgainst && (!opts.i && nextCharInSource === nextCharToCompareAgainst || opts.i && nextCharInSource.toLowerCase() === nextCharToCompareAgainst.toLowerCase()) && (
|
|
151
|
-
!opts.firstMustMatch || charsToCheckCount !== whatToMatchVal.length)) {
|
|
152
|
-
if (!charsMatchedTotal && !opts.hungry) {
|
|
153
|
-
return false;
|
|
154
|
-
}
|
|
155
|
-
charsToCheckCount -= 1;
|
|
156
|
-
somethingFound = true;
|
|
157
|
-
break;
|
|
158
|
-
} else if (nextCharToCompareAgainst === undefined && patience >= 0 && somethingFound && (!opts.firstMustMatch || firstCharacterMatched) && (!opts.lastMustMatch || lastCharacterMatched)) {
|
|
159
|
-
return i;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
if (!somethingFound) {
|
|
163
|
-
lastWasMismatched = i;
|
|
164
|
-
}
|
|
165
|
-
} else if (i === 0 && charsToCheckCount === 1 && !opts.lastMustMatch && atLeastSomethingWasMatched) {
|
|
166
|
-
return 0;
|
|
167
|
-
} else {
|
|
168
|
-
return false;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
if (lastWasMismatched !== false && lastWasMismatched !== i) {
|
|
172
|
-
lastWasMismatched = false;
|
|
173
|
-
}
|
|
174
|
-
if (charsToCheckCount < 1) {
|
|
175
|
-
return i;
|
|
176
|
-
}
|
|
177
|
-
i = getNextIdx(i);
|
|
178
|
-
}
|
|
179
|
-
if (charsToCheckCount > 0) {
|
|
180
|
-
if (special && whatToMatchValVal === "EOL") {
|
|
181
|
-
return true;
|
|
182
|
-
}
|
|
183
|
-
if (opts && opts.maxMismatches >= charsToCheckCount && atLeastSomethingWasMatched) {
|
|
184
|
-
return lastWasMismatched || 0;
|
|
185
|
-
}
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
function main(mode, str, position, originalWhatToMatch, originalOpts) {
|
|
190
|
-
if (isObj(originalOpts) && Object.prototype.hasOwnProperty.call(originalOpts, "trimBeforeMatching") && typeof originalOpts.trimBeforeMatching !== "boolean") {
|
|
191
|
-
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?` : ""}`);
|
|
192
|
-
}
|
|
193
|
-
const opts = { ...defaults$4,
|
|
194
|
-
...originalOpts
|
|
195
|
-
};
|
|
196
|
-
if (typeof opts.trimCharsBeforeMatching === "string") {
|
|
197
|
-
opts.trimCharsBeforeMatching = arrayiffy(opts.trimCharsBeforeMatching);
|
|
198
|
-
}
|
|
199
|
-
opts.trimCharsBeforeMatching = opts.trimCharsBeforeMatching.map(el => isStr$1(el) ? el : String(el));
|
|
200
|
-
if (!isStr$1(str)) {
|
|
201
|
-
return false;
|
|
202
|
-
}
|
|
203
|
-
if (!str.length) {
|
|
204
|
-
return false;
|
|
205
|
-
}
|
|
206
|
-
if (!Number.isInteger(position) || position < 0) {
|
|
207
|
-
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)}`);
|
|
208
|
-
}
|
|
209
|
-
let whatToMatch;
|
|
210
|
-
let special;
|
|
211
|
-
if (isStr$1(originalWhatToMatch)) {
|
|
212
|
-
whatToMatch = [originalWhatToMatch];
|
|
213
|
-
} else if (Array.isArray(originalWhatToMatch)) {
|
|
214
|
-
whatToMatch = originalWhatToMatch;
|
|
215
|
-
} else if (!originalWhatToMatch) {
|
|
216
|
-
whatToMatch = originalWhatToMatch;
|
|
217
|
-
} else if (typeof originalWhatToMatch === "function") {
|
|
218
|
-
whatToMatch = [];
|
|
219
|
-
whatToMatch.push(originalWhatToMatch);
|
|
220
|
-
} else {
|
|
221
|
-
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)}`);
|
|
222
|
-
}
|
|
223
|
-
if (originalOpts && !isObj(originalOpts)) {
|
|
224
|
-
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)}`);
|
|
225
|
-
}
|
|
226
|
-
let culpritsIndex = 0;
|
|
227
|
-
let culpritsVal = "";
|
|
228
|
-
if (opts && opts.trimCharsBeforeMatching && opts.trimCharsBeforeMatching.some((el, i) => {
|
|
229
|
-
if (el.length > 1) {
|
|
230
|
-
culpritsIndex = i;
|
|
231
|
-
culpritsVal = el;
|
|
232
|
-
return true;
|
|
233
|
-
}
|
|
234
|
-
return false;
|
|
235
|
-
})) {
|
|
236
|
-
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.`);
|
|
237
|
-
}
|
|
238
|
-
if (!whatToMatch || !Array.isArray(whatToMatch) ||
|
|
239
|
-
Array.isArray(whatToMatch) && !whatToMatch.length ||
|
|
240
|
-
Array.isArray(whatToMatch) && whatToMatch.length === 1 && isStr$1(whatToMatch[0]) && !whatToMatch[0].trim()
|
|
241
|
-
) {
|
|
242
|
-
if (typeof opts.cb === "function") {
|
|
243
|
-
let firstCharOutsideIndex;
|
|
244
|
-
let startingPosition = position;
|
|
245
|
-
if (mode === "matchLeftIncl" || mode === "matchRight") {
|
|
246
|
-
startingPosition += 1;
|
|
247
|
-
}
|
|
248
|
-
if (mode[5] === "L") {
|
|
249
|
-
for (let y = startingPosition; y--;) {
|
|
250
|
-
const currentChar = str[y];
|
|
251
|
-
if ((!opts.trimBeforeMatching || opts.trimBeforeMatching && currentChar !== undefined && currentChar.trim()) && (!opts.trimCharsBeforeMatching || !opts.trimCharsBeforeMatching.length || currentChar !== undefined && !opts.trimCharsBeforeMatching.includes(currentChar))) {
|
|
252
|
-
firstCharOutsideIndex = y;
|
|
253
|
-
break;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
} else if (mode.startsWith("matchRight")) {
|
|
257
|
-
for (let y = startingPosition; y < str.length; y++) {
|
|
258
|
-
const currentChar = str[y];
|
|
259
|
-
if ((!opts.trimBeforeMatching || opts.trimBeforeMatching && currentChar.trim()) && (!opts.trimCharsBeforeMatching || !opts.trimCharsBeforeMatching.length || !opts.trimCharsBeforeMatching.includes(currentChar))) {
|
|
260
|
-
firstCharOutsideIndex = y;
|
|
261
|
-
break;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
if (firstCharOutsideIndex === undefined) {
|
|
266
|
-
return false;
|
|
267
|
-
}
|
|
268
|
-
const wholeCharacterOutside = str[firstCharOutsideIndex];
|
|
269
|
-
const indexOfTheCharacterAfter = firstCharOutsideIndex + 1;
|
|
270
|
-
let theRemainderOfTheString = "";
|
|
271
|
-
if (indexOfTheCharacterAfter && indexOfTheCharacterAfter > 0) {
|
|
272
|
-
theRemainderOfTheString = str.slice(0, indexOfTheCharacterAfter);
|
|
273
|
-
}
|
|
274
|
-
if (mode[5] === "L") {
|
|
275
|
-
return opts.cb(wholeCharacterOutside, theRemainderOfTheString, firstCharOutsideIndex);
|
|
276
|
-
}
|
|
277
|
-
if (firstCharOutsideIndex && firstCharOutsideIndex > 0) {
|
|
278
|
-
theRemainderOfTheString = str.slice(firstCharOutsideIndex);
|
|
279
|
-
}
|
|
280
|
-
return opts.cb(wholeCharacterOutside, theRemainderOfTheString, firstCharOutsideIndex);
|
|
281
|
-
}
|
|
282
|
-
let extraNote = "";
|
|
283
|
-
if (!originalOpts) {
|
|
284
|
-
extraNote = " More so, the whole options object, the fourth input argument, is missing!";
|
|
285
|
-
}
|
|
286
|
-
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}`);
|
|
287
|
-
}
|
|
288
|
-
for (let i = 0, len = whatToMatch.length; i < len; i++) {
|
|
289
|
-
special = typeof whatToMatch[i] === "function";
|
|
290
|
-
const whatToMatchVal = whatToMatch[i];
|
|
291
|
-
let fullCharacterInFront;
|
|
292
|
-
let indexOfTheCharacterInFront;
|
|
293
|
-
let restOfStringInFront = "";
|
|
294
|
-
let startingPosition = position;
|
|
295
|
-
if (mode === "matchRight") {
|
|
296
|
-
startingPosition += 1;
|
|
297
|
-
} else if (mode === "matchLeft") {
|
|
298
|
-
startingPosition -= 1;
|
|
299
|
-
}
|
|
300
|
-
const found = march(str, startingPosition, whatToMatchVal, opts, special, i2 => mode[5] === "L" ? i2 - 1 : i2 + 1);
|
|
301
|
-
if (found && special && typeof whatToMatchVal === "function" && whatToMatchVal() === "EOL") {
|
|
302
|
-
return whatToMatchVal() && (opts.cb ? opts.cb(fullCharacterInFront, restOfStringInFront, indexOfTheCharacterInFront) : true) ? whatToMatchVal() : false;
|
|
303
|
-
}
|
|
304
|
-
if (Number.isInteger(found)) {
|
|
305
|
-
indexOfTheCharacterInFront = mode.startsWith("matchLeft") ? found - 1 : found + 1;
|
|
306
|
-
if (mode[5] === "L") {
|
|
307
|
-
restOfStringInFront = str.slice(0, found);
|
|
308
|
-
} else {
|
|
309
|
-
restOfStringInFront = str.slice(indexOfTheCharacterInFront);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
if (indexOfTheCharacterInFront < 0) {
|
|
313
|
-
indexOfTheCharacterInFront = undefined;
|
|
314
|
-
}
|
|
315
|
-
if (str[indexOfTheCharacterInFront]) {
|
|
316
|
-
fullCharacterInFront = str[indexOfTheCharacterInFront];
|
|
317
|
-
}
|
|
318
|
-
if (Number.isInteger(found) && (opts.cb ? opts.cb(fullCharacterInFront, restOfStringInFront, indexOfTheCharacterInFront) : true)) {
|
|
319
|
-
return whatToMatchVal;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
return false;
|
|
323
|
-
}
|
|
324
|
-
function matchRightIncl(str, position, whatToMatch, opts) {
|
|
325
|
-
return main("matchRightIncl", str, position, whatToMatch, opts);
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* lodash (Custom Build) <https://lodash.com/>
|
|
330
|
-
* Build: `lodash modularize exports="npm" -o ./`
|
|
331
|
-
* Copyright jQuery Foundation and other contributors <https://jquery.org/>
|
|
332
|
-
* Released under MIT license <https://lodash.com/license>
|
|
333
|
-
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
334
|
-
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
335
|
-
*/
|
|
336
|
-
|
|
337
|
-
/** Used for built-in method references. */
|
|
338
|
-
var funcProto = Function.prototype;
|
|
339
|
-
|
|
340
|
-
/** Used to resolve the decompiled source of functions. */
|
|
341
|
-
var funcToString = funcProto.toString;
|
|
342
|
-
|
|
343
|
-
/** Used to infer the `Object` constructor. */
|
|
344
|
-
funcToString.call(Object);
|
|
345
|
-
|
|
346
|
-
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
347
|
-
|
|
348
|
-
function createCommonjsModule(fn) {
|
|
349
|
-
var module = { exports: {} };
|
|
350
|
-
return fn(module, module.exports), module.exports;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* lodash (Custom Build) <https://lodash.com/>
|
|
355
|
-
* Build: `lodash modularize exports="npm" -o ./`
|
|
356
|
-
* Copyright jQuery Foundation and other contributors <https://jquery.org/>
|
|
357
|
-
* Released under MIT license <https://lodash.com/license>
|
|
358
|
-
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
359
|
-
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
360
|
-
*/
|
|
361
|
-
|
|
362
|
-
createCommonjsModule(function (module, exports) {
|
|
363
|
-
/** Used as the size to enable large array optimizations. */
|
|
364
|
-
var LARGE_ARRAY_SIZE = 200;
|
|
365
|
-
|
|
366
|
-
/** Used to stand-in for `undefined` hash values. */
|
|
367
|
-
var HASH_UNDEFINED = '__lodash_hash_undefined__';
|
|
368
|
-
|
|
369
|
-
/** Used as references for various `Number` constants. */
|
|
370
|
-
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
371
|
-
|
|
372
|
-
/** `Object#toString` result references. */
|
|
373
|
-
var argsTag = '[object Arguments]',
|
|
374
|
-
arrayTag = '[object Array]',
|
|
375
|
-
boolTag = '[object Boolean]',
|
|
376
|
-
dateTag = '[object Date]',
|
|
377
|
-
errorTag = '[object Error]',
|
|
378
|
-
funcTag = '[object Function]',
|
|
379
|
-
genTag = '[object GeneratorFunction]',
|
|
380
|
-
mapTag = '[object Map]',
|
|
381
|
-
numberTag = '[object Number]',
|
|
382
|
-
objectTag = '[object Object]',
|
|
383
|
-
promiseTag = '[object Promise]',
|
|
384
|
-
regexpTag = '[object RegExp]',
|
|
385
|
-
setTag = '[object Set]',
|
|
386
|
-
stringTag = '[object String]',
|
|
387
|
-
symbolTag = '[object Symbol]',
|
|
388
|
-
weakMapTag = '[object WeakMap]';
|
|
389
|
-
|
|
390
|
-
var arrayBufferTag = '[object ArrayBuffer]',
|
|
391
|
-
dataViewTag = '[object DataView]',
|
|
392
|
-
float32Tag = '[object Float32Array]',
|
|
393
|
-
float64Tag = '[object Float64Array]',
|
|
394
|
-
int8Tag = '[object Int8Array]',
|
|
395
|
-
int16Tag = '[object Int16Array]',
|
|
396
|
-
int32Tag = '[object Int32Array]',
|
|
397
|
-
uint8Tag = '[object Uint8Array]',
|
|
398
|
-
uint8ClampedTag = '[object Uint8ClampedArray]',
|
|
399
|
-
uint16Tag = '[object Uint16Array]',
|
|
400
|
-
uint32Tag = '[object Uint32Array]';
|
|
401
|
-
|
|
402
|
-
/**
|
|
403
|
-
* Used to match `RegExp`
|
|
404
|
-
* [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
|
|
405
|
-
*/
|
|
406
|
-
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
|
|
407
|
-
|
|
408
|
-
/** Used to match `RegExp` flags from their coerced string values. */
|
|
409
|
-
var reFlags = /\w*$/;
|
|
410
|
-
|
|
411
|
-
/** Used to detect host constructors (Safari). */
|
|
412
|
-
var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
|
413
|
-
|
|
414
|
-
/** Used to detect unsigned integer values. */
|
|
415
|
-
var reIsUint = /^(?:0|[1-9]\d*)$/;
|
|
416
|
-
|
|
417
|
-
/** Used to identify `toStringTag` values supported by `_.clone`. */
|
|
418
|
-
var cloneableTags = {};
|
|
419
|
-
cloneableTags[argsTag] = cloneableTags[arrayTag] =
|
|
420
|
-
cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
|
|
421
|
-
cloneableTags[boolTag] = cloneableTags[dateTag] =
|
|
422
|
-
cloneableTags[float32Tag] = cloneableTags[float64Tag] =
|
|
423
|
-
cloneableTags[int8Tag] = cloneableTags[int16Tag] =
|
|
424
|
-
cloneableTags[int32Tag] = cloneableTags[mapTag] =
|
|
425
|
-
cloneableTags[numberTag] = cloneableTags[objectTag] =
|
|
426
|
-
cloneableTags[regexpTag] = cloneableTags[setTag] =
|
|
427
|
-
cloneableTags[stringTag] = cloneableTags[symbolTag] =
|
|
428
|
-
cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
|
|
429
|
-
cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
|
|
430
|
-
cloneableTags[errorTag] = cloneableTags[funcTag] =
|
|
431
|
-
cloneableTags[weakMapTag] = false;
|
|
432
|
-
|
|
433
|
-
/** Detect free variable `global` from Node.js. */
|
|
434
|
-
var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
|
|
435
|
-
|
|
436
|
-
/** Detect free variable `self`. */
|
|
437
|
-
var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
|
|
438
|
-
|
|
439
|
-
/** Used as a reference to the global object. */
|
|
440
|
-
var root = freeGlobal || freeSelf || Function('return this')();
|
|
441
|
-
|
|
442
|
-
/** Detect free variable `exports`. */
|
|
443
|
-
var freeExports = exports && !exports.nodeType && exports;
|
|
444
|
-
|
|
445
|
-
/** Detect free variable `module`. */
|
|
446
|
-
var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
|
|
447
|
-
|
|
448
|
-
/** Detect the popular CommonJS extension `module.exports`. */
|
|
449
|
-
var moduleExports = freeModule && freeModule.exports === freeExports;
|
|
450
|
-
|
|
451
|
-
/**
|
|
452
|
-
* Adds the key-value `pair` to `map`.
|
|
453
|
-
*
|
|
454
|
-
* @private
|
|
455
|
-
* @param {Object} map The map to modify.
|
|
456
|
-
* @param {Array} pair The key-value pair to add.
|
|
457
|
-
* @returns {Object} Returns `map`.
|
|
458
|
-
*/
|
|
459
|
-
function addMapEntry(map, pair) {
|
|
460
|
-
// Don't return `map.set` because it's not chainable in IE 11.
|
|
461
|
-
map.set(pair[0], pair[1]);
|
|
462
|
-
return map;
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
/**
|
|
466
|
-
* Adds `value` to `set`.
|
|
467
|
-
*
|
|
468
|
-
* @private
|
|
469
|
-
* @param {Object} set The set to modify.
|
|
470
|
-
* @param {*} value The value to add.
|
|
471
|
-
* @returns {Object} Returns `set`.
|
|
472
|
-
*/
|
|
473
|
-
function addSetEntry(set, value) {
|
|
474
|
-
// Don't return `set.add` because it's not chainable in IE 11.
|
|
475
|
-
set.add(value);
|
|
476
|
-
return set;
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
* A specialized version of `_.forEach` for arrays without support for
|
|
481
|
-
* iteratee shorthands.
|
|
482
|
-
*
|
|
483
|
-
* @private
|
|
484
|
-
* @param {Array} [array] The array to iterate over.
|
|
485
|
-
* @param {Function} iteratee The function invoked per iteration.
|
|
486
|
-
* @returns {Array} Returns `array`.
|
|
487
|
-
*/
|
|
488
|
-
function arrayEach(array, iteratee) {
|
|
489
|
-
var index = -1,
|
|
490
|
-
length = array ? array.length : 0;
|
|
491
|
-
|
|
492
|
-
while (++index < length) {
|
|
493
|
-
if (iteratee(array[index], index, array) === false) {
|
|
494
|
-
break;
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
return array;
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
/**
|
|
501
|
-
* Appends the elements of `values` to `array`.
|
|
502
|
-
*
|
|
503
|
-
* @private
|
|
504
|
-
* @param {Array} array The array to modify.
|
|
505
|
-
* @param {Array} values The values to append.
|
|
506
|
-
* @returns {Array} Returns `array`.
|
|
507
|
-
*/
|
|
508
|
-
function arrayPush(array, values) {
|
|
509
|
-
var index = -1,
|
|
510
|
-
length = values.length,
|
|
511
|
-
offset = array.length;
|
|
512
|
-
|
|
513
|
-
while (++index < length) {
|
|
514
|
-
array[offset + index] = values[index];
|
|
515
|
-
}
|
|
516
|
-
return array;
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
/**
|
|
520
|
-
* A specialized version of `_.reduce` for arrays without support for
|
|
521
|
-
* iteratee shorthands.
|
|
522
|
-
*
|
|
523
|
-
* @private
|
|
524
|
-
* @param {Array} [array] The array to iterate over.
|
|
525
|
-
* @param {Function} iteratee The function invoked per iteration.
|
|
526
|
-
* @param {*} [accumulator] The initial value.
|
|
527
|
-
* @param {boolean} [initAccum] Specify using the first element of `array` as
|
|
528
|
-
* the initial value.
|
|
529
|
-
* @returns {*} Returns the accumulated value.
|
|
530
|
-
*/
|
|
531
|
-
function arrayReduce(array, iteratee, accumulator, initAccum) {
|
|
532
|
-
var index = -1,
|
|
533
|
-
length = array ? array.length : 0;
|
|
534
|
-
|
|
535
|
-
if (initAccum && length) {
|
|
536
|
-
accumulator = array[++index];
|
|
537
|
-
}
|
|
538
|
-
while (++index < length) {
|
|
539
|
-
accumulator = iteratee(accumulator, array[index], index, array);
|
|
540
|
-
}
|
|
541
|
-
return accumulator;
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
/**
|
|
545
|
-
* The base implementation of `_.times` without support for iteratee shorthands
|
|
546
|
-
* or max array length checks.
|
|
547
|
-
*
|
|
548
|
-
* @private
|
|
549
|
-
* @param {number} n The number of times to invoke `iteratee`.
|
|
550
|
-
* @param {Function} iteratee The function invoked per iteration.
|
|
551
|
-
* @returns {Array} Returns the array of results.
|
|
552
|
-
*/
|
|
553
|
-
function baseTimes(n, iteratee) {
|
|
554
|
-
var index = -1,
|
|
555
|
-
result = Array(n);
|
|
556
|
-
|
|
557
|
-
while (++index < n) {
|
|
558
|
-
result[index] = iteratee(index);
|
|
559
|
-
}
|
|
560
|
-
return result;
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
/**
|
|
564
|
-
* Gets the value at `key` of `object`.
|
|
565
|
-
*
|
|
566
|
-
* @private
|
|
567
|
-
* @param {Object} [object] The object to query.
|
|
568
|
-
* @param {string} key The key of the property to get.
|
|
569
|
-
* @returns {*} Returns the property value.
|
|
570
|
-
*/
|
|
571
|
-
function getValue(object, key) {
|
|
572
|
-
return object == null ? undefined : object[key];
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
/**
|
|
576
|
-
* Checks if `value` is a host object in IE < 9.
|
|
577
|
-
*
|
|
578
|
-
* @private
|
|
579
|
-
* @param {*} value The value to check.
|
|
580
|
-
* @returns {boolean} Returns `true` if `value` is a host object, else `false`.
|
|
581
|
-
*/
|
|
582
|
-
function isHostObject(value) {
|
|
583
|
-
// Many host objects are `Object` objects that can coerce to strings
|
|
584
|
-
// despite having improperly defined `toString` methods.
|
|
585
|
-
var result = false;
|
|
586
|
-
if (value != null && typeof value.toString != 'function') {
|
|
587
|
-
try {
|
|
588
|
-
result = !!(value + '');
|
|
589
|
-
} catch (e) {}
|
|
590
|
-
}
|
|
591
|
-
return result;
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
/**
|
|
595
|
-
* Converts `map` to its key-value pairs.
|
|
596
|
-
*
|
|
597
|
-
* @private
|
|
598
|
-
* @param {Object} map The map to convert.
|
|
599
|
-
* @returns {Array} Returns the key-value pairs.
|
|
600
|
-
*/
|
|
601
|
-
function mapToArray(map) {
|
|
602
|
-
var index = -1,
|
|
603
|
-
result = Array(map.size);
|
|
604
|
-
|
|
605
|
-
map.forEach(function(value, key) {
|
|
606
|
-
result[++index] = [key, value];
|
|
607
|
-
});
|
|
608
|
-
return result;
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
/**
|
|
612
|
-
* Creates a unary function that invokes `func` with its argument transformed.
|
|
613
|
-
*
|
|
614
|
-
* @private
|
|
615
|
-
* @param {Function} func The function to wrap.
|
|
616
|
-
* @param {Function} transform The argument transform.
|
|
617
|
-
* @returns {Function} Returns the new function.
|
|
618
|
-
*/
|
|
619
|
-
function overArg(func, transform) {
|
|
620
|
-
return function(arg) {
|
|
621
|
-
return func(transform(arg));
|
|
622
|
-
};
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
/**
|
|
626
|
-
* Converts `set` to an array of its values.
|
|
627
|
-
*
|
|
628
|
-
* @private
|
|
629
|
-
* @param {Object} set The set to convert.
|
|
630
|
-
* @returns {Array} Returns the values.
|
|
631
|
-
*/
|
|
632
|
-
function setToArray(set) {
|
|
633
|
-
var index = -1,
|
|
634
|
-
result = Array(set.size);
|
|
635
|
-
|
|
636
|
-
set.forEach(function(value) {
|
|
637
|
-
result[++index] = value;
|
|
638
|
-
});
|
|
639
|
-
return result;
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
/** Used for built-in method references. */
|
|
643
|
-
var arrayProto = Array.prototype,
|
|
644
|
-
funcProto = Function.prototype,
|
|
645
|
-
objectProto = Object.prototype;
|
|
646
|
-
|
|
647
|
-
/** Used to detect overreaching core-js shims. */
|
|
648
|
-
var coreJsData = root['__core-js_shared__'];
|
|
649
|
-
|
|
650
|
-
/** Used to detect methods masquerading as native. */
|
|
651
|
-
var maskSrcKey = (function() {
|
|
652
|
-
var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
|
|
653
|
-
return uid ? ('Symbol(src)_1.' + uid) : '';
|
|
654
|
-
}());
|
|
655
|
-
|
|
656
|
-
/** Used to resolve the decompiled source of functions. */
|
|
657
|
-
var funcToString = funcProto.toString;
|
|
658
|
-
|
|
659
|
-
/** Used to check objects for own properties. */
|
|
660
|
-
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
661
|
-
|
|
662
|
-
/**
|
|
663
|
-
* Used to resolve the
|
|
664
|
-
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
|
|
665
|
-
* of values.
|
|
666
|
-
*/
|
|
667
|
-
var objectToString = objectProto.toString;
|
|
668
|
-
|
|
669
|
-
/** Used to detect if a method is native. */
|
|
670
|
-
var reIsNative = RegExp('^' +
|
|
671
|
-
funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
|
|
672
|
-
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
|
673
|
-
);
|
|
674
|
-
|
|
675
|
-
/** Built-in value references. */
|
|
676
|
-
var Buffer = moduleExports ? root.Buffer : undefined,
|
|
677
|
-
Symbol = root.Symbol,
|
|
678
|
-
Uint8Array = root.Uint8Array,
|
|
679
|
-
getPrototype = overArg(Object.getPrototypeOf, Object),
|
|
680
|
-
objectCreate = Object.create,
|
|
681
|
-
propertyIsEnumerable = objectProto.propertyIsEnumerable,
|
|
682
|
-
splice = arrayProto.splice;
|
|
683
|
-
|
|
684
|
-
/* Built-in method references for those with the same name as other `lodash` methods. */
|
|
685
|
-
var nativeGetSymbols = Object.getOwnPropertySymbols,
|
|
686
|
-
nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
|
|
687
|
-
nativeKeys = overArg(Object.keys, Object);
|
|
688
|
-
|
|
689
|
-
/* Built-in method references that are verified to be native. */
|
|
690
|
-
var DataView = getNative(root, 'DataView'),
|
|
691
|
-
Map = getNative(root, 'Map'),
|
|
692
|
-
Promise = getNative(root, 'Promise'),
|
|
693
|
-
Set = getNative(root, 'Set'),
|
|
694
|
-
WeakMap = getNative(root, 'WeakMap'),
|
|
695
|
-
nativeCreate = getNative(Object, 'create');
|
|
696
|
-
|
|
697
|
-
/** Used to detect maps, sets, and weakmaps. */
|
|
698
|
-
var dataViewCtorString = toSource(DataView),
|
|
699
|
-
mapCtorString = toSource(Map),
|
|
700
|
-
promiseCtorString = toSource(Promise),
|
|
701
|
-
setCtorString = toSource(Set),
|
|
702
|
-
weakMapCtorString = toSource(WeakMap);
|
|
703
|
-
|
|
704
|
-
/** Used to convert symbols to primitives and strings. */
|
|
705
|
-
var symbolProto = Symbol ? Symbol.prototype : undefined,
|
|
706
|
-
symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
|
|
707
|
-
|
|
708
|
-
/**
|
|
709
|
-
* Creates a hash object.
|
|
710
|
-
*
|
|
711
|
-
* @private
|
|
712
|
-
* @constructor
|
|
713
|
-
* @param {Array} [entries] The key-value pairs to cache.
|
|
714
|
-
*/
|
|
715
|
-
function Hash(entries) {
|
|
716
|
-
var index = -1,
|
|
717
|
-
length = entries ? entries.length : 0;
|
|
718
|
-
|
|
719
|
-
this.clear();
|
|
720
|
-
while (++index < length) {
|
|
721
|
-
var entry = entries[index];
|
|
722
|
-
this.set(entry[0], entry[1]);
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
/**
|
|
727
|
-
* Removes all key-value entries from the hash.
|
|
728
|
-
*
|
|
729
|
-
* @private
|
|
730
|
-
* @name clear
|
|
731
|
-
* @memberOf Hash
|
|
732
|
-
*/
|
|
733
|
-
function hashClear() {
|
|
734
|
-
this.__data__ = nativeCreate ? nativeCreate(null) : {};
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
/**
|
|
738
|
-
* Removes `key` and its value from the hash.
|
|
739
|
-
*
|
|
740
|
-
* @private
|
|
741
|
-
* @name delete
|
|
742
|
-
* @memberOf Hash
|
|
743
|
-
* @param {Object} hash The hash to modify.
|
|
744
|
-
* @param {string} key The key of the value to remove.
|
|
745
|
-
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
|
746
|
-
*/
|
|
747
|
-
function hashDelete(key) {
|
|
748
|
-
return this.has(key) && delete this.__data__[key];
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
/**
|
|
752
|
-
* Gets the hash value for `key`.
|
|
753
|
-
*
|
|
754
|
-
* @private
|
|
755
|
-
* @name get
|
|
756
|
-
* @memberOf Hash
|
|
757
|
-
* @param {string} key The key of the value to get.
|
|
758
|
-
* @returns {*} Returns the entry value.
|
|
759
|
-
*/
|
|
760
|
-
function hashGet(key) {
|
|
761
|
-
var data = this.__data__;
|
|
762
|
-
if (nativeCreate) {
|
|
763
|
-
var result = data[key];
|
|
764
|
-
return result === HASH_UNDEFINED ? undefined : result;
|
|
765
|
-
}
|
|
766
|
-
return hasOwnProperty.call(data, key) ? data[key] : undefined;
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
/**
|
|
770
|
-
* Checks if a hash value for `key` exists.
|
|
771
|
-
*
|
|
772
|
-
* @private
|
|
773
|
-
* @name has
|
|
774
|
-
* @memberOf Hash
|
|
775
|
-
* @param {string} key The key of the entry to check.
|
|
776
|
-
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
|
777
|
-
*/
|
|
778
|
-
function hashHas(key) {
|
|
779
|
-
var data = this.__data__;
|
|
780
|
-
return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
/**
|
|
784
|
-
* Sets the hash `key` to `value`.
|
|
785
|
-
*
|
|
786
|
-
* @private
|
|
787
|
-
* @name set
|
|
788
|
-
* @memberOf Hash
|
|
789
|
-
* @param {string} key The key of the value to set.
|
|
790
|
-
* @param {*} value The value to set.
|
|
791
|
-
* @returns {Object} Returns the hash instance.
|
|
792
|
-
*/
|
|
793
|
-
function hashSet(key, value) {
|
|
794
|
-
var data = this.__data__;
|
|
795
|
-
data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
|
|
796
|
-
return this;
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
// Add methods to `Hash`.
|
|
800
|
-
Hash.prototype.clear = hashClear;
|
|
801
|
-
Hash.prototype['delete'] = hashDelete;
|
|
802
|
-
Hash.prototype.get = hashGet;
|
|
803
|
-
Hash.prototype.has = hashHas;
|
|
804
|
-
Hash.prototype.set = hashSet;
|
|
805
|
-
|
|
806
|
-
/**
|
|
807
|
-
* Creates an list cache object.
|
|
808
|
-
*
|
|
809
|
-
* @private
|
|
810
|
-
* @constructor
|
|
811
|
-
* @param {Array} [entries] The key-value pairs to cache.
|
|
812
|
-
*/
|
|
813
|
-
function ListCache(entries) {
|
|
814
|
-
var index = -1,
|
|
815
|
-
length = entries ? entries.length : 0;
|
|
816
|
-
|
|
817
|
-
this.clear();
|
|
818
|
-
while (++index < length) {
|
|
819
|
-
var entry = entries[index];
|
|
820
|
-
this.set(entry[0], entry[1]);
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
/**
|
|
825
|
-
* Removes all key-value entries from the list cache.
|
|
826
|
-
*
|
|
827
|
-
* @private
|
|
828
|
-
* @name clear
|
|
829
|
-
* @memberOf ListCache
|
|
830
|
-
*/
|
|
831
|
-
function listCacheClear() {
|
|
832
|
-
this.__data__ = [];
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
/**
|
|
836
|
-
* Removes `key` and its value from the list cache.
|
|
837
|
-
*
|
|
838
|
-
* @private
|
|
839
|
-
* @name delete
|
|
840
|
-
* @memberOf ListCache
|
|
841
|
-
* @param {string} key The key of the value to remove.
|
|
842
|
-
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
|
843
|
-
*/
|
|
844
|
-
function listCacheDelete(key) {
|
|
845
|
-
var data = this.__data__,
|
|
846
|
-
index = assocIndexOf(data, key);
|
|
847
|
-
|
|
848
|
-
if (index < 0) {
|
|
849
|
-
return false;
|
|
850
|
-
}
|
|
851
|
-
var lastIndex = data.length - 1;
|
|
852
|
-
if (index == lastIndex) {
|
|
853
|
-
data.pop();
|
|
854
|
-
} else {
|
|
855
|
-
splice.call(data, index, 1);
|
|
856
|
-
}
|
|
857
|
-
return true;
|
|
858
|
-
}
|
|
859
|
-
|
|
860
|
-
/**
|
|
861
|
-
* Gets the list cache value for `key`.
|
|
862
|
-
*
|
|
863
|
-
* @private
|
|
864
|
-
* @name get
|
|
865
|
-
* @memberOf ListCache
|
|
866
|
-
* @param {string} key The key of the value to get.
|
|
867
|
-
* @returns {*} Returns the entry value.
|
|
868
|
-
*/
|
|
869
|
-
function listCacheGet(key) {
|
|
870
|
-
var data = this.__data__,
|
|
871
|
-
index = assocIndexOf(data, key);
|
|
872
|
-
|
|
873
|
-
return index < 0 ? undefined : data[index][1];
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
/**
|
|
877
|
-
* Checks if a list cache value for `key` exists.
|
|
878
|
-
*
|
|
879
|
-
* @private
|
|
880
|
-
* @name has
|
|
881
|
-
* @memberOf ListCache
|
|
882
|
-
* @param {string} key The key of the entry to check.
|
|
883
|
-
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
|
884
|
-
*/
|
|
885
|
-
function listCacheHas(key) {
|
|
886
|
-
return assocIndexOf(this.__data__, key) > -1;
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
/**
|
|
890
|
-
* Sets the list cache `key` to `value`.
|
|
891
|
-
*
|
|
892
|
-
* @private
|
|
893
|
-
* @name set
|
|
894
|
-
* @memberOf ListCache
|
|
895
|
-
* @param {string} key The key of the value to set.
|
|
896
|
-
* @param {*} value The value to set.
|
|
897
|
-
* @returns {Object} Returns the list cache instance.
|
|
898
|
-
*/
|
|
899
|
-
function listCacheSet(key, value) {
|
|
900
|
-
var data = this.__data__,
|
|
901
|
-
index = assocIndexOf(data, key);
|
|
902
|
-
|
|
903
|
-
if (index < 0) {
|
|
904
|
-
data.push([key, value]);
|
|
905
|
-
} else {
|
|
906
|
-
data[index][1] = value;
|
|
907
|
-
}
|
|
908
|
-
return this;
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
// Add methods to `ListCache`.
|
|
912
|
-
ListCache.prototype.clear = listCacheClear;
|
|
913
|
-
ListCache.prototype['delete'] = listCacheDelete;
|
|
914
|
-
ListCache.prototype.get = listCacheGet;
|
|
915
|
-
ListCache.prototype.has = listCacheHas;
|
|
916
|
-
ListCache.prototype.set = listCacheSet;
|
|
917
|
-
|
|
918
|
-
/**
|
|
919
|
-
* Creates a map cache object to store key-value pairs.
|
|
920
|
-
*
|
|
921
|
-
* @private
|
|
922
|
-
* @constructor
|
|
923
|
-
* @param {Array} [entries] The key-value pairs to cache.
|
|
924
|
-
*/
|
|
925
|
-
function MapCache(entries) {
|
|
926
|
-
var index = -1,
|
|
927
|
-
length = entries ? entries.length : 0;
|
|
928
|
-
|
|
929
|
-
this.clear();
|
|
930
|
-
while (++index < length) {
|
|
931
|
-
var entry = entries[index];
|
|
932
|
-
this.set(entry[0], entry[1]);
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
/**
|
|
937
|
-
* Removes all key-value entries from the map.
|
|
938
|
-
*
|
|
939
|
-
* @private
|
|
940
|
-
* @name clear
|
|
941
|
-
* @memberOf MapCache
|
|
942
|
-
*/
|
|
943
|
-
function mapCacheClear() {
|
|
944
|
-
this.__data__ = {
|
|
945
|
-
'hash': new Hash,
|
|
946
|
-
'map': new (Map || ListCache),
|
|
947
|
-
'string': new Hash
|
|
948
|
-
};
|
|
949
|
-
}
|
|
950
|
-
|
|
951
|
-
/**
|
|
952
|
-
* Removes `key` and its value from the map.
|
|
953
|
-
*
|
|
954
|
-
* @private
|
|
955
|
-
* @name delete
|
|
956
|
-
* @memberOf MapCache
|
|
957
|
-
* @param {string} key The key of the value to remove.
|
|
958
|
-
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
|
959
|
-
*/
|
|
960
|
-
function mapCacheDelete(key) {
|
|
961
|
-
return getMapData(this, key)['delete'](key);
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
/**
|
|
965
|
-
* Gets the map value for `key`.
|
|
966
|
-
*
|
|
967
|
-
* @private
|
|
968
|
-
* @name get
|
|
969
|
-
* @memberOf MapCache
|
|
970
|
-
* @param {string} key The key of the value to get.
|
|
971
|
-
* @returns {*} Returns the entry value.
|
|
972
|
-
*/
|
|
973
|
-
function mapCacheGet(key) {
|
|
974
|
-
return getMapData(this, key).get(key);
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
/**
|
|
978
|
-
* Checks if a map value for `key` exists.
|
|
979
|
-
*
|
|
980
|
-
* @private
|
|
981
|
-
* @name has
|
|
982
|
-
* @memberOf MapCache
|
|
983
|
-
* @param {string} key The key of the entry to check.
|
|
984
|
-
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
|
985
|
-
*/
|
|
986
|
-
function mapCacheHas(key) {
|
|
987
|
-
return getMapData(this, key).has(key);
|
|
988
|
-
}
|
|
989
|
-
|
|
990
|
-
/**
|
|
991
|
-
* Sets the map `key` to `value`.
|
|
992
|
-
*
|
|
993
|
-
* @private
|
|
994
|
-
* @name set
|
|
995
|
-
* @memberOf MapCache
|
|
996
|
-
* @param {string} key The key of the value to set.
|
|
997
|
-
* @param {*} value The value to set.
|
|
998
|
-
* @returns {Object} Returns the map cache instance.
|
|
999
|
-
*/
|
|
1000
|
-
function mapCacheSet(key, value) {
|
|
1001
|
-
getMapData(this, key).set(key, value);
|
|
1002
|
-
return this;
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
// Add methods to `MapCache`.
|
|
1006
|
-
MapCache.prototype.clear = mapCacheClear;
|
|
1007
|
-
MapCache.prototype['delete'] = mapCacheDelete;
|
|
1008
|
-
MapCache.prototype.get = mapCacheGet;
|
|
1009
|
-
MapCache.prototype.has = mapCacheHas;
|
|
1010
|
-
MapCache.prototype.set = mapCacheSet;
|
|
1011
|
-
|
|
1012
|
-
/**
|
|
1013
|
-
* Creates a stack cache object to store key-value pairs.
|
|
1014
|
-
*
|
|
1015
|
-
* @private
|
|
1016
|
-
* @constructor
|
|
1017
|
-
* @param {Array} [entries] The key-value pairs to cache.
|
|
1018
|
-
*/
|
|
1019
|
-
function Stack(entries) {
|
|
1020
|
-
this.__data__ = new ListCache(entries);
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
/**
|
|
1024
|
-
* Removes all key-value entries from the stack.
|
|
1025
|
-
*
|
|
1026
|
-
* @private
|
|
1027
|
-
* @name clear
|
|
1028
|
-
* @memberOf Stack
|
|
1029
|
-
*/
|
|
1030
|
-
function stackClear() {
|
|
1031
|
-
this.__data__ = new ListCache;
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
/**
|
|
1035
|
-
* Removes `key` and its value from the stack.
|
|
1036
|
-
*
|
|
1037
|
-
* @private
|
|
1038
|
-
* @name delete
|
|
1039
|
-
* @memberOf Stack
|
|
1040
|
-
* @param {string} key The key of the value to remove.
|
|
1041
|
-
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
|
1042
|
-
*/
|
|
1043
|
-
function stackDelete(key) {
|
|
1044
|
-
return this.__data__['delete'](key);
|
|
1045
|
-
}
|
|
1046
|
-
|
|
1047
|
-
/**
|
|
1048
|
-
* Gets the stack value for `key`.
|
|
1049
|
-
*
|
|
1050
|
-
* @private
|
|
1051
|
-
* @name get
|
|
1052
|
-
* @memberOf Stack
|
|
1053
|
-
* @param {string} key The key of the value to get.
|
|
1054
|
-
* @returns {*} Returns the entry value.
|
|
1055
|
-
*/
|
|
1056
|
-
function stackGet(key) {
|
|
1057
|
-
return this.__data__.get(key);
|
|
1058
|
-
}
|
|
1059
|
-
|
|
1060
|
-
/**
|
|
1061
|
-
* Checks if a stack value for `key` exists.
|
|
1062
|
-
*
|
|
1063
|
-
* @private
|
|
1064
|
-
* @name has
|
|
1065
|
-
* @memberOf Stack
|
|
1066
|
-
* @param {string} key The key of the entry to check.
|
|
1067
|
-
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
|
1068
|
-
*/
|
|
1069
|
-
function stackHas(key) {
|
|
1070
|
-
return this.__data__.has(key);
|
|
1071
|
-
}
|
|
1072
|
-
|
|
1073
|
-
/**
|
|
1074
|
-
* Sets the stack `key` to `value`.
|
|
1075
|
-
*
|
|
1076
|
-
* @private
|
|
1077
|
-
* @name set
|
|
1078
|
-
* @memberOf Stack
|
|
1079
|
-
* @param {string} key The key of the value to set.
|
|
1080
|
-
* @param {*} value The value to set.
|
|
1081
|
-
* @returns {Object} Returns the stack cache instance.
|
|
1082
|
-
*/
|
|
1083
|
-
function stackSet(key, value) {
|
|
1084
|
-
var cache = this.__data__;
|
|
1085
|
-
if (cache instanceof ListCache) {
|
|
1086
|
-
var pairs = cache.__data__;
|
|
1087
|
-
if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
|
|
1088
|
-
pairs.push([key, value]);
|
|
1089
|
-
return this;
|
|
1090
|
-
}
|
|
1091
|
-
cache = this.__data__ = new MapCache(pairs);
|
|
1092
|
-
}
|
|
1093
|
-
cache.set(key, value);
|
|
1094
|
-
return this;
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1097
|
-
// Add methods to `Stack`.
|
|
1098
|
-
Stack.prototype.clear = stackClear;
|
|
1099
|
-
Stack.prototype['delete'] = stackDelete;
|
|
1100
|
-
Stack.prototype.get = stackGet;
|
|
1101
|
-
Stack.prototype.has = stackHas;
|
|
1102
|
-
Stack.prototype.set = stackSet;
|
|
1103
|
-
|
|
1104
|
-
/**
|
|
1105
|
-
* Creates an array of the enumerable property names of the array-like `value`.
|
|
1106
|
-
*
|
|
1107
|
-
* @private
|
|
1108
|
-
* @param {*} value The value to query.
|
|
1109
|
-
* @param {boolean} inherited Specify returning inherited property names.
|
|
1110
|
-
* @returns {Array} Returns the array of property names.
|
|
1111
|
-
*/
|
|
1112
|
-
function arrayLikeKeys(value, inherited) {
|
|
1113
|
-
// Safari 8.1 makes `arguments.callee` enumerable in strict mode.
|
|
1114
|
-
// Safari 9 makes `arguments.length` enumerable in strict mode.
|
|
1115
|
-
var result = (isArray(value) || isArguments(value))
|
|
1116
|
-
? baseTimes(value.length, String)
|
|
1117
|
-
: [];
|
|
1118
|
-
|
|
1119
|
-
var length = result.length,
|
|
1120
|
-
skipIndexes = !!length;
|
|
1121
|
-
|
|
1122
|
-
for (var key in value) {
|
|
1123
|
-
if ((inherited || hasOwnProperty.call(value, key)) &&
|
|
1124
|
-
!(skipIndexes && (key == 'length' || isIndex(key, length)))) {
|
|
1125
|
-
result.push(key);
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
|
-
return result;
|
|
1129
|
-
}
|
|
1130
|
-
|
|
1131
|
-
/**
|
|
1132
|
-
* Assigns `value` to `key` of `object` if the existing value is not equivalent
|
|
1133
|
-
* using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
|
1134
|
-
* for equality comparisons.
|
|
1135
|
-
*
|
|
1136
|
-
* @private
|
|
1137
|
-
* @param {Object} object The object to modify.
|
|
1138
|
-
* @param {string} key The key of the property to assign.
|
|
1139
|
-
* @param {*} value The value to assign.
|
|
1140
|
-
*/
|
|
1141
|
-
function assignValue(object, key, value) {
|
|
1142
|
-
var objValue = object[key];
|
|
1143
|
-
if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
|
|
1144
|
-
(value === undefined && !(key in object))) {
|
|
1145
|
-
object[key] = value;
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
1148
|
-
|
|
1149
|
-
/**
|
|
1150
|
-
* Gets the index at which the `key` is found in `array` of key-value pairs.
|
|
1151
|
-
*
|
|
1152
|
-
* @private
|
|
1153
|
-
* @param {Array} array The array to inspect.
|
|
1154
|
-
* @param {*} key The key to search for.
|
|
1155
|
-
* @returns {number} Returns the index of the matched value, else `-1`.
|
|
1156
|
-
*/
|
|
1157
|
-
function assocIndexOf(array, key) {
|
|
1158
|
-
var length = array.length;
|
|
1159
|
-
while (length--) {
|
|
1160
|
-
if (eq(array[length][0], key)) {
|
|
1161
|
-
return length;
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
return -1;
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1167
|
-
/**
|
|
1168
|
-
* The base implementation of `_.assign` without support for multiple sources
|
|
1169
|
-
* or `customizer` functions.
|
|
1170
|
-
*
|
|
1171
|
-
* @private
|
|
1172
|
-
* @param {Object} object The destination object.
|
|
1173
|
-
* @param {Object} source The source object.
|
|
1174
|
-
* @returns {Object} Returns `object`.
|
|
1175
|
-
*/
|
|
1176
|
-
function baseAssign(object, source) {
|
|
1177
|
-
return object && copyObject(source, keys(source), object);
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
|
-
/**
|
|
1181
|
-
* The base implementation of `_.clone` and `_.cloneDeep` which tracks
|
|
1182
|
-
* traversed objects.
|
|
1183
|
-
*
|
|
1184
|
-
* @private
|
|
1185
|
-
* @param {*} value The value to clone.
|
|
1186
|
-
* @param {boolean} [isDeep] Specify a deep clone.
|
|
1187
|
-
* @param {boolean} [isFull] Specify a clone including symbols.
|
|
1188
|
-
* @param {Function} [customizer] The function to customize cloning.
|
|
1189
|
-
* @param {string} [key] The key of `value`.
|
|
1190
|
-
* @param {Object} [object] The parent object of `value`.
|
|
1191
|
-
* @param {Object} [stack] Tracks traversed objects and their clone counterparts.
|
|
1192
|
-
* @returns {*} Returns the cloned value.
|
|
1193
|
-
*/
|
|
1194
|
-
function baseClone(value, isDeep, isFull, customizer, key, object, stack) {
|
|
1195
|
-
var result;
|
|
1196
|
-
if (customizer) {
|
|
1197
|
-
result = object ? customizer(value, key, object, stack) : customizer(value);
|
|
1198
|
-
}
|
|
1199
|
-
if (result !== undefined) {
|
|
1200
|
-
return result;
|
|
1201
|
-
}
|
|
1202
|
-
if (!isObject(value)) {
|
|
1203
|
-
return value;
|
|
1204
|
-
}
|
|
1205
|
-
var isArr = isArray(value);
|
|
1206
|
-
if (isArr) {
|
|
1207
|
-
result = initCloneArray(value);
|
|
1208
|
-
if (!isDeep) {
|
|
1209
|
-
return copyArray(value, result);
|
|
1210
|
-
}
|
|
1211
|
-
} else {
|
|
1212
|
-
var tag = getTag(value),
|
|
1213
|
-
isFunc = tag == funcTag || tag == genTag;
|
|
1214
|
-
|
|
1215
|
-
if (isBuffer(value)) {
|
|
1216
|
-
return cloneBuffer(value, isDeep);
|
|
1217
|
-
}
|
|
1218
|
-
if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
|
|
1219
|
-
if (isHostObject(value)) {
|
|
1220
|
-
return object ? value : {};
|
|
1221
|
-
}
|
|
1222
|
-
result = initCloneObject(isFunc ? {} : value);
|
|
1223
|
-
if (!isDeep) {
|
|
1224
|
-
return copySymbols(value, baseAssign(result, value));
|
|
1225
|
-
}
|
|
1226
|
-
} else {
|
|
1227
|
-
if (!cloneableTags[tag]) {
|
|
1228
|
-
return object ? value : {};
|
|
1229
|
-
}
|
|
1230
|
-
result = initCloneByTag(value, tag, baseClone, isDeep);
|
|
1231
|
-
}
|
|
1232
|
-
}
|
|
1233
|
-
// Check for circular references and return its corresponding clone.
|
|
1234
|
-
stack || (stack = new Stack);
|
|
1235
|
-
var stacked = stack.get(value);
|
|
1236
|
-
if (stacked) {
|
|
1237
|
-
return stacked;
|
|
1238
|
-
}
|
|
1239
|
-
stack.set(value, result);
|
|
1240
|
-
|
|
1241
|
-
if (!isArr) {
|
|
1242
|
-
var props = isFull ? getAllKeys(value) : keys(value);
|
|
1243
|
-
}
|
|
1244
|
-
arrayEach(props || value, function(subValue, key) {
|
|
1245
|
-
if (props) {
|
|
1246
|
-
key = subValue;
|
|
1247
|
-
subValue = value[key];
|
|
1248
|
-
}
|
|
1249
|
-
// Recursively populate clone (susceptible to call stack limits).
|
|
1250
|
-
assignValue(result, key, baseClone(subValue, isDeep, isFull, customizer, key, value, stack));
|
|
1251
|
-
});
|
|
1252
|
-
return result;
|
|
1253
|
-
}
|
|
1254
|
-
|
|
1255
|
-
/**
|
|
1256
|
-
* The base implementation of `_.create` without support for assigning
|
|
1257
|
-
* properties to the created object.
|
|
1258
|
-
*
|
|
1259
|
-
* @private
|
|
1260
|
-
* @param {Object} prototype The object to inherit from.
|
|
1261
|
-
* @returns {Object} Returns the new object.
|
|
1262
|
-
*/
|
|
1263
|
-
function baseCreate(proto) {
|
|
1264
|
-
return isObject(proto) ? objectCreate(proto) : {};
|
|
1265
|
-
}
|
|
1266
|
-
|
|
1267
|
-
/**
|
|
1268
|
-
* The base implementation of `getAllKeys` and `getAllKeysIn` which uses
|
|
1269
|
-
* `keysFunc` and `symbolsFunc` to get the enumerable property names and
|
|
1270
|
-
* symbols of `object`.
|
|
1271
|
-
*
|
|
1272
|
-
* @private
|
|
1273
|
-
* @param {Object} object The object to query.
|
|
1274
|
-
* @param {Function} keysFunc The function to get the keys of `object`.
|
|
1275
|
-
* @param {Function} symbolsFunc The function to get the symbols of `object`.
|
|
1276
|
-
* @returns {Array} Returns the array of property names and symbols.
|
|
1277
|
-
*/
|
|
1278
|
-
function baseGetAllKeys(object, keysFunc, symbolsFunc) {
|
|
1279
|
-
var result = keysFunc(object);
|
|
1280
|
-
return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
|
|
1281
|
-
}
|
|
1282
|
-
|
|
1283
|
-
/**
|
|
1284
|
-
* The base implementation of `getTag`.
|
|
1285
|
-
*
|
|
1286
|
-
* @private
|
|
1287
|
-
* @param {*} value The value to query.
|
|
1288
|
-
* @returns {string} Returns the `toStringTag`.
|
|
1289
|
-
*/
|
|
1290
|
-
function baseGetTag(value) {
|
|
1291
|
-
return objectToString.call(value);
|
|
1292
|
-
}
|
|
1293
|
-
|
|
1294
|
-
/**
|
|
1295
|
-
* The base implementation of `_.isNative` without bad shim checks.
|
|
1296
|
-
*
|
|
1297
|
-
* @private
|
|
1298
|
-
* @param {*} value The value to check.
|
|
1299
|
-
* @returns {boolean} Returns `true` if `value` is a native function,
|
|
1300
|
-
* else `false`.
|
|
1301
|
-
*/
|
|
1302
|
-
function baseIsNative(value) {
|
|
1303
|
-
if (!isObject(value) || isMasked(value)) {
|
|
1304
|
-
return false;
|
|
1305
|
-
}
|
|
1306
|
-
var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor;
|
|
1307
|
-
return pattern.test(toSource(value));
|
|
1308
|
-
}
|
|
1309
|
-
|
|
1310
|
-
/**
|
|
1311
|
-
* The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
|
|
1312
|
-
*
|
|
1313
|
-
* @private
|
|
1314
|
-
* @param {Object} object The object to query.
|
|
1315
|
-
* @returns {Array} Returns the array of property names.
|
|
1316
|
-
*/
|
|
1317
|
-
function baseKeys(object) {
|
|
1318
|
-
if (!isPrototype(object)) {
|
|
1319
|
-
return nativeKeys(object);
|
|
1320
|
-
}
|
|
1321
|
-
var result = [];
|
|
1322
|
-
for (var key in Object(object)) {
|
|
1323
|
-
if (hasOwnProperty.call(object, key) && key != 'constructor') {
|
|
1324
|
-
result.push(key);
|
|
1325
|
-
}
|
|
1326
|
-
}
|
|
1327
|
-
return result;
|
|
1328
|
-
}
|
|
1329
|
-
|
|
1330
|
-
/**
|
|
1331
|
-
* Creates a clone of `buffer`.
|
|
1332
|
-
*
|
|
1333
|
-
* @private
|
|
1334
|
-
* @param {Buffer} buffer The buffer to clone.
|
|
1335
|
-
* @param {boolean} [isDeep] Specify a deep clone.
|
|
1336
|
-
* @returns {Buffer} Returns the cloned buffer.
|
|
1337
|
-
*/
|
|
1338
|
-
function cloneBuffer(buffer, isDeep) {
|
|
1339
|
-
if (isDeep) {
|
|
1340
|
-
return buffer.slice();
|
|
1341
|
-
}
|
|
1342
|
-
var result = new buffer.constructor(buffer.length);
|
|
1343
|
-
buffer.copy(result);
|
|
1344
|
-
return result;
|
|
1345
|
-
}
|
|
1346
|
-
|
|
1347
|
-
/**
|
|
1348
|
-
* Creates a clone of `arrayBuffer`.
|
|
1349
|
-
*
|
|
1350
|
-
* @private
|
|
1351
|
-
* @param {ArrayBuffer} arrayBuffer The array buffer to clone.
|
|
1352
|
-
* @returns {ArrayBuffer} Returns the cloned array buffer.
|
|
1353
|
-
*/
|
|
1354
|
-
function cloneArrayBuffer(arrayBuffer) {
|
|
1355
|
-
var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
|
|
1356
|
-
new Uint8Array(result).set(new Uint8Array(arrayBuffer));
|
|
1357
|
-
return result;
|
|
1358
|
-
}
|
|
1359
|
-
|
|
1360
|
-
/**
|
|
1361
|
-
* Creates a clone of `dataView`.
|
|
1362
|
-
*
|
|
1363
|
-
* @private
|
|
1364
|
-
* @param {Object} dataView The data view to clone.
|
|
1365
|
-
* @param {boolean} [isDeep] Specify a deep clone.
|
|
1366
|
-
* @returns {Object} Returns the cloned data view.
|
|
1367
|
-
*/
|
|
1368
|
-
function cloneDataView(dataView, isDeep) {
|
|
1369
|
-
var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
|
|
1370
|
-
return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
|
|
1371
|
-
}
|
|
1372
|
-
|
|
1373
|
-
/**
|
|
1374
|
-
* Creates a clone of `map`.
|
|
1375
|
-
*
|
|
1376
|
-
* @private
|
|
1377
|
-
* @param {Object} map The map to clone.
|
|
1378
|
-
* @param {Function} cloneFunc The function to clone values.
|
|
1379
|
-
* @param {boolean} [isDeep] Specify a deep clone.
|
|
1380
|
-
* @returns {Object} Returns the cloned map.
|
|
1381
|
-
*/
|
|
1382
|
-
function cloneMap(map, isDeep, cloneFunc) {
|
|
1383
|
-
var array = isDeep ? cloneFunc(mapToArray(map), true) : mapToArray(map);
|
|
1384
|
-
return arrayReduce(array, addMapEntry, new map.constructor);
|
|
1385
|
-
}
|
|
1386
|
-
|
|
1387
|
-
/**
|
|
1388
|
-
* Creates a clone of `regexp`.
|
|
1389
|
-
*
|
|
1390
|
-
* @private
|
|
1391
|
-
* @param {Object} regexp The regexp to clone.
|
|
1392
|
-
* @returns {Object} Returns the cloned regexp.
|
|
1393
|
-
*/
|
|
1394
|
-
function cloneRegExp(regexp) {
|
|
1395
|
-
var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
|
|
1396
|
-
result.lastIndex = regexp.lastIndex;
|
|
1397
|
-
return result;
|
|
1398
|
-
}
|
|
1399
|
-
|
|
1400
|
-
/**
|
|
1401
|
-
* Creates a clone of `set`.
|
|
1402
|
-
*
|
|
1403
|
-
* @private
|
|
1404
|
-
* @param {Object} set The set to clone.
|
|
1405
|
-
* @param {Function} cloneFunc The function to clone values.
|
|
1406
|
-
* @param {boolean} [isDeep] Specify a deep clone.
|
|
1407
|
-
* @returns {Object} Returns the cloned set.
|
|
1408
|
-
*/
|
|
1409
|
-
function cloneSet(set, isDeep, cloneFunc) {
|
|
1410
|
-
var array = isDeep ? cloneFunc(setToArray(set), true) : setToArray(set);
|
|
1411
|
-
return arrayReduce(array, addSetEntry, new set.constructor);
|
|
1412
|
-
}
|
|
1413
|
-
|
|
1414
|
-
/**
|
|
1415
|
-
* Creates a clone of the `symbol` object.
|
|
1416
|
-
*
|
|
1417
|
-
* @private
|
|
1418
|
-
* @param {Object} symbol The symbol object to clone.
|
|
1419
|
-
* @returns {Object} Returns the cloned symbol object.
|
|
1420
|
-
*/
|
|
1421
|
-
function cloneSymbol(symbol) {
|
|
1422
|
-
return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
|
|
1423
|
-
}
|
|
1424
|
-
|
|
1425
|
-
/**
|
|
1426
|
-
* Creates a clone of `typedArray`.
|
|
1427
|
-
*
|
|
1428
|
-
* @private
|
|
1429
|
-
* @param {Object} typedArray The typed array to clone.
|
|
1430
|
-
* @param {boolean} [isDeep] Specify a deep clone.
|
|
1431
|
-
* @returns {Object} Returns the cloned typed array.
|
|
1432
|
-
*/
|
|
1433
|
-
function cloneTypedArray(typedArray, isDeep) {
|
|
1434
|
-
var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
|
|
1435
|
-
return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
|
|
1436
|
-
}
|
|
1437
|
-
|
|
1438
|
-
/**
|
|
1439
|
-
* Copies the values of `source` to `array`.
|
|
1440
|
-
*
|
|
1441
|
-
* @private
|
|
1442
|
-
* @param {Array} source The array to copy values from.
|
|
1443
|
-
* @param {Array} [array=[]] The array to copy values to.
|
|
1444
|
-
* @returns {Array} Returns `array`.
|
|
1445
|
-
*/
|
|
1446
|
-
function copyArray(source, array) {
|
|
1447
|
-
var index = -1,
|
|
1448
|
-
length = source.length;
|
|
1449
|
-
|
|
1450
|
-
array || (array = Array(length));
|
|
1451
|
-
while (++index < length) {
|
|
1452
|
-
array[index] = source[index];
|
|
1453
|
-
}
|
|
1454
|
-
return array;
|
|
1455
|
-
}
|
|
1456
|
-
|
|
1457
|
-
/**
|
|
1458
|
-
* Copies properties of `source` to `object`.
|
|
1459
|
-
*
|
|
1460
|
-
* @private
|
|
1461
|
-
* @param {Object} source The object to copy properties from.
|
|
1462
|
-
* @param {Array} props The property identifiers to copy.
|
|
1463
|
-
* @param {Object} [object={}] The object to copy properties to.
|
|
1464
|
-
* @param {Function} [customizer] The function to customize copied values.
|
|
1465
|
-
* @returns {Object} Returns `object`.
|
|
1466
|
-
*/
|
|
1467
|
-
function copyObject(source, props, object, customizer) {
|
|
1468
|
-
object || (object = {});
|
|
1469
|
-
|
|
1470
|
-
var index = -1,
|
|
1471
|
-
length = props.length;
|
|
1472
|
-
|
|
1473
|
-
while (++index < length) {
|
|
1474
|
-
var key = props[index];
|
|
1475
|
-
|
|
1476
|
-
var newValue = customizer
|
|
1477
|
-
? customizer(object[key], source[key], key, object, source)
|
|
1478
|
-
: undefined;
|
|
1479
|
-
|
|
1480
|
-
assignValue(object, key, newValue === undefined ? source[key] : newValue);
|
|
1481
|
-
}
|
|
1482
|
-
return object;
|
|
1483
|
-
}
|
|
1484
|
-
|
|
1485
|
-
/**
|
|
1486
|
-
* Copies own symbol properties of `source` to `object`.
|
|
1487
|
-
*
|
|
1488
|
-
* @private
|
|
1489
|
-
* @param {Object} source The object to copy symbols from.
|
|
1490
|
-
* @param {Object} [object={}] The object to copy symbols to.
|
|
1491
|
-
* @returns {Object} Returns `object`.
|
|
1492
|
-
*/
|
|
1493
|
-
function copySymbols(source, object) {
|
|
1494
|
-
return copyObject(source, getSymbols(source), object);
|
|
1495
|
-
}
|
|
1496
|
-
|
|
1497
|
-
/**
|
|
1498
|
-
* Creates an array of own enumerable property names and symbols of `object`.
|
|
1499
|
-
*
|
|
1500
|
-
* @private
|
|
1501
|
-
* @param {Object} object The object to query.
|
|
1502
|
-
* @returns {Array} Returns the array of property names and symbols.
|
|
1503
|
-
*/
|
|
1504
|
-
function getAllKeys(object) {
|
|
1505
|
-
return baseGetAllKeys(object, keys, getSymbols);
|
|
1506
|
-
}
|
|
1507
|
-
|
|
1508
|
-
/**
|
|
1509
|
-
* Gets the data for `map`.
|
|
1510
|
-
*
|
|
1511
|
-
* @private
|
|
1512
|
-
* @param {Object} map The map to query.
|
|
1513
|
-
* @param {string} key The reference key.
|
|
1514
|
-
* @returns {*} Returns the map data.
|
|
1515
|
-
*/
|
|
1516
|
-
function getMapData(map, key) {
|
|
1517
|
-
var data = map.__data__;
|
|
1518
|
-
return isKeyable(key)
|
|
1519
|
-
? data[typeof key == 'string' ? 'string' : 'hash']
|
|
1520
|
-
: data.map;
|
|
1521
|
-
}
|
|
1522
|
-
|
|
1523
|
-
/**
|
|
1524
|
-
* Gets the native function at `key` of `object`.
|
|
1525
|
-
*
|
|
1526
|
-
* @private
|
|
1527
|
-
* @param {Object} object The object to query.
|
|
1528
|
-
* @param {string} key The key of the method to get.
|
|
1529
|
-
* @returns {*} Returns the function if it's native, else `undefined`.
|
|
1530
|
-
*/
|
|
1531
|
-
function getNative(object, key) {
|
|
1532
|
-
var value = getValue(object, key);
|
|
1533
|
-
return baseIsNative(value) ? value : undefined;
|
|
1534
|
-
}
|
|
1535
|
-
|
|
1536
|
-
/**
|
|
1537
|
-
* Creates an array of the own enumerable symbol properties of `object`.
|
|
1538
|
-
*
|
|
1539
|
-
* @private
|
|
1540
|
-
* @param {Object} object The object to query.
|
|
1541
|
-
* @returns {Array} Returns the array of symbols.
|
|
1542
|
-
*/
|
|
1543
|
-
var getSymbols = nativeGetSymbols ? overArg(nativeGetSymbols, Object) : stubArray;
|
|
1544
|
-
|
|
1545
|
-
/**
|
|
1546
|
-
* Gets the `toStringTag` of `value`.
|
|
1547
|
-
*
|
|
1548
|
-
* @private
|
|
1549
|
-
* @param {*} value The value to query.
|
|
1550
|
-
* @returns {string} Returns the `toStringTag`.
|
|
1551
|
-
*/
|
|
1552
|
-
var getTag = baseGetTag;
|
|
1553
|
-
|
|
1554
|
-
// Fallback for data views, maps, sets, and weak maps in IE 11,
|
|
1555
|
-
// for data views in Edge < 14, and promises in Node.js.
|
|
1556
|
-
if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
|
|
1557
|
-
(Map && getTag(new Map) != mapTag) ||
|
|
1558
|
-
(Promise && getTag(Promise.resolve()) != promiseTag) ||
|
|
1559
|
-
(Set && getTag(new Set) != setTag) ||
|
|
1560
|
-
(WeakMap && getTag(new WeakMap) != weakMapTag)) {
|
|
1561
|
-
getTag = function(value) {
|
|
1562
|
-
var result = objectToString.call(value),
|
|
1563
|
-
Ctor = result == objectTag ? value.constructor : undefined,
|
|
1564
|
-
ctorString = Ctor ? toSource(Ctor) : undefined;
|
|
1565
|
-
|
|
1566
|
-
if (ctorString) {
|
|
1567
|
-
switch (ctorString) {
|
|
1568
|
-
case dataViewCtorString: return dataViewTag;
|
|
1569
|
-
case mapCtorString: return mapTag;
|
|
1570
|
-
case promiseCtorString: return promiseTag;
|
|
1571
|
-
case setCtorString: return setTag;
|
|
1572
|
-
case weakMapCtorString: return weakMapTag;
|
|
1573
|
-
}
|
|
1574
|
-
}
|
|
1575
|
-
return result;
|
|
1576
|
-
};
|
|
1577
|
-
}
|
|
1578
|
-
|
|
1579
|
-
/**
|
|
1580
|
-
* Initializes an array clone.
|
|
1581
|
-
*
|
|
1582
|
-
* @private
|
|
1583
|
-
* @param {Array} array The array to clone.
|
|
1584
|
-
* @returns {Array} Returns the initialized clone.
|
|
1585
|
-
*/
|
|
1586
|
-
function initCloneArray(array) {
|
|
1587
|
-
var length = array.length,
|
|
1588
|
-
result = array.constructor(length);
|
|
1589
|
-
|
|
1590
|
-
// Add properties assigned by `RegExp#exec`.
|
|
1591
|
-
if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
|
|
1592
|
-
result.index = array.index;
|
|
1593
|
-
result.input = array.input;
|
|
1594
|
-
}
|
|
1595
|
-
return result;
|
|
1596
|
-
}
|
|
1597
|
-
|
|
1598
|
-
/**
|
|
1599
|
-
* Initializes an object clone.
|
|
1600
|
-
*
|
|
1601
|
-
* @private
|
|
1602
|
-
* @param {Object} object The object to clone.
|
|
1603
|
-
* @returns {Object} Returns the initialized clone.
|
|
1604
|
-
*/
|
|
1605
|
-
function initCloneObject(object) {
|
|
1606
|
-
return (typeof object.constructor == 'function' && !isPrototype(object))
|
|
1607
|
-
? baseCreate(getPrototype(object))
|
|
1608
|
-
: {};
|
|
1609
|
-
}
|
|
1610
|
-
|
|
1611
|
-
/**
|
|
1612
|
-
* Initializes an object clone based on its `toStringTag`.
|
|
1613
|
-
*
|
|
1614
|
-
* **Note:** This function only supports cloning values with tags of
|
|
1615
|
-
* `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
|
|
1616
|
-
*
|
|
1617
|
-
* @private
|
|
1618
|
-
* @param {Object} object The object to clone.
|
|
1619
|
-
* @param {string} tag The `toStringTag` of the object to clone.
|
|
1620
|
-
* @param {Function} cloneFunc The function to clone values.
|
|
1621
|
-
* @param {boolean} [isDeep] Specify a deep clone.
|
|
1622
|
-
* @returns {Object} Returns the initialized clone.
|
|
1623
|
-
*/
|
|
1624
|
-
function initCloneByTag(object, tag, cloneFunc, isDeep) {
|
|
1625
|
-
var Ctor = object.constructor;
|
|
1626
|
-
switch (tag) {
|
|
1627
|
-
case arrayBufferTag:
|
|
1628
|
-
return cloneArrayBuffer(object);
|
|
1629
|
-
|
|
1630
|
-
case boolTag:
|
|
1631
|
-
case dateTag:
|
|
1632
|
-
return new Ctor(+object);
|
|
1633
|
-
|
|
1634
|
-
case dataViewTag:
|
|
1635
|
-
return cloneDataView(object, isDeep);
|
|
1636
|
-
|
|
1637
|
-
case float32Tag: case float64Tag:
|
|
1638
|
-
case int8Tag: case int16Tag: case int32Tag:
|
|
1639
|
-
case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
|
|
1640
|
-
return cloneTypedArray(object, isDeep);
|
|
1641
|
-
|
|
1642
|
-
case mapTag:
|
|
1643
|
-
return cloneMap(object, isDeep, cloneFunc);
|
|
1644
|
-
|
|
1645
|
-
case numberTag:
|
|
1646
|
-
case stringTag:
|
|
1647
|
-
return new Ctor(object);
|
|
1648
|
-
|
|
1649
|
-
case regexpTag:
|
|
1650
|
-
return cloneRegExp(object);
|
|
1651
|
-
|
|
1652
|
-
case setTag:
|
|
1653
|
-
return cloneSet(object, isDeep, cloneFunc);
|
|
1654
|
-
|
|
1655
|
-
case symbolTag:
|
|
1656
|
-
return cloneSymbol(object);
|
|
1657
|
-
}
|
|
1658
|
-
}
|
|
1659
|
-
|
|
1660
|
-
/**
|
|
1661
|
-
* Checks if `value` is a valid array-like index.
|
|
1662
|
-
*
|
|
1663
|
-
* @private
|
|
1664
|
-
* @param {*} value The value to check.
|
|
1665
|
-
* @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
|
|
1666
|
-
* @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
|
|
1667
|
-
*/
|
|
1668
|
-
function isIndex(value, length) {
|
|
1669
|
-
length = length == null ? MAX_SAFE_INTEGER : length;
|
|
1670
|
-
return !!length &&
|
|
1671
|
-
(typeof value == 'number' || reIsUint.test(value)) &&
|
|
1672
|
-
(value > -1 && value % 1 == 0 && value < length);
|
|
1673
|
-
}
|
|
1674
|
-
|
|
1675
|
-
/**
|
|
1676
|
-
* Checks if `value` is suitable for use as unique object key.
|
|
1677
|
-
*
|
|
1678
|
-
* @private
|
|
1679
|
-
* @param {*} value The value to check.
|
|
1680
|
-
* @returns {boolean} Returns `true` if `value` is suitable, else `false`.
|
|
1681
|
-
*/
|
|
1682
|
-
function isKeyable(value) {
|
|
1683
|
-
var type = typeof value;
|
|
1684
|
-
return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
|
|
1685
|
-
? (value !== '__proto__')
|
|
1686
|
-
: (value === null);
|
|
1687
|
-
}
|
|
1688
|
-
|
|
1689
|
-
/**
|
|
1690
|
-
* Checks if `func` has its source masked.
|
|
1691
|
-
*
|
|
1692
|
-
* @private
|
|
1693
|
-
* @param {Function} func The function to check.
|
|
1694
|
-
* @returns {boolean} Returns `true` if `func` is masked, else `false`.
|
|
1695
|
-
*/
|
|
1696
|
-
function isMasked(func) {
|
|
1697
|
-
return !!maskSrcKey && (maskSrcKey in func);
|
|
1698
|
-
}
|
|
1699
|
-
|
|
1700
|
-
/**
|
|
1701
|
-
* Checks if `value` is likely a prototype object.
|
|
1702
|
-
*
|
|
1703
|
-
* @private
|
|
1704
|
-
* @param {*} value The value to check.
|
|
1705
|
-
* @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
|
|
1706
|
-
*/
|
|
1707
|
-
function isPrototype(value) {
|
|
1708
|
-
var Ctor = value && value.constructor,
|
|
1709
|
-
proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
|
|
1710
|
-
|
|
1711
|
-
return value === proto;
|
|
1712
|
-
}
|
|
1713
|
-
|
|
1714
|
-
/**
|
|
1715
|
-
* Converts `func` to its source code.
|
|
1716
|
-
*
|
|
1717
|
-
* @private
|
|
1718
|
-
* @param {Function} func The function to process.
|
|
1719
|
-
* @returns {string} Returns the source code.
|
|
1720
|
-
*/
|
|
1721
|
-
function toSource(func) {
|
|
1722
|
-
if (func != null) {
|
|
1723
|
-
try {
|
|
1724
|
-
return funcToString.call(func);
|
|
1725
|
-
} catch (e) {}
|
|
1726
|
-
try {
|
|
1727
|
-
return (func + '');
|
|
1728
|
-
} catch (e) {}
|
|
1729
|
-
}
|
|
1730
|
-
return '';
|
|
1731
|
-
}
|
|
1732
|
-
|
|
1733
|
-
/**
|
|
1734
|
-
* This method is like `_.clone` except that it recursively clones `value`.
|
|
1735
|
-
*
|
|
1736
|
-
* @static
|
|
1737
|
-
* @memberOf _
|
|
1738
|
-
* @since 1.0.0
|
|
1739
|
-
* @category Lang
|
|
1740
|
-
* @param {*} value The value to recursively clone.
|
|
1741
|
-
* @returns {*} Returns the deep cloned value.
|
|
1742
|
-
* @see _.clone
|
|
1743
|
-
* @example
|
|
1744
|
-
*
|
|
1745
|
-
* var objects = [{ 'a': 1 }, { 'b': 2 }];
|
|
1746
|
-
*
|
|
1747
|
-
* var deep = _.cloneDeep(objects);
|
|
1748
|
-
* console.log(deep[0] === objects[0]);
|
|
1749
|
-
* // => false
|
|
1750
|
-
*/
|
|
1751
|
-
function cloneDeep(value) {
|
|
1752
|
-
return baseClone(value, true, true);
|
|
1753
|
-
}
|
|
1754
|
-
|
|
1755
|
-
/**
|
|
1756
|
-
* Performs a
|
|
1757
|
-
* [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
|
1758
|
-
* comparison between two values to determine if they are equivalent.
|
|
1759
|
-
*
|
|
1760
|
-
* @static
|
|
1761
|
-
* @memberOf _
|
|
1762
|
-
* @since 4.0.0
|
|
1763
|
-
* @category Lang
|
|
1764
|
-
* @param {*} value The value to compare.
|
|
1765
|
-
* @param {*} other The other value to compare.
|
|
1766
|
-
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
|
1767
|
-
* @example
|
|
1768
|
-
*
|
|
1769
|
-
* var object = { 'a': 1 };
|
|
1770
|
-
* var other = { 'a': 1 };
|
|
1771
|
-
*
|
|
1772
|
-
* _.eq(object, object);
|
|
1773
|
-
* // => true
|
|
1774
|
-
*
|
|
1775
|
-
* _.eq(object, other);
|
|
1776
|
-
* // => false
|
|
1777
|
-
*
|
|
1778
|
-
* _.eq('a', 'a');
|
|
1779
|
-
* // => true
|
|
1780
|
-
*
|
|
1781
|
-
* _.eq('a', Object('a'));
|
|
1782
|
-
* // => false
|
|
1783
|
-
*
|
|
1784
|
-
* _.eq(NaN, NaN);
|
|
1785
|
-
* // => true
|
|
1786
|
-
*/
|
|
1787
|
-
function eq(value, other) {
|
|
1788
|
-
return value === other || (value !== value && other !== other);
|
|
1789
|
-
}
|
|
1790
|
-
|
|
1791
|
-
/**
|
|
1792
|
-
* Checks if `value` is likely an `arguments` object.
|
|
1793
|
-
*
|
|
1794
|
-
* @static
|
|
1795
|
-
* @memberOf _
|
|
1796
|
-
* @since 0.1.0
|
|
1797
|
-
* @category Lang
|
|
1798
|
-
* @param {*} value The value to check.
|
|
1799
|
-
* @returns {boolean} Returns `true` if `value` is an `arguments` object,
|
|
1800
|
-
* else `false`.
|
|
1801
|
-
* @example
|
|
1802
|
-
*
|
|
1803
|
-
* _.isArguments(function() { return arguments; }());
|
|
1804
|
-
* // => true
|
|
1805
|
-
*
|
|
1806
|
-
* _.isArguments([1, 2, 3]);
|
|
1807
|
-
* // => false
|
|
1808
|
-
*/
|
|
1809
|
-
function isArguments(value) {
|
|
1810
|
-
// Safari 8.1 makes `arguments.callee` enumerable in strict mode.
|
|
1811
|
-
return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
|
|
1812
|
-
(!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
|
|
1813
|
-
}
|
|
1814
|
-
|
|
1815
|
-
/**
|
|
1816
|
-
* Checks if `value` is classified as an `Array` object.
|
|
1817
|
-
*
|
|
1818
|
-
* @static
|
|
1819
|
-
* @memberOf _
|
|
1820
|
-
* @since 0.1.0
|
|
1821
|
-
* @category Lang
|
|
1822
|
-
* @param {*} value The value to check.
|
|
1823
|
-
* @returns {boolean} Returns `true` if `value` is an array, else `false`.
|
|
1824
|
-
* @example
|
|
1825
|
-
*
|
|
1826
|
-
* _.isArray([1, 2, 3]);
|
|
1827
|
-
* // => true
|
|
1828
|
-
*
|
|
1829
|
-
* _.isArray(document.body.children);
|
|
1830
|
-
* // => false
|
|
1831
|
-
*
|
|
1832
|
-
* _.isArray('abc');
|
|
1833
|
-
* // => false
|
|
1834
|
-
*
|
|
1835
|
-
* _.isArray(_.noop);
|
|
1836
|
-
* // => false
|
|
1837
|
-
*/
|
|
1838
|
-
var isArray = Array.isArray;
|
|
1839
|
-
|
|
1840
|
-
/**
|
|
1841
|
-
* Checks if `value` is array-like. A value is considered array-like if it's
|
|
1842
|
-
* not a function and has a `value.length` that's an integer greater than or
|
|
1843
|
-
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
|
|
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 array-like, else `false`.
|
|
1851
|
-
* @example
|
|
1852
|
-
*
|
|
1853
|
-
* _.isArrayLike([1, 2, 3]);
|
|
1854
|
-
* // => true
|
|
1855
|
-
*
|
|
1856
|
-
* _.isArrayLike(document.body.children);
|
|
1857
|
-
* // => true
|
|
1858
|
-
*
|
|
1859
|
-
* _.isArrayLike('abc');
|
|
1860
|
-
* // => true
|
|
1861
|
-
*
|
|
1862
|
-
* _.isArrayLike(_.noop);
|
|
1863
|
-
* // => false
|
|
1864
|
-
*/
|
|
1865
|
-
function isArrayLike(value) {
|
|
1866
|
-
return value != null && isLength(value.length) && !isFunction(value);
|
|
1867
|
-
}
|
|
1868
|
-
|
|
1869
|
-
/**
|
|
1870
|
-
* This method is like `_.isArrayLike` except that it also checks if `value`
|
|
1871
|
-
* is an object.
|
|
1872
|
-
*
|
|
1873
|
-
* @static
|
|
1874
|
-
* @memberOf _
|
|
1875
|
-
* @since 4.0.0
|
|
1876
|
-
* @category Lang
|
|
1877
|
-
* @param {*} value The value to check.
|
|
1878
|
-
* @returns {boolean} Returns `true` if `value` is an array-like object,
|
|
1879
|
-
* else `false`.
|
|
1880
|
-
* @example
|
|
1881
|
-
*
|
|
1882
|
-
* _.isArrayLikeObject([1, 2, 3]);
|
|
1883
|
-
* // => true
|
|
1884
|
-
*
|
|
1885
|
-
* _.isArrayLikeObject(document.body.children);
|
|
1886
|
-
* // => true
|
|
1887
|
-
*
|
|
1888
|
-
* _.isArrayLikeObject('abc');
|
|
1889
|
-
* // => false
|
|
1890
|
-
*
|
|
1891
|
-
* _.isArrayLikeObject(_.noop);
|
|
1892
|
-
* // => false
|
|
1893
|
-
*/
|
|
1894
|
-
function isArrayLikeObject(value) {
|
|
1895
|
-
return isObjectLike(value) && isArrayLike(value);
|
|
1896
|
-
}
|
|
1897
|
-
|
|
1898
|
-
/**
|
|
1899
|
-
* Checks if `value` is a buffer.
|
|
1900
|
-
*
|
|
1901
|
-
* @static
|
|
1902
|
-
* @memberOf _
|
|
1903
|
-
* @since 4.3.0
|
|
1904
|
-
* @category Lang
|
|
1905
|
-
* @param {*} value The value to check.
|
|
1906
|
-
* @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
|
|
1907
|
-
* @example
|
|
1908
|
-
*
|
|
1909
|
-
* _.isBuffer(new Buffer(2));
|
|
1910
|
-
* // => true
|
|
1911
|
-
*
|
|
1912
|
-
* _.isBuffer(new Uint8Array(2));
|
|
1913
|
-
* // => false
|
|
1914
|
-
*/
|
|
1915
|
-
var isBuffer = nativeIsBuffer || stubFalse;
|
|
1916
|
-
|
|
1917
|
-
/**
|
|
1918
|
-
* Checks if `value` is classified as a `Function` object.
|
|
1919
|
-
*
|
|
1920
|
-
* @static
|
|
1921
|
-
* @memberOf _
|
|
1922
|
-
* @since 0.1.0
|
|
1923
|
-
* @category Lang
|
|
1924
|
-
* @param {*} value The value to check.
|
|
1925
|
-
* @returns {boolean} Returns `true` if `value` is a function, else `false`.
|
|
1926
|
-
* @example
|
|
1927
|
-
*
|
|
1928
|
-
* _.isFunction(_);
|
|
1929
|
-
* // => true
|
|
1930
|
-
*
|
|
1931
|
-
* _.isFunction(/abc/);
|
|
1932
|
-
* // => false
|
|
1933
|
-
*/
|
|
1934
|
-
function isFunction(value) {
|
|
1935
|
-
// The use of `Object#toString` avoids issues with the `typeof` operator
|
|
1936
|
-
// in Safari 8-9 which returns 'object' for typed array and other constructors.
|
|
1937
|
-
var tag = isObject(value) ? objectToString.call(value) : '';
|
|
1938
|
-
return tag == funcTag || tag == genTag;
|
|
1939
|
-
}
|
|
1940
|
-
|
|
1941
|
-
/**
|
|
1942
|
-
* Checks if `value` is a valid array-like length.
|
|
1943
|
-
*
|
|
1944
|
-
* **Note:** This method is loosely based on
|
|
1945
|
-
* [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
|
|
1946
|
-
*
|
|
1947
|
-
* @static
|
|
1948
|
-
* @memberOf _
|
|
1949
|
-
* @since 4.0.0
|
|
1950
|
-
* @category Lang
|
|
1951
|
-
* @param {*} value The value to check.
|
|
1952
|
-
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
|
1953
|
-
* @example
|
|
1954
|
-
*
|
|
1955
|
-
* _.isLength(3);
|
|
1956
|
-
* // => true
|
|
1957
|
-
*
|
|
1958
|
-
* _.isLength(Number.MIN_VALUE);
|
|
1959
|
-
* // => false
|
|
1960
|
-
*
|
|
1961
|
-
* _.isLength(Infinity);
|
|
1962
|
-
* // => false
|
|
1963
|
-
*
|
|
1964
|
-
* _.isLength('3');
|
|
1965
|
-
* // => false
|
|
1966
|
-
*/
|
|
1967
|
-
function isLength(value) {
|
|
1968
|
-
return typeof value == 'number' &&
|
|
1969
|
-
value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
|
1970
|
-
}
|
|
1971
|
-
|
|
1972
|
-
/**
|
|
1973
|
-
* Checks if `value` is the
|
|
1974
|
-
* [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
|
|
1975
|
-
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|
1976
|
-
*
|
|
1977
|
-
* @static
|
|
1978
|
-
* @memberOf _
|
|
1979
|
-
* @since 0.1.0
|
|
1980
|
-
* @category Lang
|
|
1981
|
-
* @param {*} value The value to check.
|
|
1982
|
-
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|
1983
|
-
* @example
|
|
1984
|
-
*
|
|
1985
|
-
* _.isObject({});
|
|
1986
|
-
* // => true
|
|
1987
|
-
*
|
|
1988
|
-
* _.isObject([1, 2, 3]);
|
|
1989
|
-
* // => true
|
|
1990
|
-
*
|
|
1991
|
-
* _.isObject(_.noop);
|
|
1992
|
-
* // => true
|
|
1993
|
-
*
|
|
1994
|
-
* _.isObject(null);
|
|
1995
|
-
* // => false
|
|
1996
|
-
*/
|
|
1997
|
-
function isObject(value) {
|
|
1998
|
-
var type = typeof value;
|
|
1999
|
-
return !!value && (type == 'object' || type == 'function');
|
|
2000
|
-
}
|
|
2001
|
-
|
|
2002
|
-
/**
|
|
2003
|
-
* Checks if `value` is object-like. A value is object-like if it's not `null`
|
|
2004
|
-
* and has a `typeof` result of "object".
|
|
2005
|
-
*
|
|
2006
|
-
* @static
|
|
2007
|
-
* @memberOf _
|
|
2008
|
-
* @since 4.0.0
|
|
2009
|
-
* @category Lang
|
|
2010
|
-
* @param {*} value The value to check.
|
|
2011
|
-
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
|
2012
|
-
* @example
|
|
2013
|
-
*
|
|
2014
|
-
* _.isObjectLike({});
|
|
2015
|
-
* // => true
|
|
2016
|
-
*
|
|
2017
|
-
* _.isObjectLike([1, 2, 3]);
|
|
2018
|
-
* // => true
|
|
2019
|
-
*
|
|
2020
|
-
* _.isObjectLike(_.noop);
|
|
2021
|
-
* // => false
|
|
2022
|
-
*
|
|
2023
|
-
* _.isObjectLike(null);
|
|
2024
|
-
* // => false
|
|
2025
|
-
*/
|
|
2026
|
-
function isObjectLike(value) {
|
|
2027
|
-
return !!value && typeof value == 'object';
|
|
2028
|
-
}
|
|
2029
|
-
|
|
2030
|
-
/**
|
|
2031
|
-
* Creates an array of the own enumerable property names of `object`.
|
|
2032
|
-
*
|
|
2033
|
-
* **Note:** Non-object values are coerced to objects. See the
|
|
2034
|
-
* [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
|
|
2035
|
-
* for more details.
|
|
2036
|
-
*
|
|
2037
|
-
* @static
|
|
2038
|
-
* @since 0.1.0
|
|
2039
|
-
* @memberOf _
|
|
2040
|
-
* @category Object
|
|
2041
|
-
* @param {Object} object The object to query.
|
|
2042
|
-
* @returns {Array} Returns the array of property names.
|
|
2043
|
-
* @example
|
|
2044
|
-
*
|
|
2045
|
-
* function Foo() {
|
|
2046
|
-
* this.a = 1;
|
|
2047
|
-
* this.b = 2;
|
|
2048
|
-
* }
|
|
2049
|
-
*
|
|
2050
|
-
* Foo.prototype.c = 3;
|
|
2051
|
-
*
|
|
2052
|
-
* _.keys(new Foo);
|
|
2053
|
-
* // => ['a', 'b'] (iteration order is not guaranteed)
|
|
2054
|
-
*
|
|
2055
|
-
* _.keys('hi');
|
|
2056
|
-
* // => ['0', '1']
|
|
2057
|
-
*/
|
|
2058
|
-
function keys(object) {
|
|
2059
|
-
return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
|
|
2060
|
-
}
|
|
2061
|
-
|
|
2062
|
-
/**
|
|
2063
|
-
* This method returns a new empty array.
|
|
2064
|
-
*
|
|
2065
|
-
* @static
|
|
2066
|
-
* @memberOf _
|
|
2067
|
-
* @since 4.13.0
|
|
2068
|
-
* @category Util
|
|
2069
|
-
* @returns {Array} Returns the new empty array.
|
|
2070
|
-
* @example
|
|
2071
|
-
*
|
|
2072
|
-
* var arrays = _.times(2, _.stubArray);
|
|
2073
|
-
*
|
|
2074
|
-
* console.log(arrays);
|
|
2075
|
-
* // => [[], []]
|
|
2076
|
-
*
|
|
2077
|
-
* console.log(arrays[0] === arrays[1]);
|
|
2078
|
-
* // => false
|
|
2079
|
-
*/
|
|
2080
|
-
function stubArray() {
|
|
2081
|
-
return [];
|
|
2082
|
-
}
|
|
2083
|
-
|
|
2084
|
-
/**
|
|
2085
|
-
* This method returns `false`.
|
|
2086
|
-
*
|
|
2087
|
-
* @static
|
|
2088
|
-
* @memberOf _
|
|
2089
|
-
* @since 4.13.0
|
|
2090
|
-
* @category Util
|
|
2091
|
-
* @returns {boolean} Returns `false`.
|
|
2092
|
-
* @example
|
|
2093
|
-
*
|
|
2094
|
-
* _.times(2, _.stubFalse);
|
|
2095
|
-
* // => [false, false]
|
|
2096
|
-
*/
|
|
2097
|
-
function stubFalse() {
|
|
2098
|
-
return false;
|
|
2099
|
-
}
|
|
2100
|
-
|
|
2101
|
-
module.exports = cloneDeep;
|
|
2102
|
-
});
|
|
2103
|
-
|
|
2104
|
-
/**
|
|
2105
|
-
* @name string-left-right
|
|
2106
|
-
* @fileoverview Looks up the first non-whitespace character to the left/right of a given index
|
|
2107
|
-
* @version 4.0.16
|
|
2108
|
-
* @author Roy Revelt, Codsen Ltd
|
|
2109
|
-
* @license MIT
|
|
2110
|
-
* {@link https://codsen.com/os/string-left-right/}
|
|
2111
|
-
*/
|
|
2112
|
-
const RAWNBSP = "\u00A0";
|
|
2113
|
-
function rightMain({
|
|
2114
|
-
str,
|
|
2115
|
-
idx = 0,
|
|
2116
|
-
stopAtNewlines = false,
|
|
2117
|
-
stopAtRawNbsp = false
|
|
2118
|
-
}) {
|
|
2119
|
-
if (typeof str !== "string" || !str.length) {
|
|
2120
|
-
return null;
|
|
2121
|
-
}
|
|
2122
|
-
if (!idx || typeof idx !== "number") {
|
|
2123
|
-
idx = 0;
|
|
2124
|
-
}
|
|
2125
|
-
if (!str[idx + 1]) {
|
|
2126
|
-
return null;
|
|
2127
|
-
}
|
|
2128
|
-
if (
|
|
2129
|
-
str[idx + 1] && (
|
|
2130
|
-
str[idx + 1].trim() ||
|
|
2131
|
-
stopAtNewlines &&
|
|
2132
|
-
"\n\r".includes(str[idx + 1]) ||
|
|
2133
|
-
stopAtRawNbsp &&
|
|
2134
|
-
str[idx + 1] === RAWNBSP)) {
|
|
2135
|
-
return idx + 1;
|
|
2136
|
-
}
|
|
2137
|
-
if (
|
|
2138
|
-
str[idx + 2] && (
|
|
2139
|
-
str[idx + 2].trim() ||
|
|
2140
|
-
stopAtNewlines &&
|
|
2141
|
-
"\n\r".includes(str[idx + 2]) ||
|
|
2142
|
-
stopAtRawNbsp &&
|
|
2143
|
-
str[idx + 2] === RAWNBSP)) {
|
|
2144
|
-
return idx + 2;
|
|
2145
|
-
}
|
|
2146
|
-
for (let i = idx + 1, len = str.length; i < len; i++) {
|
|
2147
|
-
if (
|
|
2148
|
-
str[i].trim() ||
|
|
2149
|
-
stopAtNewlines &&
|
|
2150
|
-
"\n\r".includes(str[i]) ||
|
|
2151
|
-
stopAtRawNbsp &&
|
|
2152
|
-
str[i] === RAWNBSP) {
|
|
2153
|
-
return i;
|
|
2154
|
-
}
|
|
2155
|
-
}
|
|
2156
|
-
return null;
|
|
2157
|
-
}
|
|
2158
|
-
function right(str, idx = 0) {
|
|
2159
|
-
return rightMain({
|
|
2160
|
-
str,
|
|
2161
|
-
idx,
|
|
2162
|
-
stopAtNewlines: false,
|
|
2163
|
-
stopAtRawNbsp: false
|
|
2164
|
-
});
|
|
2165
|
-
}
|
|
2166
|
-
function leftMain({
|
|
2167
|
-
str,
|
|
2168
|
-
idx,
|
|
2169
|
-
stopAtNewlines,
|
|
2170
|
-
stopAtRawNbsp
|
|
2171
|
-
}) {
|
|
2172
|
-
if (typeof str !== "string" || !str.length) {
|
|
2173
|
-
return null;
|
|
2174
|
-
}
|
|
2175
|
-
if (!idx || typeof idx !== "number") {
|
|
2176
|
-
idx = 0;
|
|
2177
|
-
}
|
|
2178
|
-
if (idx < 1) {
|
|
2179
|
-
return null;
|
|
2180
|
-
}
|
|
2181
|
-
if (
|
|
2182
|
-
str[~-idx] && (
|
|
2183
|
-
str[~-idx].trim() ||
|
|
2184
|
-
stopAtNewlines &&
|
|
2185
|
-
"\n\r".includes(str[~-idx]) ||
|
|
2186
|
-
stopAtRawNbsp &&
|
|
2187
|
-
str[~-idx] === RAWNBSP)) {
|
|
2188
|
-
return ~-idx;
|
|
2189
|
-
}
|
|
2190
|
-
if (
|
|
2191
|
-
str[idx - 2] && (
|
|
2192
|
-
str[idx - 2].trim() ||
|
|
2193
|
-
stopAtNewlines &&
|
|
2194
|
-
"\n\r".includes(str[idx - 2]) ||
|
|
2195
|
-
stopAtRawNbsp &&
|
|
2196
|
-
str[idx - 2] === RAWNBSP)) {
|
|
2197
|
-
return idx - 2;
|
|
2198
|
-
}
|
|
2199
|
-
for (let i = idx; i--;) {
|
|
2200
|
-
if (str[i] && (
|
|
2201
|
-
str[i].trim() ||
|
|
2202
|
-
stopAtNewlines &&
|
|
2203
|
-
"\n\r".includes(str[i]) ||
|
|
2204
|
-
stopAtRawNbsp &&
|
|
2205
|
-
str[i] === RAWNBSP)) {
|
|
2206
|
-
return i;
|
|
2207
|
-
}
|
|
2208
|
-
}
|
|
2209
|
-
return null;
|
|
2210
|
-
}
|
|
2211
|
-
function left(str, idx = 0) {
|
|
2212
|
-
return leftMain({
|
|
2213
|
-
str,
|
|
2214
|
-
idx,
|
|
2215
|
-
stopAtNewlines: false,
|
|
2216
|
-
stopAtRawNbsp: false
|
|
2217
|
-
});
|
|
2218
|
-
}
|
|
2219
|
-
|
|
2220
|
-
/**
|
|
2221
|
-
* @name string-collapse-leading-whitespace
|
|
2222
|
-
* @fileoverview Collapse the leading and trailing whitespace of a string
|
|
2223
|
-
* @version 5.0.16
|
|
2224
|
-
* @author Roy Revelt, Codsen Ltd
|
|
2225
|
-
* @license MIT
|
|
2226
|
-
* {@link https://codsen.com/os/string-collapse-leading-whitespace/}
|
|
2227
|
-
*/
|
|
2228
|
-
function collWhitespace(str, originallineBreakLimit = 1) {
|
|
2229
|
-
const rawNbsp = "\u00A0";
|
|
2230
|
-
function reverse(s) {
|
|
2231
|
-
return Array.from(s).reverse().join("");
|
|
2232
|
-
}
|
|
2233
|
-
function prep(whitespaceChunk, limit, trailing) {
|
|
2234
|
-
const firstBreakChar = trailing ? "\n" : "\r";
|
|
2235
|
-
const secondBreakChar = trailing ? "\r" : "\n";
|
|
2236
|
-
if (!whitespaceChunk) {
|
|
2237
|
-
return whitespaceChunk;
|
|
2238
|
-
}
|
|
2239
|
-
let crlfCount = 0;
|
|
2240
|
-
let res = "";
|
|
2241
|
-
for (let i = 0, len = whitespaceChunk.length; i < len; i++) {
|
|
2242
|
-
if (whitespaceChunk[i] === firstBreakChar || whitespaceChunk[i] === secondBreakChar && whitespaceChunk[i - 1] !== firstBreakChar) {
|
|
2243
|
-
crlfCount++;
|
|
2244
|
-
}
|
|
2245
|
-
if (`\r\n`.includes(whitespaceChunk[i]) || whitespaceChunk[i] === rawNbsp) {
|
|
2246
|
-
if (whitespaceChunk[i] === rawNbsp) {
|
|
2247
|
-
res += whitespaceChunk[i];
|
|
2248
|
-
} else if (whitespaceChunk[i] === firstBreakChar) {
|
|
2249
|
-
if (crlfCount <= limit) {
|
|
2250
|
-
res += whitespaceChunk[i];
|
|
2251
|
-
if (whitespaceChunk[i + 1] === secondBreakChar) {
|
|
2252
|
-
res += whitespaceChunk[i + 1];
|
|
2253
|
-
i++;
|
|
2254
|
-
}
|
|
2255
|
-
}
|
|
2256
|
-
} else if (whitespaceChunk[i] === secondBreakChar && (!whitespaceChunk[i - 1] || whitespaceChunk[i - 1] !== firstBreakChar) && crlfCount <= limit) {
|
|
2257
|
-
res += whitespaceChunk[i];
|
|
2258
|
-
}
|
|
2259
|
-
} else {
|
|
2260
|
-
if (!whitespaceChunk[i + 1] && !crlfCount) {
|
|
2261
|
-
res += " ";
|
|
2262
|
-
}
|
|
2263
|
-
}
|
|
2264
|
-
}
|
|
2265
|
-
return res;
|
|
2266
|
-
}
|
|
2267
|
-
if (typeof str === "string" && str.length) {
|
|
2268
|
-
let lineBreakLimit = 1;
|
|
2269
|
-
if (typeof +originallineBreakLimit === "number" && Number.isInteger(+originallineBreakLimit) && +originallineBreakLimit >= 0) {
|
|
2270
|
-
lineBreakLimit = +originallineBreakLimit;
|
|
2271
|
-
}
|
|
2272
|
-
let frontPart = "";
|
|
2273
|
-
let endPart = "";
|
|
2274
|
-
if (!str.trim()) {
|
|
2275
|
-
frontPart = str;
|
|
2276
|
-
} else if (!str[0].trim()) {
|
|
2277
|
-
for (let i = 0, len = str.length; i < len; i++) {
|
|
2278
|
-
if (str[i].trim()) {
|
|
2279
|
-
frontPart = str.slice(0, i);
|
|
2280
|
-
break;
|
|
2281
|
-
}
|
|
2282
|
-
}
|
|
2283
|
-
}
|
|
2284
|
-
if (str.trim() && (str.slice(-1).trim() === "" || str.slice(-1) === rawNbsp)) {
|
|
2285
|
-
for (let i = str.length; i--;) {
|
|
2286
|
-
if (str[i].trim()) {
|
|
2287
|
-
endPart = str.slice(i + 1);
|
|
2288
|
-
break;
|
|
2289
|
-
}
|
|
2290
|
-
}
|
|
2291
|
-
}
|
|
2292
|
-
return `${prep(frontPart, lineBreakLimit, false)}${str.trim()}${reverse(prep(reverse(endPart), lineBreakLimit, true))}`;
|
|
2293
|
-
}
|
|
2294
|
-
return str;
|
|
2295
|
-
}
|
|
2296
|
-
|
|
2297
|
-
/**
|
|
2298
|
-
* @name ranges-sort
|
|
2299
|
-
* @fileoverview Sort string index ranges
|
|
2300
|
-
* @version 4.0.16
|
|
2301
|
-
* @author Roy Revelt, Codsen Ltd
|
|
2302
|
-
* @license MIT
|
|
2303
|
-
* {@link https://codsen.com/os/ranges-sort/}
|
|
2304
|
-
*/
|
|
2305
|
-
const defaults$3 = {
|
|
2306
|
-
strictlyTwoElementsInRangeArrays: false,
|
|
2307
|
-
progressFn: null
|
|
2308
|
-
};
|
|
2309
|
-
function rSort(arrOfRanges, originalOptions) {
|
|
2310
|
-
if (!Array.isArray(arrOfRanges) || !arrOfRanges.length) {
|
|
2311
|
-
return arrOfRanges;
|
|
2312
|
-
}
|
|
2313
|
-
const opts = { ...defaults$3,
|
|
2314
|
-
...originalOptions
|
|
2315
|
-
};
|
|
2316
|
-
let culpritsIndex;
|
|
2317
|
-
let culpritsLen;
|
|
2318
|
-
if (opts.strictlyTwoElementsInRangeArrays && !arrOfRanges.filter(range => range).every((rangeArr, indx) => {
|
|
2319
|
-
if (rangeArr.length !== 2) {
|
|
2320
|
-
culpritsIndex = indx;
|
|
2321
|
-
culpritsLen = rangeArr.length;
|
|
2322
|
-
return false;
|
|
2323
|
-
}
|
|
2324
|
-
return true;
|
|
2325
|
-
})) {
|
|
2326
|
-
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!`);
|
|
2327
|
-
}
|
|
2328
|
-
if (!arrOfRanges.filter(range => range).every((rangeArr, indx) => {
|
|
2329
|
-
if (!Number.isInteger(rangeArr[0]) || rangeArr[0] < 0 || !Number.isInteger(rangeArr[1]) || rangeArr[1] < 0) {
|
|
2330
|
-
culpritsIndex = indx;
|
|
2331
|
-
return false;
|
|
2332
|
-
}
|
|
2333
|
-
return true;
|
|
2334
|
-
})) {
|
|
2335
|
-
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!`);
|
|
2336
|
-
}
|
|
2337
|
-
const maxPossibleIterations = arrOfRanges.filter(range => range).length ** 2;
|
|
2338
|
-
let counter = 0;
|
|
2339
|
-
return Array.from(arrOfRanges).filter(range => range).sort((range1, range2) => {
|
|
2340
|
-
if (opts.progressFn) {
|
|
2341
|
-
counter += 1;
|
|
2342
|
-
opts.progressFn(Math.floor(counter * 100 / maxPossibleIterations));
|
|
2343
|
-
}
|
|
2344
|
-
if (range1[0] === range2[0]) {
|
|
2345
|
-
if (range1[1] < range2[1]) {
|
|
2346
|
-
return -1;
|
|
2347
|
-
}
|
|
2348
|
-
if (range1[1] > range2[1]) {
|
|
2349
|
-
return 1;
|
|
2350
|
-
}
|
|
2351
|
-
return 0;
|
|
2352
|
-
}
|
|
2353
|
-
if (range1[0] < range2[0]) {
|
|
2354
|
-
return -1;
|
|
2355
|
-
}
|
|
2356
|
-
return 1;
|
|
2357
|
-
});
|
|
2358
|
-
}
|
|
2359
|
-
|
|
2360
|
-
/**
|
|
2361
|
-
* @name ranges-merge
|
|
2362
|
-
* @fileoverview Merge and sort string index ranges
|
|
2363
|
-
* @version 7.0.16
|
|
2364
|
-
* @author Roy Revelt, Codsen Ltd
|
|
2365
|
-
* @license MIT
|
|
2366
|
-
* {@link https://codsen.com/os/ranges-merge/}
|
|
2367
|
-
*/
|
|
2368
|
-
const defaults$2 = {
|
|
2369
|
-
mergeType: 1,
|
|
2370
|
-
progressFn: null,
|
|
2371
|
-
joinRangesThatTouchEdges: true
|
|
2372
|
-
};
|
|
2373
|
-
function rMerge(arrOfRanges, originalOpts) {
|
|
2374
|
-
function isObj(something) {
|
|
2375
|
-
return something && typeof something === "object" && !Array.isArray(something);
|
|
2376
|
-
}
|
|
2377
|
-
if (!Array.isArray(arrOfRanges) || !arrOfRanges.length) {
|
|
2378
|
-
return null;
|
|
2379
|
-
}
|
|
2380
|
-
let opts;
|
|
2381
|
-
if (originalOpts) {
|
|
2382
|
-
if (isObj(originalOpts)) {
|
|
2383
|
-
opts = { ...defaults$2,
|
|
2384
|
-
...originalOpts
|
|
2385
|
-
};
|
|
2386
|
-
if (opts.progressFn && isObj(opts.progressFn) && !Object.keys(opts.progressFn).length) {
|
|
2387
|
-
opts.progressFn = null;
|
|
2388
|
-
} else if (opts.progressFn && typeof opts.progressFn !== "function") {
|
|
2389
|
-
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)}`);
|
|
2390
|
-
}
|
|
2391
|
-
if (opts.mergeType && +opts.mergeType !== 1 && +opts.mergeType !== 2) {
|
|
2392
|
-
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)}`);
|
|
2393
|
-
}
|
|
2394
|
-
if (typeof opts.joinRangesThatTouchEdges !== "boolean") {
|
|
2395
|
-
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)}`);
|
|
2396
|
-
}
|
|
2397
|
-
} else {
|
|
2398
|
-
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})`);
|
|
2399
|
-
}
|
|
2400
|
-
} else {
|
|
2401
|
-
opts = { ...defaults$2
|
|
2402
|
-
};
|
|
2403
|
-
}
|
|
2404
|
-
const filtered = arrOfRanges
|
|
2405
|
-
.filter(range => range).map(subarr => [...subarr]).filter(
|
|
2406
|
-
rangeArr => rangeArr[2] !== undefined || rangeArr[0] !== rangeArr[1]);
|
|
2407
|
-
let sortedRanges;
|
|
2408
|
-
let lastPercentageDone;
|
|
2409
|
-
let percentageDone;
|
|
2410
|
-
if (opts.progressFn) {
|
|
2411
|
-
sortedRanges = rSort(filtered, {
|
|
2412
|
-
progressFn: percentage => {
|
|
2413
|
-
percentageDone = Math.floor(percentage / 5);
|
|
2414
|
-
if (percentageDone !== lastPercentageDone) {
|
|
2415
|
-
lastPercentageDone = percentageDone;
|
|
2416
|
-
opts.progressFn(percentageDone);
|
|
2417
|
-
}
|
|
2418
|
-
}
|
|
2419
|
-
});
|
|
2420
|
-
} else {
|
|
2421
|
-
sortedRanges = rSort(filtered);
|
|
2422
|
-
}
|
|
2423
|
-
if (!sortedRanges) {
|
|
2424
|
-
return null;
|
|
2425
|
-
}
|
|
2426
|
-
const len = sortedRanges.length - 1;
|
|
2427
|
-
for (let i = len; i > 0; i--) {
|
|
2428
|
-
if (opts.progressFn) {
|
|
2429
|
-
percentageDone = Math.floor((1 - i / len) * 78) + 21;
|
|
2430
|
-
if (percentageDone !== lastPercentageDone && percentageDone > lastPercentageDone) {
|
|
2431
|
-
lastPercentageDone = percentageDone;
|
|
2432
|
-
opts.progressFn(percentageDone);
|
|
2433
|
-
}
|
|
2434
|
-
}
|
|
2435
|
-
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]) {
|
|
2436
|
-
sortedRanges[i - 1][0] = Math.min(sortedRanges[i][0], sortedRanges[i - 1][0]);
|
|
2437
|
-
sortedRanges[i - 1][1] = Math.max(sortedRanges[i][1], sortedRanges[i - 1][1]);
|
|
2438
|
-
if (sortedRanges[i][2] !== undefined && (sortedRanges[i - 1][0] >= sortedRanges[i][0] || sortedRanges[i - 1][1] <= sortedRanges[i][1])) {
|
|
2439
|
-
if (sortedRanges[i - 1][2] !== null) {
|
|
2440
|
-
if (sortedRanges[i][2] === null && sortedRanges[i - 1][2] !== null) {
|
|
2441
|
-
sortedRanges[i - 1][2] = null;
|
|
2442
|
-
} else if (sortedRanges[i - 1][2] != null) {
|
|
2443
|
-
if (+opts.mergeType === 2 && sortedRanges[i - 1][0] === sortedRanges[i][0]) {
|
|
2444
|
-
sortedRanges[i - 1][2] = sortedRanges[i][2];
|
|
2445
|
-
} else {
|
|
2446
|
-
sortedRanges[i - 1][2] += sortedRanges[i][2];
|
|
2447
|
-
}
|
|
2448
|
-
} else {
|
|
2449
|
-
sortedRanges[i - 1][2] = sortedRanges[i][2];
|
|
2450
|
-
}
|
|
2451
|
-
}
|
|
2452
|
-
}
|
|
2453
|
-
sortedRanges.splice(i, 1);
|
|
2454
|
-
i = sortedRanges.length;
|
|
2455
|
-
}
|
|
2456
|
-
}
|
|
2457
|
-
return sortedRanges.length ? sortedRanges : null;
|
|
2458
|
-
}
|
|
2459
|
-
|
|
2460
|
-
/**
|
|
2461
|
-
* @name ranges-push
|
|
2462
|
-
* @fileoverview Gather string index ranges
|
|
2463
|
-
* @version 5.0.16
|
|
2464
|
-
* @author Roy Revelt, Codsen Ltd
|
|
2465
|
-
* @license MIT
|
|
2466
|
-
* {@link https://codsen.com/os/ranges-push/}
|
|
2467
|
-
*/
|
|
2468
|
-
function existy(x) {
|
|
2469
|
-
return x != null;
|
|
2470
|
-
}
|
|
2471
|
-
function isNum(something) {
|
|
2472
|
-
return Number.isInteger(something) && something >= 0;
|
|
2473
|
-
}
|
|
2474
|
-
function isStr(something) {
|
|
2475
|
-
return typeof something === "string";
|
|
2476
|
-
}
|
|
2477
|
-
const defaults$1 = {
|
|
2478
|
-
limitToBeAddedWhitespace: false,
|
|
2479
|
-
limitLinebreaksCount: 1,
|
|
2480
|
-
mergeType: 1
|
|
2481
|
-
};
|
|
2482
|
-
class Ranges {
|
|
2483
|
-
constructor(originalOpts) {
|
|
2484
|
-
const opts = { ...defaults$1,
|
|
2485
|
-
...originalOpts
|
|
2486
|
-
};
|
|
2487
|
-
if (opts.mergeType && opts.mergeType !== 1 && opts.mergeType !== 2) {
|
|
2488
|
-
if (isStr(opts.mergeType) && opts.mergeType.trim() === "1") {
|
|
2489
|
-
opts.mergeType = 1;
|
|
2490
|
-
} else if (isStr(opts.mergeType) && opts.mergeType.trim() === "2") {
|
|
2491
|
-
opts.mergeType = 2;
|
|
2492
|
-
} else {
|
|
2493
|
-
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)}`);
|
|
2494
|
-
}
|
|
2495
|
-
}
|
|
2496
|
-
this.opts = opts;
|
|
2497
|
-
this.ranges = [];
|
|
2498
|
-
}
|
|
2499
|
-
add(originalFrom, originalTo, addVal) {
|
|
2500
|
-
if (originalFrom == null && originalTo == null) {
|
|
2501
|
-
return;
|
|
2502
|
-
}
|
|
2503
|
-
if (existy(originalFrom) && !existy(originalTo)) {
|
|
2504
|
-
if (Array.isArray(originalFrom)) {
|
|
2505
|
-
if (originalFrom.length) {
|
|
2506
|
-
if (originalFrom.some(el => Array.isArray(el))) {
|
|
2507
|
-
originalFrom.forEach(thing => {
|
|
2508
|
-
if (Array.isArray(thing)) {
|
|
2509
|
-
this.add(...thing);
|
|
2510
|
-
}
|
|
2511
|
-
});
|
|
2512
|
-
return;
|
|
2513
|
-
}
|
|
2514
|
-
if (originalFrom.length && isNum(+originalFrom[0]) && isNum(+originalFrom[1])) {
|
|
2515
|
-
this.add(...originalFrom);
|
|
2516
|
-
}
|
|
2517
|
-
}
|
|
2518
|
-
return;
|
|
2519
|
-
}
|
|
2520
|
-
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)})`);
|
|
2521
|
-
} else if (!existy(originalFrom) && existy(originalTo)) {
|
|
2522
|
-
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)})`);
|
|
2523
|
-
}
|
|
2524
|
-
const from = +originalFrom;
|
|
2525
|
-
const to = +originalTo;
|
|
2526
|
-
if (isNum(addVal)) {
|
|
2527
|
-
addVal = String(addVal);
|
|
2528
|
-
}
|
|
2529
|
-
if (isNum(from) && isNum(to)) {
|
|
2530
|
-
if (existy(addVal) && !isStr(addVal) && !isNum(addVal)) {
|
|
2531
|
-
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)}`);
|
|
2532
|
-
}
|
|
2533
|
-
if (existy(this.ranges) && Array.isArray(this.last()) && from === this.last()[1]) {
|
|
2534
|
-
this.last()[1] = to;
|
|
2535
|
-
if (this.last()[2] === null || addVal === null) ;
|
|
2536
|
-
if (this.last()[2] !== null && existy(addVal)) {
|
|
2537
|
-
let calculatedVal = this.last()[2] && this.last()[2].length > 0 && (!this.opts || !this.opts.mergeType || this.opts.mergeType === 1) ? this.last()[2] + addVal : addVal;
|
|
2538
|
-
if (this.opts.limitToBeAddedWhitespace) {
|
|
2539
|
-
calculatedVal = collWhitespace(calculatedVal, this.opts.limitLinebreaksCount);
|
|
2540
|
-
}
|
|
2541
|
-
if (!(isStr(calculatedVal) && !calculatedVal.length)) {
|
|
2542
|
-
this.last()[2] = calculatedVal;
|
|
2543
|
-
}
|
|
2544
|
-
}
|
|
2545
|
-
} else {
|
|
2546
|
-
if (!this.ranges) {
|
|
2547
|
-
this.ranges = [];
|
|
2548
|
-
}
|
|
2549
|
-
const whatToPush = addVal !== undefined && !(isStr(addVal) && !addVal.length) ? [from, to, addVal && this.opts.limitToBeAddedWhitespace ? collWhitespace(addVal, this.opts.limitLinebreaksCount) : addVal] : [from, to];
|
|
2550
|
-
this.ranges.push(whatToPush);
|
|
2551
|
-
}
|
|
2552
|
-
} else {
|
|
2553
|
-
if (!(isNum(from) && from >= 0)) {
|
|
2554
|
-
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)}`);
|
|
2555
|
-
} else {
|
|
2556
|
-
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)}`);
|
|
2557
|
-
}
|
|
2558
|
-
}
|
|
2559
|
-
}
|
|
2560
|
-
push(originalFrom, originalTo, addVal) {
|
|
2561
|
-
this.add(originalFrom, originalTo, addVal);
|
|
2562
|
-
}
|
|
2563
|
-
current() {
|
|
2564
|
-
if (Array.isArray(this.ranges) && this.ranges.length) {
|
|
2565
|
-
this.ranges = rMerge(this.ranges, {
|
|
2566
|
-
mergeType: this.opts.mergeType
|
|
2567
|
-
});
|
|
2568
|
-
if (this.ranges && this.opts.limitToBeAddedWhitespace) {
|
|
2569
|
-
return this.ranges.map(val => {
|
|
2570
|
-
if (existy(val[2])) {
|
|
2571
|
-
return [val[0], val[1], collWhitespace(val[2], this.opts.limitLinebreaksCount)];
|
|
2572
|
-
}
|
|
2573
|
-
return val;
|
|
2574
|
-
});
|
|
2575
|
-
}
|
|
2576
|
-
return this.ranges;
|
|
2577
|
-
}
|
|
2578
|
-
return null;
|
|
2579
|
-
}
|
|
2580
|
-
wipe() {
|
|
2581
|
-
this.ranges = [];
|
|
2582
|
-
}
|
|
2583
|
-
replace(givenRanges) {
|
|
2584
|
-
if (Array.isArray(givenRanges) && givenRanges.length) {
|
|
2585
|
-
if (!(Array.isArray(givenRanges[0]) && isNum(givenRanges[0][0]))) {
|
|
2586
|
-
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.`);
|
|
2587
|
-
} else {
|
|
2588
|
-
this.ranges = Array.from(givenRanges);
|
|
2589
|
-
}
|
|
2590
|
-
} else {
|
|
2591
|
-
this.ranges = [];
|
|
2592
|
-
}
|
|
2593
|
-
}
|
|
2594
|
-
last() {
|
|
2595
|
-
if (Array.isArray(this.ranges) && this.ranges.length) {
|
|
2596
|
-
return this.ranges[this.ranges.length - 1];
|
|
2597
|
-
}
|
|
2598
|
-
return null;
|
|
2599
|
-
}
|
|
2600
|
-
}
|
|
2601
|
-
|
|
2602
|
-
/**
|
|
2603
|
-
* @name ranges-apply
|
|
2604
|
-
* @fileoverview Take an array of string index ranges, delete/replace the string according to them
|
|
2605
|
-
* @version 5.0.16
|
|
2606
|
-
* @author Roy Revelt, Codsen Ltd
|
|
2607
|
-
* @license MIT
|
|
2608
|
-
* {@link https://codsen.com/os/ranges-apply/}
|
|
2609
|
-
*/
|
|
2610
|
-
function rApply(str, originalRangesArr, progressFn) {
|
|
2611
|
-
let percentageDone = 0;
|
|
2612
|
-
let lastPercentageDone = 0;
|
|
2613
|
-
if (arguments.length === 0) {
|
|
2614
|
-
throw new Error("ranges-apply: [THROW_ID_01] inputs missing!");
|
|
2615
|
-
}
|
|
2616
|
-
if (typeof str !== "string") {
|
|
2617
|
-
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)}`);
|
|
2618
|
-
}
|
|
2619
|
-
if (originalRangesArr && !Array.isArray(originalRangesArr)) {
|
|
2620
|
-
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)}`);
|
|
2621
|
-
}
|
|
2622
|
-
if (progressFn && typeof progressFn !== "function") {
|
|
2623
|
-
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)}`);
|
|
2624
|
-
}
|
|
2625
|
-
if (!originalRangesArr || !originalRangesArr.filter(range => range).length) {
|
|
2626
|
-
return str;
|
|
2627
|
-
}
|
|
2628
|
-
let rangesArr;
|
|
2629
|
-
if (Array.isArray(originalRangesArr) && Number.isInteger(originalRangesArr[0]) && Number.isInteger(originalRangesArr[1])) {
|
|
2630
|
-
rangesArr = [Array.from(originalRangesArr)];
|
|
2631
|
-
} else {
|
|
2632
|
-
rangesArr = Array.from(originalRangesArr);
|
|
2633
|
-
}
|
|
2634
|
-
const len = rangesArr.length;
|
|
2635
|
-
let counter = 0;
|
|
2636
|
-
rangesArr.filter(range => range).forEach((el, i) => {
|
|
2637
|
-
if (progressFn) {
|
|
2638
|
-
percentageDone = Math.floor(counter / len * 10);
|
|
2639
|
-
/* istanbul ignore else */
|
|
2640
|
-
if (percentageDone !== lastPercentageDone) {
|
|
2641
|
-
lastPercentageDone = percentageDone;
|
|
2642
|
-
progressFn(percentageDone);
|
|
2643
|
-
}
|
|
2644
|
-
}
|
|
2645
|
-
if (!Array.isArray(el)) {
|
|
2646
|
-
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}`);
|
|
2647
|
-
}
|
|
2648
|
-
if (!Number.isInteger(el[0])) {
|
|
2649
|
-
if (!Number.isInteger(+el[0]) || +el[0] < 0) {
|
|
2650
|
-
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)}.`);
|
|
2651
|
-
} else {
|
|
2652
|
-
rangesArr[i][0] = +rangesArr[i][0];
|
|
2653
|
-
}
|
|
2654
|
-
}
|
|
2655
|
-
if (!Number.isInteger(el[1])) {
|
|
2656
|
-
if (!Number.isInteger(+el[1]) || +el[1] < 0) {
|
|
2657
|
-
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)}.`);
|
|
2658
|
-
} else {
|
|
2659
|
-
rangesArr[i][1] = +rangesArr[i][1];
|
|
2660
|
-
}
|
|
2661
|
-
}
|
|
2662
|
-
counter += 1;
|
|
2663
|
-
});
|
|
2664
|
-
const workingRanges = rMerge(rangesArr, {
|
|
2665
|
-
progressFn: perc => {
|
|
2666
|
-
if (progressFn) {
|
|
2667
|
-
percentageDone = 10 + Math.floor(perc / 10);
|
|
2668
|
-
/* istanbul ignore else */
|
|
2669
|
-
if (percentageDone !== lastPercentageDone) {
|
|
2670
|
-
lastPercentageDone = percentageDone;
|
|
2671
|
-
progressFn(percentageDone);
|
|
2672
|
-
}
|
|
2673
|
-
}
|
|
2674
|
-
}
|
|
2675
|
-
});
|
|
2676
|
-
const len2 = Array.isArray(workingRanges) ? workingRanges.length : 0;
|
|
2677
|
-
/* istanbul ignore else */
|
|
2678
|
-
if (len2 > 0) {
|
|
2679
|
-
const tails = str.slice(workingRanges[len2 - 1][1]);
|
|
2680
|
-
str = workingRanges.reduce((acc, _val, i, arr) => {
|
|
2681
|
-
if (progressFn) {
|
|
2682
|
-
percentageDone = 20 + Math.floor(i / len2 * 80);
|
|
2683
|
-
/* istanbul ignore else */
|
|
2684
|
-
if (percentageDone !== lastPercentageDone) {
|
|
2685
|
-
lastPercentageDone = percentageDone;
|
|
2686
|
-
progressFn(percentageDone);
|
|
2687
|
-
}
|
|
2688
|
-
}
|
|
2689
|
-
const beginning = i === 0 ? 0 : arr[i - 1][1];
|
|
2690
|
-
const ending = arr[i][0];
|
|
2691
|
-
return acc + str.slice(beginning, ending) + (arr[i][2] || "");
|
|
2692
|
-
}, "");
|
|
2693
|
-
str += tails;
|
|
2694
|
-
}
|
|
2695
|
-
return str;
|
|
2696
|
-
}
|
|
2697
|
-
|
|
2698
|
-
var version$1 = "2.0.16";
|
|
2699
|
-
|
|
2700
|
-
// consts
|
|
2701
|
-
const rawnbsp = "\u00A0";
|
|
2702
|
-
const encodedNbspHtml = " ";
|
|
2703
|
-
const encodedNbspCss = "\\00A0";
|
|
2704
|
-
const encodedNbspJs = "\\u00A0";
|
|
2705
|
-
const rawNdash = "\u2013";
|
|
2706
|
-
const encodedNdashHtml = "–";
|
|
2707
|
-
const encodedNdashCss = "\\2013";
|
|
2708
|
-
const encodedNdashJs = "\\u2013";
|
|
2709
|
-
const rawMdash = "\u2014";
|
|
2710
|
-
const encodedMdashHtml = "—";
|
|
2711
|
-
const encodedMdashCss = "\\2014";
|
|
2712
|
-
const encodedMdashJs = "\\u2014";
|
|
2713
|
-
const headsAndTailsJinja = [
|
|
2714
|
-
{
|
|
2715
|
-
heads: "{{",
|
|
2716
|
-
tails: "}}",
|
|
2717
|
-
},
|
|
2718
|
-
{
|
|
2719
|
-
heads: ["{% if", "{%- if"],
|
|
2720
|
-
tails: ["{% endif", "{%- endif"],
|
|
2721
|
-
},
|
|
2722
|
-
{
|
|
2723
|
-
heads: ["{% for", "{%- for"],
|
|
2724
|
-
tails: ["{% endfor", "{%- endfor"],
|
|
2725
|
-
},
|
|
2726
|
-
{
|
|
2727
|
-
heads: ["{%", "{%-"],
|
|
2728
|
-
tails: ["%}", "-%}"],
|
|
2729
|
-
},
|
|
2730
|
-
{
|
|
2731
|
-
heads: "{#",
|
|
2732
|
-
tails: "#}",
|
|
2733
|
-
},
|
|
2734
|
-
];
|
|
2735
|
-
const headsAndTailsHugo = [
|
|
2736
|
-
{
|
|
2737
|
-
heads: "{{",
|
|
2738
|
-
tails: "}}",
|
|
2739
|
-
},
|
|
2740
|
-
];
|
|
2741
|
-
const headsAndTailsHexo = [
|
|
2742
|
-
{
|
|
2743
|
-
heads: ["<%", "<%=", "<%-"],
|
|
2744
|
-
tails: ["%>", "=%>", "-%>"],
|
|
2745
|
-
},
|
|
2746
|
-
];
|
|
2747
|
-
const knownHTMLTags = [
|
|
2748
|
-
"abbr",
|
|
2749
|
-
"address",
|
|
2750
|
-
"area",
|
|
2751
|
-
"article",
|
|
2752
|
-
"aside",
|
|
2753
|
-
"audio",
|
|
2754
|
-
"base",
|
|
2755
|
-
"bdi",
|
|
2756
|
-
"bdo",
|
|
2757
|
-
"blockquote",
|
|
2758
|
-
"body",
|
|
2759
|
-
"br",
|
|
2760
|
-
"button",
|
|
2761
|
-
"canvas",
|
|
2762
|
-
"caption",
|
|
2763
|
-
"center",
|
|
2764
|
-
"cite",
|
|
2765
|
-
"code",
|
|
2766
|
-
"col",
|
|
2767
|
-
"colgroup",
|
|
2768
|
-
"data",
|
|
2769
|
-
"datalist",
|
|
2770
|
-
"dd",
|
|
2771
|
-
"del",
|
|
2772
|
-
"details",
|
|
2773
|
-
"dfn",
|
|
2774
|
-
"dialog",
|
|
2775
|
-
"div",
|
|
2776
|
-
"dl",
|
|
2777
|
-
"doctype",
|
|
2778
|
-
"dt",
|
|
2779
|
-
"em",
|
|
2780
|
-
"embed",
|
|
2781
|
-
"fieldset",
|
|
2782
|
-
"figcaption",
|
|
2783
|
-
"figure",
|
|
2784
|
-
"footer",
|
|
2785
|
-
"form",
|
|
2786
|
-
"h1",
|
|
2787
|
-
"h2",
|
|
2788
|
-
"h3",
|
|
2789
|
-
"h4",
|
|
2790
|
-
"h5",
|
|
2791
|
-
"h6",
|
|
2792
|
-
"head",
|
|
2793
|
-
"header",
|
|
2794
|
-
"hgroup",
|
|
2795
|
-
"hr",
|
|
2796
|
-
"html",
|
|
2797
|
-
"iframe",
|
|
2798
|
-
"img",
|
|
2799
|
-
"input",
|
|
2800
|
-
"ins",
|
|
2801
|
-
"kbd",
|
|
2802
|
-
"keygen",
|
|
2803
|
-
"label",
|
|
2804
|
-
"legend",
|
|
2805
|
-
"li",
|
|
2806
|
-
"link",
|
|
2807
|
-
"main",
|
|
2808
|
-
"map",
|
|
2809
|
-
"mark",
|
|
2810
|
-
"math",
|
|
2811
|
-
"menu",
|
|
2812
|
-
"menuitem",
|
|
2813
|
-
"meta",
|
|
2814
|
-
"meter",
|
|
2815
|
-
"nav",
|
|
2816
|
-
"noscript",
|
|
2817
|
-
"object",
|
|
2818
|
-
"ol",
|
|
2819
|
-
"optgroup",
|
|
2820
|
-
"option",
|
|
2821
|
-
"output",
|
|
2822
|
-
"param",
|
|
2823
|
-
"picture",
|
|
2824
|
-
"pre",
|
|
2825
|
-
"progress",
|
|
2826
|
-
"rb",
|
|
2827
|
-
"rp",
|
|
2828
|
-
"rt",
|
|
2829
|
-
"rtc",
|
|
2830
|
-
"ruby",
|
|
2831
|
-
"samp",
|
|
2832
|
-
"script",
|
|
2833
|
-
"section",
|
|
2834
|
-
"select",
|
|
2835
|
-
"slot",
|
|
2836
|
-
"small",
|
|
2837
|
-
"source",
|
|
2838
|
-
"span",
|
|
2839
|
-
"strong",
|
|
2840
|
-
"style",
|
|
2841
|
-
"sub",
|
|
2842
|
-
"summary",
|
|
2843
|
-
"sup",
|
|
2844
|
-
"svg",
|
|
2845
|
-
"table",
|
|
2846
|
-
"tbody",
|
|
2847
|
-
"td",
|
|
2848
|
-
"template",
|
|
2849
|
-
"textarea",
|
|
2850
|
-
"tfoot",
|
|
2851
|
-
"th",
|
|
2852
|
-
"thead",
|
|
2853
|
-
"time",
|
|
2854
|
-
"title",
|
|
2855
|
-
"tr",
|
|
2856
|
-
"track",
|
|
2857
|
-
"ul",
|
|
2858
|
-
"var",
|
|
2859
|
-
"video",
|
|
2860
|
-
"wbr",
|
|
2861
|
-
"xml",
|
|
2862
|
-
];
|
|
2863
|
-
|
|
2864
|
-
const version = version$1;
|
|
2865
|
-
const defaults = {
|
|
2866
|
-
removeWidowPreventionMeasures: false,
|
|
2867
|
-
convertEntities: true,
|
|
2868
|
-
targetLanguage: "html",
|
|
2869
|
-
UKPostcodes: false,
|
|
2870
|
-
hyphens: true,
|
|
2871
|
-
minWordCount: 4,
|
|
2872
|
-
minCharCount: 5,
|
|
2873
|
-
ignore: [],
|
|
2874
|
-
reportProgressFunc: null,
|
|
2875
|
-
reportProgressFuncFrom: 0,
|
|
2876
|
-
reportProgressFuncTo: 100,
|
|
2877
|
-
tagRanges: [],
|
|
2878
|
-
};
|
|
2879
|
-
function removeWidows(str, originalOpts) {
|
|
2880
|
-
// track time taken
|
|
2881
|
-
const start = Date.now();
|
|
2882
|
-
// insurance:
|
|
2883
|
-
if (typeof str !== "string") {
|
|
2884
|
-
if (str === undefined) {
|
|
2885
|
-
throw new Error("string-remove-widows: [THROW_ID_01] the first input argument is completely missing! It should be given as string.");
|
|
2886
|
-
}
|
|
2887
|
-
else {
|
|
2888
|
-
throw new Error(`string-remove-widows: [THROW_ID_02] the first input argument must be string! It was given as "${typeof str}", equal to:\n${JSON.stringify(str, null, 4)}`);
|
|
2889
|
-
}
|
|
2890
|
-
}
|
|
2891
|
-
if (originalOpts && typeof originalOpts !== "object") {
|
|
2892
|
-
throw new Error(`string-remove-widows: [THROW_ID_03] the second input argument, options object, should be a plain object but it was given as type ${typeof originalOpts}, equal to ${JSON.stringify(originalOpts, null, 4)}`);
|
|
2893
|
-
}
|
|
2894
|
-
// consts
|
|
2895
|
-
const isArr = Array.isArray;
|
|
2896
|
-
const len = str.length;
|
|
2897
|
-
const rangesArr = new Ranges({ mergeType: 2 });
|
|
2898
|
-
const punctuationCharsToConsiderWidowIssue = ["."];
|
|
2899
|
-
const postcodeRegexFront = /[A-Z]{1,2}[0-9][0-9A-Z]?$/;
|
|
2900
|
-
const postcodeRegexEnd = /^[0-9][A-Z]{2}/;
|
|
2901
|
-
const leavePercForLastStage = 0.06; // in range of [0, 1]
|
|
2902
|
-
// vars
|
|
2903
|
-
let currentPercentageDone;
|
|
2904
|
-
let lastPercentage = 0;
|
|
2905
|
-
let wordCount = 0; // counted per-chunk (paragraph)
|
|
2906
|
-
let charCount = 0; // counted per-character, per chunk (paragraph)
|
|
2907
|
-
let secondToLastWhitespaceStartedAt; // necessary to support whitespace at line ends
|
|
2908
|
-
let secondToLastWhitespaceEndedAt; // necessary to support whitespace at line ends
|
|
2909
|
-
let lastWhitespaceStartedAt;
|
|
2910
|
-
let lastWhitespaceEndedAt;
|
|
2911
|
-
let lastEncodedNbspStartedAt;
|
|
2912
|
-
let lastEncodedNbspEndedAt;
|
|
2913
|
-
// let lineBreakCount;
|
|
2914
|
-
let doNothingUntil;
|
|
2915
|
-
// requests to bump word count in the future:
|
|
2916
|
-
let bumpWordCountAt;
|
|
2917
|
-
// prep the opts
|
|
2918
|
-
const opts = { ...defaults, ...originalOpts };
|
|
2919
|
-
// Now, strictly speaking, this program can remove widow words but also
|
|
2920
|
-
// it will decode any entities it encounters if option convertEntities is off.
|
|
2921
|
-
// We need an interface to report what actions were taken:
|
|
2922
|
-
const whatWasDone = {
|
|
2923
|
-
removeWidows: false,
|
|
2924
|
-
convertEntities: false,
|
|
2925
|
-
};
|
|
2926
|
-
if (!opts.ignore ||
|
|
2927
|
-
(!isArr(opts.ignore) && typeof opts.ignore !== "string")) {
|
|
2928
|
-
opts.ignore = [];
|
|
2929
|
-
}
|
|
2930
|
-
else {
|
|
2931
|
-
// arrayiffy
|
|
2932
|
-
if (typeof opts.ignore === "string") {
|
|
2933
|
-
opts.ignore = [opts.ignore];
|
|
2934
|
-
}
|
|
2935
|
-
// expand the string value presets
|
|
2936
|
-
if (opts.ignore.includes("all")) {
|
|
2937
|
-
// hugo heads tails and included in jinja's list, so can be omitted
|
|
2938
|
-
opts.ignore = opts.ignore.concat(headsAndTailsJinja.concat(headsAndTailsHexo));
|
|
2939
|
-
}
|
|
2940
|
-
else if (opts.ignore.some((val) => typeof val === "string")) {
|
|
2941
|
-
// if some values are strings, we need to either remove them or expand them
|
|
2942
|
-
// from string to recognised list of heads/tails
|
|
2943
|
-
let temp = [];
|
|
2944
|
-
// console.log(
|
|
2945
|
-
// `166 ${`\u001b[${31}m${`OLD`}\u001b[${39}m`} ${`\u001b[${33}m${`opts.ignore`}\u001b[${39}m`} = ${JSON.stringify(
|
|
2946
|
-
// opts.ignore,
|
|
2947
|
-
// null,
|
|
2948
|
-
// 0
|
|
2949
|
-
// )}`
|
|
2950
|
-
// );
|
|
2951
|
-
opts.ignore = opts.ignore.filter((val) => {
|
|
2952
|
-
if (typeof val === "string" && val.length) {
|
|
2953
|
-
if (["nunjucks", "jinja", "liquid"].includes(val.trim().toLowerCase())) {
|
|
2954
|
-
temp = temp.concat(headsAndTailsJinja);
|
|
2955
|
-
}
|
|
2956
|
-
else if (["hugo"].includes(val.trim().toLowerCase())) {
|
|
2957
|
-
temp = temp.concat(headsAndTailsHugo);
|
|
2958
|
-
}
|
|
2959
|
-
else if (["hexo"].includes(val.trim().toLowerCase())) {
|
|
2960
|
-
temp = temp.concat(headsAndTailsHexo);
|
|
2961
|
-
}
|
|
2962
|
-
return false;
|
|
2963
|
-
}
|
|
2964
|
-
if (typeof val === "object") {
|
|
2965
|
-
return true;
|
|
2966
|
-
}
|
|
2967
|
-
// otherwise false is returned, value is excluded
|
|
2968
|
-
});
|
|
2969
|
-
if (temp.length) {
|
|
2970
|
-
opts.ignore = opts.ignore.concat(temp);
|
|
2971
|
-
}
|
|
2972
|
-
}
|
|
2973
|
-
}
|
|
2974
|
-
let ceil;
|
|
2975
|
-
if (opts.reportProgressFunc) {
|
|
2976
|
-
// ceil is the top the range [0, 100], or whatever it was customised to,
|
|
2977
|
-
// [opts.reportProgressFuncFrom, opts.reportProgressFuncTo].
|
|
2978
|
-
// Also, leavePercForLastStage needs to be left to next stage, so "100" or
|
|
2979
|
-
// "opts.reportProgressFuncTo" is multiplied by (1 - leavePercForLastStage).
|
|
2980
|
-
ceil = Math.floor(opts.reportProgressFuncTo -
|
|
2981
|
-
(opts.reportProgressFuncTo - opts.reportProgressFuncFrom) *
|
|
2982
|
-
leavePercForLastStage -
|
|
2983
|
-
opts.reportProgressFuncFrom);
|
|
2984
|
-
}
|
|
2985
|
-
function push(finalStart, finalEnd) {
|
|
2986
|
-
let finalWhatToInsert = rawnbsp;
|
|
2987
|
-
// calculate what to insert
|
|
2988
|
-
if (opts.removeWidowPreventionMeasures) {
|
|
2989
|
-
finalWhatToInsert = " ";
|
|
2990
|
-
}
|
|
2991
|
-
else if (opts.convertEntities) {
|
|
2992
|
-
finalWhatToInsert = encodedNbspHtml;
|
|
2993
|
-
if (typeof opts.targetLanguage === "string") {
|
|
2994
|
-
if (opts.targetLanguage.trim().toLowerCase() === "css") {
|
|
2995
|
-
finalWhatToInsert = encodedNbspCss;
|
|
2996
|
-
}
|
|
2997
|
-
else if (opts.targetLanguage.trim().toLowerCase() === "js") {
|
|
2998
|
-
finalWhatToInsert = encodedNbspJs;
|
|
2999
|
-
}
|
|
3000
|
-
}
|
|
3001
|
-
}
|
|
3002
|
-
if (str.slice(finalStart, finalEnd) !== finalWhatToInsert) {
|
|
3003
|
-
rangesArr.push(finalStart, finalEnd, finalWhatToInsert);
|
|
3004
|
-
}
|
|
3005
|
-
}
|
|
3006
|
-
function resetAll() {
|
|
3007
|
-
wordCount = 0;
|
|
3008
|
-
charCount = 0;
|
|
3009
|
-
secondToLastWhitespaceStartedAt = undefined;
|
|
3010
|
-
secondToLastWhitespaceEndedAt = undefined;
|
|
3011
|
-
lastWhitespaceStartedAt = undefined;
|
|
3012
|
-
lastWhitespaceEndedAt = undefined;
|
|
3013
|
-
lastEncodedNbspStartedAt = undefined;
|
|
3014
|
-
lastEncodedNbspEndedAt = undefined;
|
|
3015
|
-
// lineBreakCount = undefined;
|
|
3016
|
-
}
|
|
3017
|
-
resetAll();
|
|
3018
|
-
// iterate the string
|
|
3019
|
-
for (let i = 0; i <= len; i++) {
|
|
3020
|
-
//
|
|
3021
|
-
//
|
|
3022
|
-
//
|
|
3023
|
-
//
|
|
3024
|
-
// TOP
|
|
3025
|
-
//
|
|
3026
|
-
//
|
|
3027
|
-
//
|
|
3028
|
-
//
|
|
3029
|
-
// Logging:
|
|
3030
|
-
// ███████████████████████████████████████
|
|
3031
|
-
// detect templating language heads and tails
|
|
3032
|
-
if (!doNothingUntil && isArr(opts.ignore) && opts.ignore.length) {
|
|
3033
|
-
opts.ignore.some((valObj, y) => {
|
|
3034
|
-
if ((isArr(valObj.heads) &&
|
|
3035
|
-
valObj.heads.some((oneOfHeads) => str.startsWith(oneOfHeads, i))) ||
|
|
3036
|
-
(typeof valObj.heads === "string" && str.startsWith(valObj.heads, i))) {
|
|
3037
|
-
wordCount += 1;
|
|
3038
|
-
doNothingUntil = opts.ignore[y].tails;
|
|
3039
|
-
return true;
|
|
3040
|
-
}
|
|
3041
|
-
});
|
|
3042
|
-
}
|
|
3043
|
-
// if there was word count bump request issued in the past for current
|
|
3044
|
-
// index, do bump it:
|
|
3045
|
-
if (!doNothingUntil && bumpWordCountAt && bumpWordCountAt === i) {
|
|
3046
|
-
wordCount += 1;
|
|
3047
|
-
bumpWordCountAt = undefined;
|
|
3048
|
-
}
|
|
3049
|
-
// Report the progress. Used in web worker setups.
|
|
3050
|
-
if (typeof opts.reportProgressFunc === "function") {
|
|
3051
|
-
// defaults:
|
|
3052
|
-
// opts.reportProgressFuncFrom = 0
|
|
3053
|
-
// opts.reportProgressFuncTo = 100
|
|
3054
|
-
currentPercentageDone =
|
|
3055
|
-
opts.reportProgressFuncFrom + Math.floor((i / len) * (ceil || 1));
|
|
3056
|
-
// console.log(
|
|
3057
|
-
// `309 ${`\u001b[${33}m${`currentPercentageDone`}\u001b[${39}m`} = ${currentPercentageDone}; ${`\u001b[${33}m${`lastPercentage`}\u001b[${39}m`} = ${lastPercentage};`
|
|
3058
|
-
// );
|
|
3059
|
-
if (currentPercentageDone !== lastPercentage) {
|
|
3060
|
-
lastPercentage = currentPercentageDone;
|
|
3061
|
-
opts.reportProgressFunc(currentPercentageDone);
|
|
3062
|
-
}
|
|
3063
|
-
}
|
|
3064
|
-
// catch the end of whitespace (must be at the top)
|
|
3065
|
-
if (!doNothingUntil &&
|
|
3066
|
-
i &&
|
|
3067
|
-
str[i] &&
|
|
3068
|
-
str[i].trim() &&
|
|
3069
|
-
(!str[i - 1] || (str[i - 1] && !str[i - 1].trim()))) {
|
|
3070
|
-
// 1. mark the ending
|
|
3071
|
-
lastWhitespaceEndedAt = i;
|
|
3072
|
-
}
|
|
3073
|
-
if (!doNothingUntil && str[i] && str[i].trim()) {
|
|
3074
|
-
charCount += 1;
|
|
3075
|
-
}
|
|
3076
|
-
//
|
|
3077
|
-
//
|
|
3078
|
-
//
|
|
3079
|
-
//
|
|
3080
|
-
//
|
|
3081
|
-
//
|
|
3082
|
-
//
|
|
3083
|
-
//
|
|
3084
|
-
// MIDDLE
|
|
3085
|
-
//
|
|
3086
|
-
//
|
|
3087
|
-
//
|
|
3088
|
-
//
|
|
3089
|
-
//
|
|
3090
|
-
//
|
|
3091
|
-
//
|
|
3092
|
-
//
|
|
3093
|
-
// catch dashes
|
|
3094
|
-
if (!doNothingUntil &&
|
|
3095
|
-
opts.hyphens &&
|
|
3096
|
-
(`-${rawMdash}${rawNdash}`.includes(str[i]) ||
|
|
3097
|
-
str.startsWith(encodedNdashHtml, i) ||
|
|
3098
|
-
str.startsWith(encodedNdashCss, i) ||
|
|
3099
|
-
str.startsWith(encodedNdashJs, i) ||
|
|
3100
|
-
str.startsWith(encodedMdashHtml, i) ||
|
|
3101
|
-
str.startsWith(encodedMdashCss, i) ||
|
|
3102
|
-
str.startsWith(encodedMdashJs, i)) &&
|
|
3103
|
-
str[i + 1] &&
|
|
3104
|
-
(!str[i + 1].trim() || str[i] === "&")) {
|
|
3105
|
-
if (str[i - 1] && !str[i - 1].trim() && str[left(str, i)]) {
|
|
3106
|
-
push(left(str, i) + 1, i);
|
|
3107
|
-
// report what was done:
|
|
3108
|
-
whatWasDone.removeWidows = true;
|
|
3109
|
-
}
|
|
3110
|
-
}
|
|
3111
|
-
// catch the HTML-encoded (named or numeric) nbsp's:
|
|
3112
|
-
if (!doNothingUntil &&
|
|
3113
|
-
(str.startsWith(" ", i) || str.startsWith(" ", i))) {
|
|
3114
|
-
lastEncodedNbspStartedAt = i;
|
|
3115
|
-
lastEncodedNbspEndedAt = i + 6;
|
|
3116
|
-
// since there was no whitespace, word counting needs to ba taken care of
|
|
3117
|
-
// separately, but the index-bumping must happen in future, at correct time
|
|
3118
|
-
if (str[i + 6] && str[i + 6].trim()) {
|
|
3119
|
-
bumpWordCountAt = i + 6;
|
|
3120
|
-
}
|
|
3121
|
-
// if it opts.convertEntities is off, replace it right away
|
|
3122
|
-
if (!opts.convertEntities) {
|
|
3123
|
-
rangesArr.push(i, i + 6, rawnbsp);
|
|
3124
|
-
whatWasDone.convertEntities = true;
|
|
3125
|
-
}
|
|
3126
|
-
else if (opts.targetLanguage === "css" ||
|
|
3127
|
-
opts.targetLanguage === "js") {
|
|
3128
|
-
rangesArr.push(i, i + 6, opts.targetLanguage === "css" ? encodedNbspCss : encodedNbspJs);
|
|
3129
|
-
whatWasDone.convertEntities = true;
|
|
3130
|
-
}
|
|
3131
|
-
}
|
|
3132
|
-
// catch the CSS-encoded (\00A0) nbsp's:
|
|
3133
|
-
if (!doNothingUntil &&
|
|
3134
|
-
str[i + 4] &&
|
|
3135
|
-
str[i] === "\\" &&
|
|
3136
|
-
str[i + 1] === "0" &&
|
|
3137
|
-
str[i + 2] === "0" &&
|
|
3138
|
-
str[i + 3].toUpperCase() === "A" &&
|
|
3139
|
-
str[i + 4] === "0") {
|
|
3140
|
-
lastEncodedNbspStartedAt = i;
|
|
3141
|
-
lastEncodedNbspEndedAt = i + 5;
|
|
3142
|
-
// since there was no whitespace, word counting needs to ba taken care of
|
|
3143
|
-
// separately, but the index-bumping must happen in future, at correct time
|
|
3144
|
-
if (str[i + 5] && str[i + 5].trim()) {
|
|
3145
|
-
bumpWordCountAt = i + 5;
|
|
3146
|
-
}
|
|
3147
|
-
// if it opts.convertEntities is off, replace it right away
|
|
3148
|
-
if (!opts.convertEntities) {
|
|
3149
|
-
rangesArr.push(i, i + 5, rawnbsp);
|
|
3150
|
-
whatWasDone.convertEntities = true;
|
|
3151
|
-
}
|
|
3152
|
-
else if (opts.targetLanguage === "html" ||
|
|
3153
|
-
opts.targetLanguage === "js") {
|
|
3154
|
-
rangesArr.push(i, i + 5, opts.targetLanguage === "html" ? encodedNbspHtml : encodedNbspJs);
|
|
3155
|
-
whatWasDone.convertEntities = true;
|
|
3156
|
-
}
|
|
3157
|
-
}
|
|
3158
|
-
// catch the JS-encoded (\u00A0) nbsp's:
|
|
3159
|
-
if (!doNothingUntil &&
|
|
3160
|
-
str[i] === "\\" &&
|
|
3161
|
-
str[i + 1] &&
|
|
3162
|
-
str[i + 1].toLowerCase() === "u" &&
|
|
3163
|
-
str[i + 2] === "0" &&
|
|
3164
|
-
str[i + 3] === "0" &&
|
|
3165
|
-
str[i + 4] &&
|
|
3166
|
-
str[i + 4].toUpperCase() === "A" &&
|
|
3167
|
-
str[i + 5] === "0") {
|
|
3168
|
-
lastEncodedNbspStartedAt = i;
|
|
3169
|
-
lastEncodedNbspEndedAt = i + 6;
|
|
3170
|
-
// since there was no whitespace, word counting needs to ba taken care of
|
|
3171
|
-
// separately, but the index-bumping must happen in future, at correct time
|
|
3172
|
-
if (str[i + 6] && str[i + 6].trim()) {
|
|
3173
|
-
bumpWordCountAt = i + 6;
|
|
3174
|
-
}
|
|
3175
|
-
// if it opts.convertEntities is off, replace it right away
|
|
3176
|
-
if (!opts.convertEntities) {
|
|
3177
|
-
rangesArr.push(i, i + 6, rawnbsp);
|
|
3178
|
-
}
|
|
3179
|
-
else if (opts.targetLanguage === "html" ||
|
|
3180
|
-
opts.targetLanguage === "css") {
|
|
3181
|
-
rangesArr.push(i, i + 6, opts.targetLanguage === "html" ? encodedNbspHtml : encodedNbspCss);
|
|
3182
|
-
}
|
|
3183
|
-
}
|
|
3184
|
-
// catch raw nbsp's:
|
|
3185
|
-
if (!doNothingUntil && str[i] === rawnbsp) {
|
|
3186
|
-
lastEncodedNbspStartedAt = i;
|
|
3187
|
-
lastEncodedNbspEndedAt = i + 1;
|
|
3188
|
-
// if it opts.convertEntities is off, replace it right away
|
|
3189
|
-
if (opts.convertEntities) {
|
|
3190
|
-
rangesArr.push(i, i + 1, opts.targetLanguage === "css"
|
|
3191
|
-
? encodedNbspCss
|
|
3192
|
-
: opts.targetLanguage === "js"
|
|
3193
|
-
? encodedNbspJs
|
|
3194
|
-
: encodedNbspHtml);
|
|
3195
|
-
}
|
|
3196
|
-
}
|
|
3197
|
-
// catch the first letter of the first word
|
|
3198
|
-
if (!doNothingUntil &&
|
|
3199
|
-
str[i] &&
|
|
3200
|
-
str[i].trim() &&
|
|
3201
|
-
(!str[i - 1] || !str[i - 1].trim())) {
|
|
3202
|
-
// 1. bump the word counter
|
|
3203
|
-
wordCount += 1;
|
|
3204
|
-
}
|
|
3205
|
-
// catch the ending of paragraphs or the EOL - here's where the action happens
|
|
3206
|
-
if (!doNothingUntil &&
|
|
3207
|
-
(!str[i] ||
|
|
3208
|
-
`\r\n`.includes(str[i]) ||
|
|
3209
|
-
((str[i] === "\n" ||
|
|
3210
|
-
str[i] === "\r" ||
|
|
3211
|
-
(str[i] === "\r" && str[i + 1] === "\n")) &&
|
|
3212
|
-
left(str, i) &&
|
|
3213
|
-
punctuationCharsToConsiderWidowIssue.includes(str[left(str, i)])))) {
|
|
3214
|
-
if ((!opts.minWordCount || wordCount >= opts.minWordCount) &&
|
|
3215
|
-
(!opts.minCharCount || charCount >= opts.minCharCount)) {
|
|
3216
|
-
let finalStart;
|
|
3217
|
-
let finalEnd;
|
|
3218
|
-
// calculate start and end values
|
|
3219
|
-
if (lastWhitespaceStartedAt !== undefined &&
|
|
3220
|
-
lastWhitespaceEndedAt !== undefined &&
|
|
3221
|
-
lastEncodedNbspStartedAt !== undefined &&
|
|
3222
|
-
lastEncodedNbspEndedAt !== undefined) {
|
|
3223
|
-
if (lastWhitespaceStartedAt > lastEncodedNbspStartedAt) {
|
|
3224
|
-
finalStart = lastWhitespaceStartedAt;
|
|
3225
|
-
finalEnd = lastWhitespaceEndedAt;
|
|
3226
|
-
}
|
|
3227
|
-
else {
|
|
3228
|
-
finalStart = lastEncodedNbspStartedAt;
|
|
3229
|
-
finalEnd = lastEncodedNbspEndedAt;
|
|
3230
|
-
}
|
|
3231
|
-
}
|
|
3232
|
-
else if (lastWhitespaceStartedAt !== undefined &&
|
|
3233
|
-
lastWhitespaceEndedAt !== undefined) {
|
|
3234
|
-
finalStart = lastWhitespaceStartedAt;
|
|
3235
|
-
finalEnd = lastWhitespaceEndedAt;
|
|
3236
|
-
}
|
|
3237
|
-
else if (lastEncodedNbspStartedAt !== undefined &&
|
|
3238
|
-
lastEncodedNbspEndedAt !== undefined) {
|
|
3239
|
-
finalStart = lastEncodedNbspStartedAt;
|
|
3240
|
-
finalEnd = lastEncodedNbspEndedAt;
|
|
3241
|
-
}
|
|
3242
|
-
// if by now the point to insert non-breaking space was not found,
|
|
3243
|
-
// give last chance to secondToLastWhitespaceStartedAt and
|
|
3244
|
-
// secondToLastWhitespaceEndedAt:
|
|
3245
|
-
if (!(finalStart && finalEnd) &&
|
|
3246
|
-
secondToLastWhitespaceStartedAt &&
|
|
3247
|
-
secondToLastWhitespaceEndedAt) {
|
|
3248
|
-
finalStart = secondToLastWhitespaceStartedAt;
|
|
3249
|
-
finalEnd = secondToLastWhitespaceEndedAt;
|
|
3250
|
-
}
|
|
3251
|
-
if (finalStart && finalEnd) {
|
|
3252
|
-
push(finalStart, finalEnd);
|
|
3253
|
-
whatWasDone.removeWidows = true;
|
|
3254
|
-
}
|
|
3255
|
-
}
|
|
3256
|
-
resetAll();
|
|
3257
|
-
}
|
|
3258
|
-
// catch postcodes
|
|
3259
|
-
// postcodeRegexFront, postcodeRegexEnd
|
|
3260
|
-
if (opts.UKPostcodes &&
|
|
3261
|
-
str[i] &&
|
|
3262
|
-
!str[i].trim() &&
|
|
3263
|
-
str[i - 1] &&
|
|
3264
|
-
str[i - 1].trim() &&
|
|
3265
|
-
postcodeRegexFront.test(str.slice(0, i)) &&
|
|
3266
|
-
str[right(str, i)] &&
|
|
3267
|
-
postcodeRegexEnd.test(str.slice(right(str, i)))) {
|
|
3268
|
-
push(i, right(str, i));
|
|
3269
|
-
whatWasDone.removeWidows = true;
|
|
3270
|
-
}
|
|
3271
|
-
//
|
|
3272
|
-
//
|
|
3273
|
-
//
|
|
3274
|
-
//
|
|
3275
|
-
//
|
|
3276
|
-
//
|
|
3277
|
-
//
|
|
3278
|
-
//
|
|
3279
|
-
//
|
|
3280
|
-
// BOTTOM
|
|
3281
|
-
//
|
|
3282
|
-
//
|
|
3283
|
-
//
|
|
3284
|
-
//
|
|
3285
|
-
//
|
|
3286
|
-
//
|
|
3287
|
-
//
|
|
3288
|
-
//
|
|
3289
|
-
// catch the start of whitespace (must be at the bottom)
|
|
3290
|
-
//
|
|
3291
|
-
// either it's first whitespace character ever met, or we're overwriting an
|
|
3292
|
-
// old whitespace record and it's the first character of new whitespace chunk
|
|
3293
|
-
if (!doNothingUntil &&
|
|
3294
|
-
str[i] &&
|
|
3295
|
-
!str[i].trim() &&
|
|
3296
|
-
str[i - 1] &&
|
|
3297
|
-
str[i - 1].trim() &&
|
|
3298
|
-
(lastWhitespaceStartedAt === undefined ||
|
|
3299
|
-
(str[lastWhitespaceStartedAt - 1] &&
|
|
3300
|
-
str[lastWhitespaceStartedAt - 1].trim())) &&
|
|
3301
|
-
!"/>".includes(str[right(str, i)]) &&
|
|
3302
|
-
!str.slice(0, i).trim().endsWith("br") &&
|
|
3303
|
-
!str.slice(0, i).trim().endsWith("hr") &&
|
|
3304
|
-
!(str.slice(0, i).endsWith("<") &&
|
|
3305
|
-
knownHTMLTags.some((tag) => str.startsWith(tag, right(str, i))))) {
|
|
3306
|
-
// 1. current value becomes second-to-last
|
|
3307
|
-
secondToLastWhitespaceStartedAt = lastWhitespaceStartedAt;
|
|
3308
|
-
secondToLastWhitespaceEndedAt = lastWhitespaceEndedAt;
|
|
3309
|
-
// 2. mark new-one
|
|
3310
|
-
lastWhitespaceStartedAt = i;
|
|
3311
|
-
// 2. wipe the ending of new-one
|
|
3312
|
-
lastWhitespaceEndedAt = undefined;
|
|
3313
|
-
// 3. wipe the records of the last nbsp because they are not relevant
|
|
3314
|
-
if (lastEncodedNbspStartedAt !== undefined ||
|
|
3315
|
-
lastEncodedNbspEndedAt !== undefined) {
|
|
3316
|
-
lastEncodedNbspStartedAt = undefined;
|
|
3317
|
-
lastEncodedNbspEndedAt = undefined;
|
|
3318
|
-
}
|
|
3319
|
-
}
|
|
3320
|
-
// look for templating tails
|
|
3321
|
-
let tempTailFinding;
|
|
3322
|
-
if (doNothingUntil) {
|
|
3323
|
-
if (typeof doNothingUntil === "string" &&
|
|
3324
|
-
(!doNothingUntil.length || str.startsWith(doNothingUntil, i))) {
|
|
3325
|
-
doNothingUntil = undefined;
|
|
3326
|
-
}
|
|
3327
|
-
else if (isArr(doNothingUntil) &&
|
|
3328
|
-
(!doNothingUntil.length ||
|
|
3329
|
-
doNothingUntil.some((val) => {
|
|
3330
|
-
if (str.startsWith(val, i)) {
|
|
3331
|
-
tempTailFinding = val;
|
|
3332
|
-
return true;
|
|
3333
|
-
}
|
|
3334
|
-
}))) {
|
|
3335
|
-
doNothingUntil = undefined;
|
|
3336
|
-
i += tempTailFinding.length;
|
|
3337
|
-
// imagine we caught "{% endif" of the following string:
|
|
3338
|
-
// {% if something %} some text and more text {% endif %}
|
|
3339
|
-
// we need to tackle the "%}" that follows.
|
|
3340
|
-
if (isArr(opts.ignore) && opts.ignore.length && str[i + 1]) {
|
|
3341
|
-
opts.ignore.some((oneOfHeadsTailsObjs) => {
|
|
3342
|
-
// console.log("\n\n\n");
|
|
3343
|
-
// console.log(
|
|
3344
|
-
// `857 ${`\u001b[${36}m${`███████████████████████████████████████`}\u001b[${39}m`}\n\n\n`
|
|
3345
|
-
// );
|
|
3346
|
-
// console.log(
|
|
3347
|
-
// `860 PROCESSING ${`\u001b[${33}m${`oneOfHeadsTailsObjs`}\u001b[${39}m`} = ${JSON.stringify(
|
|
3348
|
-
// oneOfHeadsTailsObjs,
|
|
3349
|
-
// null,
|
|
3350
|
-
// 4
|
|
3351
|
-
// )}`
|
|
3352
|
-
// );
|
|
3353
|
-
return matchRightIncl(str, i, oneOfHeadsTailsObjs.tails, {
|
|
3354
|
-
trimBeforeMatching: true,
|
|
3355
|
-
cb: (_char, _theRemainderOfTheString, index) => {
|
|
3356
|
-
if (index) {
|
|
3357
|
-
i = index - 1;
|
|
3358
|
-
if (str[i + 1] && str[i + 1].trim()) {
|
|
3359
|
-
wordCount += 1;
|
|
3360
|
-
}
|
|
3361
|
-
}
|
|
3362
|
-
return true;
|
|
3363
|
-
},
|
|
3364
|
-
});
|
|
3365
|
-
});
|
|
3366
|
-
}
|
|
3367
|
-
}
|
|
3368
|
-
}
|
|
3369
|
-
// if it's a CR or LF, reset the word/letter counts
|
|
3370
|
-
if (str[i] && `\r\n`.includes(str[i])) {
|
|
3371
|
-
wordCount = 0;
|
|
3372
|
-
charCount = 0;
|
|
3373
|
-
}
|
|
3374
|
-
// skip known tag ranges
|
|
3375
|
-
if (isArr(opts.tagRanges) &&
|
|
3376
|
-
opts.tagRanges.length &&
|
|
3377
|
-
opts.tagRanges.some((rangeArr) => {
|
|
3378
|
-
if (i >= rangeArr[0] && i <= rangeArr[1] && rangeArr[1] - 1 > i) {
|
|
3379
|
-
i = rangeArr[1] - 1;
|
|
3380
|
-
return true;
|
|
3381
|
-
}
|
|
3382
|
-
})) ;
|
|
3383
|
-
// logging after each loop's iteration:
|
|
3384
|
-
// ███████████████████████████████████████
|
|
3385
|
-
//
|
|
3386
|
-
//
|
|
3387
|
-
//
|
|
3388
|
-
// end of the loop
|
|
3389
|
-
}
|
|
3390
|
-
rApply(str, rangesArr.current())
|
|
3391
|
-
.split("")
|
|
3392
|
-
.forEach((key, i) => {
|
|
3393
|
-
});
|
|
3394
|
-
return {
|
|
3395
|
-
res: rApply(str, rangesArr.current(), opts.reportProgressFunc
|
|
3396
|
-
? (incomingPerc) => {
|
|
3397
|
-
currentPercentageDone = Math.floor((opts.reportProgressFuncTo - opts.reportProgressFuncFrom) *
|
|
3398
|
-
(1 - leavePercForLastStage) +
|
|
3399
|
-
(incomingPerc / 100) *
|
|
3400
|
-
(opts.reportProgressFuncTo - opts.reportProgressFuncFrom) *
|
|
3401
|
-
leavePercForLastStage);
|
|
3402
|
-
if (currentPercentageDone !== lastPercentage) {
|
|
3403
|
-
lastPercentage = currentPercentageDone;
|
|
3404
|
-
opts.reportProgressFunc(currentPercentageDone);
|
|
3405
|
-
}
|
|
3406
|
-
}
|
|
3407
|
-
: undefined),
|
|
3408
|
-
ranges: rangesArr.current(),
|
|
3409
|
-
log: {
|
|
3410
|
-
timeTakenInMilliseconds: Date.now() - start,
|
|
3411
|
-
},
|
|
3412
|
-
whatWasDone,
|
|
3413
|
-
};
|
|
3414
|
-
}
|
|
3415
|
-
|
|
3416
|
-
exports.defaults = defaults;
|
|
3417
|
-
exports.removeWidows = removeWidows;
|
|
3418
|
-
exports.version = version;
|
|
3419
|
-
|
|
3420
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3421
|
-
|
|
3422
|
-
})));
|