mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-21 17:18:52 +00:00
23 lines
612 B
TypeScript
23 lines
612 B
TypeScript
export function truncate(str: string, len: number): string {
|
|
const overflow = str.length - len;
|
|
if (overflow < 0) {
|
|
return str;
|
|
}
|
|
|
|
const half = Math.floor((len - 1) / 2);
|
|
|
|
const start = str.slice(0, half);
|
|
const end = str.slice(-half);
|
|
return `${start} ########### ${end}`;
|
|
}
|
|
|
|
export function chunk<T>(items: T[], chunkSize: number): T[][] {
|
|
const chunks: T[][] = [];
|
|
for (let i = 0; i < items.length; i += chunkSize) {
|
|
chunks.push(items.slice(i, i + chunkSize));
|
|
}
|
|
return chunks;
|
|
}
|
|
|
|
export const MD5_REGEX = /([a-fA-F0-9]{32})/;
|
|
export const TWEET_SNOWFLAKE_REGEX = /([0-9]{19})/;
|