@nyaomaru/divider 1.0.17 → 1.0.19
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
|
@@ -4,7 +4,8 @@ exports.divider = divider;
|
|
|
4
4
|
const parser_1 = require("@/core/parser");
|
|
5
5
|
const validator_1 = require("@/core/validator");
|
|
6
6
|
function divider(input, ...args) {
|
|
7
|
-
if (input
|
|
7
|
+
if (typeof input !== 'string' && !Array.isArray(input)) {
|
|
8
|
+
console.warn("divider: 'input' must be a string or an array of strings. So returning an empty array.");
|
|
8
9
|
return [];
|
|
9
10
|
}
|
|
10
11
|
if (args.length === 0) {
|
|
@@ -12,18 +13,17 @@ function divider(input, ...args) {
|
|
|
12
13
|
}
|
|
13
14
|
// Extract the options from the input
|
|
14
15
|
const lastArg = args[args.length - 1];
|
|
15
|
-
const options = (0, validator_1.isOptions)(lastArg) ? lastArg : {};
|
|
16
|
+
const options = (0, validator_1.isOptions)(lastArg) ? (args.pop(), lastArg) : {};
|
|
16
17
|
// Filter out only numbers and strings
|
|
17
|
-
const numSeparators =
|
|
18
|
-
const strSeparators = [];
|
|
19
|
-
for (const arg of args) {
|
|
18
|
+
const { numSeparators, strSeparators } = args.reduce((acc, arg) => {
|
|
20
19
|
if (typeof arg === 'number') {
|
|
21
|
-
numSeparators.push(arg);
|
|
20
|
+
acc.numSeparators.push(arg);
|
|
22
21
|
}
|
|
23
22
|
else if (typeof arg === 'string') {
|
|
24
|
-
strSeparators.push(arg);
|
|
23
|
+
acc.strSeparators.push(arg);
|
|
25
24
|
}
|
|
26
|
-
|
|
25
|
+
return acc;
|
|
26
|
+
}, { numSeparators: [], strSeparators: [] });
|
|
27
27
|
if (typeof input === 'string') {
|
|
28
28
|
return (0, parser_1.divideString)(input, numSeparators, strSeparators);
|
|
29
29
|
}
|
package/dist/esm/core/divider.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { divideString } from '@/core/parser';
|
|
2
2
|
import { isOptions } from '@/core/validator';
|
|
3
3
|
export function divider(input, ...args) {
|
|
4
|
-
if (input
|
|
4
|
+
if (typeof input !== 'string' && !Array.isArray(input)) {
|
|
5
|
+
console.warn("divider: 'input' must be a string or an array of strings. So returning an empty array.");
|
|
5
6
|
return [];
|
|
6
7
|
}
|
|
7
8
|
if (args.length === 0) {
|
|
@@ -9,18 +10,17 @@ export function divider(input, ...args) {
|
|
|
9
10
|
}
|
|
10
11
|
// Extract the options from the input
|
|
11
12
|
const lastArg = args[args.length - 1];
|
|
12
|
-
const options = isOptions(lastArg) ? lastArg : {};
|
|
13
|
+
const options = isOptions(lastArg) ? (args.pop(), lastArg) : {};
|
|
13
14
|
// Filter out only numbers and strings
|
|
14
|
-
const numSeparators =
|
|
15
|
-
const strSeparators = [];
|
|
16
|
-
for (const arg of args) {
|
|
15
|
+
const { numSeparators, strSeparators } = args.reduce((acc, arg) => {
|
|
17
16
|
if (typeof arg === 'number') {
|
|
18
|
-
numSeparators.push(arg);
|
|
17
|
+
acc.numSeparators.push(arg);
|
|
19
18
|
}
|
|
20
19
|
else if (typeof arg === 'string') {
|
|
21
|
-
strSeparators.push(arg);
|
|
20
|
+
acc.strSeparators.push(arg);
|
|
22
21
|
}
|
|
23
|
-
|
|
22
|
+
return acc;
|
|
23
|
+
}, { numSeparators: [], strSeparators: [] });
|
|
24
24
|
if (typeof input === 'string') {
|
|
25
25
|
return divideString(input, numSeparators, strSeparators);
|
|
26
26
|
}
|