<commit_before>/**
# uuid

Random and non-random unique ids. All generated using `crypto.getRandomValues`, i.e. a
[cryptographically strong random number generator](https://developer.mozilla.org/en-US/docs/Web/API/Crypto)

    import {uuid, unique, randId, now36, id} from 'path/to/uuid.js'

    // () => crypto.randomUUID()
    const myId = uuid()

Other ways of generating random / unique ids:

    // randpm string of digits in specified base
    const tenDigits = randId(10, 10)

    // default base is 36, this is a 20 digit string
    const uid = randId(20)

The convenience functions now36() and randId(length, base) can
be used to create very good ids

    // i.e. a unique id that is also going to sort into creation order
    // ms since epoch as 9-digit base 36 string + 11 digit base 36 digits
    // note that now36() will have a leading '0' until May 25th 2059
    const myId = now36() + randId(11)

    // or...
    const myId = id()

> ## Do not use `unique`
>
> The problem with this (deprecated) function is that it can cause subtle
> bugs if two different bits of code rely on different instances of this
> function in overlapping domains (e.g. two different functions can add
> elements with "unique" ids using different instances of `unique` to the 
> same array that are *very* likely not to be unique.)

Also, if you use `unique()` as a database key (which you should never ever
do) you are hosed.

The nice thing about id() is that it's pretty efficient, and it's not
going to bite you if you use it as a database key.
    
    // where practical, use id() instead
    const tempId = unique()

~~~~
const {uuid, unique, randId, now36, id} = await import('../source/uuid.js');
Test(() => uuid().match(/[0-9a-f]+/g).length).shouldBe(5);
Test(() => uuid().match(/[0-9a-f]+/g).map(s => s.length)).shouldBeJSON([8,4,4,4,12]);
Test(() => uuid().length).shouldBe(36);
Test(() => uuid()).shouldNotBe(uuid());<commit_msg>Update uuid.js<commit_after>/**
# uuid

Random and non-random unique ids. All generated using `crypto.getRandomValues`, i.e. a
[cryptographically strong random number generator](https://developer.mozilla.org/en-US/docs/Web/API/Crypto)

    import {uuid, unique, randId, now36, id} from 'path/to/uuid.js'

    // () => crypto.randomUUID()
    const myId = uuid()

Other ways of generating random / unique ids:

    // randpm string of digits in specified base
    const tenDigits = randId(10, 10)

    // default base is 36, this is a 20 digit string
    const uid = randId(20)

The convenience functions now36() and randId(length, base) can
be used to create very good ids

    // i.e. a unique id that is also going to sort into creation order
    // ms since epoch as 9-digit base 36 string + 11 digit base 36 digits
    // note that now36() will have a leading '0' until May 25th 2059
    const myId = now36() + randId(11)

    // or...
    const myId = id()

> ### Do not use `unique`
>
> The problem with this (deprecated) function is that it can cause subtle
> bugs if two different bits of code rely on different instances of this
> function in overlapping domains (e.g. two different functions can add
> elements with "unique" ids using different instances of `unique` to the 
> same array that are *very* likely not to be unique.)

Also, if you use `unique()` as a database key (which you should never ever
do) you are hosed.

The nice thing about id() is that it's pretty efficient, and it's not
going to bite you if you use it as a database key.
    
    // where practical, use id() instead
    const tempId = unique()

~~~~
const {uuid, unique, randId, now36, id} = await import('../source/uuid.js');
Test(() => uuid().match(/[0-9a-f]+/g).length).shouldBe(5);
Test(() => uuid().match(/[0-9a-f]+/g).map(s => s.length)).shouldBeJSON([8,4,4,4,12]);
Test(() => uuid().length).shouldBe(36);
Test(() => uuid()).shouldNotBe(uuid());
{'fraction_non_alphanumeric': 0.13009808982963345, 'fraction_numerical': 0.025296850800206504, 'mean_word_length': 3.4489092996555684, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7007582', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1175, 'n_words': 500}