UNPKG

molstar

Version:

A comprehensive macromolecular library.

40 lines 1.48 kB
"use strict"; /** * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.UUID = void 0; var now_1 = require("../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()) + (0, now_1.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()) + (0, now_1.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 = {})); exports.UUID = UUID; //# sourceMappingURL=uuid.js.map