Skip to content
Snippets Groups Projects
Select Git revision
  • 372f69853c05c3e0d40bccf506e599f57072ea2a
  • zig default
  • master
  • zig-threaded
  • openat
  • chdir
  • clear
  • compll
  • v1.18.1
  • v2.2.2
  • v1.18
  • v2.2.1
  • v2.2
  • v1.17
  • v2.1.2
  • v2.1.1
  • v2.1
  • v2.0.1
  • v2.0
  • v2.0-beta3
  • v2.0-beta2
  • v2.0-beta1
  • v1.16
  • v1.15.1
  • v1.15
  • v1.14.2
  • v1.14.1
  • v1.14
28 results

calc.h

Blame
  • uuid.ts 1.04 KiB
    /**
     * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info.
     *
     * @author David Sehnal <david.sehnal@gmail.com>
     */
    
    import { now } from 'mol-util/now';
    
    type UUID = string & { '@type': 'uuid' }
    
    namespace UUID {
        const chars: string[] = [];
        /** Creates 22 characted "base64" UUID */
        export function create22(): UUID {
            let d = (+new Date()) + now();
            for (let i = 0; i < 16; i++) {
                chars[i] = String.fromCharCode((d + Math.random()*0xff)%0xff | 0);
                d = Math.floor(d/0xff);
            }
            return btoa(chars.join('')).replace(/\+/g, '-').replace(/\//g, '_').substr(0, 22) as UUID;
        }
    
        export function createv4(): UUID {
            let d = (+new Date()) + now();
            const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
                const r = (d + Math.random()*16)%16 | 0;
                d = Math.floor(d/16);
                return (c==='x' ? r : (r&0x3|0x8)).toString(16);
            });
            return uuid as any;
        }
    }
    
    export default UUID;