Sometimes there is a requirement to get 32 character UUID (may be I shouldn't call that UUID :) ).
However the UUID generated by this library is 36 chars length. Because of dashes.
Is it possible to add an option to omit dashes? Something like this:
function v4(options, buf, offset) {
...
return buf || bytesToUuid(rnds, 0, options.nodash);
}
function bytesToUuid(buf, offset, nodash) {
var i = offset || 0;
var bth = byteToHex;
return bth[buf[i++]] + bth[buf[i++]] +
bth[buf[i++]] + bth[buf[i++]] + (nodash ? '' : '-') +
...
}
The dashes are part of the RFC4122 spec:
The formal definition of the UUID string representation provided by the following ABNF [7]:
UUID = time-low "-" time-mid "-"
time-high-and-version "-"
clock-seq-and-reserved
clock-seq-low "-" node
If you need to remove them, uuid().replace(/-/g, '') should do the trick.
@broofa : I also need to get non-canonical UUIDs (without dashes), and it may be the case for many users.
Indeed, using replace() works, but it might be a nice touch to add an option that would not include the dashes in the first place, for better performance and cleaner code.
What are your thoughts?
@LeoDupont: I have zero interest supporting non-standard id formats.
Just to add to this, this might be useful for downstream client libraries like express-request-id which allow users to pass params to uuid
@jakesyl to re-iterate: This library focuses on what's covered by RFC4122, we have no interest in supporting non-standard formats.
If you are looking for more compact unique identifiers to be used in URLs and don't need UUID compliance you could look into some of the alternatives:
The fact that some of these libraries use base64 encoding instead of hex encoding allows them to encode the same amount of entropy in shorter strings which can be handy when storing & using IDs as opaque strings.
Most helpful comment
@LeoDupont: I have zero interest supporting non-standard id formats.