@nyaomaru/divider 1.3.3 → 1.3.5
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/cjs/core/divider.js
CHANGED
|
@@ -14,9 +14,9 @@ function divider(input, ...args) {
|
|
|
14
14
|
// Extract the options from the input
|
|
15
15
|
const clonedArgs = [...args];
|
|
16
16
|
const lastArg = clonedArgs.at(-1);
|
|
17
|
-
const options = (0, is_1.isOptions)(lastArg) ? (clonedArgs.
|
|
17
|
+
const options = (0, is_1.isOptions)(lastArg) ? (clonedArgs.pop(), lastArg) : {};
|
|
18
18
|
// Filter out only numbers and strings
|
|
19
|
-
const { numSeparators, strSeparators } =
|
|
19
|
+
const { numSeparators, strSeparators } = clonedArgs.reduce((acc, arg) => {
|
|
20
20
|
if ((0, is_1.isNumber)(arg)) {
|
|
21
21
|
acc.numSeparators.push(arg);
|
|
22
22
|
}
|
package/dist/cjs/core/parser.js
CHANGED
|
@@ -12,7 +12,7 @@ function divideString(input, numSeparators, strSeparators) {
|
|
|
12
12
|
const regex = (0, regex_1.getRegex)(strSeparators);
|
|
13
13
|
// Divide by number delimiters
|
|
14
14
|
numSeparators.sort((a, b) => a - b);
|
|
15
|
-
|
|
15
|
+
const parts = (0, slice_1.sliceByIndexes)(input, numSeparators);
|
|
16
16
|
// Divide by string delimiters
|
|
17
17
|
return regex
|
|
18
18
|
? parts.flatMap((part) => part.split(regex)).filter(Boolean)
|
package/dist/cjs/utils/slice.js
CHANGED
|
@@ -8,7 +8,7 @@ function sliceByIndexes(input, indexes) {
|
|
|
8
8
|
const parts = [];
|
|
9
9
|
let start = 0;
|
|
10
10
|
for (const index of indexes) {
|
|
11
|
-
if (index <= start ||
|
|
11
|
+
if (index <= start || input.length <= index)
|
|
12
12
|
continue;
|
|
13
13
|
parts.push(input.slice(start, index));
|
|
14
14
|
start = index;
|
package/dist/esm/core/divider.js
CHANGED
|
@@ -11,9 +11,9 @@ export function divider(input, ...args) {
|
|
|
11
11
|
// Extract the options from the input
|
|
12
12
|
const clonedArgs = [...args];
|
|
13
13
|
const lastArg = clonedArgs.at(-1);
|
|
14
|
-
const options = isOptions(lastArg) ? (clonedArgs.
|
|
14
|
+
const options = isOptions(lastArg) ? (clonedArgs.pop(), lastArg) : {};
|
|
15
15
|
// Filter out only numbers and strings
|
|
16
|
-
const { numSeparators, strSeparators } =
|
|
16
|
+
const { numSeparators, strSeparators } = clonedArgs.reduce((acc, arg) => {
|
|
17
17
|
if (isNumber(arg)) {
|
|
18
18
|
acc.numSeparators.push(arg);
|
|
19
19
|
}
|
package/dist/esm/core/parser.js
CHANGED
|
@@ -9,7 +9,7 @@ export function divideString(input, numSeparators, strSeparators) {
|
|
|
9
9
|
const regex = getRegex(strSeparators);
|
|
10
10
|
// Divide by number delimiters
|
|
11
11
|
numSeparators.sort((a, b) => a - b);
|
|
12
|
-
|
|
12
|
+
const parts = sliceByIndexes(input, numSeparators);
|
|
13
13
|
// Divide by string delimiters
|
|
14
14
|
return regex
|
|
15
15
|
? parts.flatMap((part) => part.split(regex)).filter(Boolean)
|
package/dist/esm/utils/slice.js
CHANGED
|
@@ -5,7 +5,7 @@ export function sliceByIndexes(input, indexes) {
|
|
|
5
5
|
const parts = [];
|
|
6
6
|
let start = 0;
|
|
7
7
|
for (const index of indexes) {
|
|
8
|
-
if (index <= start ||
|
|
8
|
+
if (index <= start || input.length <= index)
|
|
9
9
|
continue;
|
|
10
10
|
parts.push(input.slice(start, index));
|
|
11
11
|
start = index;
|