I'm looking for a solution to generate base62 UUIDs in node.js. I'd like to avoid base64 as I intend to create folders based on these UUIDs and characters like =, \, -, _ (as in some implementations) are not that human/filesystem friendly.
Base62 also has the advantage (in my context) of being shorter than a typical v4 UUID.
UPDATE (for clarity): I should have said earlier that I already tried using base62 module but this doesn't solve my issue since base62 takes numbers in javascript integer numbers are only precise up to 52 bits while UUIDs have 128.
Here is a comprehensive answer:
Solution A:
base-x+node-uuidInspired by @Jonathan's earlier comment.
Use node-uuid to generate the UUID and then encode it with base-x:
base-xis very fast so this is the most performant solution.Solution B:
uuid-base62Before knowing about
base-xI went ahead and created a module for the base62 encoding (b62) and another for the base62 UUID generation: uuid-base62:This is the no frills solution.
Currently it's not as fast as A sinceb62is much slower but I intend to replace it withbase-x.UPDATE:
uuid-base62has been updated to usebase-x.