@nyaomaru/divider 1.6.0 → 1.6.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/index.cjs +27 -20
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +25 -19
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -23,7 +23,8 @@ __export(index_exports, {
|
|
|
23
23
|
divider: () => divider,
|
|
24
24
|
dividerFirst: () => dividerFirst,
|
|
25
25
|
dividerLast: () => dividerLast,
|
|
26
|
-
dividerLoop: () => dividerLoop
|
|
26
|
+
dividerLoop: () => dividerLoop,
|
|
27
|
+
dividerNumberString: () => dividerNumberString
|
|
27
28
|
});
|
|
28
29
|
module.exports = __toCommonJS(index_exports);
|
|
29
30
|
|
|
@@ -104,7 +105,7 @@ function ensureArray(input) {
|
|
|
104
105
|
return Array.isArray(input) ? input : [input];
|
|
105
106
|
}
|
|
106
107
|
|
|
107
|
-
// src/utils/
|
|
108
|
+
// src/utils/option.ts
|
|
108
109
|
function extractOptions(args) {
|
|
109
110
|
const clonedArgs = [...args];
|
|
110
111
|
const lastArg = clonedArgs.at(-1);
|
|
@@ -117,6 +118,17 @@ function extractOptions(args) {
|
|
|
117
118
|
options
|
|
118
119
|
};
|
|
119
120
|
}
|
|
121
|
+
function applyDividerOptions(result, options) {
|
|
122
|
+
let output = result;
|
|
123
|
+
if (options.trim) {
|
|
124
|
+
const trim = (s) => s.trim();
|
|
125
|
+
output = isNestedStringArray(output) ? output.map((row) => row.map(trim).filter(Boolean)) : output.map(trim).filter(Boolean);
|
|
126
|
+
}
|
|
127
|
+
if (options.flatten) {
|
|
128
|
+
output = output.flat();
|
|
129
|
+
}
|
|
130
|
+
return output;
|
|
131
|
+
}
|
|
120
132
|
|
|
121
133
|
// src/utils/separator.ts
|
|
122
134
|
function classifySeparators(args) {
|
|
@@ -130,23 +142,6 @@ function classifySeparators(args) {
|
|
|
130
142
|
);
|
|
131
143
|
}
|
|
132
144
|
|
|
133
|
-
// src/utils/option.ts
|
|
134
|
-
function applyDividerOptions(result, options) {
|
|
135
|
-
let output = result;
|
|
136
|
-
if (options.trim) {
|
|
137
|
-
const trimPart = (s) => s.trim();
|
|
138
|
-
if (isNestedStringArray(result)) {
|
|
139
|
-
output = result.map((row) => row.map(trimPart).filter(Boolean));
|
|
140
|
-
} else {
|
|
141
|
-
output = result.map(trimPart).filter(Boolean);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
if (options.flatten) {
|
|
145
|
-
output = output.flat();
|
|
146
|
-
}
|
|
147
|
-
return output;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
145
|
// src/core/divider.ts
|
|
151
146
|
function divider(input, ...args) {
|
|
152
147
|
if (!isValidInput(input)) {
|
|
@@ -200,10 +195,22 @@ function dividerLoop(input, size, options) {
|
|
|
200
195
|
const result = input.map(applyChunking);
|
|
201
196
|
return applyDividerOptions(result, options ?? {});
|
|
202
197
|
}
|
|
198
|
+
|
|
199
|
+
// src/utils/divide.ts
|
|
200
|
+
function divideNumberString(str) {
|
|
201
|
+
return (str.match(/\d+|\D+/g) || []).filter(Boolean);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// src/core/divider-number-string.ts
|
|
205
|
+
function dividerNumberString(input, options) {
|
|
206
|
+
const result = isString(input) ? divideNumberString(input) : input.map(divideNumberString);
|
|
207
|
+
return applyDividerOptions(result, options ?? {});
|
|
208
|
+
}
|
|
203
209
|
// Annotate the CommonJS export names for ESM import in node:
|
|
204
210
|
0 && (module.exports = {
|
|
205
211
|
divider,
|
|
206
212
|
dividerFirst,
|
|
207
213
|
dividerLast,
|
|
208
|
-
dividerLoop
|
|
214
|
+
dividerLoop,
|
|
215
|
+
dividerNumberString
|
|
209
216
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -11,4 +11,6 @@ declare function dividerLast(input: string | string[], ...args: DividerSeparator
|
|
|
11
11
|
|
|
12
12
|
declare function dividerLoop<T extends string | string[], F extends boolean>(input: T, size: number, options?: DividerOptions<F>): DividerResult<T, F>;
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
declare function dividerNumberString<T extends string | string[], F extends boolean = false>(input: T, options?: DividerOptions<F>): DividerResult<T, F>;
|
|
15
|
+
|
|
16
|
+
export { type DividerResult, divider, dividerFirst, dividerLast, dividerLoop, dividerNumberString };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,4 +11,6 @@ declare function dividerLast(input: string | string[], ...args: DividerSeparator
|
|
|
11
11
|
|
|
12
12
|
declare function dividerLoop<T extends string | string[], F extends boolean>(input: T, size: number, options?: DividerOptions<F>): DividerResult<T, F>;
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
declare function dividerNumberString<T extends string | string[], F extends boolean = false>(input: T, options?: DividerOptions<F>): DividerResult<T, F>;
|
|
15
|
+
|
|
16
|
+
export { type DividerResult, divider, dividerFirst, dividerLast, dividerLoop, dividerNumberString };
|
package/dist/index.js
CHANGED
|
@@ -75,7 +75,7 @@ function ensureArray(input) {
|
|
|
75
75
|
return Array.isArray(input) ? input : [input];
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
// src/utils/
|
|
78
|
+
// src/utils/option.ts
|
|
79
79
|
function extractOptions(args) {
|
|
80
80
|
const clonedArgs = [...args];
|
|
81
81
|
const lastArg = clonedArgs.at(-1);
|
|
@@ -88,6 +88,17 @@ function extractOptions(args) {
|
|
|
88
88
|
options
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
|
+
function applyDividerOptions(result, options) {
|
|
92
|
+
let output = result;
|
|
93
|
+
if (options.trim) {
|
|
94
|
+
const trim = (s) => s.trim();
|
|
95
|
+
output = isNestedStringArray(output) ? output.map((row) => row.map(trim).filter(Boolean)) : output.map(trim).filter(Boolean);
|
|
96
|
+
}
|
|
97
|
+
if (options.flatten) {
|
|
98
|
+
output = output.flat();
|
|
99
|
+
}
|
|
100
|
+
return output;
|
|
101
|
+
}
|
|
91
102
|
|
|
92
103
|
// src/utils/separator.ts
|
|
93
104
|
function classifySeparators(args) {
|
|
@@ -101,23 +112,6 @@ function classifySeparators(args) {
|
|
|
101
112
|
);
|
|
102
113
|
}
|
|
103
114
|
|
|
104
|
-
// src/utils/option.ts
|
|
105
|
-
function applyDividerOptions(result, options) {
|
|
106
|
-
let output = result;
|
|
107
|
-
if (options.trim) {
|
|
108
|
-
const trimPart = (s) => s.trim();
|
|
109
|
-
if (isNestedStringArray(result)) {
|
|
110
|
-
output = result.map((row) => row.map(trimPart).filter(Boolean));
|
|
111
|
-
} else {
|
|
112
|
-
output = result.map(trimPart).filter(Boolean);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
if (options.flatten) {
|
|
116
|
-
output = output.flat();
|
|
117
|
-
}
|
|
118
|
-
return output;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
115
|
// src/core/divider.ts
|
|
122
116
|
function divider(input, ...args) {
|
|
123
117
|
if (!isValidInput(input)) {
|
|
@@ -171,9 +165,21 @@ function dividerLoop(input, size, options) {
|
|
|
171
165
|
const result = input.map(applyChunking);
|
|
172
166
|
return applyDividerOptions(result, options ?? {});
|
|
173
167
|
}
|
|
168
|
+
|
|
169
|
+
// src/utils/divide.ts
|
|
170
|
+
function divideNumberString(str) {
|
|
171
|
+
return (str.match(/\d+|\D+/g) || []).filter(Boolean);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// src/core/divider-number-string.ts
|
|
175
|
+
function dividerNumberString(input, options) {
|
|
176
|
+
const result = isString(input) ? divideNumberString(input) : input.map(divideNumberString);
|
|
177
|
+
return applyDividerOptions(result, options ?? {});
|
|
178
|
+
}
|
|
174
179
|
export {
|
|
175
180
|
divider,
|
|
176
181
|
dividerFirst,
|
|
177
182
|
dividerLast,
|
|
178
|
-
dividerLoop
|
|
183
|
+
dividerLoop,
|
|
184
|
+
dividerNumberString
|
|
179
185
|
};
|