UNPKG

@aurigma/design-atoms-model

Version:

Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.

47 lines 1.77 kB
//Use code from https://code.google.com/p/accept/source/browse/html/res/jquery.Guid.js?r=3e72134c6a29a9ccf30f3a2d0802bca7d14788ea import { Exception } from "../Exception"; var Uuid = /** @class */ (function () { function Uuid(value) { this._value = "00000000-0000-0000-0000-000000000000"; if (value != null) this.value = value; else this.generateNewGuid(); } Object.defineProperty(Uuid.prototype, "value", { get: function () { return this._value; }, set: function (value) { if (!this.isValid(value)) throw new Exception(value + "is incorrect uuid!"); this._value = value; }, enumerable: true, configurable: true }); Uuid.prototype.isValid = function (value) { value = value.toUpperCase(); var validationExpression = new RegExp("\\b(?:[A-F0-9]{8})(?:-[A-F0-9]{4}){3}-(?:[A-F0-9]{12})\\b"); return validationExpression.exec(value) != null; }; Uuid.prototype.generateNewGuid = function () { //TODO use UUID.js(create(1)) for genereation? var d = new Date().getTime(); var value = '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 & 0x7 | 0x8)).toString(16); }); this.value = value; }; Uuid.prototype.toString = function () { return this._value; }; Uuid.prototype.equals = function (other) { return other._value === this._value; }; return Uuid; }()); export { Uuid }; //# sourceMappingURL=Uuid.js.map