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.

41 lines 1.44 kB
//Use code from https://code.google.com/p/accept/source/browse/html/res/jquery.Guid.js?r=3e72134c6a29a9ccf30f3a2d0802bca7d14788ea import { Exception } from "../Exception"; export class Uuid { constructor(value) { this._value = "00000000-0000-0000-0000-000000000000"; if (value != null) this.value = value; else this.generateNewGuid(); } set value(value) { if (!this.isValid(value)) throw new Exception(value + "is incorrect uuid!"); this._value = value; } get value() { return this._value; } isValid(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; } generateNewGuid() { //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; } toString() { return this._value; } equals(other) { return other._value === this._value; } } //# sourceMappingURL=Uuid.js.map