Echo JS 0.11.0

<~>

tracker1 1436 days ago. link 2 points
Okay, liked this implementation, so took the time to update my uuid4 npm package to use a modified version for the browser implementation... also cleaned up some cruft and added module version(s) for both browser and node packages.

https://www.npmjs.com/package/uuid4
tracker1 1436 days ago. link 2 points
Looks like ie11 does have the URL method needed, but the result has a `blob:` prefixed before the UUID portion.  So replacing the substr check with a split/pop that includes a colon or \/ works.

    function uuid() {
      var temp_url = URL.createObjectURL(new Blob());
      var uuid = temp_url.toString();
      URL.revokeObjectURL(temp_url);
      return uuid.split(/[:\/]/g).pop(); // remove prefixes
    }

-- edited: original reply below. ---------------------

No IE support[1], but many are no longer supporting even IE11 at this point, at least for internalized apps.

It's cool, but not sure if this is any better than just using crypto.getRandomValues()[2][3] directly, which is supported by at least IE11 forward.  Assuming you only care about browser generation, otherwise node as a getRandom method on its' crypto implementation as well.

    window.crypto = window.crypto || window.msCrypto;

All of that said, your best bet is to still probably prefer the uuid[4] module's v4 implementation which handles most of the platform issues for you.

If you want a close to direct implementation, you could also try my uuid4[5] module.  If you want the implementation, you could always snag the browser.js source... it's bigger than TFA, but will at least work in a relatively widely used browser that doesn't support the URL api.

1. https://caniuse.com/#feat=url
2. https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
3. https://caniuse.com/#feat=getrandomvalues
4. https://www.npmjs.com/package/uuid
5. https://www.npmjs.com/package/uuid4