Re: A UUID function for web developers

"L. David Baron" <[email protected]>
Newsgroups gmane.comp.mozilla.devel.seamonkey
Message-ID <[email protected]>
You could also write your own, such as the following (which probably
could be simplified, but it works for me):

function hex_pad(num)
{
    var s = num.toString(16);
    while (s.length < 4) {
        s = "0" + s;
    }
    return s;
}

function uuidgen()
{
    var a = new Uint16Array(8);
    window.crypto.getRandomValues(a);
    return a.reduce((prev, item, idx) =>
                      prev + hex_pad(item) + (1 <= idx && idx < 5 ? "-" : ""),
                    "");
}

It doesn't seem like there's a need to add it to the platform given
that it can be written relatively simply using existing platform
features.

-David

On Thursday 2016-03-17 17:44 -0400, Kohei Yoshino wrote:
> I have a simple utility function to get a UUID:
> https://github.com/bzdeck/flaretail.js/blob/master/scripts/helpers.js#L864
> 
> Does it work?
> 
> -Kohei
> 
> On 2016-03-17 5:25 PM, [email protected] wrote:
> >Is it possible to introduce a function for getting a system generated UUID through javascript? It has been a long time coming. I am of the opinion this function should be fast-tracked into browsers, since it has been a lingering and deepening hole in the feature set of browsers.
> >
> >Maybe at the next meeting of groups of developers of different browsers, a consensus can be made regarding how to add this function, and they can immediately set out to independently roll it out. Having it become a part of an official standards document is a secondary concern.

-- 
𝄞   L. David Baron                         http://dbaron.org/   𝄂
𝄢   Mozilla                          https://www.mozilla.org/   𝄂
             Before I built a wall I'd ask to know
             What I was walling in or walling out,
             And to whom I was like to give offense.
               - Robert Frost, Mending Wall (1914)

_______________________________________________
dev-planning mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-planning
signature.asc (application/pgp-signature, 819 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBCAAGBQJW6yiFAAoJEO/hYSUPhPwhXS4P/0EKT2l1ehNKtAr70gszNq27
EH9Rya1PANa7XBEo5EKtSGhsplTGdWc/LGjMt5/Fk1fuyFng50TW6PbO93H/QBo9
BvCpBUhI2qbf7+5uKdSNgscwJ+BiV/vI4Zx6Dh/wyHHBQ14938sXzX+TkuIQNXbd
v1cRUPTBzRl+3egRyM3EUOazyWgr+z5VoruT0YvKH1g/DlC04OriIdERO1fOwOlf
96PyEfbcZ0nuBbINewDIO3e8Bo7B8RgjJXFiDseXYFPXWFN3t4LL70D+9dOZNhCX
8oOFamb5YxT+bzwQ2spauesaAbE74gvvhbXZaedc+MVb7Ahyec8eypo0CwwjS33l
8aLMzGWJRX0GtNStSO2tImlTQ9MgVNYCM5eWfm9eiR6EWRT5wyMcoWgT03P5IQPx
UPVrPUOdq87TGwsvow5pAl6YHrqatbvi2QHEFh7GnQ6tL67M+anA00L6abwxP1nF
5m0h1a+R026YlVowrw1Zg/n+/pHDdFvAV2hDu44a40LXF8AVsuFKhvFwCPfeKJso
+28fszftqqCxeKvg2jRGEqPbfV9hGT96BW4bpKGj5rlSwkpG1xid/kWusQkiimU0
X3/QLOnpiAZ0W5eSc0Xx/xQv2MTFJpQ9hUuvgYeq0yHxJ6uv0u/RYX6Ux3t2Gvhl
/5DS+YaeIJK22UupxIOp
=tpbG
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.