ai / nanoid

A tiny (124 bytes), secure, URL-friendly, unique string ID generator for JavaScript
https://zelark.github.io/nano-id-cc/
MIT License
24.62k stars 790 forks source link

Add formating #291

Closed LucianPetri closed 3 years ago

LucianPetri commented 3 years ago

Feature Request

The GUID data type is a text string representing a Class identifier (ID). COM must be able to convert the string to a valid Class ID. All GUIDs must be authored in uppercase.

The valid format for a GUID is {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} where X is a hex digit (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F).

Note that utilities such as GUIDGEN can generate GUIDs containing lowercase letters. 
These must all be changed to uppercase letters before the GUID can be used by the installer as a valid product code, package code, or component code.

big companies like the one I work for like to strongly type everything, one of those things is also the ID type of database objects, I would like to change all my uuidv4 usage with nanoid but the problem is that in most of the projects there's a specific ID format type expected. I can't safely change to nanoid yet since it will break most of the projects since it does not generate GUID format like random ID.

ai commented 3 years ago

You can use change alphabet and use RegExp to add - on special position.

But will you really need Nano ID for this case?

The core idea of Nano ID is to use shorter string compare to UUID. With same alphabet and dashes, you will lose most of Nano ID benefits.

LucianPetri commented 3 years ago

My focus is to improve project dependencies by replacing current libraries with smaller and faster ones, in this case, with the usage of uuidv4, we have a requirement to use guid for it needs too many project structures to be changed while maintaining the already built infrastrucure.

Even though I personally am not a fan of so many detailed requirements there are more underlying barriers from which these projects stem.

my only option right is to use nanoid as usual where there is no need for a specific format of the id and add RegExp custom alphabet where it's required.

Thank you for the clarification!

ai commented 3 years ago

The size and performance difference with uuidv4 do not enough for the migration.

Especially, because Nano ID with new alphabet and dashes will not be a valid UUID v4 (it has special bits in ID).