@nyaomaru/divider 1.0.17 → 1.0.18

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.
@@ -12,18 +12,17 @@ function divider(input, ...args) {
12
12
  }
13
13
  // Extract the options from the input
14
14
  const lastArg = args[args.length - 1];
15
- const options = (0, validator_1.isOptions)(lastArg) ? lastArg : {};
15
+ const options = (0, validator_1.isOptions)(lastArg) ? (args.pop(), lastArg) : {};
16
16
  // Filter out only numbers and strings
17
- const numSeparators = [];
18
- const strSeparators = [];
19
- for (const arg of args) {
17
+ const { numSeparators, strSeparators } = args.reduce((acc, arg) => {
20
18
  if (typeof arg === 'number') {
21
- numSeparators.push(arg);
19
+ acc.numSeparators.push(arg);
22
20
  }
23
21
  else if (typeof arg === 'string') {
24
- strSeparators.push(arg);
22
+ acc.strSeparators.push(arg);
25
23
  }
26
- }
24
+ return acc;
25
+ }, { numSeparators: [], strSeparators: [] });
27
26
  if (typeof input === 'string') {
28
27
  return (0, parser_1.divideString)(input, numSeparators, strSeparators);
29
28
  }
@@ -9,18 +9,17 @@ export function divider(input, ...args) {
9
9
  }
10
10
  // Extract the options from the input
11
11
  const lastArg = args[args.length - 1];
12
- const options = isOptions(lastArg) ? lastArg : {};
12
+ const options = isOptions(lastArg) ? (args.pop(), lastArg) : {};
13
13
  // Filter out only numbers and strings
14
- const numSeparators = [];
15
- const strSeparators = [];
16
- for (const arg of args) {
14
+ const { numSeparators, strSeparators } = args.reduce((acc, arg) => {
17
15
  if (typeof arg === 'number') {
18
- numSeparators.push(arg);
16
+ acc.numSeparators.push(arg);
19
17
  }
20
18
  else if (typeof arg === 'string') {
21
- strSeparators.push(arg);
19
+ acc.strSeparators.push(arg);
22
20
  }
23
- }
21
+ return acc;
22
+ }, { numSeparators: [], strSeparators: [] });
24
23
  if (typeof input === 'string') {
25
24
  return divideString(input, numSeparators, strSeparators);
26
25
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nyaomaru/divider",
3
3
  "type": "module",
4
- "version": "1.0.17",
4
+ "version": "1.0.18",
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",