@tsed/core 8.44.3 → 8.44.5

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.
@@ -3,9 +3,7 @@ import { isArrowFn } from "./isArrowFn.js";
3
3
  import { isBuffer } from "./isBuffer.js";
4
4
  import { isClassObject } from "./isPlainObject.js";
5
5
  import { isDate } from "./isDate.js";
6
- import { isPrimitiveOrPrimitiveClass } from "./isPrimitive.js";
7
6
  import { isPromise } from "./isPromise.js";
8
- import { isSymbol } from "./isSymbol.js";
9
7
  import { isTemporal } from "./isTemporal.js";
10
8
  /**
11
9
  * Determines whether a given value represents a class (constructor function).
@@ -20,15 +18,26 @@ export function isClass(target) {
20
18
  if (!target) {
21
19
  return false;
22
20
  }
21
+ const type = typeof target;
22
+ // primitives are never classes: skip the checks below (bigint keeps the previous path)
23
+ if (type === "string" || type === "number" || type === "boolean" || type === "symbol") {
24
+ return false;
25
+ }
23
26
  if (isArrowFn(target)) {
24
27
  return false;
25
28
  }
26
- return !(isSymbol(target) ||
27
- isPrimitiveOrPrimitiveClass(target) ||
29
+ return !(
30
+ // the part of isPrimitiveOrPrimitiveClass() the typeof check above does not cover
31
+ (target === String ||
32
+ target === Number ||
33
+ target === Boolean ||
34
+ target instanceof String ||
35
+ target instanceof Number ||
36
+ target instanceof Boolean ||
28
37
  isClassObject(target) ||
29
38
  isDate(target) ||
30
39
  isTemporal(target) ||
31
40
  isPromise(target) ||
32
41
  isArrayOrArrayClass(target) ||
33
- isBuffer(target));
42
+ isBuffer(target)));
34
43
  }
@@ -1,6 +1,3 @@
1
- import { isBoolean, isBooleanOrBooleanClass } from "./isBoolean.js";
2
- import { isNumber, isNumberOrNumberClass } from "./isNumber.js";
3
- import { isString, isStringOrStringClass } from "./isString.js";
4
1
  /**
5
2
  * Checks if a value is a primitive or primitive class constructor (String, Number, Boolean).
6
3
  *
@@ -8,7 +5,17 @@ import { isString, isStringOrStringClass } from "./isString.js";
8
5
  * @since v7.0.0
9
6
  */
10
7
  export function isPrimitiveOrPrimitiveClass(target) {
11
- return isStringOrStringClass(target) || isNumberOrNumberClass(target) || isBooleanOrBooleanClass(target);
8
+ const type = typeof target;
9
+ // inlined isStringOrStringClass() || isNumberOrNumberClass() || isBooleanOrBooleanClass(): called per value
10
+ if (type === "string" || type === "number" || type === "boolean") {
11
+ return true;
12
+ }
13
+ return (target instanceof String ||
14
+ target === String ||
15
+ target instanceof Number ||
16
+ target === Number ||
17
+ target instanceof Boolean ||
18
+ target === Boolean);
12
19
  }
13
20
  /**
14
21
  * Checks if a value is a primitive type (string, number, or boolean).
@@ -17,7 +24,9 @@ export function isPrimitiveOrPrimitiveClass(target) {
17
24
  * @since v7.0.0
18
25
  */
19
26
  export function isPrimitive(target) {
20
- return isString(target) || isNumber(target) || isBoolean(target);
27
+ const type = typeof target;
28
+ // inlined isString() || isNumber() || isBoolean(), which also accepts `Boolean` and `new Boolean()`
29
+ return type === "string" || type === "number" || type === "boolean" || target instanceof Boolean || target === Boolean;
21
30
  }
22
31
  /**
23
32
  * Checks if a value is a primitive class constructor (String, Number, or Boolean).
@@ -27,8 +27,13 @@ export function isTemporal(target) {
27
27
  if (!target || !Temporal) {
28
28
  return false;
29
29
  }
30
- return TEMPORAL_TYPE_NAMES.some((name) => {
31
- const ctor = Temporal[name];
32
- return !!ctor && (target === ctor || target instanceof ctor);
33
- });
30
+ // plain loop instead of Array.some(): no closure per call. The constructors are read on each
31
+ // call, so a Temporal.* member replaced at runtime is taken into account.
32
+ for (let i = 0; i < TEMPORAL_TYPE_NAMES.length; i++) {
33
+ const ctor = Temporal[TEMPORAL_TYPE_NAMES[i]];
34
+ if (ctor && (target === ctor || target instanceof ctor)) {
35
+ return true;
36
+ }
37
+ }
38
+ return false;
34
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/core",
3
- "version": "8.44.3",
3
+ "version": "8.44.5",
4
4
  "description": "Core module for Ts.ED Framework",
5
5
  "source": "./src/index.ts",
6
6
  "type": "module",
@@ -39,10 +39,10 @@
39
39
  "tslib": ">=2.7.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@tsed/barrels": "8.44.3",
42
+ "@tsed/barrels": "8.44.5",
43
43
  "@tsed/monorepo-utils": "3.3.3",
44
- "@tsed/typescript": "8.44.3",
45
- "@tsed/vitest": "8.44.3",
44
+ "@tsed/typescript": "8.44.5",
45
+ "@tsed/vitest": "8.44.5",
46
46
  "temporal-polyfill": "1.0.1",
47
47
  "typescript": "6.0.2",
48
48
  "vitest": "4.1.4"