@nyaomaru/divider 1.3.6 → 1.3.7

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.
@@ -4,6 +4,7 @@ exports.divideString = divideString;
4
4
  const is_1 = require("@/utils/is");
5
5
  const regex_1 = require("@/utils/regex");
6
6
  const slice_1 = require("@/utils/slice");
7
+ const sort_1 = require("@/utils/sort");
7
8
  function divideString(input, numSeparators, strSeparators) {
8
9
  if ((0, is_1.isEmptyArray)(numSeparators) && (0, is_1.isEmptyArray)(strSeparators)) {
9
10
  return [input];
@@ -11,8 +12,8 @@ function divideString(input, numSeparators, strSeparators) {
11
12
  // Precompile regex for string separators
12
13
  const regex = (0, regex_1.getRegex)(strSeparators);
13
14
  // Divide by number delimiters
14
- numSeparators.sort((a, b) => a - b);
15
- const parts = (0, slice_1.sliceByIndexes)(input, numSeparators);
15
+ const sortedNumSeparators = (0, sort_1.sortAscending)(numSeparators);
16
+ const parts = (0, slice_1.sliceByIndexes)(input, sortedNumSeparators);
16
17
  // Divide by string delimiters
17
18
  return regex
18
19
  ? parts.flatMap((part) => part.split(regex)).filter(Boolean)
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sortAscending = sortAscending;
4
+ function sortAscending(numbers) {
5
+ return [...numbers].sort((a, b) => a - b);
6
+ }
@@ -1,6 +1,7 @@
1
1
  import { isEmptyArray } from '@/utils/is';
2
2
  import { getRegex } from '@/utils/regex';
3
3
  import { sliceByIndexes } from '@/utils/slice';
4
+ import { sortAscending } from '@/utils/sort';
4
5
  export function divideString(input, numSeparators, strSeparators) {
5
6
  if (isEmptyArray(numSeparators) && isEmptyArray(strSeparators)) {
6
7
  return [input];
@@ -8,8 +9,8 @@ export function divideString(input, numSeparators, strSeparators) {
8
9
  // Precompile regex for string separators
9
10
  const regex = getRegex(strSeparators);
10
11
  // Divide by number delimiters
11
- numSeparators.sort((a, b) => a - b);
12
- const parts = sliceByIndexes(input, numSeparators);
12
+ const sortedNumSeparators = sortAscending(numSeparators);
13
+ const parts = sliceByIndexes(input, sortedNumSeparators);
13
14
  // Divide by string delimiters
14
15
  return regex
15
16
  ? parts.flatMap((part) => part.split(regex)).filter(Boolean)
@@ -0,0 +1,3 @@
1
+ export function sortAscending(numbers) {
2
+ return [...numbers].sort((a, b) => a - b);
3
+ }
@@ -0,0 +1 @@
1
+ export declare function sortAscending(numbers: number[]): number[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nyaomaru/divider",
3
3
  "type": "module",
4
- "version": "1.3.6",
4
+ "version": "1.3.7",
5
5
  "description": "To divide string or string[] with a given separator",
6
6
  "main": "dist/cjs/index.js",
7
7
  "module": "dist/esm/index.js",