string-left-right 5.0.2 → 5.0.6
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 +0 -6
- package/LICENSE +1 -1
- package/dist/string-left-right.esm.js +347 -343
- package/dist/string-left-right.umd.js +2 -2
- package/package.json +36 -40
package/CHANGELOG.md
CHANGED
|
@@ -3,12 +3,6 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## 5.0.1 (2021-09-13)
|
|
7
|
-
|
|
8
|
-
### Bug Fixes
|
|
9
|
-
|
|
10
|
-
- bump TS and separate ESLint plugins away from this monorepo ([2e07d42](https://github.com/codsen/codsen/commit/2e07d424222b6ffedf5fb45c83ad453627ec2904))
|
|
11
|
-
|
|
12
6
|
## 5.0.0 (2021-09-09)
|
|
13
7
|
|
|
14
8
|
### Features
|
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2010
|
|
3
|
+
Copyright (c) 2010-2021 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
|
|
@@ -1,7 +1,7 @@
|
|
|
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.6
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/string-left-right/}
|
|
@@ -10,397 +10,401 @@
|
|
|
10
10
|
import isObj from 'lodash.isplainobject';
|
|
11
11
|
import clone from 'lodash.clonedeep';
|
|
12
12
|
|
|
13
|
-
var version$1 = "5.0.
|
|
13
|
+
var version$1 = "5.0.6";
|
|
14
14
|
|
|
15
15
|
const version = version$1;
|
|
16
16
|
const RAWNBSP = "\u00A0";
|
|
17
17
|
function x(something) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
res.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
18
|
+
const res = {
|
|
19
|
+
value: something,
|
|
20
|
+
hungry: false,
|
|
21
|
+
optional: false,
|
|
22
|
+
};
|
|
23
|
+
if ((res.value.endsWith("?*") || res.value.endsWith("*?")) &&
|
|
24
|
+
res.value.length > 2) {
|
|
25
|
+
res.value = res.value.slice(0, res.value.length - 2);
|
|
26
|
+
res.optional = true;
|
|
27
|
+
res.hungry = true;
|
|
28
|
+
}
|
|
29
|
+
else if (res.value.endsWith("?") && res.value.length > 1) {
|
|
30
|
+
res.value = res.value.slice(0, ~-res.value.length);
|
|
31
|
+
res.optional = true;
|
|
32
|
+
}
|
|
33
|
+
else if (res.value.endsWith("*") && res.value.length > 1) {
|
|
34
|
+
res.value = res.value.slice(0, ~-res.value.length);
|
|
35
|
+
res.hungry = true;
|
|
36
|
+
}
|
|
37
|
+
return res;
|
|
35
38
|
}
|
|
36
39
|
function isNum(something) {
|
|
37
|
-
|
|
40
|
+
return typeof something === "number";
|
|
38
41
|
}
|
|
39
42
|
function isStr(something) {
|
|
40
|
-
|
|
43
|
+
return typeof something === "string";
|
|
41
44
|
}
|
|
42
|
-
function rightMain({
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return idx + 1;
|
|
62
|
-
}
|
|
63
|
-
if (
|
|
64
|
-
str[idx + 2] && (str[idx + 2].trim() || stopAtNewlines &&
|
|
65
|
-
"\n\r".includes(str[idx + 2]) || stopAtRawNbsp &&
|
|
66
|
-
str[idx + 2] === RAWNBSP)) {
|
|
67
|
-
return idx + 2;
|
|
68
|
-
}
|
|
69
|
-
for (let i = idx + 1, len = str.length; i < len; i++) {
|
|
45
|
+
function rightMain({ str, idx = 0, stopAtNewlines = false, stopAtRawNbsp = false, }) {
|
|
46
|
+
if (typeof str !== "string" || !str.length) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
if (!idx || typeof idx !== "number") {
|
|
50
|
+
idx = 0;
|
|
51
|
+
}
|
|
52
|
+
if (!str[idx + 1]) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
if (
|
|
56
|
+
str[idx + 1] &&
|
|
57
|
+
(str[idx + 1].trim() ||
|
|
58
|
+
(stopAtNewlines &&
|
|
59
|
+
"\n\r".includes(str[idx + 1])) ||
|
|
60
|
+
(stopAtRawNbsp &&
|
|
61
|
+
str[idx + 1] === RAWNBSP))) {
|
|
62
|
+
return idx + 1;
|
|
63
|
+
}
|
|
70
64
|
if (
|
|
71
|
-
str[
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
65
|
+
str[idx + 2] &&
|
|
66
|
+
(str[idx + 2].trim() ||
|
|
67
|
+
(stopAtNewlines &&
|
|
68
|
+
"\n\r".includes(str[idx + 2])) ||
|
|
69
|
+
(stopAtRawNbsp &&
|
|
70
|
+
str[idx + 2] === RAWNBSP))) {
|
|
71
|
+
return idx + 2;
|
|
72
|
+
}
|
|
73
|
+
for (let i = idx + 1, len = str.length; i < len; i++) {
|
|
74
|
+
if (
|
|
75
|
+
str[i].trim() ||
|
|
76
|
+
(stopAtNewlines &&
|
|
77
|
+
"\n\r".includes(str[i])) ||
|
|
78
|
+
(stopAtRawNbsp &&
|
|
79
|
+
str[i] === RAWNBSP)) {
|
|
80
|
+
return i;
|
|
81
|
+
}
|
|
75
82
|
}
|
|
76
|
-
|
|
77
|
-
return null;
|
|
83
|
+
return null;
|
|
78
84
|
}
|
|
79
85
|
function right(str, idx = 0) {
|
|
80
|
-
|
|
81
|
-
str,
|
|
82
|
-
idx,
|
|
83
|
-
stopAtNewlines: false,
|
|
84
|
-
stopAtRawNbsp: false
|
|
85
|
-
});
|
|
86
|
+
return rightMain({ str, idx, stopAtNewlines: false, stopAtRawNbsp: false });
|
|
86
87
|
}
|
|
87
88
|
function rightStopAtNewLines(str, idx) {
|
|
88
|
-
|
|
89
|
-
str,
|
|
90
|
-
idx,
|
|
91
|
-
stopAtNewlines: true,
|
|
92
|
-
stopAtRawNbsp: false
|
|
93
|
-
});
|
|
89
|
+
return rightMain({ str, idx, stopAtNewlines: true, stopAtRawNbsp: false });
|
|
94
90
|
}
|
|
95
91
|
function rightStopAtRawNbsp(str, idx) {
|
|
96
|
-
|
|
97
|
-
str,
|
|
98
|
-
idx,
|
|
99
|
-
stopAtNewlines: false,
|
|
100
|
-
stopAtRawNbsp: true
|
|
101
|
-
});
|
|
92
|
+
return rightMain({ str, idx, stopAtNewlines: false, stopAtRawNbsp: true });
|
|
102
93
|
}
|
|
103
|
-
function leftMain({
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
94
|
+
function leftMain({ str, idx, stopAtNewlines, stopAtRawNbsp }) {
|
|
95
|
+
if (typeof str !== "string" || !str.length) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
if (!idx || typeof idx !== "number") {
|
|
99
|
+
idx = 0;
|
|
100
|
+
}
|
|
101
|
+
if (idx < 1) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
if (
|
|
105
|
+
str[~-idx] &&
|
|
106
|
+
(str[~-idx].trim() ||
|
|
107
|
+
(stopAtNewlines &&
|
|
108
|
+
"\n\r".includes(str[~-idx])) ||
|
|
109
|
+
(stopAtRawNbsp &&
|
|
110
|
+
str[~-idx] === RAWNBSP))) {
|
|
111
|
+
return ~-idx;
|
|
112
|
+
}
|
|
113
|
+
if (
|
|
114
|
+
str[idx - 2] &&
|
|
115
|
+
(str[idx - 2].trim() ||
|
|
116
|
+
(stopAtNewlines &&
|
|
117
|
+
"\n\r".includes(str[idx - 2])) ||
|
|
118
|
+
(stopAtRawNbsp &&
|
|
119
|
+
str[idx - 2] === RAWNBSP))) {
|
|
120
|
+
return idx - 2;
|
|
121
|
+
}
|
|
122
|
+
for (let i = idx; i--;) {
|
|
123
|
+
if (str[i] &&
|
|
124
|
+
(str[i].trim() ||
|
|
125
|
+
(stopAtNewlines &&
|
|
126
|
+
"\n\r".includes(str[i])) ||
|
|
127
|
+
(stopAtRawNbsp &&
|
|
128
|
+
str[i] === RAWNBSP))) {
|
|
129
|
+
return i;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
116
132
|
return null;
|
|
117
|
-
}
|
|
118
|
-
if (
|
|
119
|
-
str[~-idx] && (str[~-idx].trim() || stopAtNewlines &&
|
|
120
|
-
"\n\r".includes(str[~-idx]) || stopAtRawNbsp &&
|
|
121
|
-
str[~-idx] === RAWNBSP)) {
|
|
122
|
-
return ~-idx;
|
|
123
|
-
}
|
|
124
|
-
if (
|
|
125
|
-
str[idx - 2] && (str[idx - 2].trim() || stopAtNewlines &&
|
|
126
|
-
"\n\r".includes(str[idx - 2]) || stopAtRawNbsp &&
|
|
127
|
-
str[idx - 2] === RAWNBSP)) {
|
|
128
|
-
return idx - 2;
|
|
129
|
-
}
|
|
130
|
-
for (let i = idx; i--;) {
|
|
131
|
-
if (str[i] && (str[i].trim() || stopAtNewlines &&
|
|
132
|
-
"\n\r".includes(str[i]) || stopAtRawNbsp &&
|
|
133
|
-
str[i] === RAWNBSP)) {
|
|
134
|
-
return i;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return null;
|
|
138
133
|
}
|
|
139
134
|
function left(str, idx = 0) {
|
|
140
|
-
|
|
141
|
-
str,
|
|
142
|
-
idx,
|
|
143
|
-
stopAtNewlines: false,
|
|
144
|
-
stopAtRawNbsp: false
|
|
145
|
-
});
|
|
135
|
+
return leftMain({ str, idx, stopAtNewlines: false, stopAtRawNbsp: false });
|
|
146
136
|
}
|
|
147
137
|
function leftStopAtNewLines(str, idx) {
|
|
148
|
-
|
|
149
|
-
str,
|
|
150
|
-
idx,
|
|
151
|
-
stopAtNewlines: true,
|
|
152
|
-
stopAtRawNbsp: false
|
|
153
|
-
});
|
|
138
|
+
return leftMain({ str, idx, stopAtNewlines: true, stopAtRawNbsp: false });
|
|
154
139
|
}
|
|
155
140
|
function leftStopAtRawNbsp(str, idx) {
|
|
156
|
-
|
|
157
|
-
str,
|
|
158
|
-
idx,
|
|
159
|
-
stopAtNewlines: false,
|
|
160
|
-
stopAtRawNbsp: true
|
|
161
|
-
});
|
|
141
|
+
return leftMain({ str, idx, stopAtNewlines: false, stopAtRawNbsp: true });
|
|
162
142
|
}
|
|
163
143
|
function seq(direction, str, idx, opts, args) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const {
|
|
185
|
-
value,
|
|
186
|
-
optional,
|
|
187
|
-
hungry
|
|
188
|
-
} = x(args[i]);
|
|
189
|
-
const whattsOnTheSide = direction === "right" ? right(str, lastFinding) : left(str, lastFinding);
|
|
190
|
-
if (opts.i && str[whattsOnTheSide].toLowerCase() === value.toLowerCase() || !opts.i && str[whattsOnTheSide] === value) {
|
|
191
|
-
const temp = direction === "right" ? right(str, whattsOnTheSide) : left(str, whattsOnTheSide);
|
|
192
|
-
if (hungry && (opts.i && str[temp].toLowerCase() === value.toLowerCase() || !opts.i && str[temp] === value)) {
|
|
193
|
-
satiated = true;
|
|
194
|
-
} else {
|
|
195
|
-
i += 1;
|
|
196
|
-
}
|
|
197
|
-
if (typeof whattsOnTheSide === "number" && direction === "right" && whattsOnTheSide > lastFinding + 1) {
|
|
198
|
-
gaps.push([lastFinding + 1, whattsOnTheSide]);
|
|
199
|
-
} else if (direction === "left" && typeof whattsOnTheSide === "number" && whattsOnTheSide < ~-lastFinding) {
|
|
200
|
-
gaps.unshift([whattsOnTheSide + 1, lastFinding]);
|
|
201
|
-
}
|
|
202
|
-
lastFinding = whattsOnTheSide;
|
|
203
|
-
if (direction === "right") {
|
|
204
|
-
if (leftmostChar === undefined) {
|
|
205
|
-
leftmostChar = whattsOnTheSide;
|
|
144
|
+
if (typeof str !== "string" || !str.length) {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
if (typeof idx !== "number") {
|
|
148
|
+
idx = 0;
|
|
149
|
+
}
|
|
150
|
+
if ((direction === "right" && !str[idx + 1]) ||
|
|
151
|
+
(direction === "left" && !str[~-idx])) {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
let lastFinding = idx;
|
|
155
|
+
const gaps = [];
|
|
156
|
+
let leftmostChar;
|
|
157
|
+
let rightmostChar;
|
|
158
|
+
let satiated;
|
|
159
|
+
let i = 0;
|
|
160
|
+
while (i < args.length) {
|
|
161
|
+
if (!isStr(args[i]) || !args[i].length) {
|
|
162
|
+
i += 1;
|
|
163
|
+
continue;
|
|
206
164
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
if (
|
|
210
|
-
|
|
165
|
+
const { value, optional, hungry } = x(args[i]);
|
|
166
|
+
const whattsOnTheSide = direction === "right" ? right(str, lastFinding) : left(str, lastFinding);
|
|
167
|
+
if ((opts.i &&
|
|
168
|
+
str[whattsOnTheSide].toLowerCase() === value.toLowerCase()) ||
|
|
169
|
+
(!opts.i && str[whattsOnTheSide] === value)) {
|
|
170
|
+
const temp = direction === "right"
|
|
171
|
+
? right(str, whattsOnTheSide)
|
|
172
|
+
: left(str, whattsOnTheSide);
|
|
173
|
+
if (hungry &&
|
|
174
|
+
((opts.i &&
|
|
175
|
+
str[temp].toLowerCase() === value.toLowerCase()) ||
|
|
176
|
+
(!opts.i && str[temp] === value))) {
|
|
177
|
+
satiated = true;
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
i += 1;
|
|
181
|
+
}
|
|
182
|
+
if (typeof whattsOnTheSide === "number" &&
|
|
183
|
+
direction === "right" &&
|
|
184
|
+
whattsOnTheSide > lastFinding + 1) {
|
|
185
|
+
gaps.push([lastFinding + 1, whattsOnTheSide]);
|
|
186
|
+
}
|
|
187
|
+
else if (direction === "left" &&
|
|
188
|
+
typeof whattsOnTheSide === "number" &&
|
|
189
|
+
whattsOnTheSide < ~-lastFinding) {
|
|
190
|
+
gaps.unshift([whattsOnTheSide + 1, lastFinding]);
|
|
191
|
+
}
|
|
192
|
+
lastFinding = whattsOnTheSide;
|
|
193
|
+
if (direction === "right") {
|
|
194
|
+
if (leftmostChar === undefined) {
|
|
195
|
+
leftmostChar = whattsOnTheSide;
|
|
196
|
+
}
|
|
197
|
+
rightmostChar = whattsOnTheSide;
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
if (rightmostChar === undefined) {
|
|
201
|
+
rightmostChar = whattsOnTheSide;
|
|
202
|
+
}
|
|
203
|
+
leftmostChar = whattsOnTheSide;
|
|
204
|
+
}
|
|
211
205
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
gaps,
|
|
230
|
-
leftmostChar,
|
|
231
|
-
rightmostChar
|
|
232
|
-
};
|
|
206
|
+
else if (optional) {
|
|
207
|
+
i += 1;
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
else if (satiated) {
|
|
211
|
+
i += 1;
|
|
212
|
+
satiated = undefined;
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (leftmostChar === undefined || rightmostChar === undefined) {
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
return { gaps, leftmostChar, rightmostChar };
|
|
233
223
|
}
|
|
234
224
|
const seqDefaults = {
|
|
235
|
-
|
|
225
|
+
i: false,
|
|
236
226
|
};
|
|
237
227
|
function leftSeq(str, idx, ...args) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
return seq("left", str, idx, opts, Array.from(args).reverse());
|
|
228
|
+
if (!args || !args.length) {
|
|
229
|
+
throw new Error(`string-left-right/leftSeq(): only two input arguments were passed! Did you intend to use left() method instead?`);
|
|
230
|
+
}
|
|
231
|
+
let opts;
|
|
232
|
+
if (isObj(args[0])) {
|
|
233
|
+
opts = { ...seqDefaults, ...args.shift() };
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
opts = seqDefaults;
|
|
237
|
+
}
|
|
238
|
+
return seq("left", str, idx, opts, Array.from(args).reverse());
|
|
250
239
|
}
|
|
251
240
|
function rightSeq(str, idx, ...args) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
return seq("right", str, idx, opts, args);
|
|
241
|
+
if (!args || !args.length) {
|
|
242
|
+
throw new Error(`string-left-right/rightSeq(): only two input arguments were passed! Did you intend to use right() method instead?`);
|
|
243
|
+
}
|
|
244
|
+
let opts;
|
|
245
|
+
if (isObj(args[0])) {
|
|
246
|
+
opts = { ...seqDefaults, ...args.shift() };
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
opts = seqDefaults;
|
|
250
|
+
}
|
|
251
|
+
return seq("right", str, idx, opts, args);
|
|
264
252
|
}
|
|
265
253
|
function chomp(direction, str, idx, opts, args = []) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
269
|
-
if (!idx || typeof idx !== "number") {
|
|
270
|
-
idx = 0;
|
|
271
|
-
}
|
|
272
|
-
if (direction === "right" && !str[idx + 1] || direction === "left" && +idx === 0) {
|
|
273
|
-
return null;
|
|
274
|
-
}
|
|
275
|
-
let lastRes = null;
|
|
276
|
-
let lastIdx = null;
|
|
277
|
-
do {
|
|
278
|
-
lastRes = direction === "right" ? rightSeq(str, typeof lastIdx === "number" ? lastIdx : idx, ...args) : leftSeq(str, typeof lastIdx === "number" ? lastIdx : idx, ...args);
|
|
279
|
-
if (lastRes !== null) {
|
|
280
|
-
lastIdx = direction === "right" ? lastRes.rightmostChar : lastRes.leftmostChar;
|
|
281
|
-
}
|
|
282
|
-
} while (lastRes);
|
|
283
|
-
if (lastIdx != null && direction === "right") {
|
|
284
|
-
lastIdx += 1;
|
|
285
|
-
}
|
|
286
|
-
if (lastIdx === null) {
|
|
287
|
-
return null;
|
|
288
|
-
}
|
|
289
|
-
if (direction === "right") {
|
|
290
|
-
if (str[lastIdx] && str[lastIdx].trim()) {
|
|
291
|
-
return lastIdx;
|
|
254
|
+
if (typeof str !== "string" || !str.length) {
|
|
255
|
+
return null;
|
|
292
256
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
257
|
+
if (!idx || typeof idx !== "number") {
|
|
258
|
+
idx = 0;
|
|
259
|
+
}
|
|
260
|
+
if ((direction === "right" && !str[idx + 1]) ||
|
|
261
|
+
(direction === "left" && +idx === 0)) {
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
let lastRes = null;
|
|
265
|
+
let lastIdx = null;
|
|
266
|
+
do {
|
|
267
|
+
lastRes =
|
|
268
|
+
direction === "right"
|
|
269
|
+
? rightSeq(str, typeof lastIdx === "number" ? lastIdx : idx, ...args)
|
|
270
|
+
: leftSeq(str, typeof lastIdx === "number" ? lastIdx : idx, ...args);
|
|
271
|
+
if (lastRes !== null) {
|
|
272
|
+
lastIdx =
|
|
273
|
+
direction === "right" ? lastRes.rightmostChar : lastRes.leftmostChar;
|
|
274
|
+
}
|
|
275
|
+
} while (lastRes);
|
|
276
|
+
if (lastIdx != null && direction === "right") {
|
|
277
|
+
lastIdx += 1;
|
|
278
|
+
}
|
|
279
|
+
if (lastIdx === null) {
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
if (direction === "right") {
|
|
283
|
+
if (str[lastIdx] && str[lastIdx].trim()) {
|
|
284
|
+
return lastIdx;
|
|
285
|
+
}
|
|
286
|
+
const whatsOnTheRight = right(str, lastIdx);
|
|
287
|
+
if (!opts || opts.mode === 0) {
|
|
288
|
+
if (whatsOnTheRight === lastIdx + 1) {
|
|
289
|
+
return lastIdx;
|
|
290
|
+
}
|
|
291
|
+
if (str.slice(lastIdx, whatsOnTheRight || str.length).trim() ||
|
|
292
|
+
str.slice(lastIdx, whatsOnTheRight || str.length).includes("\n") ||
|
|
293
|
+
str.slice(lastIdx, whatsOnTheRight || str.length).includes("\r")) {
|
|
294
|
+
for (let y = lastIdx, len = str.length; y < len; y++) {
|
|
295
|
+
if (`\n\r`.includes(str[y])) {
|
|
296
|
+
return y;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
return whatsOnTheRight ? ~-whatsOnTheRight : str.length;
|
|
302
|
+
}
|
|
303
303
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
304
|
+
else if (opts.mode === 1) {
|
|
305
|
+
return lastIdx;
|
|
306
|
+
}
|
|
307
|
+
else if (opts.mode === 2) {
|
|
308
|
+
const remainderString = str.slice(lastIdx);
|
|
309
|
+
if (remainderString.trim() ||
|
|
310
|
+
remainderString.includes("\n") ||
|
|
311
|
+
remainderString.includes("\r")) {
|
|
312
|
+
for (let y = lastIdx, len = str.length; y < len; y++) {
|
|
313
|
+
if (str[y].trim() || `\n\r`.includes(str[y])) {
|
|
314
|
+
return y;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return str.length;
|
|
319
|
+
}
|
|
320
|
+
return whatsOnTheRight || str.length;
|
|
321
|
+
}
|
|
322
|
+
if (str[lastIdx] && str[~-lastIdx] && str[~-lastIdx].trim()) {
|
|
323
|
+
return lastIdx;
|
|
324
|
+
}
|
|
325
|
+
const whatsOnTheLeft = left(str, lastIdx);
|
|
326
|
+
if (!opts || opts.mode === 0) {
|
|
327
|
+
if (whatsOnTheLeft === lastIdx - 2) {
|
|
328
|
+
return lastIdx;
|
|
316
329
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
const whatsOnTheLeft = left(str, lastIdx);
|
|
326
|
-
if (!opts || opts.mode === 0) {
|
|
327
|
-
if (whatsOnTheLeft === lastIdx - 2) {
|
|
328
|
-
return lastIdx;
|
|
329
|
-
}
|
|
330
|
-
if (str.slice(0, lastIdx).trim() || str.slice(0, lastIdx).includes("\n") || str.slice(0, lastIdx).includes("\r")) {
|
|
331
|
-
for (let y = lastIdx; y--;) {
|
|
332
|
-
if (`\n\r`.includes(str[y]) || str[y].trim()) {
|
|
333
|
-
return y + 1 + (str[y].trim() ? 1 : 0);
|
|
330
|
+
if (str.slice(0, lastIdx).trim() ||
|
|
331
|
+
str.slice(0, lastIdx).includes("\n") ||
|
|
332
|
+
str.slice(0, lastIdx).includes("\r")) {
|
|
333
|
+
for (let y = lastIdx; y--;) {
|
|
334
|
+
if (`\n\r`.includes(str[y]) || str[y].trim()) {
|
|
335
|
+
return y + 1 + (str[y].trim() ? 1 : 0);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
334
338
|
}
|
|
335
|
-
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
339
|
+
return 0;
|
|
340
|
+
}
|
|
341
|
+
if (opts.mode === 1) {
|
|
342
|
+
return lastIdx;
|
|
343
|
+
}
|
|
344
|
+
if (opts.mode === 2) {
|
|
345
|
+
const remainderString = str.slice(0, lastIdx);
|
|
346
|
+
if (remainderString.trim() ||
|
|
347
|
+
remainderString.includes("\n") ||
|
|
348
|
+
remainderString.includes("\r")) {
|
|
349
|
+
for (let y = lastIdx; y--;) {
|
|
350
|
+
if (str[y].trim() || `\n\r`.includes(str[y])) {
|
|
351
|
+
return y + 1;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
348
354
|
}
|
|
349
|
-
|
|
355
|
+
return 0;
|
|
350
356
|
}
|
|
351
|
-
return 0;
|
|
352
|
-
}
|
|
353
|
-
return whatsOnTheLeft !== null ? whatsOnTheLeft + 1 : 0;
|
|
357
|
+
return whatsOnTheLeft !== null ? whatsOnTheLeft + 1 : 0;
|
|
354
358
|
}
|
|
355
359
|
function chompLeft(str, idx, ...args) {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
};
|
|
362
|
-
if (isObj(args[0])) {
|
|
363
|
-
const opts = { ...defaults,
|
|
364
|
-
...clone(args[0])
|
|
360
|
+
if (!args.length || (args.length === 1 && isObj(args[0]))) {
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
const defaults = {
|
|
364
|
+
mode: 0,
|
|
365
365
|
};
|
|
366
|
-
if (
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
366
|
+
if (isObj(args[0])) {
|
|
367
|
+
const opts = { ...defaults, ...clone(args[0]) };
|
|
368
|
+
if (!opts.mode) {
|
|
369
|
+
opts.mode = 0;
|
|
370
|
+
}
|
|
371
|
+
else if (isStr(opts.mode) && `0123`.includes(opts.mode)) {
|
|
372
|
+
opts.mode = Number.parseInt(opts.mode, 10);
|
|
373
|
+
}
|
|
374
|
+
else if (!isNum(opts.mode)) {
|
|
375
|
+
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})`);
|
|
376
|
+
}
|
|
377
|
+
return chomp("left", str, idx, opts, clone(args).slice(1));
|
|
378
|
+
}
|
|
379
|
+
if (!isStr(args[0])) {
|
|
380
|
+
return chomp("left", str, idx, defaults, clone(args).slice(1));
|
|
381
|
+
}
|
|
382
|
+
return chomp("left", str, idx, defaults, clone(args));
|
|
379
383
|
}
|
|
380
384
|
function chompRight(str, idx, ...args) {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
};
|
|
387
|
-
if (isObj(args[0])) {
|
|
388
|
-
const opts = { ...defaults,
|
|
389
|
-
...clone(args[0])
|
|
385
|
+
if (!args.length || (args.length === 1 && isObj(args[0]))) {
|
|
386
|
+
return null;
|
|
387
|
+
}
|
|
388
|
+
const defaults = {
|
|
389
|
+
mode: 0,
|
|
390
390
|
};
|
|
391
|
-
if (
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
391
|
+
if (isObj(args[0])) {
|
|
392
|
+
const opts = { ...defaults, ...clone(args[0]) };
|
|
393
|
+
if (!opts.mode) {
|
|
394
|
+
opts.mode = 0;
|
|
395
|
+
}
|
|
396
|
+
else if (isStr(opts.mode) && `0123`.includes(opts.mode)) {
|
|
397
|
+
opts.mode = Number.parseInt(opts.mode, 10);
|
|
398
|
+
}
|
|
399
|
+
else if (!isNum(opts.mode)) {
|
|
400
|
+
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})`);
|
|
401
|
+
}
|
|
402
|
+
return chomp("right", str, idx, opts, clone(args).slice(1));
|
|
403
|
+
}
|
|
404
|
+
if (!isStr(args[0])) {
|
|
405
|
+
return chomp("right", str, idx, defaults, clone(args).slice(1));
|
|
406
|
+
}
|
|
407
|
+
return chomp("right", str, idx, defaults, clone(args));
|
|
404
408
|
}
|
|
405
409
|
|
|
406
410
|
export { chompLeft, chompRight, left, leftSeq, leftStopAtNewLines, leftStopAtRawNbsp, right, rightSeq, rightStopAtNewLines, rightStopAtRawNbsp, version };
|
|
@@ -1,10 +1,10 @@
|
|
|
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.6
|
|
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.2",Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
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.6",Object.defineProperty(t,"__esModule",{value:!0})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "string-left-right",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.6",
|
|
4
4
|
"description": "Looks up the first non-whitespace character to the left/right of a given index",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"check",
|
|
@@ -37,9 +37,10 @@
|
|
|
37
37
|
"types": "types/index.d.ts",
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "rollup -c",
|
|
40
|
-
"esbuild": "node '../../scripts/esbuild.js'",
|
|
41
|
-
"
|
|
42
|
-
"ci_test": "npm run build && npm run format && tap --no-only --reporter=silent
|
|
40
|
+
"build:esbuild": "node '../../scripts/esbuild.js'",
|
|
41
|
+
"build:esbuild:dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
|
|
42
|
+
"ci_test": "npm run build && npm run format && tap --no-only --reporter=silent",
|
|
43
|
+
"clean_types": "../../scripts/cleanTypes.js",
|
|
43
44
|
"dev": "rollup -c --dev",
|
|
44
45
|
"devunittest": "npm run dev && tap --only -R 'base'",
|
|
45
46
|
"format": "npm run lect && npm run prettier && npm run lint",
|
|
@@ -49,20 +50,15 @@
|
|
|
49
50
|
"prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent",
|
|
50
51
|
"republish": "npm publish || :",
|
|
51
52
|
"tap": "tap",
|
|
52
|
-
"tsc": "tsc",
|
|
53
53
|
"pretest": "npm run build",
|
|
54
|
-
"test": "npm run
|
|
54
|
+
"test": "npm run test:ci && npm run perf",
|
|
55
|
+
"test:ci": "npm run unittest && npm run test:examples && npm run format",
|
|
55
56
|
"test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"clean_types": "../../scripts/cleanTypes.js"
|
|
57
|
+
"tsc": "tsc",
|
|
58
|
+
"unittest": "tap --no-only --reporter=terse && tsc -p tsconfig.json --noEmit"
|
|
59
59
|
},
|
|
60
60
|
"tap": {
|
|
61
61
|
"check-coverage": false,
|
|
62
|
-
"coverage-report": [
|
|
63
|
-
"json-summary",
|
|
64
|
-
"text"
|
|
65
|
-
],
|
|
66
62
|
"node-arg": [
|
|
67
63
|
"--no-warnings",
|
|
68
64
|
"--experimental-loader",
|
|
@@ -85,51 +81,51 @@
|
|
|
85
81
|
}
|
|
86
82
|
},
|
|
87
83
|
"dependencies": {
|
|
88
|
-
"@babel/runtime": "^7.
|
|
84
|
+
"@babel/runtime": "^7.16.3",
|
|
89
85
|
"lodash.clonedeep": "^4.5.0",
|
|
90
86
|
"lodash.isplainobject": "^4.0.6"
|
|
91
87
|
},
|
|
92
88
|
"devDependencies": {
|
|
93
|
-
"@babel/cli": "^7.
|
|
94
|
-
"@babel/core": "^7.
|
|
95
|
-
"@babel/node": "^7.
|
|
96
|
-
"@babel/plugin-external-helpers": "^7.
|
|
97
|
-
"@babel/plugin-proposal-class-properties": "^7.
|
|
98
|
-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.
|
|
99
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.
|
|
100
|
-
"@babel/plugin-proposal-optional-chaining": "^7.
|
|
101
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
102
|
-
"@babel/preset-env": "^7.
|
|
103
|
-
"@babel/preset-typescript": "^7.
|
|
104
|
-
"@babel/register": "^7.
|
|
89
|
+
"@babel/cli": "^7.16.0",
|
|
90
|
+
"@babel/core": "^7.16.0",
|
|
91
|
+
"@babel/node": "^7.16.0",
|
|
92
|
+
"@babel/plugin-external-helpers": "^7.16.0",
|
|
93
|
+
"@babel/plugin-proposal-class-properties": "^7.16.0",
|
|
94
|
+
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
|
|
95
|
+
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
|
|
96
|
+
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
|
|
97
|
+
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
98
|
+
"@babel/preset-env": "^7.16.4",
|
|
99
|
+
"@babel/preset-typescript": "^7.16.0",
|
|
100
|
+
"@babel/register": "^7.16.0",
|
|
105
101
|
"@istanbuljs/esm-loader-hook": "^0.1.2",
|
|
106
102
|
"@rollup/plugin-babel": "^5.3.0",
|
|
107
|
-
"@rollup/plugin-commonjs": "^
|
|
103
|
+
"@rollup/plugin-commonjs": "^21.0.1",
|
|
108
104
|
"@rollup/plugin-json": "^4.1.0",
|
|
109
|
-
"@rollup/plugin-node-resolve": "^13.0.
|
|
105
|
+
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
110
106
|
"@rollup/plugin-strip": "^2.1.0",
|
|
111
|
-
"@rollup/plugin-typescript": "^8.
|
|
107
|
+
"@rollup/plugin-typescript": "^8.3.0",
|
|
112
108
|
"@types/lodash.clonedeep": "^4.5.6",
|
|
113
109
|
"@types/lodash.isplainobject": "^4.0.6",
|
|
114
|
-
"@types/node": "^16.9
|
|
110
|
+
"@types/node": "^16.11.9",
|
|
115
111
|
"@types/tap": "^15.0.5",
|
|
116
|
-
"@typescript-eslint/eslint-plugin": "^4.
|
|
117
|
-
"@typescript-eslint/parser": "^4.
|
|
118
|
-
"core-js": "^3.
|
|
112
|
+
"@typescript-eslint/eslint-plugin": "^5.4.0",
|
|
113
|
+
"@typescript-eslint/parser": "^5.4.0",
|
|
114
|
+
"core-js": "^3.19.1",
|
|
119
115
|
"cross-env": "^7.0.3",
|
|
120
|
-
"eslint": "^
|
|
121
|
-
"lect": "^0.18.
|
|
122
|
-
"rollup": "^2.
|
|
116
|
+
"eslint": "^8.3.0",
|
|
117
|
+
"lect": "^0.18.6",
|
|
118
|
+
"rollup": "^2.60.0",
|
|
123
119
|
"rollup-plugin-ascii": "^0.0.3",
|
|
124
120
|
"rollup-plugin-banner": "^0.2.1",
|
|
125
121
|
"rollup-plugin-cleanup": "^3.2.1",
|
|
126
|
-
"rollup-plugin-dts": "^4.0.
|
|
122
|
+
"rollup-plugin-dts": "^4.0.1",
|
|
127
123
|
"rollup-plugin-terser": "^7.0.2",
|
|
128
|
-
"tap": "^15.
|
|
124
|
+
"tap": "^15.1.2",
|
|
129
125
|
"tslib": "^2.3.1",
|
|
130
|
-
"typescript": "^4.
|
|
126
|
+
"typescript": "^4.5.2"
|
|
131
127
|
},
|
|
132
128
|
"engines": {
|
|
133
|
-
"node": ">=
|
|
129
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
134
130
|
}
|
|
135
131
|
}
|