Skip to content

Commit a420744

Browse files
committed
Refactor Type class
and... - for primitives, Type class' .objectType is now set to an empty string instead of undefined
1 parent 2a3fd1b commit a420744

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

isType.mjs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,26 @@ const String = globalThis["String"];
44
const Number = globalThis["Number"];
55
const Boolean = globalThis["Boolean"];
66

7-
class Type extends String {
7+
class Type {
88
/**
99
* @constructor
10-
* @param {string} typeName - The type's name, regardless of whether it's an object or a primitive.
11-
* @param {string} [objectType] - If this is an object, the object's name. Falsy for a primitive.
10+
* @param {string} typeName - The result of the `typeof` operator.
11+
* @param {string} [objectType] - For objects, the object's class name. Falsy for primitives.
1212
*/
1313
constructor(typeName, objectType){
1414
if(!(typeof typeName === "string" || typeName instanceof String))
1515
throw new TypeError("'typeName' must be a string");
1616
if(typeName == "")
1717
throw new RangeError("'typeName' cannot be an empty string");
18-
typeName = String(typeName);
19-
if(objectType){
20-
if(!(typeof objectType === "string" || objectType instanceof String))
21-
throw new TypeError("'objectType' must be a string");
22-
objectType = String(objectType);
23-
}
18+
if(objectType && !(typeof objectType === "string" || objectType instanceof String))
19+
throw new TypeError("'objectType' must be a string");
2420

25-
super();
21+
this.type = typeName;
22+
this.objectType = objectType || "";
2623

2724
this.type = typeName;
28-
if(objectType){
29-
this.objectType = objectType;
30-
this.object = true;
31-
}
32-
else{
33-
this.primitive = true;
34-
}
25+
this.primitive = !this.objectType;
26+
this.object = !this.primitive;
3527
}
3628
}
3729

0 commit comments

Comments
 (0)