dino-core
Version:
A dependency injection framework for NodeJS applications
53 lines • 1.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Id = void 0;
const object_helper_1 = require("../../helper/object.helper");
/**
* Represent an identifier for an entity
*/
class Id {
constructor(value) {
this.value = value;
}
/**
* Compare two id for equality
* > if other object is not defined return false
* > if this object and other object are not of the same type then return false
* > if any of this object properties is not same as the same property on other object then return false
* > otherwise return true
* @param other the other archetype to compare
* @returns true if the two Ids are same, false otherwise
*/
equals(other) {
if (!object_helper_1.ObjectHelper.isDefined(other)) {
return false;
}
if (!object_helper_1.ObjectHelper.instanceOf(other, Id)) {
return false;
}
if (typeof this.value === 'string') {
return this.value.toLowerCase() === other.value.toLowerCase();
}
return this.value === other.value;
}
/**
* Allows to access this identifier internal value
* @returns the identifier internal value
*/
get() {
return this.value;
}
/**
* Create a new identifier
* @param value the Id internal value
* @returns a new Id instance
*/
static create(value) {
return new Id(value);
}
toString() {
return `${this.value}`;
}
}
exports.Id = Id;
//# sourceMappingURL=Id.js.map