UNPKG

molstar

Version:

A comprehensive macromolecular library.

37 lines (36 loc) 1.32 kB
/** * 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'; var UUID; (function (UUID) { var _btoa = typeof btoa !== 'undefined' ? btoa : function (s) { return Buffer.from(s).toString('base64'); }; var chars = []; /** Creates a 22 characters 'base64' encoded UUID */ function create22() { var d = (+new Date()) + now(); for (var 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); } UUID.create22 = create22; function createv4() { var d = (+new Date()) + now(); var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = (d + Math.random() * 16) % 16 | 0; d = Math.floor(d / 16); return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16); }); return uuid; } UUID.createv4 = createv4; function is(x) { return typeof x === 'string'; } UUID.is = is; })(UUID || (UUID = {})); export { UUID };