string-left-right 4.1.0 → 5.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/README.md +4 -0
- package/dist/string-left-right.esm.js +2 -2
- package/dist/string-left-right.umd.js +2 -2
- package/package.json +50 -42
- package/dist/string-left-right.cjs.js +0 -455
- package/dist/string-left-right.dev.umd.js +0 -2600
|
@@ -1,455 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @name string-left-right
|
|
3
|
-
* @fileoverview Looks up the first non-whitespace character to the left/right of a given index
|
|
4
|
-
* @version 4.1.0
|
|
5
|
-
* @author Roy Revelt, Codsen Ltd
|
|
6
|
-
* @license MIT
|
|
7
|
-
* {@link https://codsen.com/os/string-left-right/}
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
'use strict';
|
|
11
|
-
|
|
12
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
13
|
-
|
|
14
|
-
var _typeof = require('@babel/runtime/helpers/typeof');
|
|
15
|
-
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
16
|
-
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
17
|
-
var isObj = require('lodash.isplainobject');
|
|
18
|
-
var clone = require('lodash.clonedeep');
|
|
19
|
-
|
|
20
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
21
|
-
|
|
22
|
-
var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
|
|
23
|
-
var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
|
|
24
|
-
var _objectSpread__default = /*#__PURE__*/_interopDefaultLegacy(_objectSpread);
|
|
25
|
-
var isObj__default = /*#__PURE__*/_interopDefaultLegacy(isObj);
|
|
26
|
-
var clone__default = /*#__PURE__*/_interopDefaultLegacy(clone);
|
|
27
|
-
|
|
28
|
-
var version$1 = "4.1.0";
|
|
29
|
-
|
|
30
|
-
var version = version$1;
|
|
31
|
-
var RAWNBSP = "\xA0";
|
|
32
|
-
function x(something) {
|
|
33
|
-
var res = {
|
|
34
|
-
value: something,
|
|
35
|
-
hungry: false,
|
|
36
|
-
optional: false
|
|
37
|
-
};
|
|
38
|
-
if ((res.value.endsWith("?*") || res.value.endsWith("*?")) && res.value.length > 2) {
|
|
39
|
-
res.value = res.value.slice(0, res.value.length - 2);
|
|
40
|
-
res.optional = true;
|
|
41
|
-
res.hungry = true;
|
|
42
|
-
} else if (res.value.endsWith("?") && res.value.length > 1) {
|
|
43
|
-
res.value = res.value.slice(0, ~-res.value.length);
|
|
44
|
-
res.optional = true;
|
|
45
|
-
} else if (res.value.endsWith("*") && res.value.length > 1) {
|
|
46
|
-
res.value = res.value.slice(0, ~-res.value.length);
|
|
47
|
-
res.hungry = true;
|
|
48
|
-
}
|
|
49
|
-
return res;
|
|
50
|
-
}
|
|
51
|
-
function isNum(something) {
|
|
52
|
-
return typeof something === "number";
|
|
53
|
-
}
|
|
54
|
-
function isStr(something) {
|
|
55
|
-
return typeof something === "string";
|
|
56
|
-
}
|
|
57
|
-
function rightMain(_ref) {
|
|
58
|
-
var str = _ref.str,
|
|
59
|
-
_ref$idx = _ref.idx,
|
|
60
|
-
idx = _ref$idx === void 0 ? 0 : _ref$idx,
|
|
61
|
-
_ref$stopAtNewlines = _ref.stopAtNewlines,
|
|
62
|
-
stopAtNewlines = _ref$stopAtNewlines === void 0 ? false : _ref$stopAtNewlines,
|
|
63
|
-
_ref$stopAtRawNbsp = _ref.stopAtRawNbsp,
|
|
64
|
-
stopAtRawNbsp = _ref$stopAtRawNbsp === void 0 ? false : _ref$stopAtRawNbsp;
|
|
65
|
-
if (typeof str !== "string" || !str.length) {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
if (!idx || typeof idx !== "number") {
|
|
69
|
-
idx = 0;
|
|
70
|
-
}
|
|
71
|
-
if (!str[idx + 1]) {
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
if (
|
|
75
|
-
str[idx + 1] && (
|
|
76
|
-
str[idx + 1].trim() ||
|
|
77
|
-
stopAtNewlines &&
|
|
78
|
-
"\n\r".includes(str[idx + 1]) ||
|
|
79
|
-
stopAtRawNbsp &&
|
|
80
|
-
str[idx + 1] === RAWNBSP)) {
|
|
81
|
-
return idx + 1;
|
|
82
|
-
}
|
|
83
|
-
if (
|
|
84
|
-
str[idx + 2] && (
|
|
85
|
-
str[idx + 2].trim() ||
|
|
86
|
-
stopAtNewlines &&
|
|
87
|
-
"\n\r".includes(str[idx + 2]) ||
|
|
88
|
-
stopAtRawNbsp &&
|
|
89
|
-
str[idx + 2] === RAWNBSP)) {
|
|
90
|
-
return idx + 2;
|
|
91
|
-
}
|
|
92
|
-
for (var i = idx + 1, len = str.length; i < len; i++) {
|
|
93
|
-
if (
|
|
94
|
-
str[i].trim() ||
|
|
95
|
-
stopAtNewlines &&
|
|
96
|
-
"\n\r".includes(str[i]) ||
|
|
97
|
-
stopAtRawNbsp &&
|
|
98
|
-
str[i] === RAWNBSP) {
|
|
99
|
-
return i;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
function right(str) {
|
|
105
|
-
var idx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
106
|
-
return rightMain({
|
|
107
|
-
str: str,
|
|
108
|
-
idx: idx,
|
|
109
|
-
stopAtNewlines: false,
|
|
110
|
-
stopAtRawNbsp: false
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
function rightStopAtNewLines(str, idx) {
|
|
114
|
-
return rightMain({
|
|
115
|
-
str: str,
|
|
116
|
-
idx: idx,
|
|
117
|
-
stopAtNewlines: true,
|
|
118
|
-
stopAtRawNbsp: false
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
function rightStopAtRawNbsp(str, idx) {
|
|
122
|
-
return rightMain({
|
|
123
|
-
str: str,
|
|
124
|
-
idx: idx,
|
|
125
|
-
stopAtNewlines: false,
|
|
126
|
-
stopAtRawNbsp: true
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
function leftMain(_ref2) {
|
|
130
|
-
var str = _ref2.str,
|
|
131
|
-
idx = _ref2.idx,
|
|
132
|
-
stopAtNewlines = _ref2.stopAtNewlines,
|
|
133
|
-
stopAtRawNbsp = _ref2.stopAtRawNbsp;
|
|
134
|
-
if (typeof str !== "string" || !str.length) {
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
if (!idx || typeof idx !== "number") {
|
|
138
|
-
idx = 0;
|
|
139
|
-
}
|
|
140
|
-
if (idx < 1) {
|
|
141
|
-
return null;
|
|
142
|
-
}
|
|
143
|
-
if (
|
|
144
|
-
str[~-idx] && (
|
|
145
|
-
str[~-idx].trim() ||
|
|
146
|
-
stopAtNewlines &&
|
|
147
|
-
"\n\r".includes(str[~-idx]) ||
|
|
148
|
-
stopAtRawNbsp &&
|
|
149
|
-
str[~-idx] === RAWNBSP)) {
|
|
150
|
-
return ~-idx;
|
|
151
|
-
}
|
|
152
|
-
if (
|
|
153
|
-
str[idx - 2] && (
|
|
154
|
-
str[idx - 2].trim() ||
|
|
155
|
-
stopAtNewlines &&
|
|
156
|
-
"\n\r".includes(str[idx - 2]) ||
|
|
157
|
-
stopAtRawNbsp &&
|
|
158
|
-
str[idx - 2] === RAWNBSP)) {
|
|
159
|
-
return idx - 2;
|
|
160
|
-
}
|
|
161
|
-
for (var i = idx; i--;) {
|
|
162
|
-
if (str[i] && (
|
|
163
|
-
str[i].trim() ||
|
|
164
|
-
stopAtNewlines &&
|
|
165
|
-
"\n\r".includes(str[i]) ||
|
|
166
|
-
stopAtRawNbsp &&
|
|
167
|
-
str[i] === RAWNBSP)) {
|
|
168
|
-
return i;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
return null;
|
|
172
|
-
}
|
|
173
|
-
function left(str) {
|
|
174
|
-
var idx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
175
|
-
return leftMain({
|
|
176
|
-
str: str,
|
|
177
|
-
idx: idx,
|
|
178
|
-
stopAtNewlines: false,
|
|
179
|
-
stopAtRawNbsp: false
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
function leftStopAtNewLines(str, idx) {
|
|
183
|
-
return leftMain({
|
|
184
|
-
str: str,
|
|
185
|
-
idx: idx,
|
|
186
|
-
stopAtNewlines: true,
|
|
187
|
-
stopAtRawNbsp: false
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
function leftStopAtRawNbsp(str, idx) {
|
|
191
|
-
return leftMain({
|
|
192
|
-
str: str,
|
|
193
|
-
idx: idx,
|
|
194
|
-
stopAtNewlines: false,
|
|
195
|
-
stopAtRawNbsp: true
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
function seq(direction, str, idx, opts, args) {
|
|
199
|
-
if (typeof str !== "string" || !str.length) {
|
|
200
|
-
return null;
|
|
201
|
-
}
|
|
202
|
-
if (typeof idx !== "number") {
|
|
203
|
-
idx = 0;
|
|
204
|
-
}
|
|
205
|
-
if (direction === "right" && !str[idx + 1] || direction === "left" && !str[~-idx]) {
|
|
206
|
-
return null;
|
|
207
|
-
}
|
|
208
|
-
var lastFinding = idx;
|
|
209
|
-
var gaps = [];
|
|
210
|
-
var leftmostChar;
|
|
211
|
-
var rightmostChar;
|
|
212
|
-
var satiated;
|
|
213
|
-
var i = 0;
|
|
214
|
-
while (i < args.length) {
|
|
215
|
-
if (!isStr(args[i]) || !args[i].length) {
|
|
216
|
-
i += 1;
|
|
217
|
-
continue;
|
|
218
|
-
}
|
|
219
|
-
var _x = x(args[i]),
|
|
220
|
-
value = _x.value,
|
|
221
|
-
optional = _x.optional,
|
|
222
|
-
hungry = _x.hungry;
|
|
223
|
-
var whattsOnTheSide = direction === "right" ? right(str, lastFinding) : left(str, lastFinding);
|
|
224
|
-
if (opts.i && str[whattsOnTheSide].toLowerCase() === value.toLowerCase() || !opts.i && str[whattsOnTheSide] === value) {
|
|
225
|
-
var temp = direction === "right" ? right(str, whattsOnTheSide) : left(str, whattsOnTheSide);
|
|
226
|
-
if (hungry && (opts.i && str[temp].toLowerCase() === value.toLowerCase() || !opts.i && str[temp] === value)) {
|
|
227
|
-
satiated = true;
|
|
228
|
-
} else {
|
|
229
|
-
i += 1;
|
|
230
|
-
}
|
|
231
|
-
if (typeof whattsOnTheSide === "number" && direction === "right" && whattsOnTheSide > lastFinding + 1) {
|
|
232
|
-
gaps.push([lastFinding + 1, whattsOnTheSide]);
|
|
233
|
-
} else if (direction === "left" && typeof whattsOnTheSide === "number" && whattsOnTheSide < ~-lastFinding) {
|
|
234
|
-
gaps.unshift([whattsOnTheSide + 1, lastFinding]);
|
|
235
|
-
}
|
|
236
|
-
lastFinding = whattsOnTheSide;
|
|
237
|
-
if (direction === "right") {
|
|
238
|
-
if (leftmostChar === undefined) {
|
|
239
|
-
leftmostChar = whattsOnTheSide;
|
|
240
|
-
}
|
|
241
|
-
rightmostChar = whattsOnTheSide;
|
|
242
|
-
} else {
|
|
243
|
-
if (rightmostChar === undefined) {
|
|
244
|
-
rightmostChar = whattsOnTheSide;
|
|
245
|
-
}
|
|
246
|
-
leftmostChar = whattsOnTheSide;
|
|
247
|
-
}
|
|
248
|
-
} else if (optional) {
|
|
249
|
-
i += 1;
|
|
250
|
-
continue;
|
|
251
|
-
} else if (satiated) {
|
|
252
|
-
i += 1;
|
|
253
|
-
satiated = undefined;
|
|
254
|
-
continue;
|
|
255
|
-
} else {
|
|
256
|
-
return null;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
if (leftmostChar === undefined || rightmostChar === undefined) {
|
|
260
|
-
return null;
|
|
261
|
-
}
|
|
262
|
-
return {
|
|
263
|
-
gaps: gaps,
|
|
264
|
-
leftmostChar: leftmostChar,
|
|
265
|
-
rightmostChar: rightmostChar
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
var seqDefaults = {
|
|
269
|
-
i: false
|
|
270
|
-
};
|
|
271
|
-
function leftSeq(str, idx) {
|
|
272
|
-
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
273
|
-
args[_key - 2] = arguments[_key];
|
|
274
|
-
}
|
|
275
|
-
if (!args || !args.length) {
|
|
276
|
-
throw new Error("string-left-right/leftSeq(): only two input arguments were passed! Did you intend to use left() method instead?");
|
|
277
|
-
}
|
|
278
|
-
var opts;
|
|
279
|
-
if (isObj__default['default'](args[0])) {
|
|
280
|
-
opts = _objectSpread__default['default'](_objectSpread__default['default']({}, seqDefaults), args.shift());
|
|
281
|
-
} else {
|
|
282
|
-
opts = seqDefaults;
|
|
283
|
-
}
|
|
284
|
-
return seq("left", str, idx, opts, Array.from(args).reverse());
|
|
285
|
-
}
|
|
286
|
-
function rightSeq(str, idx) {
|
|
287
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
288
|
-
args[_key2 - 2] = arguments[_key2];
|
|
289
|
-
}
|
|
290
|
-
if (!args || !args.length) {
|
|
291
|
-
throw new Error("string-left-right/rightSeq(): only two input arguments were passed! Did you intend to use right() method instead?");
|
|
292
|
-
}
|
|
293
|
-
var opts;
|
|
294
|
-
if (isObj__default['default'](args[0])) {
|
|
295
|
-
opts = _objectSpread__default['default'](_objectSpread__default['default']({}, seqDefaults), args.shift());
|
|
296
|
-
} else {
|
|
297
|
-
opts = seqDefaults;
|
|
298
|
-
}
|
|
299
|
-
return seq("right", str, idx, opts, args);
|
|
300
|
-
}
|
|
301
|
-
function chomp(direction, str, idx, opts) {
|
|
302
|
-
var args = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
|
|
303
|
-
if (typeof str !== "string" || !str.length) {
|
|
304
|
-
return null;
|
|
305
|
-
}
|
|
306
|
-
if (!idx || typeof idx !== "number") {
|
|
307
|
-
idx = 0;
|
|
308
|
-
}
|
|
309
|
-
if (direction === "right" && !str[idx + 1] || direction === "left" && +idx === 0) {
|
|
310
|
-
return null;
|
|
311
|
-
}
|
|
312
|
-
var lastRes = null;
|
|
313
|
-
var lastIdx = null;
|
|
314
|
-
do {
|
|
315
|
-
lastRes = direction === "right" ? rightSeq.apply(void 0, [str, typeof lastIdx === "number" ? lastIdx : idx].concat(_toConsumableArray__default['default'](args))) : leftSeq.apply(void 0, [str, typeof lastIdx === "number" ? lastIdx : idx].concat(_toConsumableArray__default['default'](args)));
|
|
316
|
-
if (lastRes !== null) {
|
|
317
|
-
lastIdx = direction === "right" ? lastRes.rightmostChar : lastRes.leftmostChar;
|
|
318
|
-
}
|
|
319
|
-
} while (lastRes);
|
|
320
|
-
if (lastIdx != null && direction === "right") {
|
|
321
|
-
lastIdx += 1;
|
|
322
|
-
}
|
|
323
|
-
if (lastIdx === null) {
|
|
324
|
-
return null;
|
|
325
|
-
}
|
|
326
|
-
if (direction === "right") {
|
|
327
|
-
if (str[lastIdx] && str[lastIdx].trim()) {
|
|
328
|
-
return lastIdx;
|
|
329
|
-
}
|
|
330
|
-
var whatsOnTheRight = right(str, lastIdx);
|
|
331
|
-
if (!opts || opts.mode === 0) {
|
|
332
|
-
if (whatsOnTheRight === lastIdx + 1) {
|
|
333
|
-
return lastIdx;
|
|
334
|
-
}
|
|
335
|
-
if (str.slice(lastIdx, whatsOnTheRight || str.length).trim() || str.slice(lastIdx, whatsOnTheRight || str.length).includes("\n") || str.slice(lastIdx, whatsOnTheRight || str.length).includes("\r")) {
|
|
336
|
-
for (var y = lastIdx, len = str.length; y < len; y++) {
|
|
337
|
-
if ("\n\r".includes(str[y])) {
|
|
338
|
-
return y;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
} else {
|
|
342
|
-
return whatsOnTheRight ? ~-whatsOnTheRight : str.length;
|
|
343
|
-
}
|
|
344
|
-
} else if (opts.mode === 1) {
|
|
345
|
-
return lastIdx;
|
|
346
|
-
} else if (opts.mode === 2) {
|
|
347
|
-
var remainderString = str.slice(lastIdx);
|
|
348
|
-
if (remainderString.trim() || remainderString.includes("\n") || remainderString.includes("\r")) {
|
|
349
|
-
for (var _y = lastIdx, _len3 = str.length; _y < _len3; _y++) {
|
|
350
|
-
if (str[_y].trim() || "\n\r".includes(str[_y])) {
|
|
351
|
-
return _y;
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
return str.length;
|
|
356
|
-
}
|
|
357
|
-
return whatsOnTheRight || str.length;
|
|
358
|
-
}
|
|
359
|
-
if (str[lastIdx] && str[~-lastIdx] && str[~-lastIdx].trim()) {
|
|
360
|
-
return lastIdx;
|
|
361
|
-
}
|
|
362
|
-
var whatsOnTheLeft = left(str, lastIdx);
|
|
363
|
-
if (!opts || opts.mode === 0) {
|
|
364
|
-
if (whatsOnTheLeft === lastIdx - 2) {
|
|
365
|
-
return lastIdx;
|
|
366
|
-
}
|
|
367
|
-
if (str.slice(0, lastIdx).trim() || str.slice(0, lastIdx).includes("\n") || str.slice(0, lastIdx).includes("\r")) {
|
|
368
|
-
for (var _y2 = lastIdx; _y2--;) {
|
|
369
|
-
if ("\n\r".includes(str[_y2]) || str[_y2].trim()) {
|
|
370
|
-
return _y2 + 1 + (str[_y2].trim() ? 1 : 0);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
return 0;
|
|
375
|
-
}
|
|
376
|
-
if (opts.mode === 1) {
|
|
377
|
-
return lastIdx;
|
|
378
|
-
}
|
|
379
|
-
if (opts.mode === 2) {
|
|
380
|
-
var _remainderString = str.slice(0, lastIdx);
|
|
381
|
-
if (_remainderString.trim() || _remainderString.includes("\n") || _remainderString.includes("\r")) {
|
|
382
|
-
for (var _y3 = lastIdx; _y3--;) {
|
|
383
|
-
if (str[_y3].trim() || "\n\r".includes(str[_y3])) {
|
|
384
|
-
return _y3 + 1;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
return 0;
|
|
389
|
-
}
|
|
390
|
-
return whatsOnTheLeft !== null ? whatsOnTheLeft + 1 : 0;
|
|
391
|
-
}
|
|
392
|
-
function chompLeft(str, idx) {
|
|
393
|
-
for (var _len4 = arguments.length, args = new Array(_len4 > 2 ? _len4 - 2 : 0), _key3 = 2; _key3 < _len4; _key3++) {
|
|
394
|
-
args[_key3 - 2] = arguments[_key3];
|
|
395
|
-
}
|
|
396
|
-
if (!args.length || args.length === 1 && isObj__default['default'](args[0])) {
|
|
397
|
-
return null;
|
|
398
|
-
}
|
|
399
|
-
var defaults = {
|
|
400
|
-
mode: 0
|
|
401
|
-
};
|
|
402
|
-
if (isObj__default['default'](args[0])) {
|
|
403
|
-
var opts = _objectSpread__default['default'](_objectSpread__default['default']({}, defaults), clone__default['default'](args[0]));
|
|
404
|
-
if (!opts.mode) {
|
|
405
|
-
opts.mode = 0;
|
|
406
|
-
} else if (isStr(opts.mode) && "0123".includes(opts.mode)) {
|
|
407
|
-
opts.mode = Number.parseInt(opts.mode, 10);
|
|
408
|
-
} else if (!isNum(opts.mode)) {
|
|
409
|
-
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 ".concat(opts.mode, " (type ").concat(_typeof__default['default'](opts.mode), ")"));
|
|
410
|
-
}
|
|
411
|
-
return chomp("left", str, idx, opts, clone__default['default'](args).slice(1));
|
|
412
|
-
}
|
|
413
|
-
if (!isStr(args[0])) {
|
|
414
|
-
return chomp("left", str, idx, defaults, clone__default['default'](args).slice(1));
|
|
415
|
-
}
|
|
416
|
-
return chomp("left", str, idx, defaults, clone__default['default'](args));
|
|
417
|
-
}
|
|
418
|
-
function chompRight(str, idx) {
|
|
419
|
-
for (var _len5 = arguments.length, args = new Array(_len5 > 2 ? _len5 - 2 : 0), _key4 = 2; _key4 < _len5; _key4++) {
|
|
420
|
-
args[_key4 - 2] = arguments[_key4];
|
|
421
|
-
}
|
|
422
|
-
if (!args.length || args.length === 1 && isObj__default['default'](args[0])) {
|
|
423
|
-
return null;
|
|
424
|
-
}
|
|
425
|
-
var defaults = {
|
|
426
|
-
mode: 0
|
|
427
|
-
};
|
|
428
|
-
if (isObj__default['default'](args[0])) {
|
|
429
|
-
var opts = _objectSpread__default['default'](_objectSpread__default['default']({}, defaults), clone__default['default'](args[0]));
|
|
430
|
-
if (!opts.mode) {
|
|
431
|
-
opts.mode = 0;
|
|
432
|
-
} else if (isStr(opts.mode) && "0123".includes(opts.mode)) {
|
|
433
|
-
opts.mode = Number.parseInt(opts.mode, 10);
|
|
434
|
-
} else if (!isNum(opts.mode)) {
|
|
435
|
-
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 ".concat(opts.mode, " (type ").concat(_typeof__default['default'](opts.mode), ")"));
|
|
436
|
-
}
|
|
437
|
-
return chomp("right", str, idx, opts, clone__default['default'](args).slice(1));
|
|
438
|
-
}
|
|
439
|
-
if (!isStr(args[0])) {
|
|
440
|
-
return chomp("right", str, idx, defaults, clone__default['default'](args).slice(1));
|
|
441
|
-
}
|
|
442
|
-
return chomp("right", str, idx, defaults, clone__default['default'](args));
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
exports.chompLeft = chompLeft;
|
|
446
|
-
exports.chompRight = chompRight;
|
|
447
|
-
exports.left = left;
|
|
448
|
-
exports.leftSeq = leftSeq;
|
|
449
|
-
exports.leftStopAtNewLines = leftStopAtNewLines;
|
|
450
|
-
exports.leftStopAtRawNbsp = leftStopAtRawNbsp;
|
|
451
|
-
exports.right = right;
|
|
452
|
-
exports.rightSeq = rightSeq;
|
|
453
|
-
exports.rightStopAtNewLines = rightStopAtNewLines;
|
|
454
|
-
exports.rightStopAtRawNbsp = rightStopAtRawNbsp;
|
|
455
|
-
exports.version = version;
|