@nyaomaru/divider 2.0.8 → 2.0.9

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/dist/index.cjs CHANGED
@@ -108,6 +108,9 @@ function isNestedStringArray(value) {
108
108
  const firstRow = value[0];
109
109
  return Array.isArray(firstRow) && firstRow.every((item) => isString(item));
110
110
  }
111
+ function isSpaceOrTab(value) {
112
+ return value === WHITE_SPACE || value === TAB;
113
+ }
111
114
  function isWhitespaceOnly(value) {
112
115
  return value.trim() === "";
113
116
  }
@@ -488,19 +491,19 @@ function dividePreserve(input, separator) {
488
491
  }
489
492
 
490
493
  // src/utils/strip-outer-quotes.ts
491
- var findNonSpaceBounds = (text, isWhitespace) => {
494
+ var findNonSpaceBounds = (text) => {
492
495
  let left = 0;
493
496
  let right = text.length - 1;
494
- while (left <= right && isWhitespace(text[left])) left++;
495
- while (right >= left && isWhitespace(text[right])) right--;
497
+ while (left <= right && isSpaceOrTab(text[left])) left++;
498
+ while (right >= left && isSpaceOrTab(text[right])) right--;
496
499
  return { left, right };
497
500
  };
498
501
  var stripMatchedOuterQuotes = (text, left, rightQuoteStart, quote) => text.slice(0, left) + text.slice(left + quote.length, rightQuoteStart) + text.slice(rightQuoteStart + quote.length);
499
502
  var removeQuoteAt = (text, start, quote) => text.slice(0, start) + text.slice(start + quote.length);
500
- var stripTrailingQuote = (text, quote, isWhitespace) => {
503
+ var stripTrailingQuote = (text, quote) => {
501
504
  const quoteLength = quote.length;
502
505
  let lastNonSpaceIndex = text.length - 1;
503
- while (lastNonSpaceIndex >= 0 && isWhitespace(text[lastNonSpaceIndex])) {
506
+ while (lastNonSpaceIndex >= 0 && isSpaceOrTab(text[lastNonSpaceIndex])) {
504
507
  lastNonSpaceIndex--;
505
508
  }
506
509
  const trailingQuoteStart = lastNonSpaceIndex - quoteLength + 1;
@@ -509,9 +512,9 @@ var stripTrailingQuote = (text, quote, isWhitespace) => {
509
512
  }
510
513
  return removeQuoteAt(text, trailingQuoteStart, quote);
511
514
  };
512
- var stripOuterQuotesRaw = (text, quote, lenient, isWhitespace) => {
515
+ var stripOuterQuotesRaw = (text, quote, lenient) => {
513
516
  if (quote.length === 0) return text;
514
- const { left, right } = findNonSpaceBounds(text, isWhitespace);
517
+ const { left, right } = findNonSpaceBounds(text);
515
518
  if (left > right) return text;
516
519
  if (!text.startsWith(quote, left)) return text;
517
520
  const rightQuoteStart = right - quote.length + 1;
@@ -520,11 +523,10 @@ var stripOuterQuotesRaw = (text, quote, lenient, isWhitespace) => {
520
523
  }
521
524
  if (!lenient) return text;
522
525
  const withoutLeading = removeQuoteAt(text, left, quote);
523
- return stripTrailingQuote(withoutLeading, quote, isWhitespace);
526
+ return stripTrailingQuote(withoutLeading, quote);
524
527
  };
525
528
  function stripOuterQuotes(text, quoteChar, { lenient = true } = {}) {
526
- const isWhitespace = (char) => char === WHITE_SPACE || char === TAB;
527
- const stripped = stripOuterQuotesRaw(text, quoteChar, lenient, isWhitespace);
529
+ const stripped = stripOuterQuotesRaw(text, quoteChar, lenient);
528
530
  if (quoteChar.length === 0) return stripped;
529
531
  const escapedPair = quoteChar + quoteChar;
530
532
  return stripped.split(escapedPair).join(quoteChar);
package/dist/index.js CHANGED
@@ -74,6 +74,9 @@ function isNestedStringArray(value) {
74
74
  const firstRow = value[0];
75
75
  return Array.isArray(firstRow) && firstRow.every((item) => isString(item));
76
76
  }
77
+ function isSpaceOrTab(value) {
78
+ return value === WHITE_SPACE || value === TAB;
79
+ }
77
80
  function isWhitespaceOnly(value) {
78
81
  return value.trim() === "";
79
82
  }
@@ -454,19 +457,19 @@ function dividePreserve(input, separator) {
454
457
  }
455
458
 
456
459
  // src/utils/strip-outer-quotes.ts
457
- var findNonSpaceBounds = (text, isWhitespace) => {
460
+ var findNonSpaceBounds = (text) => {
458
461
  let left = 0;
459
462
  let right = text.length - 1;
460
- while (left <= right && isWhitespace(text[left])) left++;
461
- while (right >= left && isWhitespace(text[right])) right--;
463
+ while (left <= right && isSpaceOrTab(text[left])) left++;
464
+ while (right >= left && isSpaceOrTab(text[right])) right--;
462
465
  return { left, right };
463
466
  };
464
467
  var stripMatchedOuterQuotes = (text, left, rightQuoteStart, quote) => text.slice(0, left) + text.slice(left + quote.length, rightQuoteStart) + text.slice(rightQuoteStart + quote.length);
465
468
  var removeQuoteAt = (text, start, quote) => text.slice(0, start) + text.slice(start + quote.length);
466
- var stripTrailingQuote = (text, quote, isWhitespace) => {
469
+ var stripTrailingQuote = (text, quote) => {
467
470
  const quoteLength = quote.length;
468
471
  let lastNonSpaceIndex = text.length - 1;
469
- while (lastNonSpaceIndex >= 0 && isWhitespace(text[lastNonSpaceIndex])) {
472
+ while (lastNonSpaceIndex >= 0 && isSpaceOrTab(text[lastNonSpaceIndex])) {
470
473
  lastNonSpaceIndex--;
471
474
  }
472
475
  const trailingQuoteStart = lastNonSpaceIndex - quoteLength + 1;
@@ -475,9 +478,9 @@ var stripTrailingQuote = (text, quote, isWhitespace) => {
475
478
  }
476
479
  return removeQuoteAt(text, trailingQuoteStart, quote);
477
480
  };
478
- var stripOuterQuotesRaw = (text, quote, lenient, isWhitespace) => {
481
+ var stripOuterQuotesRaw = (text, quote, lenient) => {
479
482
  if (quote.length === 0) return text;
480
- const { left, right } = findNonSpaceBounds(text, isWhitespace);
483
+ const { left, right } = findNonSpaceBounds(text);
481
484
  if (left > right) return text;
482
485
  if (!text.startsWith(quote, left)) return text;
483
486
  const rightQuoteStart = right - quote.length + 1;
@@ -486,11 +489,10 @@ var stripOuterQuotesRaw = (text, quote, lenient, isWhitespace) => {
486
489
  }
487
490
  if (!lenient) return text;
488
491
  const withoutLeading = removeQuoteAt(text, left, quote);
489
- return stripTrailingQuote(withoutLeading, quote, isWhitespace);
492
+ return stripTrailingQuote(withoutLeading, quote);
490
493
  };
491
494
  function stripOuterQuotes(text, quoteChar, { lenient = true } = {}) {
492
- const isWhitespace = (char) => char === WHITE_SPACE || char === TAB;
493
- const stripped = stripOuterQuotesRaw(text, quoteChar, lenient, isWhitespace);
495
+ const stripped = stripOuterQuotesRaw(text, quoteChar, lenient);
494
496
  if (quoteChar.length === 0) return stripped;
495
497
  const escapedPair = quoteChar + quoteChar;
496
498
  return stripped.split(escapedPair).join(quoteChar);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nyaomaru/divider",
3
3
  "type": "module",
4
- "version": "2.0.8",
4
+ "version": "2.0.9",
5
5
  "description": "To divide string or string[] with a given separator",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",