mirror of
https://git.um-react.app/um/um-react.git
synced 2025-11-28 11:33:02 +00:00
feat: kwm v2 key import ui
This commit is contained in:
20
src/util/splitN.ts
Normal file
20
src/util/splitN.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
export function splitN(str: string, sep: string, maxN: number) {
|
||||
if (maxN <= 1) {
|
||||
return [str];
|
||||
}
|
||||
|
||||
const chunks: string[] = [];
|
||||
const lenSep = sep.length;
|
||||
let searchIdx = 0;
|
||||
for (; maxN > 1; maxN--) {
|
||||
const nextIdx = str.indexOf(sep, searchIdx);
|
||||
if (nextIdx === -1) {
|
||||
break;
|
||||
}
|
||||
chunks.push(str.slice(searchIdx, nextIdx));
|
||||
searchIdx = nextIdx + lenSep;
|
||||
}
|
||||
|
||||
chunks.push(str.slice(searchIdx));
|
||||
return chunks;
|
||||
}
|
||||
Reference in New Issue
Block a user