"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Guid = (function () {
/**
* Default constructor
* @classdesc Provides methos to generate an validate GUID values and to convert them from and to a String.
* @class Guid
* @param {string} string value representing a Guid Value
*/
function Guid(guid) {
if (guid === undefined) {
this.value = Guid.EMPTY;
}
else {
if (Guid.isGuid(guid)) {
this.value = guid;
}
else {
throw new Error("Invalid GUID value");
}
}
}
Guid.gen = function (count) {
var out = "";
for (var i = 0; i < count; i++) {
out += (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}
return out;
};
Guid.prototype.equals = function (other) {
// Comparing string `value` against provided `guid` will auto-call
// toString on `guid` for comparison
if (other instanceof Guid)
return this.value == other.getValue();
return Guid.isGuid(other) && this.value == other;
};
;
Guid.prototype.isEmpty = function () {
return this.value === Guid.EMPTY;
};
;
Guid.prototype.toString = function () {
return this.value;
};
;
Guid.prototype.toJSON = function () {
return this.value;
};
;
Guid.prototype.getValue = function () {
return this.value;
};
Guid.isGuid = function (value) {
return value && (value instanceof Guid || Guid.validator.test(value.toString()));
};
;
Guid.create = function () {
return new Guid([Guid.gen(2), Guid.gen(1), Guid.gen(1), Guid.gen(1), Guid.gen(3)].join("-"));
};
;
Guid.raw = function () {
return [Guid.gen(2), Guid.gen(1), Guid.gen(1), Guid.gen(1), Guid.gen(3)].join("-");
};
;
Guid.empty = function () {
return new Guid(Guid.EMPTY);
};
return Guid;
}());
Guid.EMPTY = "00000000-0000-0000-0000-000000000000";
Guid.validator = new RegExp("^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$", "i");
exports.Guid = Guid;
//# sourceMappingURL=Guid.js.map