@schukai/monster 4.43.0 → 4.43.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
 
4
4
 
5
+ ## [4.43.1] - 2025-10-02
6
+
7
+ ### Bug Fixes
8
+
9
+ - optimize typeof
10
+
11
+
12
+
5
13
  ## [4.43.0] - 2025-10-02
6
14
 
7
15
  ### Add Features
package/package.json CHANGED
@@ -1 +1 @@
1
- {"author":"schukai GmbH","dependencies":{"@floating-ui/dom":"^1.7.4","@popperjs/core":"^2.11.8"},"description":"Monster is a simple library for creating fast, robust and lightweight websites.","homepage":"https://monsterjs.org/","keywords":["framework","web","dom","css","sass","mobile-first","app","front-end","templates","schukai","core","shopcloud","alvine","monster","buildmap","stack","observer","observable","uuid","node","nodelist","css-in-js","logger","log","theme"],"license":"AGPL 3.0","main":"source/monster.mjs","module":"source/monster.mjs","name":"@schukai/monster","repository":{"type":"git","url":"https://gitlab.schukai.com/oss/libraries/javascript/monster.git"},"type":"module","version":"4.43.0"}
1
+ {"author":"schukai GmbH","dependencies":{"@floating-ui/dom":"^1.7.4","@popperjs/core":"^2.11.8"},"description":"Monster is a simple library for creating fast, robust and lightweight websites.","homepage":"https://monsterjs.org/","keywords":["framework","web","dom","css","sass","mobile-first","app","front-end","templates","schukai","core","shopcloud","alvine","monster","buildmap","stack","observer","observable","uuid","node","nodelist","css-in-js","logger","log","theme"],"license":"AGPL 3.0","main":"source/monster.mjs","module":"source/monster.mjs","name":"@schukai/monster","repository":{"type":"git","url":"https://gitlab.schukai.com/oss/libraries/javascript/monster.git"},"type":"module","version":"4.43.1"}
@@ -15,7 +15,8 @@
15
15
  export { typeOf };
16
16
 
17
17
  /**
18
- * The built-in typeof method is known to have some historical weaknesses. This function tries to provide a better and more accurate result.
18
+ * The built-in typeof method is known to have some historical weaknesses.
19
+ * This function tries to provide a better and more accurate result.
19
20
  *
20
21
  * @param {*} value
21
22
  * @return {string}
@@ -25,18 +26,26 @@ export { typeOf };
25
26
  * @throws {TypeError} value is not a primitive
26
27
  */
27
28
  function typeOf(value) {
28
- let type = {}.toString.call(value).match(/\s([a-zA-Z]+)/)[1];
29
- if ("Object" === type) {
30
- const name = value.constructor.name;
31
- if (name) {
32
- return name.toLowerCase();
33
- }
34
-
35
- const results = /^(class|function)\s+(\w+)/.exec(
36
- value.constructor.toString(),
37
- );
38
- type = results && results.length > 2 ? results[2] : "";
39
- }
40
-
41
- return type.toLowerCase();
29
+ if (value === null) {
30
+ return "null";
31
+ }
32
+
33
+ const baseType = typeof value;
34
+
35
+ if (baseType !== "object" && baseType !== "function") {
36
+ return baseType;
37
+ }
38
+
39
+ const internalType = {}.toString.call(value).slice(8, -1);
40
+
41
+ if (internalType !== "Object") {
42
+ return internalType.toLowerCase();
43
+ }
44
+
45
+ const constructorName = value.constructor?.name;
46
+ if (constructorName && constructorName !== "Object") {
47
+ return constructorName.toLowerCase();
48
+ }
49
+
50
+ return "object";
42
51
  }