-
Notifications
You must be signed in to change notification settings - Fork 3
Configuration Options
UCID isnβt just easy β itβs flexible too! Customize your ID like a pro π οΈ
Each option below lets you fine-tune the structure and formatting of your generated IDs.
Control letter casing:
-
lowercase:trueby default -
uppercase:falseby default
ucid({ uppercase: true });
// Result: TevajtrU-Eei8SnWa-0EZqr6NE-jMAHX0D6
ucid({ uppercase: true, lowercase: false });
// Result: FFJL9DAO-V3YPLZ2V-252L7URX-XCS3GWP5Toggle digits or symbols:
-
numbers:trueby default -
symbols:falseby default
ucid({ symbols: true });
// Result: 5w55an#e-kw7bw7f3-7iomwp#o-dd79$yf1
ucid({ numbers: false });
// Result: jueldfjw-ljhiphtl-ajuptedx-rramdwneSet how many segments (octets) the ID should have. Default: 4.
ucid({ octets: 3 });
// Result: 4nlwrx87-fi65iq27-43wh2s05
ucid({ octets: 6 });
// Result: hr5bg68k-ycxqfb1o-pkofgsm2-j6hnimgy-ehcxulnl-ptmvuf3jDefine how long each octet should be. Default: 8.
ucid({ octetLength: 4 });
// Result: k6ue-bvfq-fc99-oe07
ucid({ octetLength: 12 });
// Result: nz4kkg3jxxot-9v9bmx6y8ngt-x4ciymz48z9d-mqopg9mad4v2Use a custom character set to generate your ID:
ucid({ includeOnly: '1234567890abcdef' });
// Result: f800cdb7-0082b1b8-f0736eb3-4b16949aAdd timestamp to your ID. Either prefix or suffix.
- Aliases:
-
prefix:p,pre,pref -
suffix:s,suf,suff
-
ucid({ timestamp: 'prefix' });
// Result: 20250904-k0ebaf6m-j31g7koc-b25p0p2n-u9iah5i4
ucid({ timestamp: 'suff' });
// Result: 05mdc0cp-6k6xvl9c-mgc7s9e3-t98ckh3f-20250904Controls how the timestamp is formatted. Use any custom format or choose from built-ins:
-
unix,epoch militaryisoutc-
rfc(rfc3339) -
filetime,winft(Windows FILETIME)
ucid({
octets: 3,
timestamp: 's',
timestampFormat: 'dd-mm-yyyy-hh:mm:ss:ms',
});
// Result: gtrf9t1h-u00ycxuw-mxzhjuty-04-09-2025-12:09:00:39
ucid({
octets: 3,
timestamp: 'p',
timestampFormat: 'unix',
});
// Result: 1756976740-61p0xk4r-1ad6fg3l-gxwsgpgkCustomize the character(s) used to separate octets. Default: "-"
ucid({ octetSeparator: '=' });
// Result: pro9mns=odvhrd3i=28e2mqzg=t3n530m9
ucid({ octetSeparator: '~' });
// Result: qm09extn~dy7s1bd1~t6fl9q2g~mv352ie4Set the exact length of each octet individually.
ucid({ octets: 3, octetFormat: '352' });
// Result: h0c-hgkf0-k9
ucid({ octets: 4, octetFormat: [2, 4, 6, 8] });
// Result: cb-udw8-e6m4wt-i9kim7xb
ucid({ octets: 2, octetFormat: '49' });
// Result: pr3e-piis0fdy9Number of IDs to generate.
ucid({ instances: 3 });
/*
Result: [
'9v7z1v59-0v28lo6h-8g5qpnhk-dx5f6412',
'5689u3lw-ns4wk8sc-u57bgwxz-nm9r8ydf',
'ul7pdyya-bgubmkef-zlpp7b79-7v2oo5dq'
]
*/
ucid({
octets: 4,
octetFormat: [2, 4, 6, 8],
instances: 5,
});
/*
Result: [
'rd-c0ix-mtifus-z7ibcbip',
'l6-gngn-1v04eg-do2yei8v',
'kf-fprl-klp5bw-o7gcv39u',
'tm-v4hq-8h964i-cnpswp29',
'uq-iwcb-u44bey-yj0nvs98'
]
*/Use %id and %ts placeholders to inject generated values into custom strings.
ucid({
octets: 1,
octetLength: 8,
includeOnly: '1234567890abcdef',
template: 'user-%id-session-%id',
});
// Result: user-1a97ada5-session-ec64776c
ucid({
octets: 1,
octetLength: 8,
includeOnly: '1234567890abcdef',
template: 'user-%id-at-%ts',
});
// Result: user-26001cde-at-20250903Add static strings before or after your ID.
ucid({ prefix: 'ID-', suffix: '-done' });
// Result: ID-k0ebaf6m-j31g7koc-b25p0p2n-u9iah5i4-doneReturns a full object instead of just the generated ID string.
Useful for debugging, logging, or introspection.
ucid({
octets: 3,
octetLength: 12,
includeOnly: '1234567890abcdef',
verbose: true,
});
/*
Result: {
ucid: '795ebe1fd531-dbf06d32bd02-f512ad09e84a',
octets: 3,
uppercase: false,
lowercase: true,
octetLength: 12,
octetFormat: '',
numbers: true,
octetSeparator: '-',
symbols: false,
includeOnly: '1234567890abcdef',
template: null,
prefix: '',
suffix: '',
verbose: true
}
*/Function to customize each octet beyond built-in options.
ucid({
octets: 2,
octetLength: 8,
includeOnly: '1234567890abcdef',
customize: (octet, i) => (i % 2 ? octet.toUpperCase() : octet.toLowerCase()),
});
// Result: 80a1a368-A738C260
ucid({
octets: 3,
octetLength: 6,
includeOnly: '1234567890abcdef',
customize: (octet, i) =>
i == 0 ? `user-${octet}` : i == 1 ? `session-${octet}` : `${i}${octet}`,
});
// Result: user-81cd0a-session-13634d-212fb85Acts as a gate before UCID generation begins.
Must call resolve() to proceed or reject() to abort.
// Allow generation only in production
ucid({
condition: (resolve, reject) =>
process.env.NODE_ENV === 'production'
? resolve()
: reject('UCID generation is disabled in non-production environments.'),
});
// Check authentication
ucid({
condition: (resolve, reject) =>
auth?.currentUser?.email
? resolve()
: reject(new Error('User must be authenticated.')),
});Next up β Predefined Formats
π unique-custom-id β most customizable ID generator you'll ever meet
π See our contributing guide for guidelines on how to contribute
π¬ Join the conversation on discussions
πͺͺ Licensed under MIT β free to fork, remix, and build upon
π Maintained by @calebephrem β contributions welcome!
β¨ Fork it. Tweak it. Make it yours.
- π Home
- π οΈ Usage
- π οΈ How To Use UCID
- π¦ Installation
- β Importing
- π Generate Simple ID
- π§© Configuration Options
- π§° Predefined Formats
- ποΈ Predefined Formats
- π§ Format Aliases
- π Format List
- π§ͺ Usage Examples
- β Remember
- 𧬠CLI
- π UCID CLI
- π Quick Start
- π CLI Options
- π§ͺ Examples
- πͺ£ Entropy Space