@nyaomaru/divider 1.4.1 → 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
|
|
|
@@ -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
|
+
}
|
|
@@ -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
|
+
}
|