Skip to content

Instantly share code, notes, and snippets.

@LinusU
Created April 30, 2014 12:32
Show Gist options
  • Save LinusU/9a9fd1aff7efb129e513 to your computer and use it in GitHub Desktop.
Save LinusU/9a9fd1aff7efb129e513 to your computer and use it in GitHub Desktop.

Revisions

  1. LinusU revised this gist Apr 30, 2014. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion uuid-v5.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    function uuid5(data) {
    var out = crypto.createHash('sha1').update(data).digest();

  2. LinusU created this gist Apr 30, 2014.
    17 changes: 17 additions & 0 deletions uuid-v5.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@

    function uuid5(data) {
    var out = crypto.createHash('sha1').update(data).digest();

    out[8] = out[8] & 0x3f | 0xa0; // set variant
    out[6] = out[6] & 0x0f | 0x50; // set version

    var hex = out.toString('hex', 0, 16);

    return [
    hex.substring( 0, 8),
    hex.substring( 8, 12),
    hex.substring(12, 16),
    hex.substring(16, 20),
    hex.substring(20, 32)
    ].join('-');
    }