string-left-right 5.0.5 → 5.0.11
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/LICENSE +1 -1
- package/README.md +4 -5
- package/dist/string-left-right.esm.js +16 -415
- package/dist/string-left-right.umd.js +16 -2
- package/examples/_quickTake.js +2 -0
- package/package.json +24 -80
- package/types/index.d.ts +36 -8
- package/examples/api.json +0 -1
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2010-
|
|
3
|
+
Copyright (c) 2010-2022 Roy Revelt and other contributors
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
6
|
a copy of this software and associated documentation files (the
|
package/README.md
CHANGED
|
@@ -26,18 +26,17 @@
|
|
|
26
26
|
|
|
27
27
|
## Install
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
The latest version is **ESM only**: Node 12+ is needed to use it and it must be `import`ed instead of `require`d. If your project is not on ESM yet and you want to use `require`, use an older version of this program, `4.1.0`.
|
|
30
30
|
|
|
31
31
|
```bash
|
|
32
32
|
npm i string-left-right
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
If you need a legacy version which works with `require`, use version 4.1.0
|
|
36
|
-
|
|
37
35
|
## Quick Take
|
|
38
36
|
|
|
39
37
|
```js
|
|
40
38
|
import { strict as assert } from "assert";
|
|
39
|
+
|
|
41
40
|
import {
|
|
42
41
|
left,
|
|
43
42
|
right,
|
|
@@ -65,7 +64,7 @@ assert.equal(
|
|
|
65
64
|
|
|
66
65
|
## Documentation
|
|
67
66
|
|
|
68
|
-
Please [visit codsen.com](https://codsen.com/os/string-left-right/) for a full description of the API
|
|
67
|
+
Please [visit codsen.com](https://codsen.com/os/string-left-right/) for a full description of the API.
|
|
69
68
|
|
|
70
69
|
## Contributing
|
|
71
70
|
|
|
@@ -75,6 +74,6 @@ To report bugs or request features or assistance, [raise an issue](https://githu
|
|
|
75
74
|
|
|
76
75
|
MIT License
|
|
77
76
|
|
|
78
|
-
Copyright (c) 2010-
|
|
77
|
+
Copyright (c) 2010-2022 Roy Revelt and other contributors
|
|
79
78
|
|
|
80
79
|
<img src="https://codsen.com/images/png-codsen-ok.png" width="98" alt="ok" align="center"> <img src="https://codsen.com/images/png-codsen-1.png" width="148" alt="codsen" align="center"> <img src="https://codsen.com/images/png-codsen-star-small.png" width="32" alt="star" align="center">
|
|
@@ -1,423 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name string-left-right
|
|
3
3
|
* @fileoverview Looks up the first non-whitespace character to the left/right of a given index
|
|
4
|
-
* @version 5.0.
|
|
4
|
+
* @version 5.0.11
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/string-left-right/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
res.optional = true;
|
|
26
|
-
res.hungry = true;
|
|
27
|
-
} else if (res.value.endsWith("?") && res.value.length > 1) {
|
|
28
|
-
res.value = res.value.slice(0, ~-res.value.length);
|
|
29
|
-
res.optional = true;
|
|
30
|
-
} else if (res.value.endsWith("*") && res.value.length > 1) {
|
|
31
|
-
res.value = res.value.slice(0, ~-res.value.length);
|
|
32
|
-
res.hungry = true;
|
|
33
|
-
}
|
|
34
|
-
return res;
|
|
35
|
-
}
|
|
36
|
-
function isNum(something) {
|
|
37
|
-
return typeof something === "number";
|
|
38
|
-
}
|
|
39
|
-
function isStr(something) {
|
|
40
|
-
return typeof something === "string";
|
|
41
|
-
}
|
|
42
|
-
function rightMain({
|
|
43
|
-
str,
|
|
44
|
-
idx = 0,
|
|
45
|
-
stopAtNewlines = false,
|
|
46
|
-
stopAtRawNbsp = false
|
|
47
|
-
}) {
|
|
48
|
-
if (typeof str !== "string" || !str.length) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
if (!idx || typeof idx !== "number") {
|
|
52
|
-
idx = 0;
|
|
53
|
-
}
|
|
54
|
-
if (!str[idx + 1]) {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
if (
|
|
58
|
-
str[idx + 1] && (
|
|
59
|
-
str[idx + 1].trim() ||
|
|
60
|
-
stopAtNewlines &&
|
|
61
|
-
"\n\r".includes(str[idx + 1]) ||
|
|
62
|
-
stopAtRawNbsp &&
|
|
63
|
-
str[idx + 1] === RAWNBSP)) {
|
|
64
|
-
return idx + 1;
|
|
65
|
-
}
|
|
66
|
-
if (
|
|
67
|
-
str[idx + 2] && (
|
|
68
|
-
str[idx + 2].trim() ||
|
|
69
|
-
stopAtNewlines &&
|
|
70
|
-
"\n\r".includes(str[idx + 2]) ||
|
|
71
|
-
stopAtRawNbsp &&
|
|
72
|
-
str[idx + 2] === RAWNBSP)) {
|
|
73
|
-
return idx + 2;
|
|
74
|
-
}
|
|
75
|
-
for (let i = idx + 1, len = str.length; i < len; i++) {
|
|
76
|
-
if (
|
|
77
|
-
str[i].trim() ||
|
|
78
|
-
stopAtNewlines &&
|
|
79
|
-
"\n\r".includes(str[i]) ||
|
|
80
|
-
stopAtRawNbsp &&
|
|
81
|
-
str[i] === RAWNBSP) {
|
|
82
|
-
return i;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
function right(str, idx = 0) {
|
|
88
|
-
return rightMain({
|
|
89
|
-
str,
|
|
90
|
-
idx,
|
|
91
|
-
stopAtNewlines: false,
|
|
92
|
-
stopAtRawNbsp: false
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
function rightStopAtNewLines(str, idx) {
|
|
96
|
-
return rightMain({
|
|
97
|
-
str,
|
|
98
|
-
idx,
|
|
99
|
-
stopAtNewlines: true,
|
|
100
|
-
stopAtRawNbsp: false
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
function rightStopAtRawNbsp(str, idx) {
|
|
104
|
-
return rightMain({
|
|
105
|
-
str,
|
|
106
|
-
idx,
|
|
107
|
-
stopAtNewlines: false,
|
|
108
|
-
stopAtRawNbsp: true
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
function leftMain({
|
|
112
|
-
str,
|
|
113
|
-
idx,
|
|
114
|
-
stopAtNewlines,
|
|
115
|
-
stopAtRawNbsp
|
|
116
|
-
}) {
|
|
117
|
-
if (typeof str !== "string" || !str.length) {
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
if (!idx || typeof idx !== "number") {
|
|
121
|
-
idx = 0;
|
|
122
|
-
}
|
|
123
|
-
if (idx < 1) {
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
if (
|
|
127
|
-
str[~-idx] && (
|
|
128
|
-
str[~-idx].trim() ||
|
|
129
|
-
stopAtNewlines &&
|
|
130
|
-
"\n\r".includes(str[~-idx]) ||
|
|
131
|
-
stopAtRawNbsp &&
|
|
132
|
-
str[~-idx] === RAWNBSP)) {
|
|
133
|
-
return ~-idx;
|
|
134
|
-
}
|
|
135
|
-
if (
|
|
136
|
-
str[idx - 2] && (
|
|
137
|
-
str[idx - 2].trim() ||
|
|
138
|
-
stopAtNewlines &&
|
|
139
|
-
"\n\r".includes(str[idx - 2]) ||
|
|
140
|
-
stopAtRawNbsp &&
|
|
141
|
-
str[idx - 2] === RAWNBSP)) {
|
|
142
|
-
return idx - 2;
|
|
143
|
-
}
|
|
144
|
-
for (let i = idx; i--;) {
|
|
145
|
-
if (str[i] && (
|
|
146
|
-
str[i].trim() ||
|
|
147
|
-
stopAtNewlines &&
|
|
148
|
-
"\n\r".includes(str[i]) ||
|
|
149
|
-
stopAtRawNbsp &&
|
|
150
|
-
str[i] === RAWNBSP)) {
|
|
151
|
-
return i;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return null;
|
|
155
|
-
}
|
|
156
|
-
function left(str, idx = 0) {
|
|
157
|
-
return leftMain({
|
|
158
|
-
str,
|
|
159
|
-
idx,
|
|
160
|
-
stopAtNewlines: false,
|
|
161
|
-
stopAtRawNbsp: false
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
function leftStopAtNewLines(str, idx) {
|
|
165
|
-
return leftMain({
|
|
166
|
-
str,
|
|
167
|
-
idx,
|
|
168
|
-
stopAtNewlines: true,
|
|
169
|
-
stopAtRawNbsp: false
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
function leftStopAtRawNbsp(str, idx) {
|
|
173
|
-
return leftMain({
|
|
174
|
-
str,
|
|
175
|
-
idx,
|
|
176
|
-
stopAtNewlines: false,
|
|
177
|
-
stopAtRawNbsp: true
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
function seq(direction, str, idx, opts, args) {
|
|
181
|
-
if (typeof str !== "string" || !str.length) {
|
|
182
|
-
return null;
|
|
183
|
-
}
|
|
184
|
-
if (typeof idx !== "number") {
|
|
185
|
-
idx = 0;
|
|
186
|
-
}
|
|
187
|
-
if (direction === "right" && !str[idx + 1] || direction === "left" && !str[~-idx]) {
|
|
188
|
-
return null;
|
|
189
|
-
}
|
|
190
|
-
let lastFinding = idx;
|
|
191
|
-
const gaps = [];
|
|
192
|
-
let leftmostChar;
|
|
193
|
-
let rightmostChar;
|
|
194
|
-
let satiated;
|
|
195
|
-
let i = 0;
|
|
196
|
-
while (i < args.length) {
|
|
197
|
-
if (!isStr(args[i]) || !args[i].length) {
|
|
198
|
-
i += 1;
|
|
199
|
-
continue;
|
|
200
|
-
}
|
|
201
|
-
const {
|
|
202
|
-
value,
|
|
203
|
-
optional,
|
|
204
|
-
hungry
|
|
205
|
-
} = x(args[i]);
|
|
206
|
-
const whattsOnTheSide = direction === "right" ? right(str, lastFinding) : left(str, lastFinding);
|
|
207
|
-
if (opts.i && str[whattsOnTheSide].toLowerCase() === value.toLowerCase() || !opts.i && str[whattsOnTheSide] === value) {
|
|
208
|
-
const temp = direction === "right" ? right(str, whattsOnTheSide) : left(str, whattsOnTheSide);
|
|
209
|
-
if (hungry && (opts.i && str[temp].toLowerCase() === value.toLowerCase() || !opts.i && str[temp] === value)) {
|
|
210
|
-
satiated = true;
|
|
211
|
-
} else {
|
|
212
|
-
i += 1;
|
|
213
|
-
}
|
|
214
|
-
if (typeof whattsOnTheSide === "number" && direction === "right" && whattsOnTheSide > lastFinding + 1) {
|
|
215
|
-
gaps.push([lastFinding + 1, whattsOnTheSide]);
|
|
216
|
-
} else if (direction === "left" && typeof whattsOnTheSide === "number" && whattsOnTheSide < ~-lastFinding) {
|
|
217
|
-
gaps.unshift([whattsOnTheSide + 1, lastFinding]);
|
|
218
|
-
}
|
|
219
|
-
lastFinding = whattsOnTheSide;
|
|
220
|
-
if (direction === "right") {
|
|
221
|
-
if (leftmostChar === undefined) {
|
|
222
|
-
leftmostChar = whattsOnTheSide;
|
|
223
|
-
}
|
|
224
|
-
rightmostChar = whattsOnTheSide;
|
|
225
|
-
} else {
|
|
226
|
-
if (rightmostChar === undefined) {
|
|
227
|
-
rightmostChar = whattsOnTheSide;
|
|
228
|
-
}
|
|
229
|
-
leftmostChar = whattsOnTheSide;
|
|
230
|
-
}
|
|
231
|
-
} else if (optional) {
|
|
232
|
-
i += 1;
|
|
233
|
-
continue;
|
|
234
|
-
} else if (satiated) {
|
|
235
|
-
i += 1;
|
|
236
|
-
satiated = undefined;
|
|
237
|
-
continue;
|
|
238
|
-
} else {
|
|
239
|
-
return null;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
if (leftmostChar === undefined || rightmostChar === undefined) {
|
|
243
|
-
return null;
|
|
244
|
-
}
|
|
245
|
-
return {
|
|
246
|
-
gaps,
|
|
247
|
-
leftmostChar,
|
|
248
|
-
rightmostChar
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
const seqDefaults = {
|
|
252
|
-
i: false
|
|
253
|
-
};
|
|
254
|
-
function leftSeq(str, idx, ...args) {
|
|
255
|
-
if (!args || !args.length) {
|
|
256
|
-
throw new Error(`string-left-right/leftSeq(): only two input arguments were passed! Did you intend to use left() method instead?`);
|
|
257
|
-
}
|
|
258
|
-
let opts;
|
|
259
|
-
if (isObj(args[0])) {
|
|
260
|
-
opts = { ...seqDefaults,
|
|
261
|
-
...args.shift()
|
|
262
|
-
};
|
|
263
|
-
} else {
|
|
264
|
-
opts = seqDefaults;
|
|
265
|
-
}
|
|
266
|
-
return seq("left", str, idx, opts, Array.from(args).reverse());
|
|
267
|
-
}
|
|
268
|
-
function rightSeq(str, idx, ...args) {
|
|
269
|
-
if (!args || !args.length) {
|
|
270
|
-
throw new Error(`string-left-right/rightSeq(): only two input arguments were passed! Did you intend to use right() method instead?`);
|
|
271
|
-
}
|
|
272
|
-
let opts;
|
|
273
|
-
if (isObj(args[0])) {
|
|
274
|
-
opts = { ...seqDefaults,
|
|
275
|
-
...args.shift()
|
|
276
|
-
};
|
|
277
|
-
} else {
|
|
278
|
-
opts = seqDefaults;
|
|
279
|
-
}
|
|
280
|
-
return seq("right", str, idx, opts, args);
|
|
281
|
-
}
|
|
282
|
-
function chomp(direction, str, idx, opts, args = []) {
|
|
283
|
-
if (typeof str !== "string" || !str.length) {
|
|
284
|
-
return null;
|
|
285
|
-
}
|
|
286
|
-
if (!idx || typeof idx !== "number") {
|
|
287
|
-
idx = 0;
|
|
288
|
-
}
|
|
289
|
-
if (direction === "right" && !str[idx + 1] || direction === "left" && +idx === 0) {
|
|
290
|
-
return null;
|
|
291
|
-
}
|
|
292
|
-
let lastRes = null;
|
|
293
|
-
let lastIdx = null;
|
|
294
|
-
do {
|
|
295
|
-
lastRes = direction === "right" ? rightSeq(str, typeof lastIdx === "number" ? lastIdx : idx, ...args) : leftSeq(str, typeof lastIdx === "number" ? lastIdx : idx, ...args);
|
|
296
|
-
if (lastRes !== null) {
|
|
297
|
-
lastIdx = direction === "right" ? lastRes.rightmostChar : lastRes.leftmostChar;
|
|
298
|
-
}
|
|
299
|
-
} while (lastRes);
|
|
300
|
-
if (lastIdx != null && direction === "right") {
|
|
301
|
-
lastIdx += 1;
|
|
302
|
-
}
|
|
303
|
-
if (lastIdx === null) {
|
|
304
|
-
return null;
|
|
305
|
-
}
|
|
306
|
-
if (direction === "right") {
|
|
307
|
-
if (str[lastIdx] && str[lastIdx].trim()) {
|
|
308
|
-
return lastIdx;
|
|
309
|
-
}
|
|
310
|
-
const whatsOnTheRight = right(str, lastIdx);
|
|
311
|
-
if (!opts || opts.mode === 0) {
|
|
312
|
-
if (whatsOnTheRight === lastIdx + 1) {
|
|
313
|
-
return lastIdx;
|
|
314
|
-
}
|
|
315
|
-
if (str.slice(lastIdx, whatsOnTheRight || str.length).trim() || str.slice(lastIdx, whatsOnTheRight || str.length).includes("\n") || str.slice(lastIdx, whatsOnTheRight || str.length).includes("\r")) {
|
|
316
|
-
for (let y = lastIdx, len = str.length; y < len; y++) {
|
|
317
|
-
if (`\n\r`.includes(str[y])) {
|
|
318
|
-
return y;
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
} else {
|
|
322
|
-
return whatsOnTheRight ? ~-whatsOnTheRight : str.length;
|
|
323
|
-
}
|
|
324
|
-
} else if (opts.mode === 1) {
|
|
325
|
-
return lastIdx;
|
|
326
|
-
} else if (opts.mode === 2) {
|
|
327
|
-
const remainderString = str.slice(lastIdx);
|
|
328
|
-
if (remainderString.trim() || remainderString.includes("\n") || remainderString.includes("\r")) {
|
|
329
|
-
for (let y = lastIdx, len = str.length; y < len; y++) {
|
|
330
|
-
if (str[y].trim() || `\n\r`.includes(str[y])) {
|
|
331
|
-
return y;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
return str.length;
|
|
336
|
-
}
|
|
337
|
-
return whatsOnTheRight || str.length;
|
|
338
|
-
}
|
|
339
|
-
if (str[lastIdx] && str[~-lastIdx] && str[~-lastIdx].trim()) {
|
|
340
|
-
return lastIdx;
|
|
341
|
-
}
|
|
342
|
-
const whatsOnTheLeft = left(str, lastIdx);
|
|
343
|
-
if (!opts || opts.mode === 0) {
|
|
344
|
-
if (whatsOnTheLeft === lastIdx - 2) {
|
|
345
|
-
return lastIdx;
|
|
346
|
-
}
|
|
347
|
-
if (str.slice(0, lastIdx).trim() || str.slice(0, lastIdx).includes("\n") || str.slice(0, lastIdx).includes("\r")) {
|
|
348
|
-
for (let y = lastIdx; y--;) {
|
|
349
|
-
if (`\n\r`.includes(str[y]) || str[y].trim()) {
|
|
350
|
-
return y + 1 + (str[y].trim() ? 1 : 0);
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
return 0;
|
|
355
|
-
}
|
|
356
|
-
if (opts.mode === 1) {
|
|
357
|
-
return lastIdx;
|
|
358
|
-
}
|
|
359
|
-
if (opts.mode === 2) {
|
|
360
|
-
const remainderString = str.slice(0, lastIdx);
|
|
361
|
-
if (remainderString.trim() || remainderString.includes("\n") || remainderString.includes("\r")) {
|
|
362
|
-
for (let y = lastIdx; y--;) {
|
|
363
|
-
if (str[y].trim() || `\n\r`.includes(str[y])) {
|
|
364
|
-
return y + 1;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
return 0;
|
|
369
|
-
}
|
|
370
|
-
return whatsOnTheLeft !== null ? whatsOnTheLeft + 1 : 0;
|
|
371
|
-
}
|
|
372
|
-
function chompLeft(str, idx, ...args) {
|
|
373
|
-
if (!args.length || args.length === 1 && isObj(args[0])) {
|
|
374
|
-
return null;
|
|
375
|
-
}
|
|
376
|
-
const defaults = {
|
|
377
|
-
mode: 0
|
|
378
|
-
};
|
|
379
|
-
if (isObj(args[0])) {
|
|
380
|
-
const opts = { ...defaults,
|
|
381
|
-
...clone(args[0])
|
|
382
|
-
};
|
|
383
|
-
if (!opts.mode) {
|
|
384
|
-
opts.mode = 0;
|
|
385
|
-
} else if (isStr(opts.mode) && `0123`.includes(opts.mode)) {
|
|
386
|
-
opts.mode = Number.parseInt(opts.mode, 10);
|
|
387
|
-
} else if (!isNum(opts.mode)) {
|
|
388
|
-
throw new Error(`string-left-right/chompLeft(): [THROW_ID_01] the opts.mode is wrong! It should be 0, 1, 2 or 3. It was given as ${opts.mode} (type ${typeof opts.mode})`);
|
|
389
|
-
}
|
|
390
|
-
return chomp("left", str, idx, opts, clone(args).slice(1));
|
|
391
|
-
}
|
|
392
|
-
if (!isStr(args[0])) {
|
|
393
|
-
return chomp("left", str, idx, defaults, clone(args).slice(1));
|
|
394
|
-
}
|
|
395
|
-
return chomp("left", str, idx, defaults, clone(args));
|
|
396
|
-
}
|
|
397
|
-
function chompRight(str, idx, ...args) {
|
|
398
|
-
if (!args.length || args.length === 1 && isObj(args[0])) {
|
|
399
|
-
return null;
|
|
400
|
-
}
|
|
401
|
-
const defaults = {
|
|
402
|
-
mode: 0
|
|
403
|
-
};
|
|
404
|
-
if (isObj(args[0])) {
|
|
405
|
-
const opts = { ...defaults,
|
|
406
|
-
...clone(args[0])
|
|
407
|
-
};
|
|
408
|
-
if (!opts.mode) {
|
|
409
|
-
opts.mode = 0;
|
|
410
|
-
} else if (isStr(opts.mode) && `0123`.includes(opts.mode)) {
|
|
411
|
-
opts.mode = Number.parseInt(opts.mode, 10);
|
|
412
|
-
} else if (!isNum(opts.mode)) {
|
|
413
|
-
throw new Error(`string-left-right/chompRight(): [THROW_ID_02] the opts.mode is wrong! It should be 0, 1, 2 or 3. It was given as ${opts.mode} (type ${typeof opts.mode})`);
|
|
414
|
-
}
|
|
415
|
-
return chomp("right", str, idx, opts, clone(args).slice(1));
|
|
416
|
-
}
|
|
417
|
-
if (!isStr(args[0])) {
|
|
418
|
-
return chomp("right", str, idx, defaults, clone(args).slice(1));
|
|
419
|
-
}
|
|
420
|
-
return chomp("right", str, idx, defaults, clone(args));
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
export { chompLeft, chompRight, left, leftSeq, leftStopAtNewLines, leftStopAtRawNbsp, right, rightSeq, rightStopAtNewLines, rightStopAtRawNbsp, version };
|
|
10
|
+
import c from"lodash.isplainobject";import f from"lodash.clonedeep";var S="5.0.11";var C=S,h="\xA0";function I(n){let e={value:n,hungry:!1,optional:!1};return(e.value.endsWith("?*")||e.value.endsWith("*?"))&&e.value.length>2?(e.value=e.value.slice(0,e.value.length-2),e.optional=!0,e.hungry=!0):e.value.endsWith("?")&&e.value.length>1?(e.value=e.value.slice(0,~-e.value.length),e.optional=!0):e.value.endsWith("*")&&e.value.length>1&&(e.value=e.value.slice(0,~-e.value.length),e.hungry=!0),e}function R(n){return typeof n=="number"}function p(n){return typeof n=="string"}function E({str:n,idx:e=0,stopAtNewlines:l=!1,stopAtRawNbsp:u=!1}){if(typeof n!="string"||!n.length||((!e||typeof e!="number")&&(e=0),!n[e+1]))return null;if(n[e+1]&&(n[e+1].trim()||l&&`
|
|
11
|
+
\r`.includes(n[e+1])||u&&n[e+1]===h))return e+1;if(n[e+2]&&(n[e+2].trim()||l&&`
|
|
12
|
+
\r`.includes(n[e+2])||u&&n[e+2]===h))return e+2;for(let t=e+1,m=n.length;t<m;t++)if(n[t].trim()||l&&`
|
|
13
|
+
\r`.includes(n[t])||u&&n[t]===h)return t;return null}function y(n,e=0){return E({str:n,idx:e,stopAtNewlines:!1,stopAtRawNbsp:!1})}function j(n,e){return E({str:n,idx:e,stopAtNewlines:!0,stopAtRawNbsp:!1})}function k(n,e){return E({str:n,idx:e,stopAtNewlines:!1,stopAtRawNbsp:!0})}function D({str:n,idx:e,stopAtNewlines:l,stopAtRawNbsp:u}){if(typeof n!="string"||!n.length||((!e||typeof e!="number")&&(e=0),e<1))return null;if(n[~-e]&&(n[~-e].trim()||l&&`
|
|
14
|
+
\r`.includes(n[~-e])||u&&n[~-e]===h))return~-e;if(n[e-2]&&(n[e-2].trim()||l&&`
|
|
15
|
+
\r`.includes(n[e-2])||u&&n[e-2]===h))return e-2;for(let t=e;t--;)if(n[t]&&(n[t].trim()||l&&`
|
|
16
|
+
\r`.includes(n[t])||u&&n[t]===h))return t;return null}function V(n,e=0){return D({str:n,idx:e,stopAtNewlines:!1,stopAtRawNbsp:!1})}function M(n,e){return D({str:n,idx:e,stopAtNewlines:!0,stopAtRawNbsp:!1})}function W(n,e){return D({str:n,idx:e,stopAtNewlines:!1,stopAtRawNbsp:!0})}function O(n,e,l,u,t){if(typeof e!="string"||!e.length||(typeof l!="number"&&(l=0),n==="right"&&!e[l+1]||n==="left"&&!e[~-l]))return null;let m=l,o=[],a,i,s,r=0;for(;r<t.length;){if(!p(t[r])||!t[r].length){r+=1;continue}let{value:$,optional:w,hungry:T}=I(t[r]),g=n==="right"?y(e,m):V(e,m);if(u.i&&e[g].toLowerCase()===$.toLowerCase()||!u.i&&e[g]===$){let N=n==="right"?y(e,g):V(e,g);T&&(u.i&&e[N].toLowerCase()===$.toLowerCase()||!u.i&&e[N]===$)?s=!0:r+=1,typeof g=="number"&&n==="right"&&g>m+1?o.push([m+1,g]):n==="left"&&typeof g=="number"&&g<~-m&&o.unshift([g+1,m]),m=g,n==="right"?(a===void 0&&(a=g),i=g):(i===void 0&&(i=g),a=g)}else if(w){r+=1;continue}else if(s){r+=1,s=void 0;continue}else return null}return a===void 0||i===void 0?null:{gaps:o,leftmostChar:a,rightmostChar:i}}var d={i:!1};function J(n,e,...l){if(!l||!l.length)throw new Error("string-left-right/leftSeq(): only two input arguments were passed! Did you intend to use left() method instead?");let u;return c(l[0])?u={...d,...l.shift()}:u=d,O("left",n,e,u,Array.from(l).reverse())}function L(n,e,...l){if(!l||!l.length)throw new Error("string-left-right/rightSeq(): only two input arguments were passed! Did you intend to use right() method instead?");let u;return c(l[0])?u={...d,...l.shift()}:u=d,O("right",n,e,u,l)}function b(n,e,l,u,t=[]){if(typeof e!="string"||!e.length||((!l||typeof l!="number")&&(l=0),n==="right"&&!e[l+1]||n==="left"&&+l==0))return null;let m=null,o=null;do m=n==="right"?L(e,typeof o=="number"?o:l,...t):J(e,typeof o=="number"?o:l,...t),m!==null&&(o=n==="right"?m.rightmostChar:m.leftmostChar);while(m);if(o!=null&&n==="right"&&(o+=1),o===null)return null;if(n==="right"){if(e[o]?.trim())return o;let i=y(e,o);if(!u||u.mode===0){if(i===o+1)return o;if(e.slice(o,i||e.length).trim()||e.slice(o,i||e.length).includes(`
|
|
17
|
+
`)||e.slice(o,i||e.length).includes("\r")){for(let s=o,r=e.length;s<r;s++)if(`
|
|
18
|
+
\r`.includes(e[s]))return s}else return i?~-i:e.length}else{if(u.mode===1)return o;if(u.mode===2){let s=e.slice(o);if(s.trim()||s.includes(`
|
|
19
|
+
`)||s.includes("\r")){for(let r=o,$=e.length;r<$;r++)if(e[r].trim()||`
|
|
20
|
+
\r`.includes(e[r]))return r}return e.length}}return i||e.length}if(e[o]&&e[~-o]&&e[~-o].trim())return o;let a=V(e,o);if(!u||u.mode===0){if(a===o-2)return o;if(e.slice(0,o).trim()||e.slice(0,o).includes(`
|
|
21
|
+
`)||e.slice(0,o).includes("\r")){for(let i=o;i--;)if(`
|
|
22
|
+
\r`.includes(e[i])||e[i].trim())return i+1+(e[i].trim()?1:0)}return 0}if(u.mode===1)return o;if(u.mode===2){let i=e.slice(0,o);if(i.trim()||i.includes(`
|
|
23
|
+
`)||i.includes("\r")){for(let s=o;s--;)if(e[s].trim()||`
|
|
24
|
+
\r`.includes(e[s]))return s+1}return 0}return a!==null?a+1:0}function _(n,e,...l){if(!l.length||l.length===1&&c(l[0]))return null;let u={mode:0};if(c(l[0])){let t={...u,...f(l[0])};if(!t.mode)t.mode=0;else if(p(t.mode)&&"0123".includes(t.mode))t.mode=Number.parseInt(t.mode,10);else if(!R(t.mode))throw new Error(`string-left-right/chompLeft(): [THROW_ID_01] the opts.mode is wrong! It should be 0, 1, 2 or 3. It was given as ${t.mode} (type ${typeof t.mode})`);return b("left",n,e,t,f(l).slice(1))}return p(l[0])?b("left",n,e,u,f(l)):b("left",n,e,u,f(l).slice(1))}function H(n,e,...l){if(!l.length||l.length===1&&c(l[0]))return null;let u={mode:0};if(c(l[0])){let t={...u,...f(l[0])};if(!t.mode)t.mode=0;else if(p(t.mode)&&"0123".includes(t.mode))t.mode=Number.parseInt(t.mode,10);else if(!R(t.mode))throw new Error(`string-left-right/chompRight(): [THROW_ID_02] the opts.mode is wrong! It should be 0, 1, 2 or 3. It was given as ${t.mode} (type ${typeof t.mode})`);return b("right",n,e,t,f(l).slice(1))}return p(l[0])?b("right",n,e,u,f(l)):b("right",n,e,u,f(l).slice(1))}export{_ as chompLeft,H as chompRight,V as left,J as leftSeq,M as leftStopAtNewLines,W as leftStopAtRawNbsp,y as right,L as rightSeq,j as rightStopAtNewLines,k as rightStopAtRawNbsp,C as version};
|
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name string-left-right
|
|
3
3
|
* @fileoverview Looks up the first non-whitespace character to the left/right of a given index
|
|
4
|
-
* @version 5.0.
|
|
4
|
+
* @version 5.0.11
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/string-left-right/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).stringLeftRight={})}(this,(function(t){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var r,n,o=Object.prototype,i=Function.prototype.toString,u=o.hasOwnProperty,c=i.call(Object),f=o.toString,s=(r=Object.getPrototypeOf,n=Object,function(t){return r(n(t))});var l=function(t){if(!function(t){return!!t&&"object"==typeof t}(t)||"[object Object]"!=f.call(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t))return!1;var e=s(t);if(null===e)return!0;var r=u.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&i.call(r)==c},a={exports:{}};!function(t,r){var n="__lodash_hash_undefined__",o=9007199254740991,i="[object Arguments]",u="[object Boolean]",c="[object Date]",f="[object Function]",s="[object GeneratorFunction]",l="[object Map]",a="[object Number]",p="[object Object]",h="[object Promise]",d="[object RegExp]",g="[object Set]",y="[object String]",v="[object Symbol]",b="[object WeakMap]",_="[object ArrayBuffer]",m="[object DataView]",w="[object Float32Array]",j="[object Float64Array]",A="[object Int8Array]",O="[object Int16Array]",x="[object Int32Array]",N="[object Uint8Array]",S="[object Uint8ClampedArray]",R="[object Uint16Array]",I="[object Uint32Array]",$=/\w*$/,E=/^\[object .+?Constructor\]$/,L=/^(?:0|[1-9]\d*)$/,C={};C[i]=C["[object Array]"]=C[_]=C[m]=C[u]=C[c]=C[w]=C[j]=C[A]=C[O]=C[x]=C[l]=C[a]=C[p]=C[d]=C[g]=C[y]=C[v]=C[N]=C[S]=C[R]=C[I]=!0,C["[object Error]"]=C[f]=C[b]=!1;var P="object"==typeof self&&self&&self.Object===Object&&self,T="object"==typeof e&&e&&e.Object===Object&&e||P||Function("return this")(),W=r&&!r.nodeType&&r,D=W&&t&&!t.nodeType&&t,F=D&&D.exports===W;function k(t,e){return t.set(e[0],e[1]),t}function B(t,e){return t.add(e),t}function M(t,e,r,n){var o=-1,i=t?t.length:0;for(n&&i&&(r=t[++o]);++o<i;)r=e(r,t[o],o,t);return r}function U(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}function q(t){var e=-1,r=Array(t.size);return t.forEach((function(t,n){r[++e]=[n,t]})),r}function z(t,e){return function(r){return t(e(r))}}function H(t){var e=-1,r=Array(t.size);return t.forEach((function(t){r[++e]=t})),r}var V,G=Array.prototype,J=Function.prototype,K=Object.prototype,Q=T["__core-js_shared__"],X=(V=/[^.]+$/.exec(Q&&Q.keys&&Q.keys.IE_PROTO||""))?"Symbol(src)_1."+V:"",Y=J.toString,Z=K.hasOwnProperty,tt=K.toString,et=RegExp("^"+Y.call(Z).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),rt=F?T.Buffer:void 0,nt=T.Symbol,ot=T.Uint8Array,it=z(Object.getPrototypeOf,Object),ut=Object.create,ct=K.propertyIsEnumerable,ft=G.splice,st=Object.getOwnPropertySymbols,lt=rt?rt.isBuffer:void 0,at=z(Object.keys,Object),pt=Dt(T,"DataView"),ht=Dt(T,"Map"),dt=Dt(T,"Promise"),gt=Dt(T,"Set"),yt=Dt(T,"WeakMap"),vt=Dt(Object,"create"),bt=Ut(pt),_t=Ut(ht),mt=Ut(dt),wt=Ut(gt),jt=Ut(yt),At=nt?nt.prototype:void 0,Ot=At?At.valueOf:void 0;function xt(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function Nt(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function St(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function Rt(t){this.__data__=new Nt(t)}function It(t,e){var r=zt(t)||function(t){return function(t){return function(t){return!!t&&"object"==typeof t}(t)&&Ht(t)}(t)&&Z.call(t,"callee")&&(!ct.call(t,"callee")||tt.call(t)==i)}(t)?function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}(t.length,String):[],n=r.length,o=!!n;for(var u in t)!e&&!Z.call(t,u)||o&&("length"==u||Bt(u,n))||r.push(u);return r}function $t(t,e,r){var n=t[e];Z.call(t,e)&&qt(n,r)&&(void 0!==r||e in t)||(t[e]=r)}function Et(t,e){for(var r=t.length;r--;)if(qt(t[r][0],e))return r;return-1}function Lt(t,e,r,n,o,h,b){var E;if(n&&(E=h?n(t,o,h,b):n(t)),void 0!==E)return E;if(!Jt(t))return t;var L=zt(t);if(L){if(E=function(t){var e=t.length,r=t.constructor(e);e&&"string"==typeof t[0]&&Z.call(t,"index")&&(r.index=t.index,r.input=t.input);return r}(t),!e)return function(t,e){var r=-1,n=t.length;e||(e=Array(n));for(;++r<n;)e[r]=t[r];return e}(t,E)}else{var P=kt(t),T=P==f||P==s;if(Vt(t))return function(t,e){if(e)return t.slice();var r=new t.constructor(t.length);return t.copy(r),r}(t,e);if(P==p||P==i||T&&!h){if(U(t))return h?t:{};if(E=function(t){return"function"!=typeof t.constructor||Mt(t)?{}:(e=it(t),Jt(e)?ut(e):{});var e}(T?{}:t),!e)return function(t,e){return Tt(t,Ft(t),e)}(t,function(t,e){return t&&Tt(e,Kt(e),t)}(E,t))}else{if(!C[P])return h?t:{};E=function(t,e,r,n){var o=t.constructor;switch(e){case _:return Pt(t);case u:case c:return new o(+t);case m:return function(t,e){var r=e?Pt(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}(t,n);case w:case j:case A:case O:case x:case N:case S:case R:case I:return function(t,e){var r=e?Pt(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}(t,n);case l:return function(t,e,r){return M(e?r(q(t),!0):q(t),k,new t.constructor)}(t,n,r);case a:case y:return new o(t);case d:return function(t){var e=new t.constructor(t.source,$.exec(t));return e.lastIndex=t.lastIndex,e}(t);case g:return function(t,e,r){return M(e?r(H(t),!0):H(t),B,new t.constructor)}(t,n,r);case v:return i=t,Ot?Object(Ot.call(i)):{}}var i}(t,P,Lt,e)}}b||(b=new Rt);var W=b.get(t);if(W)return W;if(b.set(t,E),!L)var D=r?function(t){return function(t,e,r){var n=e(t);return zt(t)?n:function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t}(n,r(t))}(t,Kt,Ft)}(t):Kt(t);return function(t,e){for(var r=-1,n=t?t.length:0;++r<n&&!1!==e(t[r],r,t););}(D||t,(function(o,i){D&&(o=t[i=o]),$t(E,i,Lt(o,e,r,n,i,t,b))})),E}function Ct(t){return!(!Jt(t)||function(t){return!!X&&X in t}(t))&&(Gt(t)||U(t)?et:E).test(Ut(t))}function Pt(t){var e=new t.constructor(t.byteLength);return new ot(e).set(new ot(t)),e}function Tt(t,e,r,n){r||(r={});for(var o=-1,i=e.length;++o<i;){var u=e[o],c=n?n(r[u],t[u],u,r,t):void 0;$t(r,u,void 0===c?t[u]:c)}return r}function Wt(t,e){var r,n,o=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function Dt(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return Ct(r)?r:void 0}xt.prototype.clear=function(){this.__data__=vt?vt(null):{}},xt.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},xt.prototype.get=function(t){var e=this.__data__;if(vt){var r=e[t];return r===n?void 0:r}return Z.call(e,t)?e[t]:void 0},xt.prototype.has=function(t){var e=this.__data__;return vt?void 0!==e[t]:Z.call(e,t)},xt.prototype.set=function(t,e){return this.__data__[t]=vt&&void 0===e?n:e,this},Nt.prototype.clear=function(){this.__data__=[]},Nt.prototype.delete=function(t){var e=this.__data__,r=Et(e,t);return!(r<0)&&(r==e.length-1?e.pop():ft.call(e,r,1),!0)},Nt.prototype.get=function(t){var e=this.__data__,r=Et(e,t);return r<0?void 0:e[r][1]},Nt.prototype.has=function(t){return Et(this.__data__,t)>-1},Nt.prototype.set=function(t,e){var r=this.__data__,n=Et(r,t);return n<0?r.push([t,e]):r[n][1]=e,this},St.prototype.clear=function(){this.__data__={hash:new xt,map:new(ht||Nt),string:new xt}},St.prototype.delete=function(t){return Wt(this,t).delete(t)},St.prototype.get=function(t){return Wt(this,t).get(t)},St.prototype.has=function(t){return Wt(this,t).has(t)},St.prototype.set=function(t,e){return Wt(this,t).set(t,e),this},Rt.prototype.clear=function(){this.__data__=new Nt},Rt.prototype.delete=function(t){return this.__data__.delete(t)},Rt.prototype.get=function(t){return this.__data__.get(t)},Rt.prototype.has=function(t){return this.__data__.has(t)},Rt.prototype.set=function(t,e){var r=this.__data__;if(r instanceof Nt){var n=r.__data__;if(!ht||n.length<199)return n.push([t,e]),this;r=this.__data__=new St(n)}return r.set(t,e),this};var Ft=st?z(st,Object):function(){return[]},kt=function(t){return tt.call(t)};function Bt(t,e){return!!(e=null==e?o:e)&&("number"==typeof t||L.test(t))&&t>-1&&t%1==0&&t<e}function Mt(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||K)}function Ut(t){if(null!=t){try{return Y.call(t)}catch(t){}try{return t+""}catch(t){}}return""}function qt(t,e){return t===e||t!=t&&e!=e}(pt&&kt(new pt(new ArrayBuffer(1)))!=m||ht&&kt(new ht)!=l||dt&&kt(dt.resolve())!=h||gt&&kt(new gt)!=g||yt&&kt(new yt)!=b)&&(kt=function(t){var e=tt.call(t),r=e==p?t.constructor:void 0,n=r?Ut(r):void 0;if(n)switch(n){case bt:return m;case _t:return l;case mt:return h;case wt:return g;case jt:return b}return e});var zt=Array.isArray;function Ht(t){return null!=t&&function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=o}(t.length)&&!Gt(t)}var Vt=lt||function(){return!1};function Gt(t){var e=Jt(t)?tt.call(t):"";return e==f||e==s}function Jt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function Kt(t){return Ht(t)?It(t):function(t){if(!Mt(t))return at(t);var e=[];for(var r in Object(t))Z.call(t,r)&&"constructor"!=r&&e.push(r);return e}(t)}t.exports=function(t){return Lt(t,!0,!0)}}(a,a.exports);var p=a.exports;const h=" ";function d(t){const e={value:t,hungry:!1,optional:!1};return(e.value.endsWith("?*")||e.value.endsWith("*?"))&&e.value.length>2?(e.value=e.value.slice(0,e.value.length-2),e.optional=!0,e.hungry=!0):e.value.endsWith("?")&&e.value.length>1?(e.value=e.value.slice(0,~-e.value.length),e.optional=!0):e.value.endsWith("*")&&e.value.length>1&&(e.value=e.value.slice(0,~-e.value.length),e.hungry=!0),e}function g(t){return"number"==typeof t}function y(t){return"string"==typeof t}function v({str:t,idx:e=0,stopAtNewlines:r=!1,stopAtRawNbsp:n=!1}){if("string"!=typeof t||!t.length)return null;if(e&&"number"==typeof e||(e=0),!t[e+1])return null;if(t[e+1]&&(t[e+1].trim()||r&&"\n\r".includes(t[e+1])||n&&t[e+1]===h))return e+1;if(t[e+2]&&(t[e+2].trim()||r&&"\n\r".includes(t[e+2])||n&&t[e+2]===h))return e+2;for(let o=e+1,i=t.length;o<i;o++)if(t[o].trim()||r&&"\n\r".includes(t[o])||n&&t[o]===h)return o;return null}function b(t,e=0){return v({str:t,idx:e,stopAtNewlines:!1,stopAtRawNbsp:!1})}function _({str:t,idx:e,stopAtNewlines:r,stopAtRawNbsp:n}){if("string"!=typeof t||!t.length)return null;if(e&&"number"==typeof e||(e=0),e<1)return null;if(t[~-e]&&(t[~-e].trim()||r&&"\n\r".includes(t[~-e])||n&&t[~-e]===h))return~-e;if(t[e-2]&&(t[e-2].trim()||r&&"\n\r".includes(t[e-2])||n&&t[e-2]===h))return e-2;for(let o=e;o--;)if(t[o]&&(t[o].trim()||r&&"\n\r".includes(t[o])||n&&t[o]===h))return o;return null}function m(t,e=0){return _({str:t,idx:e,stopAtNewlines:!1,stopAtRawNbsp:!1})}function w(t,e,r,n,o){if("string"!=typeof e||!e.length)return null;if("number"!=typeof r&&(r=0),"right"===t&&!e[r+1]||"left"===t&&!e[~-r])return null;let i=r;const u=[];let c,f,s,l=0;for(;l<o.length;){if(!y(o[l])||!o[l].length){l+=1;continue}const{value:r,optional:a,hungry:p}=d(o[l]),h="right"===t?b(e,i):m(e,i);if(!(n.i&&e[h].toLowerCase()===r.toLowerCase()||!n.i&&e[h]===r)){if(a){l+=1;continue}if(s){l+=1,s=void 0;continue}return null}{const o="right"===t?b(e,h):m(e,h);p&&(n.i&&e[o].toLowerCase()===r.toLowerCase()||!n.i&&e[o]===r)?s=!0:l+=1,"number"==typeof h&&"right"===t&&h>i+1?u.push([i+1,h]):"left"===t&&"number"==typeof h&&h<~-i&&u.unshift([h+1,i]),i=h,"right"===t?(void 0===c&&(c=h),f=h):(void 0===f&&(f=h),c=h)}}return void 0===c||void 0===f?null:{gaps:u,leftmostChar:c,rightmostChar:f}}const j={i:!1};function A(t,e,...r){if(!r||!r.length)throw new Error("string-left-right/leftSeq(): only two input arguments were passed! Did you intend to use left() method instead?");let n;return n=l(r[0])?{...j,...r.shift()}:j,w("left",t,e,n,Array.from(r).reverse())}function O(t,e,...r){if(!r||!r.length)throw new Error("string-left-right/rightSeq(): only two input arguments were passed! Did you intend to use right() method instead?");let n;return n=l(r[0])?{...j,...r.shift()}:j,w("right",t,e,n,r)}function x(t,e,r,n,o=[]){if("string"!=typeof e||!e.length)return null;if(r&&"number"==typeof r||(r=0),"right"===t&&!e[r+1]||"left"===t&&0==+r)return null;let i=null,u=null;do{i="right"===t?O(e,"number"==typeof u?u:r,...o):A(e,"number"==typeof u?u:r,...o),null!==i&&(u="right"===t?i.rightmostChar:i.leftmostChar)}while(i);if(null!=u&&"right"===t&&(u+=1),null===u)return null;if("right"===t){if(e[u]&&e[u].trim())return u;const t=b(e,u);if(n&&0!==n.mode){if(1===n.mode)return u;if(2===n.mode){const t=e.slice(u);if(t.trim()||t.includes("\n")||t.includes("\r"))for(let t=u,r=e.length;t<r;t++)if(e[t].trim()||"\n\r".includes(e[t]))return t;return e.length}}else{if(t===u+1)return u;if(!(e.slice(u,t||e.length).trim()||e.slice(u,t||e.length).includes("\n")||e.slice(u,t||e.length).includes("\r")))return t?~-t:e.length;for(let t=u,r=e.length;t<r;t++)if("\n\r".includes(e[t]))return t}return t||e.length}if(e[u]&&e[~-u]&&e[~-u].trim())return u;const c=m(e,u);if(!n||0===n.mode){if(c===u-2)return u;if(e.slice(0,u).trim()||e.slice(0,u).includes("\n")||e.slice(0,u).includes("\r"))for(let t=u;t--;)if("\n\r".includes(e[t])||e[t].trim())return t+1+(e[t].trim()?1:0);return 0}if(1===n.mode)return u;if(2===n.mode){const t=e.slice(0,u);if(t.trim()||t.includes("\n")||t.includes("\r"))for(let t=u;t--;)if(e[t].trim()||"\n\r".includes(e[t]))return t+1;return 0}return null!==c?c+1:0}t.chompLeft=function(t,e,...r){if(!r.length||1===r.length&&l(r[0]))return null;const n={mode:0};if(l(r[0])){const o={...n,...p(r[0])};if(o.mode){if(y(o.mode)&&"0123".includes(o.mode))o.mode=Number.parseInt(o.mode,10);else if(!g(o.mode))throw new Error(`string-left-right/chompLeft(): [THROW_ID_01] the opts.mode is wrong! It should be 0, 1, 2 or 3. It was given as ${o.mode} (type ${typeof o.mode})`)}else o.mode=0;return x("left",t,e,o,p(r).slice(1))}return y(r[0])?x("left",t,e,n,p(r)):x("left",t,e,n,p(r).slice(1))},t.chompRight=function(t,e,...r){if(!r.length||1===r.length&&l(r[0]))return null;const n={mode:0};if(l(r[0])){const o={...n,...p(r[0])};if(o.mode){if(y(o.mode)&&"0123".includes(o.mode))o.mode=Number.parseInt(o.mode,10);else if(!g(o.mode))throw new Error(`string-left-right/chompRight(): [THROW_ID_02] the opts.mode is wrong! It should be 0, 1, 2 or 3. It was given as ${o.mode} (type ${typeof o.mode})`)}else o.mode=0;return x("right",t,e,o,p(r).slice(1))}return y(r[0])?x("right",t,e,n,p(r)):x("right",t,e,n,p(r).slice(1))},t.left=m,t.leftSeq=A,t.leftStopAtNewLines=function(t,e){return _({str:t,idx:e,stopAtNewlines:!0,stopAtRawNbsp:!1})},t.leftStopAtRawNbsp=function(t,e){return _({str:t,idx:e,stopAtNewlines:!1,stopAtRawNbsp:!0})},t.right=b,t.rightSeq=O,t.rightStopAtNewLines=function(t,e){return v({str:t,idx:e,stopAtNewlines:!0,stopAtRawNbsp:!1})},t.rightStopAtRawNbsp=function(t,e){return v({str:t,idx:e,stopAtNewlines:!1,stopAtRawNbsp:!0})},t.version="5.0.5",Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
10
|
+
var stringLeftRight=(()=>{var pt=Object.create;var A=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var bt=Object.getOwnPropertyNames,ce=Object.getOwnPropertySymbols,$t=Object.getPrototypeOf,fe=Object.prototype.hasOwnProperty,dt=Object.prototype.propertyIsEnumerable;var ge=(e,t,n)=>t in e?A(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,p=(e,t)=>{for(var n in t||(t={}))fe.call(t,n)&&ge(e,n,t[n]);if(ce)for(var n of ce(t))dt.call(t,n)&&ge(e,n,t[n]);return e};var he=e=>A(e,"__esModule",{value:!0});var pe=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),yt=(e,t)=>{for(var n in t)A(e,n,{get:t[n],enumerable:!0})},me=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of bt(t))!fe.call(e,o)&&(n||o!=="default")&&A(e,o,{get:()=>t[o],enumerable:!(r=mt(t,o))||r.enumerable});return e},be=(e,t)=>me(he(A(e!=null?pt($t(e)):{},"default",!t&&e&&e.__esModule?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e),Et=(e=>(t,n)=>e&&e.get(t)||(n=me(he({}),t,1),e&&e.set(t,n),n))(typeof WeakMap!="undefined"?new WeakMap:0);var Ee=pe((br,ye)=>{var St="[object Object]";function Ot(e){var t=!1;if(e!=null&&typeof e.toString!="function")try{t=!!(e+"")}catch(n){}return t}function _t(e,t){return function(n){return e(t(n))}}var wt=Function.prototype,$e=Object.prototype,de=wt.toString,Tt=$e.hasOwnProperty,Dt=de.call(Object),vt=$e.toString,Vt=_t(Object.getPrototypeOf,Object);function Nt(e){return!!e&&typeof e=="object"}function Rt(e){if(!Nt(e)||vt.call(e)!=St||Ot(e))return!1;var t=Vt(e);if(t===null)return!0;var n=Tt.call(t,"constructor")&&t.constructor;return typeof n=="function"&&n instanceof n&&de.call(n)==Dt}ye.exports=Rt});var st=pe((j,v)=>{var At=200,Se="__lodash_hash_undefined__",Oe=9007199254740991,K="[object Arguments]",Ct="[object Array]",_e="[object Boolean]",we="[object Date]",It="[object Error]",k="[object Function]",Te="[object GeneratorFunction]",F="[object Map]",De="[object Number]",Y="[object Object]",ve="[object Promise]",Ve="[object RegExp]",U="[object Set]",Ne="[object String]",Re="[object Symbol]",X="[object WeakMap]",Ae="[object ArrayBuffer]",J="[object DataView]",Ce="[object Float32Array]",Ie="[object Float64Array]",je="[object Int8Array]",Le="[object Int16Array]",Fe="[object Int32Array]",Ue="[object Uint8Array]",Je="[object Uint8ClampedArray]",Pe="[object Uint16Array]",Me="[object Uint32Array]",jt=/[\\^$.*+?()[\]{}|]/g,Lt=/\w*$/,Ft=/^\[object .+?Constructor\]$/,Ut=/^(?:0|[1-9]\d*)$/,s={};s[K]=s[Ct]=s[Ae]=s[J]=s[_e]=s[we]=s[Ce]=s[Ie]=s[je]=s[Le]=s[Fe]=s[F]=s[De]=s[Y]=s[Ve]=s[U]=s[Ne]=s[Re]=s[Ue]=s[Je]=s[Pe]=s[Me]=!0;s[It]=s[k]=s[X]=!1;var Jt=typeof global=="object"&&global&&global.Object===Object&&global,Pt=typeof self=="object"&&self&&self.Object===Object&&self,m=Jt||Pt||Function("return this")(),qe=typeof j=="object"&&j&&!j.nodeType&&j,xe=qe&&typeof v=="object"&&v&&!v.nodeType&&v,Mt=xe&&xe.exports===qe;function qt(e,t){return e.set(t[0],t[1]),e}function xt(e,t){return e.add(t),e}function Ht(e,t){for(var n=-1,r=e?e.length:0;++n<r&&t(e[n],n,e)!==!1;);return e}function Bt(e,t){for(var n=-1,r=t.length,o=e.length;++n<r;)e[o+n]=t[n];return e}function He(e,t,n,r){var o=-1,i=e?e.length:0;for(r&&i&&(n=e[++o]);++o<i;)n=t(n,e[o],o,e);return n}function Gt(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}function Wt(e,t){return e==null?void 0:e[t]}function Be(e){var t=!1;if(e!=null&&typeof e.toString!="function")try{t=!!(e+"")}catch(n){}return t}function Ge(e){var t=-1,n=Array(e.size);return e.forEach(function(r,o){n[++t]=[o,r]}),n}function Z(e,t){return function(n){return e(t(n))}}function We(e){var t=-1,n=Array(e.size);return e.forEach(function(r){n[++t]=r}),n}var Kt=Array.prototype,kt=Function.prototype,P=Object.prototype,Q=m["__core-js_shared__"],Ke=function(){var e=/[^.]+$/.exec(Q&&Q.keys&&Q.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),ke=kt.toString,d=P.hasOwnProperty,M=P.toString,Yt=RegExp("^"+ke.call(d).replace(jt,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Ye=Mt?m.Buffer:void 0,Xe=m.Symbol,Ze=m.Uint8Array,Xt=Z(Object.getPrototypeOf,Object),Zt=Object.create,Qt=P.propertyIsEnumerable,zt=Kt.splice,Qe=Object.getOwnPropertySymbols,en=Ye?Ye.isBuffer:void 0,tn=Z(Object.keys,Object),z=D(m,"DataView"),C=D(m,"Map"),ee=D(m,"Promise"),te=D(m,"Set"),ne=D(m,"WeakMap"),I=D(Object,"create"),nn=S(z),rn=S(C),on=S(ee),ln=S(te),un=S(ne),ze=Xe?Xe.prototype:void 0,et=ze?ze.valueOf:void 0;function y(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function sn(){this.__data__=I?I(null):{}}function an(e){return this.has(e)&&delete this.__data__[e]}function cn(e){var t=this.__data__;if(I){var n=t[e];return n===Se?void 0:n}return d.call(t,e)?t[e]:void 0}function fn(e){var t=this.__data__;return I?t[e]!==void 0:d.call(t,e)}function gn(e,t){var n=this.__data__;return n[e]=I&&t===void 0?Se:t,this}y.prototype.clear=sn;y.prototype.delete=an;y.prototype.get=cn;y.prototype.has=fn;y.prototype.set=gn;function b(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function hn(){this.__data__=[]}function pn(e){var t=this.__data__,n=q(t,e);if(n<0)return!1;var r=t.length-1;return n==r?t.pop():zt.call(t,n,1),!0}function mn(e){var t=this.__data__,n=q(t,e);return n<0?void 0:t[n][1]}function bn(e){return q(this.__data__,e)>-1}function $n(e,t){var n=this.__data__,r=q(n,e);return r<0?n.push([e,t]):n[r][1]=t,this}b.prototype.clear=hn;b.prototype.delete=pn;b.prototype.get=mn;b.prototype.has=bn;b.prototype.set=$n;function w(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function dn(){this.__data__={hash:new y,map:new(C||b),string:new y}}function yn(e){return x(this,e).delete(e)}function En(e){return x(this,e).get(e)}function Sn(e){return x(this,e).has(e)}function On(e,t){return x(this,e).set(e,t),this}w.prototype.clear=dn;w.prototype.delete=yn;w.prototype.get=En;w.prototype.has=Sn;w.prototype.set=On;function T(e){this.__data__=new b(e)}function _n(){this.__data__=new b}function wn(e){return this.__data__.delete(e)}function Tn(e){return this.__data__.get(e)}function Dn(e){return this.__data__.has(e)}function vn(e,t){var n=this.__data__;if(n instanceof b){var r=n.__data__;if(!C||r.length<At-1)return r.push([e,t]),this;n=this.__data__=new w(r)}return n.set(e,t),this}T.prototype.clear=_n;T.prototype.delete=wn;T.prototype.get=Tn;T.prototype.has=Dn;T.prototype.set=vn;function Vn(e,t){var n=le(e)||Qn(e)?Gt(e.length,String):[],r=n.length,o=!!r;for(var i in e)(t||d.call(e,i))&&!(o&&(i=="length"||kn(i,r)))&&n.push(i);return n}function tt(e,t,n){var r=e[t];(!(d.call(e,t)&<(r,n))||n===void 0&&!(t in e))&&(e[t]=n)}function q(e,t){for(var n=e.length;n--;)if(lt(e[n][0],t))return n;return-1}function Nn(e,t){return e&&nt(t,ie(t),e)}function re(e,t,n,r,o,i,l){var c;if(r&&(c=i?r(e,o,i,l):r(e)),c!==void 0)return c;if(!H(e))return e;var h=le(e);if(h){if(c=Gn(e),!t)return xn(e,c)}else{var u=E(e),a=u==k||u==Te;if(er(e))return Ln(e,t);if(u==Y||u==K||a&&!i){if(Be(e))return i?e:{};if(c=Wn(a?{}:e),!t)return Hn(e,Nn(c,e))}else{if(!s[u])return i?e:{};c=Kn(e,u,re,t)}}l||(l=new T);var g=l.get(e);if(g)return g;if(l.set(e,c),!h)var _=n?Bn(e):ie(e);return Ht(_||e,function(R,f){_&&(f=R,R=e[f]),tt(c,f,re(R,t,n,r,f,e,l))}),c}function Rn(e){return H(e)?Zt(e):{}}function An(e,t,n){var r=t(e);return le(e)?r:Bt(r,n(e))}function Cn(e){return M.call(e)}function In(e){if(!H(e)||Xn(e))return!1;var t=ut(e)||Be(e)?Yt:Ft;return t.test(S(e))}function jn(e){if(!ot(e))return tn(e);var t=[];for(var n in Object(e))d.call(e,n)&&n!="constructor"&&t.push(n);return t}function Ln(e,t){if(t)return e.slice();var n=new e.constructor(e.length);return e.copy(n),n}function oe(e){var t=new e.constructor(e.byteLength);return new Ze(t).set(new Ze(e)),t}function Fn(e,t){var n=t?oe(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.byteLength)}function Un(e,t,n){var r=t?n(Ge(e),!0):Ge(e);return He(r,qt,new e.constructor)}function Jn(e){var t=new e.constructor(e.source,Lt.exec(e));return t.lastIndex=e.lastIndex,t}function Pn(e,t,n){var r=t?n(We(e),!0):We(e);return He(r,xt,new e.constructor)}function Mn(e){return et?Object(et.call(e)):{}}function qn(e,t){var n=t?oe(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.length)}function xn(e,t){var n=-1,r=e.length;for(t||(t=Array(r));++n<r;)t[n]=e[n];return t}function nt(e,t,n,r){n||(n={});for(var o=-1,i=t.length;++o<i;){var l=t[o],c=r?r(n[l],e[l],l,n,e):void 0;tt(n,l,c===void 0?e[l]:c)}return n}function Hn(e,t){return nt(e,rt(e),t)}function Bn(e){return An(e,ie,rt)}function x(e,t){var n=e.__data__;return Yn(t)?n[typeof t=="string"?"string":"hash"]:n.map}function D(e,t){var n=Wt(e,t);return In(n)?n:void 0}var rt=Qe?Z(Qe,Object):rr,E=Cn;(z&&E(new z(new ArrayBuffer(1)))!=J||C&&E(new C)!=F||ee&&E(ee.resolve())!=ve||te&&E(new te)!=U||ne&&E(new ne)!=X)&&(E=function(e){var t=M.call(e),n=t==Y?e.constructor:void 0,r=n?S(n):void 0;if(r)switch(r){case nn:return J;case rn:return F;case on:return ve;case ln:return U;case un:return X}return t});function Gn(e){var t=e.length,n=e.constructor(t);return t&&typeof e[0]=="string"&&d.call(e,"index")&&(n.index=e.index,n.input=e.input),n}function Wn(e){return typeof e.constructor=="function"&&!ot(e)?Rn(Xt(e)):{}}function Kn(e,t,n,r){var o=e.constructor;switch(t){case Ae:return oe(e);case _e:case we:return new o(+e);case J:return Fn(e,r);case Ce:case Ie:case je:case Le:case Fe:case Ue:case Je:case Pe:case Me:return qn(e,r);case F:return Un(e,r,n);case De:case Ne:return new o(e);case Ve:return Jn(e);case U:return Pn(e,r,n);case Re:return Mn(e)}}function kn(e,t){return t=t==null?Oe:t,!!t&&(typeof e=="number"||Ut.test(e))&&e>-1&&e%1==0&&e<t}function Yn(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}function Xn(e){return!!Ke&&Ke in e}function ot(e){var t=e&&e.constructor,n=typeof t=="function"&&t.prototype||P;return e===n}function S(e){if(e!=null){try{return ke.call(e)}catch(t){}try{return e+""}catch(t){}}return""}function Zn(e){return re(e,!0,!0)}function lt(e,t){return e===t||e!==e&&t!==t}function Qn(e){return zn(e)&&d.call(e,"callee")&&(!Qt.call(e,"callee")||M.call(e)==K)}var le=Array.isArray;function it(e){return e!=null&&tr(e.length)&&!ut(e)}function zn(e){return nr(e)&&it(e)}var er=en||or;function ut(e){var t=H(e)?M.call(e):"";return t==k||t==Te}function tr(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=Oe}function H(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function nr(e){return!!e&&typeof e=="object"}function ie(e){return it(e)?Vn(e):jn(e)}function rr(){return[]}function or(){return!1}v.exports=Zn});var pr={};yt(pr,{chompLeft:()=>gr,chompRight:()=>hr,left:()=>G,leftSeq:()=>gt,leftStopAtNewLines:()=>cr,leftStopAtRawNbsp:()=>fr,right:()=>B,rightSeq:()=>ht,rightStopAtNewLines:()=>sr,rightStopAtRawNbsp:()=>ar,version:()=>ir});var O=be(Ee(),1),$=be(st(),1);var at="5.0.11";var ir=at,V="\xA0";function ur(e){let t={value:e,hungry:!1,optional:!1};return(t.value.endsWith("?*")||t.value.endsWith("*?"))&&t.value.length>2?(t.value=t.value.slice(0,t.value.length-2),t.optional=!0,t.hungry=!0):t.value.endsWith("?")&&t.value.length>1?(t.value=t.value.slice(0,~-t.value.length),t.optional=!0):t.value.endsWith("*")&&t.value.length>1&&(t.value=t.value.slice(0,~-t.value.length),t.hungry=!0),t}function ct(e){return typeof e=="number"}function L(e){return typeof e=="string"}function ue({str:e,idx:t=0,stopAtNewlines:n=!1,stopAtRawNbsp:r=!1}){if(typeof e!="string"||!e.length||((!t||typeof t!="number")&&(t=0),!e[t+1]))return null;if(e[t+1]&&(e[t+1].trim()||n&&`
|
|
11
|
+
\r`.includes(e[t+1])||r&&e[t+1]===V))return t+1;if(e[t+2]&&(e[t+2].trim()||n&&`
|
|
12
|
+
\r`.includes(e[t+2])||r&&e[t+2]===V))return t+2;for(let o=t+1,i=e.length;o<i;o++)if(e[o].trim()||n&&`
|
|
13
|
+
\r`.includes(e[o])||r&&e[o]===V)return o;return null}function B(e,t=0){return ue({str:e,idx:t,stopAtNewlines:!1,stopAtRawNbsp:!1})}function sr(e,t){return ue({str:e,idx:t,stopAtNewlines:!0,stopAtRawNbsp:!1})}function ar(e,t){return ue({str:e,idx:t,stopAtNewlines:!1,stopAtRawNbsp:!0})}function se({str:e,idx:t,stopAtNewlines:n,stopAtRawNbsp:r}){if(typeof e!="string"||!e.length||((!t||typeof t!="number")&&(t=0),t<1))return null;if(e[~-t]&&(e[~-t].trim()||n&&`
|
|
14
|
+
\r`.includes(e[~-t])||r&&e[~-t]===V))return~-t;if(e[t-2]&&(e[t-2].trim()||n&&`
|
|
15
|
+
\r`.includes(e[t-2])||r&&e[t-2]===V))return t-2;for(let o=t;o--;)if(e[o]&&(e[o].trim()||n&&`
|
|
16
|
+
\r`.includes(e[o])||r&&e[o]===V))return o;return null}function G(e,t=0){return se({str:e,idx:t,stopAtNewlines:!1,stopAtRawNbsp:!1})}function cr(e,t){return se({str:e,idx:t,stopAtNewlines:!0,stopAtRawNbsp:!1})}function fr(e,t){return se({str:e,idx:t,stopAtNewlines:!1,stopAtRawNbsp:!0})}function ft(e,t,n,r,o){if(typeof t!="string"||!t.length||(typeof n!="number"&&(n=0),e==="right"&&!t[n+1]||e==="left"&&!t[~-n]))return null;let i=n,l=[],c,h,u,a=0;for(;a<o.length;){if(!L(o[a])||!o[a].length){a+=1;continue}let{value:g,optional:_,hungry:R}=ur(o[a]),f=e==="right"?B(t,i):G(t,i);if(r.i&&t[f].toLowerCase()===g.toLowerCase()||!r.i&&t[f]===g){let ae=e==="right"?B(t,f):G(t,f);R&&(r.i&&t[ae].toLowerCase()===g.toLowerCase()||!r.i&&t[ae]===g)?u=!0:a+=1,typeof f=="number"&&e==="right"&&f>i+1?l.push([i+1,f]):e==="left"&&typeof f=="number"&&f<~-i&&l.unshift([f+1,i]),i=f,e==="right"?(c===void 0&&(c=f),h=f):(h===void 0&&(h=f),c=f)}else if(_){a+=1;continue}else if(u){a+=1,u=void 0;continue}else return null}return c===void 0||h===void 0?null:{gaps:l,leftmostChar:c,rightmostChar:h}}var W={i:!1};function gt(e,t,...n){if(!n||!n.length)throw new Error("string-left-right/leftSeq(): only two input arguments were passed! Did you intend to use left() method instead?");let r;return(0,O.default)(n[0])?r=p(p({},W),n.shift()):r=W,ft("left",e,t,r,Array.from(n).reverse())}function ht(e,t,...n){if(!n||!n.length)throw new Error("string-left-right/rightSeq(): only two input arguments were passed! Did you intend to use right() method instead?");let r;return(0,O.default)(n[0])?r=p(p({},W),n.shift()):r=W,ft("right",e,t,r,n)}function N(e,t,n,r,o=[]){var h;if(typeof t!="string"||!t.length||((!n||typeof n!="number")&&(n=0),e==="right"&&!t[n+1]||e==="left"&&+n==0))return null;let i=null,l=null;do i=e==="right"?ht(t,typeof l=="number"?l:n,...o):gt(t,typeof l=="number"?l:n,...o),i!==null&&(l=e==="right"?i.rightmostChar:i.leftmostChar);while(i);if(l!=null&&e==="right"&&(l+=1),l===null)return null;if(e==="right"){if((h=t[l])==null?void 0:h.trim())return l;let u=B(t,l);if(!r||r.mode===0){if(u===l+1)return l;if(t.slice(l,u||t.length).trim()||t.slice(l,u||t.length).includes(`
|
|
17
|
+
`)||t.slice(l,u||t.length).includes("\r")){for(let a=l,g=t.length;a<g;a++)if(`
|
|
18
|
+
\r`.includes(t[a]))return a}else return u?~-u:t.length}else{if(r.mode===1)return l;if(r.mode===2){let a=t.slice(l);if(a.trim()||a.includes(`
|
|
19
|
+
`)||a.includes("\r")){for(let g=l,_=t.length;g<_;g++)if(t[g].trim()||`
|
|
20
|
+
\r`.includes(t[g]))return g}return t.length}}return u||t.length}if(t[l]&&t[~-l]&&t[~-l].trim())return l;let c=G(t,l);if(!r||r.mode===0){if(c===l-2)return l;if(t.slice(0,l).trim()||t.slice(0,l).includes(`
|
|
21
|
+
`)||t.slice(0,l).includes("\r")){for(let u=l;u--;)if(`
|
|
22
|
+
\r`.includes(t[u])||t[u].trim())return u+1+(t[u].trim()?1:0)}return 0}if(r.mode===1)return l;if(r.mode===2){let u=t.slice(0,l);if(u.trim()||u.includes(`
|
|
23
|
+
`)||u.includes("\r")){for(let a=l;a--;)if(t[a].trim()||`
|
|
24
|
+
\r`.includes(t[a]))return a+1}return 0}return c!==null?c+1:0}function gr(e,t,...n){if(!n.length||n.length===1&&(0,O.default)(n[0]))return null;let r={mode:0};if((0,O.default)(n[0])){let o=p(p({},r),(0,$.default)(n[0]));if(!o.mode)o.mode=0;else if(L(o.mode)&&"0123".includes(o.mode))o.mode=Number.parseInt(o.mode,10);else if(!ct(o.mode))throw new Error(`string-left-right/chompLeft(): [THROW_ID_01] the opts.mode is wrong! It should be 0, 1, 2 or 3. It was given as ${o.mode} (type ${typeof o.mode})`);return N("left",e,t,o,(0,$.default)(n).slice(1))}return L(n[0])?N("left",e,t,r,(0,$.default)(n)):N("left",e,t,r,(0,$.default)(n).slice(1))}function hr(e,t,...n){if(!n.length||n.length===1&&(0,O.default)(n[0]))return null;let r={mode:0};if((0,O.default)(n[0])){let o=p(p({},r),(0,$.default)(n[0]));if(!o.mode)o.mode=0;else if(L(o.mode)&&"0123".includes(o.mode))o.mode=Number.parseInt(o.mode,10);else if(!ct(o.mode))throw new Error(`string-left-right/chompRight(): [THROW_ID_02] the opts.mode is wrong! It should be 0, 1, 2 or 3. It was given as ${o.mode} (type ${typeof o.mode})`);return N("right",e,t,o,(0,$.default)(n).slice(1))}return L(n[0])?N("right",e,t,r,(0,$.default)(n)):N("right",e,t,r,(0,$.default)(n).slice(1))}return Et(pr);})();
|
package/examples/_quickTake.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "string-left-right",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.11",
|
|
4
4
|
"description": "Looks up the first non-whitespace character to the left/right of a given index",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"check",
|
|
@@ -36,100 +36,44 @@
|
|
|
36
36
|
},
|
|
37
37
|
"types": "types/index.d.ts",
|
|
38
38
|
"scripts": {
|
|
39
|
-
"build": "
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"tap": "tap",
|
|
54
|
-
"pretest": "npm run build",
|
|
55
|
-
"test": "npm run lint && npm run unittest && npm run test:examples && npm run clean_cov && npm run format",
|
|
56
|
-
"test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
|
|
57
|
-
"tsc": "tsc",
|
|
58
|
-
"unittest": "tap --no-only --output-file=testStats.md --reporter=terse && tsc -p tsconfig.json --noEmit && npm run clean_cov && npm run perf"
|
|
39
|
+
"build": "node '../../ops/scripts/esbuild.js' && yarn run dts",
|
|
40
|
+
"dev": "DEV=true node '../../ops/scripts/esbuild.js' && yarn run dts",
|
|
41
|
+
"dts": "rollup -c && yarn run prettier 'types/index.d.ts' --write",
|
|
42
|
+
"examples": "node '../../ops/scripts/run-examples.js'",
|
|
43
|
+
"lect": "node '../../ops/lect/lect.js'",
|
|
44
|
+
"letspublish": "yarn publish || :",
|
|
45
|
+
"lint": "eslint . --fix",
|
|
46
|
+
"perf": "node perf/check.js",
|
|
47
|
+
"prepare": "echo 'ready'",
|
|
48
|
+
"prettier": "prettier",
|
|
49
|
+
"prettier:format": "prettier --write '**/*.{ts,tsx,md}' --no-error-on-unmatched-pattern",
|
|
50
|
+
"pretest": "yarn run lect && yarn run build",
|
|
51
|
+
"test": "c8 yarn run unit && yarn run examples && yarn run lint",
|
|
52
|
+
"unit": "uvu test"
|
|
59
53
|
},
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
"--no-warnings",
|
|
68
|
-
"--experimental-loader",
|
|
69
|
-
"@istanbuljs/esm-loader-hook"
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
56
|
+
},
|
|
57
|
+
"c8": {
|
|
58
|
+
"check-coverage": true,
|
|
59
|
+
"exclude": [
|
|
60
|
+
"**/test/**/*.*"
|
|
70
61
|
],
|
|
71
|
-
"
|
|
62
|
+
"lines": 100
|
|
72
63
|
},
|
|
73
64
|
"lect": {
|
|
74
65
|
"licence": {
|
|
75
66
|
"extras": [
|
|
76
67
|
""
|
|
77
68
|
]
|
|
78
|
-
},
|
|
79
|
-
"req": "{ left, right, leftSeq, rightSeq, chompLeft, chompRight, leftStopAtNewLines, rightStopAtNewLines }",
|
|
80
|
-
"various": {
|
|
81
|
-
"devDependencies": [
|
|
82
|
-
"@types/lodash.clonedeep",
|
|
83
|
-
"@types/lodash.isplainobject"
|
|
84
|
-
]
|
|
85
69
|
}
|
|
86
70
|
},
|
|
87
71
|
"dependencies": {
|
|
88
|
-
"@babel/runtime": "^7.16.0",
|
|
89
72
|
"lodash.clonedeep": "^4.5.0",
|
|
90
73
|
"lodash.isplainobject": "^4.0.6"
|
|
91
74
|
},
|
|
92
75
|
"devDependencies": {
|
|
93
|
-
"@babel/cli": "^7.16.0",
|
|
94
|
-
"@babel/core": "^7.16.0",
|
|
95
|
-
"@babel/node": "^7.16.0",
|
|
96
|
-
"@babel/plugin-external-helpers": "^7.16.0",
|
|
97
|
-
"@babel/plugin-proposal-class-properties": "^7.16.0",
|
|
98
|
-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
|
|
99
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
|
|
100
|
-
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
|
|
101
|
-
"@babel/plugin-transform-runtime": "^7.16.0",
|
|
102
|
-
"@babel/preset-env": "^7.16.0",
|
|
103
|
-
"@babel/preset-typescript": "^7.16.0",
|
|
104
|
-
"@babel/register": "^7.16.0",
|
|
105
|
-
"@istanbuljs/esm-loader-hook": "^0.1.2",
|
|
106
|
-
"@rollup/plugin-babel": "^5.3.0",
|
|
107
|
-
"@rollup/plugin-commonjs": "^21.0.1",
|
|
108
|
-
"@rollup/plugin-json": "^4.1.0",
|
|
109
|
-
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
110
|
-
"@rollup/plugin-strip": "^2.1.0",
|
|
111
|
-
"@rollup/plugin-typescript": "^8.3.0",
|
|
112
76
|
"@types/lodash.clonedeep": "^4.5.6",
|
|
113
|
-
"@types/lodash.isplainobject": "^4.0.6"
|
|
114
|
-
"@types/node": "^16.11.6",
|
|
115
|
-
"@types/tap": "^15.0.5",
|
|
116
|
-
"@typescript-eslint/eslint-plugin": "^5.3.0",
|
|
117
|
-
"@typescript-eslint/parser": "^5.3.0",
|
|
118
|
-
"core-js": "^3.19.1",
|
|
119
|
-
"cross-env": "^7.0.3",
|
|
120
|
-
"eslint": "^8.2.0",
|
|
121
|
-
"lect": "^0.18.5",
|
|
122
|
-
"rollup": "^2.59.0",
|
|
123
|
-
"rollup-plugin-ascii": "^0.0.3",
|
|
124
|
-
"rollup-plugin-banner": "^0.2.1",
|
|
125
|
-
"rollup-plugin-cleanup": "^3.2.1",
|
|
126
|
-
"rollup-plugin-dts": "^4.0.1",
|
|
127
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
128
|
-
"tap": "^15.0.10",
|
|
129
|
-
"tslib": "^2.3.1",
|
|
130
|
-
"typescript": "^4.4.4"
|
|
131
|
-
},
|
|
132
|
-
"engines": {
|
|
133
|
-
"node": ">=12"
|
|
77
|
+
"@types/lodash.isplainobject": "^4.0.6"
|
|
134
78
|
}
|
|
135
79
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -6,13 +6,41 @@ declare function left(str: string, idx?: number | null): number | null;
|
|
|
6
6
|
declare function leftStopAtNewLines(str: string, idx: number): number | null;
|
|
7
7
|
declare function leftStopAtRawNbsp(str: string, idx: number): number | null;
|
|
8
8
|
interface SeqOutput {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
gaps: [number, number][];
|
|
10
|
+
leftmostChar: number;
|
|
11
|
+
rightmostChar: number;
|
|
12
12
|
}
|
|
13
|
-
declare function leftSeq(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
declare function leftSeq(
|
|
14
|
+
str: string,
|
|
15
|
+
idx: number,
|
|
16
|
+
...args: any[]
|
|
17
|
+
): SeqOutput | null;
|
|
18
|
+
declare function rightSeq(
|
|
19
|
+
str: string,
|
|
20
|
+
idx: number,
|
|
21
|
+
...args: any[]
|
|
22
|
+
): SeqOutput | null;
|
|
23
|
+
declare function chompLeft(
|
|
24
|
+
str: string,
|
|
25
|
+
idx: number,
|
|
26
|
+
...args: any[]
|
|
27
|
+
): number | null;
|
|
28
|
+
declare function chompRight(
|
|
29
|
+
str: string,
|
|
30
|
+
idx: number,
|
|
31
|
+
...args: any[]
|
|
32
|
+
): number | null;
|
|
17
33
|
|
|
18
|
-
export {
|
|
34
|
+
export {
|
|
35
|
+
chompLeft,
|
|
36
|
+
chompRight,
|
|
37
|
+
left,
|
|
38
|
+
leftSeq,
|
|
39
|
+
leftStopAtNewLines,
|
|
40
|
+
leftStopAtRawNbsp,
|
|
41
|
+
right,
|
|
42
|
+
rightSeq,
|
|
43
|
+
rightStopAtNewLines,
|
|
44
|
+
rightStopAtRawNbsp,
|
|
45
|
+
version,
|
|
46
|
+
};
|
package/examples/api.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"_quickTake.js":{"title":"Quick Take","content":"import { strict as assert } from \"assert\";\nimport {\n left,\n right,\n leftSeq,\n rightSeq,\n chompLeft,\n chompRight,\n leftStopAtNewLines,\n rightStopAtNewLines,\n} from \"string-left-right\";\n\n// get the closest non-whitespace character to the left of \"d\" (which itself\n// is at string index 6)\nconst str = \"abc def\";\n// | |\n// 012345678\n\nassert.equal(\n `next non-whitespace character to the left of ${str[6]} (index 6) is ${\n str[left(str, 6)]\n } (index ${left(str, 6)})`,\n \"next non-whitespace character to the left of d (index 6) is c (index 2)\"\n);"}}
|