mirror of
https://github.com/n8n-io/n8n.git
synced 2026-05-31 16:57:08 +02:00
25 lines
606 B
TypeScript
25 lines
606 B
TypeScript
import { NANOID_ALPHABET } from '@n8n/constants';
|
|
import { customAlphabet } from 'nanoid';
|
|
|
|
/**
|
|
* Generates a unique 16-character nanoid.
|
|
*
|
|
* This is the canonical ID generator used across the entire n8n codebase for:
|
|
* - Workflow IDs
|
|
* - Project IDs
|
|
* - Variable IDs
|
|
* - API Key IDs
|
|
* - And other entity IDs
|
|
*
|
|
* Both frontend and backend MUST use this function to ensure consistency.
|
|
*
|
|
* @returns A 16-character ID
|
|
*
|
|
* @example
|
|
* ```ts
|
|
* const id = generateNanoId();
|
|
* // => 'aBcDeFgHiJkLmNoP' (16 characters)
|
|
* ```
|
|
*/
|
|
export const generateNanoId = customAlphabet(NANOID_ALPHABET, 16);
|