@ls-stack/utils 2.1.0 → 2.2.0

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.
@@ -25,7 +25,8 @@ __export(castValues_exports, {
25
25
  });
26
26
  module.exports = __toCommonJS(castValues_exports);
27
27
  function castToString(value) {
28
- return value !== null && value !== void 0 ? String(value) : null;
28
+ const valueType = typeof value;
29
+ return valueType === "string" || valueType === "number" || valueType === "boolean" || valueType === "bigint" ? String(value) : null;
29
30
  }
30
31
  function castToNumber(value) {
31
32
  return isNumeric(value) ? Number(value) : null;
@@ -1,6 +1,7 @@
1
1
  // src/castValues.ts
2
2
  function castToString(value) {
3
- return value !== null && value !== void 0 ? String(value) : null;
3
+ const valueType = typeof value;
4
+ return valueType === "string" || valueType === "number" || valueType === "boolean" || valueType === "bigint" ? String(value) : null;
4
5
  }
5
6
  function castToNumber(value) {
6
7
  return isNumeric(value) ? Number(value) : null;
@@ -14,10 +14,14 @@ function clampRange(num, v1, v2) {
14
14
  function clamp(num, min, max) {
15
15
  return num > max ? max : num < min ? min : num;
16
16
  }
17
+ function fixFloatingPointNumber(value) {
18
+ return Number(value.toPrecision(15));
19
+ }
17
20
 
18
21
  export {
19
22
  clampMax,
20
23
  clampMin,
21
24
  clampRange,
22
- clamp
25
+ clamp,
26
+ fixFloatingPointNumber
23
27
  };
@@ -2,7 +2,7 @@ import {
2
2
  clampMax,
3
3
  clampMin,
4
4
  clampRange
5
- } from "./chunk-NWXBMMHO.js";
5
+ } from "./chunk-HTCYUMDR.js";
6
6
  import {
7
7
  invariant
8
8
  } from "./chunk-4UGSP3L3.js";
@@ -23,7 +23,8 @@ __export(mathUtils_exports, {
23
23
  clamp: () => clamp,
24
24
  clampMax: () => clampMax,
25
25
  clampMin: () => clampMin,
26
- clampRange: () => clampRange
26
+ clampRange: () => clampRange,
27
+ fixFloatingPointNumber: () => fixFloatingPointNumber
27
28
  });
28
29
  module.exports = __toCommonJS(mathUtils_exports);
29
30
  function clampMax(value, max) {
@@ -41,10 +42,14 @@ function clampRange(num, v1, v2) {
41
42
  function clamp(num, min, max) {
42
43
  return num > max ? max : num < min ? min : num;
43
44
  }
45
+ function fixFloatingPointNumber(value) {
46
+ return Number(value.toPrecision(15));
47
+ }
44
48
  // Annotate the CommonJS export names for ESM import in node:
45
49
  0 && (module.exports = {
46
50
  clamp,
47
51
  clampMax,
48
52
  clampMin,
49
- clampRange
53
+ clampRange,
54
+ fixFloatingPointNumber
50
55
  });
@@ -2,5 +2,6 @@ declare function clampMax(value: number, max: number): number;
2
2
  declare function clampMin(value: number, min: number): number;
3
3
  declare function clampRange(num: number, v1: number, v2: number): number;
4
4
  declare function clamp(num: number, min: number, max: number): number;
5
+ declare function fixFloatingPointNumber(value: number): number;
5
6
 
6
- export { clamp, clampMax, clampMin, clampRange };
7
+ export { clamp, clampMax, clampMin, clampRange, fixFloatingPointNumber };
@@ -2,5 +2,6 @@ declare function clampMax(value: number, max: number): number;
2
2
  declare function clampMin(value: number, min: number): number;
3
3
  declare function clampRange(num: number, v1: number, v2: number): number;
4
4
  declare function clamp(num: number, min: number, max: number): number;
5
+ declare function fixFloatingPointNumber(value: number): number;
5
6
 
6
- export { clamp, clampMax, clampMin, clampRange };
7
+ export { clamp, clampMax, clampMin, clampRange, fixFloatingPointNumber };
package/dist/mathUtils.js CHANGED
@@ -2,11 +2,13 @@ import {
2
2
  clamp,
3
3
  clampMax,
4
4
  clampMin,
5
- clampRange
6
- } from "./chunk-NWXBMMHO.js";
5
+ clampRange,
6
+ fixFloatingPointNumber
7
+ } from "./chunk-HTCYUMDR.js";
7
8
  export {
8
9
  clamp,
9
10
  clampMax,
10
11
  clampMin,
11
- clampRange
12
+ clampRange,
13
+ fixFloatingPointNumber
12
14
  };
package/dist/testUtils.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-JQFUKJU5.js";
4
4
  import {
5
5
  clampMin
6
- } from "./chunk-NWXBMMHO.js";
6
+ } from "./chunk-HTCYUMDR.js";
7
7
  import {
8
8
  omit,
9
9
  pick
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ls-stack/utils",
3
3
  "description": "Typescript utils",
4
- "version": "2.1.0",
4
+ "version": "2.2.0",
5
5
  "license": "MIT",
6
6
  "files": [
7
7
  "dist"
@@ -164,26 +164,26 @@
164
164
  "node": ">=20.0.0"
165
165
  },
166
166
  "devDependencies": {
167
- "@ls-stack/extended-lint": "^0.2.0",
167
+ "@ls-stack/extended-lint": "^0.20.1",
168
168
  "@types/eslint": "^9.6.1",
169
169
  "@types/eslint__js": "^8.42.3",
170
- "@types/node": "^22.5.5",
171
- "@typescript-eslint/eslint-plugin": "^8.6.0",
172
- "@typescript-eslint/parser": "^8.6.0",
173
- "@vitest/ui": "^2.1.1",
170
+ "@types/node": "^22.10.2",
171
+ "@typescript-eslint/eslint-plugin": "^8.18.1",
172
+ "@typescript-eslint/parser": "^8.18.1",
173
+ "@vitest/ui": "^2.1.8",
174
174
  "dequal": "^2.0.3",
175
- "eslint": "^9.10.0",
176
- "eslint-plugin-unicorn": "^55.0.0",
175
+ "eslint": "^9.17.0",
176
+ "eslint-plugin-unicorn": "^56.0.1",
177
177
  "eslint-plugin-vitest": "^0.5.4",
178
- "mitata": "^1.0.17",
179
- "prettier": "3.3.3",
180
- "prettier-plugin-organize-imports": "^4.0.0",
178
+ "mitata": "^1.0.21",
179
+ "prettier": "3.4.2",
180
+ "prettier-plugin-organize-imports": "^4.1.0",
181
181
  "tsm": "^2.3.0",
182
- "tsup": "^8.3.0",
183
- "typescript": "^5.6.2",
184
- "typescript-eslint": "^8.6.0",
185
- "vite": "^5.4.6",
186
- "vitest": "^2.1.1"
182
+ "tsup": "^8.3.5",
183
+ "typescript": "^5.7.2",
184
+ "typescript-eslint": "^8.18.1",
185
+ "vite": "^6.0.5",
186
+ "vitest": "^2.1.8"
187
187
  },
188
188
  "typesVersions": {
189
189
  "*": {