Files
wehub-resource-sync 98e40dac97
CLI Smoke Test / smoke-test-linux (20) (push) Has been cancelled
CLI Smoke Test / smoke-test-linux (24) (push) Has been cancelled
CLI Smoke Test / smoke-test-windows (20) (push) Has been cancelled
CLI Smoke Test / smoke-test-windows (24) (push) Has been cancelled
Expo App TypeScript typecheck / typecheck (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:40:49 +08:00

13 lines
470 B
TypeScript

import * as crypto from 'crypto';
export function randomKey(prefix: string, length: number = 24): string {
while (true) {
const randomBytesBuffer = crypto.randomBytes(length * 2);
const normalized = randomBytesBuffer.toString('base64').replace(/[^a-zA-Z0-9]/g, '');
if (normalized.length < length) {
continue;
}
const base64String = normalized.slice(0, length);
return `${prefix}_${base64String}`;
}
}