@tsailab/xai
Version:
The loto-xai is an openai nodejs sdk compatible extension library.
57 lines • 1.72 kB
JavaScript
import { customAlphabet, nanoid } from 'nanoid';
export const BASE58_ALPHABET_SEED = '123456789abcdefjhijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
export const REQID_ALPHABET_SEED = '0123456789abcdefghijkmnpqrstuvwxyz._';
export const COMMON_ALPHABET_SEED = '123456789fghijkmnpqrstuvwxyzACDEFGHJMNPQRSTUVWXYZ-_';
export const CHAT_MESSAGEID_SEED = '123456789fghijkmnpqrstuvwxyzACDEFGHJMNPQRSTUVWXYZ.$';
export function createRequestId() {
return nanoid();
}
/**
*
* @param len min 6 max 40
* @returns string
*/
export function createBase58RandomId(len = 16) {
let size = len;
if (size < 6) {
size = 6;
}
if (size > 40) {
size = 40;
}
const customNanoid = customAlphabet(BASE58_ALPHABET_SEED, size);
return customNanoid();
}
/**
*
* @param prefix
* @returns
*/
export function createClientId(prefix = '') {
const customNanoid = customAlphabet(COMMON_ALPHABET_SEED, 16);
const id = customNanoid();
return prefix?.trim().length ? `${prefix.trim()}_${id}` : `loto_${id}`;
}
/**
*
* @param prefix
* @returns
*/
export function createChatid(prefix = 'xchat') {
const customNanoid = customAlphabet('123456789fghijkmnpqrstuvwxyzACDEFGHJMNPQRSTUVWXYZ', 16);
const id = customNanoid();
return prefix?.trim().length ? `${prefix.trim()}_${id}` : `xchat_${id}`;
}
/**
* chat message id
* @param len
* @param uuid
* @returns
*/
export function createChatMessageId(len = 20, uuid) {
const size = len > 10 && len < 32 ? len : 20;
const customNanoid = customAlphabet('.123456789.fghijkmnpqrstuvwxyz.ACDEFGHJMNPQRSTUVWXYZ.', size);
const id = customNanoid();
return uuid ? `${uuid}-${id}` : id;
}
//# sourceMappingURL=uuid.util.js.map