Files
ncd-fe/packages/nicolium/src/utils/strings.ts
nicole mikołajczyk acc0d9de17 nicolium: try to not add empty timeline gaps
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
2026-03-11 05:25:01 +01:00

23 lines
694 B
TypeScript

/** Capitalize the first letter of a string. */
// https://stackoverflow.com/a/1026087
const capitalize = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);
const incrementId = (str: string): string => {
const CHARS = str.match(/[a-z]/i)
? '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
: '0123456789';
const chars = [...str];
for (let i = chars.length - 1; i >= 0; i--) {
const idx = CHARS.indexOf(chars[i]);
if (idx === -1) continue;
if (idx < CHARS.length - 1) {
chars[i] = CHARS[idx + 1];
return chars.join('');
}
chars[i] = CHARS[0];
}
return CHARS[1] + chars.join('');
};
export { capitalize, incrementId };