Skip to content

Commit fd579c7

Browse files
refactor(Value): add Symbol.toStringTag() and tag getter.
1 parent 0572440 commit fd579c7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/lib/value.class.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
* @template Type
77
*/
88
export abstract class Value<Type> {
9+
/**
10+
* @description Returns the `string` tag representation of the `Value` class when used in `Object.prototype.toString.call(instance)`.
11+
* @public
12+
* @readonly
13+
* @type {string}
14+
*/
15+
public get [Symbol.toStringTag]() {
16+
return 'Value';
17+
}
18+
919
/**
1020
* @description Returns the privately stored value of generic type variable `Type`.
1121
* @public
@@ -32,6 +42,16 @@ export abstract class Value<Type> {
3242
this.#value = value;
3343
}
3444

45+
/**
46+
* @description Extracts the string tag of the current instance defined by the `Symbol.toStringTag`.
47+
* @public
48+
* @returns {string | undefined} The extracted class name, such as `'Value'`, or `undefined` if extraction fails.
49+
*/
50+
public get tag(): string | undefined {
51+
const tag = Object.prototype.toString.call(this).slice(8, -1);
52+
return tag !== 'Object' ? tag : undefined;
53+
}
54+
3555
/**
3656
* @description Sets the value of generic type variable `Type`.
3757
* @protected

0 commit comments

Comments
 (0)