@nyaomaru/divider 1.9.11 → 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 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/logo.svg" width="200px" align="center" alt="Divider logo" />
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">
package/dist/index.cjs CHANGED
@@ -234,7 +234,7 @@ function divideString(input, numSeparators, strSeparators, options) {
234
234
  const sortedNumSeparators = sortAscending(numSeparators);
235
235
  const parts = sliceByIndexes(input, sortedNumSeparators);
236
236
  const segments = regex ? parts.flatMap((part) => part.split(regex)) : parts;
237
- return shouldPreserveEmpty ? segments : segments.filter((segment) => segment !== "");
237
+ return shouldPreserveEmpty ? segments : segments.filter((segment) => !isEmptyString(segment));
238
238
  }
239
239
 
240
240
  // src/utils/array.ts
@@ -268,7 +268,7 @@ function extractOptions(args) {
268
268
  }
269
269
  function trimSegments(segments, preserveEmpty) {
270
270
  const trimmed = segments.map((segment) => segment.trim());
271
- return preserveEmpty ? trimmed : trimmed.filter((segment) => segment !== "");
271
+ return preserveEmpty ? trimmed : trimmed.filter((segment) => !isEmptyString(segment));
272
272
  }
273
273
  function trimNestedSegments(rows, preserveEmpty) {
274
274
  return rows.map((row) => trimSegments(row, preserveEmpty));
@@ -459,11 +459,11 @@ function quotedDivide(line, {
459
459
  currentFieldBuffer = "";
460
460
  };
461
461
  for (const piece of pieces) {
462
- currentFieldBuffer = currentFieldBuffer === "" ? piece : currentFieldBuffer + delimiter + piece;
462
+ currentFieldBuffer = isEmptyString(currentFieldBuffer) ? piece : currentFieldBuffer + delimiter + piece;
463
463
  insideQuotes = countUnescaped(currentFieldBuffer, quote) % 2 === 1;
464
464
  if (!insideQuotes) flush();
465
465
  }
466
- if (currentFieldBuffer !== "") flush();
466
+ if (!isEmptyString(currentFieldBuffer)) flush();
467
467
  return fields;
468
468
  }
469
469
 
@@ -499,12 +499,12 @@ function emailDivider(input, options = {}) {
499
499
  // src/presets/path-divider.ts
500
500
  function pathDivider(input, options = {}) {
501
501
  const { trim = false, collapse = true } = options;
502
- if (input === "") return [""];
502
+ if (isEmptyString(input)) return [""];
503
503
  const segments = collapse ? divider(input, PATH_SEPARATORS.SLASH, PATH_SEPARATORS.ALT) : dividePreserve(input, PATH_SEPARATORS.ALT).flatMap(
504
504
  (part) => dividePreserve(part, PATH_SEPARATORS.SLASH)
505
505
  );
506
506
  const maybeTrimmed = trim ? segments.map((segment) => segment.trim()) : segments;
507
- return collapse ? maybeTrimmed.filter((segment) => segment !== "") : maybeTrimmed;
507
+ return collapse ? maybeTrimmed.filter((segment) => !isEmptyString(segment)) : maybeTrimmed;
508
508
  }
509
509
  // Annotate the CommonJS export names for ESM import in node:
510
510
  0 && (module.exports = {
package/dist/index.js CHANGED
@@ -201,7 +201,7 @@ function divideString(input, numSeparators, strSeparators, options) {
201
201
  const sortedNumSeparators = sortAscending(numSeparators);
202
202
  const parts = sliceByIndexes(input, sortedNumSeparators);
203
203
  const segments = regex ? parts.flatMap((part) => part.split(regex)) : parts;
204
- return shouldPreserveEmpty ? segments : segments.filter((segment) => segment !== "");
204
+ return shouldPreserveEmpty ? segments : segments.filter((segment) => !isEmptyString(segment));
205
205
  }
206
206
 
207
207
  // src/utils/array.ts
@@ -235,7 +235,7 @@ function extractOptions(args) {
235
235
  }
236
236
  function trimSegments(segments, preserveEmpty) {
237
237
  const trimmed = segments.map((segment) => segment.trim());
238
- return preserveEmpty ? trimmed : trimmed.filter((segment) => segment !== "");
238
+ return preserveEmpty ? trimmed : trimmed.filter((segment) => !isEmptyString(segment));
239
239
  }
240
240
  function trimNestedSegments(rows, preserveEmpty) {
241
241
  return rows.map((row) => trimSegments(row, preserveEmpty));
@@ -426,11 +426,11 @@ function quotedDivide(line, {
426
426
  currentFieldBuffer = "";
427
427
  };
428
428
  for (const piece of pieces) {
429
- currentFieldBuffer = currentFieldBuffer === "" ? piece : currentFieldBuffer + delimiter + piece;
429
+ currentFieldBuffer = isEmptyString(currentFieldBuffer) ? piece : currentFieldBuffer + delimiter + piece;
430
430
  insideQuotes = countUnescaped(currentFieldBuffer, quote) % 2 === 1;
431
431
  if (!insideQuotes) flush();
432
432
  }
433
- if (currentFieldBuffer !== "") flush();
433
+ if (!isEmptyString(currentFieldBuffer)) flush();
434
434
  return fields;
435
435
  }
436
436
 
@@ -466,12 +466,12 @@ function emailDivider(input, options = {}) {
466
466
  // src/presets/path-divider.ts
467
467
  function pathDivider(input, options = {}) {
468
468
  const { trim = false, collapse = true } = options;
469
- if (input === "") return [""];
469
+ if (isEmptyString(input)) return [""];
470
470
  const segments = collapse ? divider(input, PATH_SEPARATORS.SLASH, PATH_SEPARATORS.ALT) : dividePreserve(input, PATH_SEPARATORS.ALT).flatMap(
471
471
  (part) => dividePreserve(part, PATH_SEPARATORS.SLASH)
472
472
  );
473
473
  const maybeTrimmed = trim ? segments.map((segment) => segment.trim()) : segments;
474
- return collapse ? maybeTrimmed.filter((segment) => segment !== "") : maybeTrimmed;
474
+ return collapse ? maybeTrimmed.filter((segment) => !isEmptyString(segment)) : maybeTrimmed;
475
475
  }
476
476
  export {
477
477
  csvDivider,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nyaomaru/divider",
3
3
  "type": "module",
4
- "version": "1.9.11",
4
+ "version": "1.9.12",
5
5
  "description": "To divide string or string[] with a given separator",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",