A partial archive of discourse.wicg.io as of Saturday February 24, 2024.

Add UUIDs API to the platform

marcosc
2017-06-01

I keep finding places where I need to use UUIDs - mostly because they are recognizable as such. I’m wondering if we should look at exposing an API to generate conforming RFC4122 UUIDv4s on the Web.

Something like: https://gist.github.com/bentranter/ed524091170137a72c1d54d641493c1f

AshleyScirra
2017-06-01

What’s wrong with leaving it in a function like the one you linked?

marcosc
2017-06-01

Technically, nothing (apart that it’s annoying to have to have a special library just for that)… but it seems like there is so many places where one can use a UUID, that it makes sense to just expose it.

Following the extensible web manifesto, I we can use: https://www.npmjs.com/package/uuid

As a guide for how many things depend on it in the Node ecosystem. There are 4755 projects that depend on UUID of some form, and there has been 19,411,452 downloads in the last month.

marcosc
2017-06-01

Sorry, rereading, I might have misunderstood what you were asking. Where you asking if we should just use the function I provided or expose it as uuid() in the browser on window?

AshleyScirra
2017-06-01

I think things like this belong in libraries, and it’s actually better to put it there. Building code in to the browser is actually incredibly inflexible, since it basically can never be changed due to backwards compatibility concerns. So it’s a lot more flexible and more future-proof to just leave that in a library.

martinthomson
2017-06-01

Marcos, I agree with Ashley. Use crypto.getRandomValues(new Uint8Array(16)) and convert to a string however fits best. UUIDs are hugely overrated as unique identifiers, they aren’t as random as the above, and they have weird formatting peccadilloes. If for some bizarre reason you actually need a UUID, yeah, JSL.

trusktr
2017-06-01

What would be your use cases, for example? If you want to use them in HTML/CSS somehow, I can understand, but in JavaScript it is simply too easy to include a UUID generator.

marcosc
2017-06-02

For example, I was working on this app, whereby I needed to store UUIDs as primary keys in IDB. The team I work with was using "GUID"s in legacy code for Firefox’s AutofillDB - I’m doing the Credit Card DB, and so wanted to also use UUIDs for the primary key - while also associating a credit card with an address via a UUID:

I know any random key could have been used there. The point is that a team had already used UUID, and I wanted consistency.

marcosc
2017-06-02

Agree, Martin. There is no actual valid technical reason. It’s just “I need a unique thing for this”… if it’s universally unique, in the true sense, doesn’t matter too much.

marcosc
2017-06-02

Agree, Ashley… looking at the node UUID lib - it supports multiple versions, etc. which is testament to the extensibility that the library approach provides.

Tigt
2017-06-08

For examples of this going poorly, look no further than the broken implementations of btoa() and atob() that are still hanging around on window today.

beaufortfrancois
2017-06-09

For info, the Web Bluetooth API had to define some Bluetooth UUIDs at https://webbluetoothcg.github.io/web-bluetooth/#uuids

jyasskin
2017-06-11

Yep, although we don’t need any way to generate UUIDs. They’re just constant strings with a particular format for Web Bluetooth.

marcosc
2017-09-28