mirror of
https://github.com/di-sukharev/opencommit.git
synced 2026-04-20 03:02:51 -04:00
fix(prepare-commit-msg-hook.ts): add missing await keyword to getStagedFiles() function call feat(prepare-commit-msg-hook.ts): add spinner to indicate commit message generation progress feat(utils/mergeDiffs.ts): add mergeDiffs function to merge array of strings into an array of strings with a maximum length The test.ts file is now ignored by git. The missing await keyword has been added to the getStagedFiles() function call. A spinner has been added to indicate the progress of commit message generation. The mergeDiffs function has been added to merge an array of strings into an array of strings with a maximum length.
18 lines
456 B
TypeScript
18 lines
456 B
TypeScript
import { tokenCount } from './tokenCount';
|
|
export function mergeDiffs(arr: string[], maxStringLength: number): string[] {
|
|
const mergedArr: string[] = [];
|
|
let currentItem: string = arr[0];
|
|
for (const item of arr.slice(1)) {
|
|
if (tokenCount(currentItem + item) <= maxStringLength) {
|
|
currentItem += item;
|
|
} else {
|
|
mergedArr.push(currentItem);
|
|
currentItem = item;
|
|
}
|
|
}
|
|
|
|
mergedArr.push(currentItem);
|
|
|
|
return mergedArr;
|
|
}
|