@typescript-package/value
Version:
A lightweight TypeScript library for encapsulating and managing a single, strongly-typed value.
71 lines (67 loc) • 1.96 kB
JavaScript
/**
* @description The class to manage the value of generic type variable `Type`.
* @export
* @class Value
* @template Type The type of the privately stored `#value`.
*/
class Value {
/**
* @description Returns the `string` tag representation of the `Value` class when used in `Object.prototype.toString.call(instance)`.
* The `tag` getter returns the actual class name defined with the `Symbol.toStringTag()` of the child class.
* @public
* @readonly
* @type {string}
*/
get [Symbol.toStringTag]() {
return Value.name;
}
/**
* @description Returns the string tag of the current instance defined by the `Symbol.toStringTag`.
* @public
* @returns {string | undefined} The extracted class name, such as `'Value'`, or `undefined` if extraction fails.
*/
get tag() {
const tag = Object.prototype.toString.call(this).slice(8, -1);
return tag !== 'Object' ? tag : undefined;
}
/**
* @description Returns the privately stored value of generic type variable `Type`.
* @public
* @readonly
* @type {Type}
*/
get value() {
return this.#value;
}
/**
* @description Privately stored value of generic type variable `Type`.
* @type {Type}
*/
#value;
/**
* Creates an instance of child class.
* @constructor
* @param {Type} value The value of generic type variable `Type`.
*/
constructor(value) {
this.#value = value;
}
/**
* @description Sets the value of generic type variable `Type`.
* @public
* @param {Type} value The value of `Type` to set.
* @returns {this} The `this` current instance.
*/
set(value) {
this.#value = value;
return this;
}
}
/*
* Public API Surface of value
*/
/**
* Generated bundle index. Do not edit.
*/
export { Value };
//# sourceMappingURL=typescript-package-value.mjs.map