@nyaomaru/divider 1.9.10 → 1.9.12
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/README.md +3 -3
- package/dist/index.cjs +12 -7
- package/dist/index.js +12 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Divider
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
<img src="https://raw.githubusercontent.com/nyaomaru/divider/main/
|
|
4
|
+
<img src="https://raw.githubusercontent.com/nyaomaru/divider/main/divider_image.png" width="600px" align="center" alt="Divider logo" />
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
@@ -276,8 +276,8 @@ const result = divider('a,,b', ',', { exclude: 'empty' });
|
|
|
276
276
|
const result = divider('a, ,b', ',', { exclude: 'whitespace' });
|
|
277
277
|
// ['a', 'b']
|
|
278
278
|
|
|
279
|
-
// You can combine with `trim` for clearer results
|
|
280
|
-
const result = divider('a, ,b', ',', {
|
|
279
|
+
// You can combine with `trim` for clearer results (note the trailing space)
|
|
280
|
+
const result = divider('a, ,b ', ',', {
|
|
281
281
|
trim: true,
|
|
282
282
|
exclude: 'whitespace',
|
|
283
283
|
});
|
package/dist/index.cjs
CHANGED
|
@@ -71,8 +71,13 @@ function isNumber(value) {
|
|
|
71
71
|
function isObject(value) {
|
|
72
72
|
return typeof value === "object" && value !== null;
|
|
73
73
|
}
|
|
74
|
-
function
|
|
74
|
+
function isPlainObject(value) {
|
|
75
75
|
if (!isObject(value)) return false;
|
|
76
|
+
const proto = Object.getPrototypeOf(value);
|
|
77
|
+
return proto === null || Object.getPrototypeOf(proto) === null;
|
|
78
|
+
}
|
|
79
|
+
function isOptions(value) {
|
|
80
|
+
if (!isPlainObject(value)) return false;
|
|
76
81
|
const options = value;
|
|
77
82
|
return DIVIDER_OPTION_KEYS.some((key) => Object.hasOwn(options, key));
|
|
78
83
|
}
|
|
@@ -229,7 +234,7 @@ function divideString(input, numSeparators, strSeparators, options) {
|
|
|
229
234
|
const sortedNumSeparators = sortAscending(numSeparators);
|
|
230
235
|
const parts = sliceByIndexes(input, sortedNumSeparators);
|
|
231
236
|
const segments = regex ? parts.flatMap((part) => part.split(regex)) : parts;
|
|
232
|
-
return shouldPreserveEmpty ? segments : segments.filter((segment) => segment
|
|
237
|
+
return shouldPreserveEmpty ? segments : segments.filter((segment) => !isEmptyString(segment));
|
|
233
238
|
}
|
|
234
239
|
|
|
235
240
|
// src/utils/array.ts
|
|
@@ -263,7 +268,7 @@ function extractOptions(args) {
|
|
|
263
268
|
}
|
|
264
269
|
function trimSegments(segments, preserveEmpty) {
|
|
265
270
|
const trimmed = segments.map((segment) => segment.trim());
|
|
266
|
-
return preserveEmpty ? trimmed : trimmed.filter((segment) => segment
|
|
271
|
+
return preserveEmpty ? trimmed : trimmed.filter((segment) => !isEmptyString(segment));
|
|
267
272
|
}
|
|
268
273
|
function trimNestedSegments(rows, preserveEmpty) {
|
|
269
274
|
return rows.map((row) => trimSegments(row, preserveEmpty));
|
|
@@ -454,11 +459,11 @@ function quotedDivide(line, {
|
|
|
454
459
|
currentFieldBuffer = "";
|
|
455
460
|
};
|
|
456
461
|
for (const piece of pieces) {
|
|
457
|
-
currentFieldBuffer = currentFieldBuffer
|
|
462
|
+
currentFieldBuffer = isEmptyString(currentFieldBuffer) ? piece : currentFieldBuffer + delimiter + piece;
|
|
458
463
|
insideQuotes = countUnescaped(currentFieldBuffer, quote) % 2 === 1;
|
|
459
464
|
if (!insideQuotes) flush();
|
|
460
465
|
}
|
|
461
|
-
if (currentFieldBuffer
|
|
466
|
+
if (!isEmptyString(currentFieldBuffer)) flush();
|
|
462
467
|
return fields;
|
|
463
468
|
}
|
|
464
469
|
|
|
@@ -494,12 +499,12 @@ function emailDivider(input, options = {}) {
|
|
|
494
499
|
// src/presets/path-divider.ts
|
|
495
500
|
function pathDivider(input, options = {}) {
|
|
496
501
|
const { trim = false, collapse = true } = options;
|
|
497
|
-
if (input
|
|
502
|
+
if (isEmptyString(input)) return [""];
|
|
498
503
|
const segments = collapse ? divider(input, PATH_SEPARATORS.SLASH, PATH_SEPARATORS.ALT) : dividePreserve(input, PATH_SEPARATORS.ALT).flatMap(
|
|
499
504
|
(part) => dividePreserve(part, PATH_SEPARATORS.SLASH)
|
|
500
505
|
);
|
|
501
506
|
const maybeTrimmed = trim ? segments.map((segment) => segment.trim()) : segments;
|
|
502
|
-
return collapse ? maybeTrimmed.filter((segment) => segment
|
|
507
|
+
return collapse ? maybeTrimmed.filter((segment) => !isEmptyString(segment)) : maybeTrimmed;
|
|
503
508
|
}
|
|
504
509
|
// Annotate the CommonJS export names for ESM import in node:
|
|
505
510
|
0 && (module.exports = {
|
package/dist/index.js
CHANGED
|
@@ -38,8 +38,13 @@ function isNumber(value) {
|
|
|
38
38
|
function isObject(value) {
|
|
39
39
|
return typeof value === "object" && value !== null;
|
|
40
40
|
}
|
|
41
|
-
function
|
|
41
|
+
function isPlainObject(value) {
|
|
42
42
|
if (!isObject(value)) return false;
|
|
43
|
+
const proto = Object.getPrototypeOf(value);
|
|
44
|
+
return proto === null || Object.getPrototypeOf(proto) === null;
|
|
45
|
+
}
|
|
46
|
+
function isOptions(value) {
|
|
47
|
+
if (!isPlainObject(value)) return false;
|
|
43
48
|
const options = value;
|
|
44
49
|
return DIVIDER_OPTION_KEYS.some((key) => Object.hasOwn(options, key));
|
|
45
50
|
}
|
|
@@ -196,7 +201,7 @@ function divideString(input, numSeparators, strSeparators, options) {
|
|
|
196
201
|
const sortedNumSeparators = sortAscending(numSeparators);
|
|
197
202
|
const parts = sliceByIndexes(input, sortedNumSeparators);
|
|
198
203
|
const segments = regex ? parts.flatMap((part) => part.split(regex)) : parts;
|
|
199
|
-
return shouldPreserveEmpty ? segments : segments.filter((segment) => segment
|
|
204
|
+
return shouldPreserveEmpty ? segments : segments.filter((segment) => !isEmptyString(segment));
|
|
200
205
|
}
|
|
201
206
|
|
|
202
207
|
// src/utils/array.ts
|
|
@@ -230,7 +235,7 @@ function extractOptions(args) {
|
|
|
230
235
|
}
|
|
231
236
|
function trimSegments(segments, preserveEmpty) {
|
|
232
237
|
const trimmed = segments.map((segment) => segment.trim());
|
|
233
|
-
return preserveEmpty ? trimmed : trimmed.filter((segment) => segment
|
|
238
|
+
return preserveEmpty ? trimmed : trimmed.filter((segment) => !isEmptyString(segment));
|
|
234
239
|
}
|
|
235
240
|
function trimNestedSegments(rows, preserveEmpty) {
|
|
236
241
|
return rows.map((row) => trimSegments(row, preserveEmpty));
|
|
@@ -421,11 +426,11 @@ function quotedDivide(line, {
|
|
|
421
426
|
currentFieldBuffer = "";
|
|
422
427
|
};
|
|
423
428
|
for (const piece of pieces) {
|
|
424
|
-
currentFieldBuffer = currentFieldBuffer
|
|
429
|
+
currentFieldBuffer = isEmptyString(currentFieldBuffer) ? piece : currentFieldBuffer + delimiter + piece;
|
|
425
430
|
insideQuotes = countUnescaped(currentFieldBuffer, quote) % 2 === 1;
|
|
426
431
|
if (!insideQuotes) flush();
|
|
427
432
|
}
|
|
428
|
-
if (currentFieldBuffer
|
|
433
|
+
if (!isEmptyString(currentFieldBuffer)) flush();
|
|
429
434
|
return fields;
|
|
430
435
|
}
|
|
431
436
|
|
|
@@ -461,12 +466,12 @@ function emailDivider(input, options = {}) {
|
|
|
461
466
|
// src/presets/path-divider.ts
|
|
462
467
|
function pathDivider(input, options = {}) {
|
|
463
468
|
const { trim = false, collapse = true } = options;
|
|
464
|
-
if (input
|
|
469
|
+
if (isEmptyString(input)) return [""];
|
|
465
470
|
const segments = collapse ? divider(input, PATH_SEPARATORS.SLASH, PATH_SEPARATORS.ALT) : dividePreserve(input, PATH_SEPARATORS.ALT).flatMap(
|
|
466
471
|
(part) => dividePreserve(part, PATH_SEPARATORS.SLASH)
|
|
467
472
|
);
|
|
468
473
|
const maybeTrimmed = trim ? segments.map((segment) => segment.trim()) : segments;
|
|
469
|
-
return collapse ? maybeTrimmed.filter((segment) => segment
|
|
474
|
+
return collapse ? maybeTrimmed.filter((segment) => !isEmptyString(segment)) : maybeTrimmed;
|
|
470
475
|
}
|
|
471
476
|
export {
|
|
472
477
|
csvDivider,
|