UNPKG

@omnia/fx-models

Version:
54 lines (53 loc) 1.63 kB
"use strict"; //export interface GuidValue { // :string; //} Object.defineProperty(exports, "__esModule", { value: true }); /** * Class to create a guid */ var Guid = /** @class */ (function () { function Guid(guid) { var _this = this; this.value = Guid._empty; //We serialize as string value this.toJSON = function () { return _this.value.toLowerCase(); }; if (guid) { if (Guid.isValid(guid)) { this.value = guid; } else { throw "The string '" + guid + "' is not a valid Guid"; } } } Guid.newGuid = function () { return new Guid('xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = Math.random() * 16 | 0; var v = (c == 'x') ? r : (r & 0x3 | 0x8); return v.toString(16); })); }; Object.defineProperty(Guid, "empty", { get: function () { return this._empty; }, enumerable: true, configurable: true }); Guid.isValid = function (guid) { var validRegex = /^[{]?[0-9a-fA-F]{8}[-]?([0-9a-fA-F]{4}[-]?){3}[0-9a-fA-F]{12}[}]?$/; return validRegex.test(guid.toString()); }; Guid.prototype.toString = function () { return this.value.toLowerCase(); }; Guid.prototype.valueOf = function () { return this.value.toLowerCase(); }; Guid._empty = '00000000-0000-0000-0000-000000000000'; return Guid; }()); exports.Guid = Guid;