@nyaomaru/divider 1.4.0 → 1.5.0

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/README.md CHANGED
@@ -132,6 +132,24 @@ const result2 = dividerLoop(['hello', 'world'], 2, { flatten: true });
132
132
  // ['he', 'll', 'ow', 'or', 'ld']
133
133
  ```
134
134
 
135
+ ### 📌 `dividerNumberString()` Usage
136
+
137
+ ```ts
138
+ import { dividerNumberString } from '@nyaomaru/divider';
139
+
140
+ // Split numbers and letters from a string
141
+ const result = dividerNumberString('abc123def456');
142
+ // ['abc', '123', 'def', '456']
143
+
144
+ // Split each string in a string[]
145
+ const result2 = dividerNumberString(['abc123', '45z']);
146
+ // [['abc', '123'], ['45', 'z']]
147
+
148
+ // Flatten option
149
+ const result3 = dividerNumberString(['abc123', '45z'], { flatten: true });
150
+ // ['abc', '123', '45', 'z']
151
+ ```
152
+
135
153
  ## 🎯 Options
136
154
 
137
155
  | Option | Type | Default | Description |
@@ -157,6 +175,7 @@ const result2 = divider(words, 2, { flatten: true });
157
175
  - Supports `multiple separators` (mixing indexes and characters)
158
176
  - Works with both `string` and `string[]` input
159
177
  - Optional `flatten` behavior to control nested results
178
+ - Includes `dividerNumberString()` to separate digits and letters
160
179
 
161
180
  ### 🎯 Targeted Extraction
162
181
 
@@ -6,18 +6,18 @@ const chunk_1 = require("@/utils/chunk");
6
6
  const divider_1 = require("@/core/divider");
7
7
  function dividerLoop(input, size, options) {
8
8
  var _a;
9
- if (!(0, is_1.isNumber)(size) || size <= 0) {
9
+ if (!(0, is_1.isPositiveInteger)(size)) {
10
10
  console.warn('dividerLoop: chunk size must be a positive number');
11
11
  return [];
12
12
  }
13
- const flatten = (_a = options === null || options === void 0 ? void 0 : options.flatten) !== null && _a !== void 0 ? _a : false;
14
13
  if ((0, is_1.isString)(input)) {
15
14
  const indexes = (0, chunk_1.generateIndexes)(input, size);
16
- return (0, divider_1.divider)(input, ...indexes, { flatten });
15
+ return (0, divider_1.divider)(input, ...indexes);
17
16
  }
18
17
  const result = input.map((item) => {
19
18
  const indexes = (0, chunk_1.generateIndexes)(item, size);
20
19
  return (0, divider_1.divider)(item, ...indexes);
21
20
  });
21
+ const flatten = (_a = options === null || options === void 0 ? void 0 : options.flatten) !== null && _a !== void 0 ? _a : false;
22
22
  return (flatten ? result.flat() : result);
23
23
  }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dividerNumberString = dividerNumberString;
4
+ const is_1 = require("@/utils/is");
5
+ function dividerNumberString(input, options) {
6
+ const regex = /\d+|\D+/g;
7
+ const divide = (str) => {
8
+ return (str.match(regex) || []).filter(Boolean);
9
+ };
10
+ if ((0, is_1.isString)(input)) {
11
+ return divide(input);
12
+ }
13
+ const result = input.map(divide);
14
+ return ((options === null || options === void 0 ? void 0 : options.flatten) ? result.flat() : result);
15
+ }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isNumber = exports.isString = void 0;
4
4
  exports.isOptions = isOptions;
5
5
  exports.isEmptyArray = isEmptyArray;
6
+ exports.isPositiveInteger = isPositiveInteger;
6
7
  const isString = (arg) => typeof arg === 'string';
7
8
  exports.isString = isString;
8
9
  const isNumber = (arg) => typeof arg === 'number';
@@ -13,3 +14,6 @@ function isOptions(arg) {
13
14
  function isEmptyArray(input) {
14
15
  return Array.isArray(input) && input.length === 0;
15
16
  }
17
+ function isPositiveInteger(value) {
18
+ return Number.isInteger(value) && value > 0;
19
+ }
@@ -1,20 +1,20 @@
1
- import { isString, isNumber } from '@/utils/is';
1
+ import { isString, isPositiveInteger } from '@/utils/is';
2
2
  import { generateIndexes } from '@/utils/chunk';
3
3
  import { divider } from '@/core/divider';
4
4
  export function dividerLoop(input, size, options) {
5
5
  var _a;
6
- if (!isNumber(size) || size <= 0) {
6
+ if (!isPositiveInteger(size)) {
7
7
  console.warn('dividerLoop: chunk size must be a positive number');
8
8
  return [];
9
9
  }
10
- const flatten = (_a = options === null || options === void 0 ? void 0 : options.flatten) !== null && _a !== void 0 ? _a : false;
11
10
  if (isString(input)) {
12
11
  const indexes = generateIndexes(input, size);
13
- return divider(input, ...indexes, { flatten });
12
+ return divider(input, ...indexes);
14
13
  }
15
14
  const result = input.map((item) => {
16
15
  const indexes = generateIndexes(item, size);
17
16
  return divider(item, ...indexes);
18
17
  });
18
+ const flatten = (_a = options === null || options === void 0 ? void 0 : options.flatten) !== null && _a !== void 0 ? _a : false;
19
19
  return (flatten ? result.flat() : result);
20
20
  }
@@ -0,0 +1,12 @@
1
+ import { isString } from '@/utils/is';
2
+ export function dividerNumberString(input, options) {
3
+ const regex = /\d+|\D+/g;
4
+ const divide = (str) => {
5
+ return (str.match(regex) || []).filter(Boolean);
6
+ };
7
+ if (isString(input)) {
8
+ return divide(input);
9
+ }
10
+ const result = input.map(divide);
11
+ return ((options === null || options === void 0 ? void 0 : options.flatten) ? result.flat() : result);
12
+ }
@@ -6,3 +6,6 @@ export function isOptions(arg) {
6
6
  export function isEmptyArray(input) {
7
7
  return Array.isArray(input) && input.length === 0;
8
8
  }
9
+ export function isPositiveInteger(value) {
10
+ return Number.isInteger(value) && value > 0;
11
+ }
@@ -0,0 +1,2 @@
1
+ import type { DividerOptions, DividerResult } from '@/core/types';
2
+ export declare function dividerNumberString<T extends string | string[], F extends boolean = false>(input: T, options?: DividerOptions<F>): DividerResult<T, F>;
@@ -4,3 +4,4 @@ export declare function isOptions(arg: unknown): arg is {
4
4
  flatten?: boolean;
5
5
  };
6
6
  export declare function isEmptyArray<T>(input: T[]): boolean;
7
+ export declare function isPositiveInteger(value: unknown): boolean;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nyaomaru/divider",
3
3
  "type": "module",
4
- "version": "1.4.0",
4
+ "version": "1.5.0",
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",