uuid-kit
v2.0.2
Published
Generate UUID values (v4, v7) with formatting, prefixes, suffixes, and flexible output shapes.
Maintainers
Readme
uuid-kit
Generate UUID values (v4, v7) with flexible formatting, prefixes, suffixes, and output shape options.
Previously published as
generate-uuid-version
Install
npm install uuid-kitUsage
import { generateUUID } from "uuid-kit";
const result = generateUUID({
count: 3,
version: "v7"
});
console.log(result);Output
{
"version": "v7",
"format": "standard",
"output_as": "array",
"count": 3,
"items": [
"uuid-1",
"uuid-2",
"uuid-3"
]
}Options
| Field | Type | Required | Default | Description |
|------|------|----------|---------|-------------|
| count | number | No | 1 | Number of UUIDs to generate |
| version | string | No | v7 | UUID version: v4 or v7 |
| format | string | No | standard | Output format: standard, compact, uppercase, uppercase-compact |
| prefix | string | No | "" | String to prepend to each UUID |
| suffix | string | No | "" | String to append to each UUID |
| outputAs | string | No | array | Output shape: array, object, or string |
Examples
Default
generateUUID({ count: 2 });Output:
{
"version": "v7",
"format": "standard",
"output_as": "array",
"count": 2,
"items": [
"uuid-1",
"uuid-2"
]
}v4
generateUUID({
count: 2,
version: "v4"
});v7
generateUUID({
count: 2,
version: "v7"
});Compact format
generateUUID({
count: 2,
format: "compact"
});Uppercase + prefix
generateUUID({
count: 2,
format: "uppercase",
prefix: "id_"
});Prefix + suffix
generateUUID({
count: 2,
prefix: "pre_",
suffix: "_end"
});Object output
generateUUID({
count: 2,
outputAs: "object"
});Output:
{
"version": "v7",
"format": "standard",
"output_as": "object",
"count": 2,
"items": [
{
"uuid": "uuid-1",
"raw": "uuid-1",
"index": 0,
"timestamp": {
"iso": "2026-04-09T18:12:34.567Z",
"unix": 1775758354567
}
},
{
"uuid": "uuid-2",
"raw": "uuid-2",
"index": 1,
"timestamp": {
"iso": "2026-04-09T18:12:35.123Z",
"unix": 1775758355123
}
}
]
}String output
generateUUID({
count: 3,
outputAs: "string"
});Output:
{
"version": "v7",
"format": "standard",
"output_as": "string",
"count": 3,
"items": "uuid-1\nuuid-2\nuuid-3"
}Formats
standard= default UUID formatcompact= removes hyphensuppercase= uppercase lettersuppercase-compact= uppercase and no hyphens
Output Shapes
outputAs: "array"
Returns items as an array of formatted UUID strings.
outputAs: "object"
Returns items as an array of objects.
Each object includes:
uuid= final formatted valueraw= original UUID before formattingindex= zero-based position in the result settimestamp= only included forv7whenoutputAsis"object"
outputAs: "string"
Returns items as a single newline-delimited string.
Supported Versions
v4= randomv7= time-based, sortable, recommended
Exposed Constants
import {
ALLOWED_FORMATS,
ALLOWED_VERSIONS,
ALLOWED_OUTPUT_AS
} from "uuid-kit";Behavior
- Invalid or missing
countdefaults to1 - Maximum
countis100 countis floored to a whole number- Invalid or missing
versiondefaults tov7 - Invalid or missing
formatdefaults tostandard - Invalid or missing
outputAsdefaults toarray
Performance Notes
uuid-kit avoids unnecessary work during generation:
- Object records are only built when
outputAsis"object" - Timestamps are only extracted for
v7object output - Array storage is preallocated for efficient generation
This keeps array and string output paths lighter and faster.
TypeScript
The package includes TypeScript definitions for:
UUIDVersionUUIDFormatUUIDOutputAsUUIDTimestampUUIDObjectGenerateUUIDOptionsGenerateUUIDResult
The generateUUID() function also uses overloads so the return type matches outputAs when it is explicitly provided.
Environment Notes
Some hosted JavaScript runtimes require you to explicitly add npm packages before use. In those environments, add:
uuid-kituuid@10
License
MIT
