UNPKG

@genexus/web-standard-functions

Version:

GeneXus JavaScript standard functions library for web generators

96 lines 2.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GxGuid = void 0; const uuid_1 = require("uuid"); class GxGuid { constructor(val = GxGuid.emptyValue) { this.value = this.normalizeValue(val); } serialize() { return this.toString(); } deserialize(x) { return new GxGuid(x); } normalizeValue(str) { const lStr = str.toLowerCase(); const regExp1 = /[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/; const regExp2 = /[0-9a-f]{32}/; if (lStr.length === 36 && regExp1.exec(lStr) !== null) { return lStr; } else if (lStr.length === 32 && regExp2.exec(lStr) !== null) { return (lStr.substr(0, 8) + "-" + lStr.substr(8, 4) + "-" + lStr.substr(12, 4) + "-" + lStr.substr(16, 4) + "-" + lStr.substr(20, 12)); } else { return GxGuid.emptyValue; } } /** * Returns true if the GUID is the emtpy GUID * @returns boolean */ isEmpty() { return this.value === GxGuid.emptyValue; } /** * Sets the given string as the GUID's value * @param {string} str The new GUID's value */ fromString(str) { this.value = this.normalizeValue(str); } /** * Returns the string representation of the GUID object * @param {string} format The desired format of the output string * @returns {string} The string representation of the GUID */ toString(format = undefined) { // TODO: apply formatting. Which are the valid formats? return this.value; } /** * Returns the empty GUID * @returns {GxGuid} The empty GUID */ static empty() { return this.emptyGUID; } /** * Creates a new GUID object from the given string * @param {string} str The string representing the GUID object to be created * @returns {GxGuid} The GUID object with representing the given string */ static fromString(str) { return new GxGuid(str); } /** * Creates a new GUID object with a randomly-generated value * @returns {GxGuid} The newly created GUID object */ static newGuid() { return new GxGuid((0, uuid_1.v4)()); } static compare(guid1, guid2) { let res; if (guid1.value === guid2.value) { res = true; } else { res = false; } return res; } } exports.GxGuid = GxGuid; GxGuid.emptyValue = "00000000-0000-0000-0000-000000000000"; GxGuid.emptyGUID = new GxGuid(GxGuid.emptyValue); //# sourceMappingURL=gxguid.js.map