@nyaomaru/divider 1.3.0 → 1.3.2
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 +5 -5
- package/dist/cjs/utils/is.js +5 -0
- package/dist/esm/core/divider.js +6 -6
- package/dist/esm/utils/is.js +2 -0
- package/dist/types/core/divider-first.d.ts +1 -1
- package/dist/types/core/divider-last.d.ts +1 -1
- package/dist/types/utils/is.d.ts +2 -0
- package/package.json +1 -1
package/dist/cjs/core/divider.js
CHANGED
|
@@ -4,27 +4,27 @@ exports.divider = divider;
|
|
|
4
4
|
const parser_1 = require("@/core/parser");
|
|
5
5
|
const is_1 = require("@/utils/is");
|
|
6
6
|
function divider(input, ...args) {
|
|
7
|
-
if (
|
|
7
|
+
if (!(0, is_1.isString)(input) && !Array.isArray(input)) {
|
|
8
8
|
console.warn("divider: 'input' must be a string or an array of strings. So returning an empty array.");
|
|
9
9
|
return [];
|
|
10
10
|
}
|
|
11
11
|
if ((0, is_1.isEmptyArray)(args)) {
|
|
12
|
-
return (
|
|
12
|
+
return ((0, is_1.isString)(input) ? [input] : input);
|
|
13
13
|
}
|
|
14
14
|
// Extract the options from the input
|
|
15
15
|
const lastArg = args[args.length - 1];
|
|
16
16
|
const options = (0, is_1.isOptions)(lastArg) ? (args.pop(), lastArg) : {};
|
|
17
17
|
// Filter out only numbers and strings
|
|
18
18
|
const { numSeparators, strSeparators } = args.reduce((acc, arg) => {
|
|
19
|
-
if (
|
|
19
|
+
if ((0, is_1.isNumber)(arg)) {
|
|
20
20
|
acc.numSeparators.push(arg);
|
|
21
21
|
}
|
|
22
|
-
else if (
|
|
22
|
+
else if ((0, is_1.isString)(arg)) {
|
|
23
23
|
acc.strSeparators.push(arg);
|
|
24
24
|
}
|
|
25
25
|
return acc;
|
|
26
26
|
}, { numSeparators: [], strSeparators: [] });
|
|
27
|
-
if (
|
|
27
|
+
if ((0, is_1.isString)(input)) {
|
|
28
28
|
return (0, parser_1.divideString)(input, numSeparators, strSeparators);
|
|
29
29
|
}
|
|
30
30
|
const result = input.map((item) => (0, parser_1.divideString)(item, numSeparators, strSeparators));
|
package/dist/cjs/utils/is.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isNumber = exports.isString = void 0;
|
|
3
4
|
exports.isOptions = isOptions;
|
|
4
5
|
exports.isEmptyArray = isEmptyArray;
|
|
6
|
+
const isString = (arg) => typeof arg === 'string';
|
|
7
|
+
exports.isString = isString;
|
|
8
|
+
const isNumber = (arg) => typeof arg === 'number';
|
|
9
|
+
exports.isNumber = isNumber;
|
|
5
10
|
function isOptions(arg) {
|
|
6
11
|
return typeof arg === 'object' && arg !== null && 'flatten' in arg;
|
|
7
12
|
}
|
package/dist/esm/core/divider.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import { divideString } from '@/core/parser';
|
|
2
|
-
import { isOptions, isEmptyArray } from '@/utils/is';
|
|
2
|
+
import { isString, isNumber, isOptions, isEmptyArray } from '@/utils/is';
|
|
3
3
|
export function divider(input, ...args) {
|
|
4
|
-
if (
|
|
4
|
+
if (!isString(input) && !Array.isArray(input)) {
|
|
5
5
|
console.warn("divider: 'input' must be a string or an array of strings. So returning an empty array.");
|
|
6
6
|
return [];
|
|
7
7
|
}
|
|
8
8
|
if (isEmptyArray(args)) {
|
|
9
|
-
return (
|
|
9
|
+
return (isString(input) ? [input] : input);
|
|
10
10
|
}
|
|
11
11
|
// Extract the options from the input
|
|
12
12
|
const lastArg = args[args.length - 1];
|
|
13
13
|
const options = isOptions(lastArg) ? (args.pop(), lastArg) : {};
|
|
14
14
|
// Filter out only numbers and strings
|
|
15
15
|
const { numSeparators, strSeparators } = args.reduce((acc, arg) => {
|
|
16
|
-
if (
|
|
16
|
+
if (isNumber(arg)) {
|
|
17
17
|
acc.numSeparators.push(arg);
|
|
18
18
|
}
|
|
19
|
-
else if (
|
|
19
|
+
else if (isString(arg)) {
|
|
20
20
|
acc.strSeparators.push(arg);
|
|
21
21
|
}
|
|
22
22
|
return acc;
|
|
23
23
|
}, { numSeparators: [], strSeparators: [] });
|
|
24
|
-
if (
|
|
24
|
+
if (isString(input)) {
|
|
25
25
|
return divideString(input, numSeparators, strSeparators);
|
|
26
26
|
}
|
|
27
27
|
const result = input.map((item) => divideString(item, numSeparators, strSeparators));
|
package/dist/esm/utils/is.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { DividerSeparators } from '@/core/types';
|
|
2
|
-
export declare function dividerFirst
|
|
2
|
+
export declare function dividerFirst(input: string | string[], ...args: DividerSeparators): string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { DividerSeparators } from '@/core/types';
|
|
2
|
-
export declare function dividerLast
|
|
2
|
+
export declare function dividerLast(input: string | string[], ...args: DividerSeparators): string;
|
package/dist/types/utils/is.d.ts
CHANGED