@fluixi/utils 1.0.0-alpha.83 → 1.0.0-alpha.85
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/dist/index.cjs +2858 -1
- package/dist/index.mjs +2838 -1
- package/dist/lib/array/advanced.cjs +2227 -1
- package/dist/lib/array/advanced.mjs +2204 -1
- package/dist/lib/array/array.cjs +57 -1
- package/dist/lib/array/array.mjs +36 -1
- package/dist/lib/array/index.cjs +2344 -1
- package/dist/lib/array/index.mjs +2322 -1
- package/dist/lib/array/utils.cjs +103 -1
- package/dist/lib/array/utils.mjs +82 -1
- package/dist/lib/color/color.cjs +2190 -1
- package/dist/lib/color/color.mjs +2167 -1
- package/dist/lib/color/constants.cjs +380 -1
- package/dist/lib/color/constants.mjs +359 -1
- package/dist/lib/color/conversions.cjs +629 -1
- package/dist/lib/color/conversions.mjs +608 -1
- package/dist/lib/color/helpers.cjs +2534 -1
- package/dist/lib/color/helpers.mjs +2511 -1
- package/dist/lib/color/index.cjs +2641 -1
- package/dist/lib/color/index.mjs +2619 -1
- package/dist/lib/color/types.cjs +18 -1
- package/dist/lib/color/utils.cjs +962 -1
- package/dist/lib/color/utils.mjs +939 -1
- package/dist/lib/compare/comparators.cjs +171 -1
- package/dist/lib/compare/comparators.mjs +150 -1
- package/dist/lib/compare/index.cjs +172 -1
- package/dist/lib/compare/index.mjs +152 -1
- package/dist/lib/crypto/hash.cjs +83 -1
- package/dist/lib/crypto/hash.mjs +62 -1
- package/dist/lib/crypto/index.cjs +85 -1
- package/dist/lib/crypto/index.mjs +62 -1
- package/dist/lib/dom/events.cjs +40 -1
- package/dist/lib/dom/events.mjs +19 -1
- package/dist/lib/dom/index.cjs +78 -1
- package/dist/lib/dom/index.mjs +56 -1
- package/dist/lib/dom/utils.cjs +57 -1
- package/dist/lib/dom/utils.mjs +36 -1
- package/dist/lib/functions/functions.cjs +366 -1
- package/dist/lib/functions/functions.mjs +345 -1
- package/dist/lib/functions/index.cjs +369 -1
- package/dist/lib/functions/index.mjs +347 -1
- package/dist/lib/functions/types.cjs +18 -1
- package/dist/lib/helpers.cjs +78 -1
- package/dist/lib/helpers.mjs +59 -1
- package/dist/lib/index.cjs +2857 -1
- package/dist/lib/index.mjs +2836 -1
- package/dist/lib/maths/constants.cjs +70 -1
- package/dist/lib/maths/constants.mjs +50 -1
- package/dist/lib/maths/fn/advanced.cjs +231 -1
- package/dist/lib/maths/fn/advanced.mjs +208 -1
- package/dist/lib/maths/fn/basic.cjs +212 -1
- package/dist/lib/maths/fn/basic.mjs +191 -1
- package/dist/lib/maths/fn/complex.cjs +268 -1
- package/dist/lib/maths/fn/complex.mjs +247 -1
- package/dist/lib/maths/fn/index.cjs +877 -1
- package/dist/lib/maths/fn/index.mjs +855 -1
- package/dist/lib/maths/fn/trigo.cjs +179 -1
- package/dist/lib/maths/fn/trigo.mjs +156 -1
- package/dist/lib/maths/fn/vector.cjs +728 -1
- package/dist/lib/maths/fn/vector.mjs +707 -1
- package/dist/lib/maths/formatter.cjs +61 -1
- package/dist/lib/maths/formatter.mjs +40 -1
- package/dist/lib/maths/guards.cjs +164 -1
- package/dist/lib/maths/guards.mjs +144 -1
- package/dist/lib/maths/index.cjs +1152 -1
- package/dist/lib/maths/index.mjs +1130 -1
- package/dist/lib/maths/parser.cjs +75 -1
- package/dist/lib/maths/parser.mjs +54 -1
- package/dist/lib/maths/random.cjs +49 -1
- package/dist/lib/maths/random.mjs +28 -1
- package/dist/lib/maths/types/advanced.cjs +18 -1
- package/dist/lib/maths/types/basic.cjs +18 -1
- package/dist/lib/maths/types/index.cjs +19 -1
- package/dist/lib/maths/types/index.mjs +1 -0
- package/dist/lib/maths/types/negative.cjs +18 -1
- package/dist/lib/maths/types/operations.cjs +18 -1
- package/dist/lib/object/clone.cjs +88 -1
- package/dist/lib/object/clone.mjs +65 -1
- package/dist/lib/object/diff.cjs +573 -1
- package/dist/lib/object/diff.mjs +550 -1
- package/dist/lib/object/getter-setter.cjs +2351 -1
- package/dist/lib/object/getter-setter.mjs +2330 -1
- package/dist/lib/object/index.cjs +3956 -6
- package/dist/lib/object/index.mjs +3936 -6
- package/dist/lib/object/merge.cjs +1029 -1
- package/dist/lib/object/merge.mjs +1006 -1
- package/dist/lib/object/object.cjs +280 -1
- package/dist/lib/object/object.mjs +257 -1
- package/dist/lib/object/omit.cjs +2022 -1
- package/dist/lib/object/omit.mjs +1999 -1
- package/dist/lib/object/reconcile.cjs +126 -1
- package/dist/lib/object/reconcile.js +1 -1
- package/dist/lib/object/reconcile.mjs +105 -1
- package/dist/lib/object/selector.cjs +303 -1
- package/dist/lib/object/selector.mjs +282 -1
- package/dist/lib/object/sort.cjs +209 -1
- package/dist/lib/object/sort.d.ts +1 -1
- package/dist/lib/object/sort.js +3 -3
- package/dist/lib/object/sort.mjs +186 -1
- package/dist/lib/object/transform.cjs +2211 -1
- package/dist/lib/object/transform.mjs +2190 -1
- package/dist/lib/object/types.cjs +18 -1
- package/dist/lib/object/utils.cjs +326 -6
- package/dist/lib/object/utils.mjs +305 -6
- package/dist/lib/primitive/boolean/boolean.cjs +407 -1
- package/dist/lib/primitive/boolean/boolean.mjs +386 -1
- package/dist/lib/primitive/boolean/index.cjs +382 -1
- package/dist/lib/primitive/boolean/index.mjs +359 -1
- package/dist/lib/primitive/boolean/types.cjs +18 -1
- package/dist/lib/primitive/date/date.cjs +1126 -1
- package/dist/lib/primitive/date/date.mjs +1105 -1
- package/dist/lib/primitive/date/index.cjs +1128 -1
- package/dist/lib/primitive/date/index.mjs +1105 -1
- package/dist/lib/primitive/date/types.cjs +18 -1
- package/dist/lib/primitive/index.cjs +2338 -5
- package/dist/lib/primitive/index.mjs +2316 -5
- package/dist/lib/primitive/string/index.cjs +875 -5
- package/dist/lib/primitive/string/index.mjs +852 -5
- package/dist/lib/primitive/string/parser-2.cjs +543 -8
- package/dist/lib/primitive/string/parser-2.mjs +522 -8
- package/dist/lib/primitive/string/parser.cjs +236 -3
- package/dist/lib/primitive/string/parser.mjs +215 -3
- package/dist/lib/primitive/string/string.cjs +926 -5
- package/dist/lib/primitive/string/string.mjs +903 -5
- package/dist/lib/primitive/string/types.cjs +18 -1
- package/dist/lib/primitive/types.cjs +18 -1
- package/dist/lib/url/index.cjs +327 -1
- package/dist/lib/url/index.mjs +304 -1
- package/dist/lib/url/parser.cjs +325 -1
- package/dist/lib/url/parser.mjs +304 -1
- package/dist/lib/url/types.cjs +18 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +5 -5
|
@@ -1 +1,61 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lib/maths/formatter.ts
|
|
21
|
+
var formatter_exports = {};
|
|
22
|
+
__export(formatter_exports, {
|
|
23
|
+
formatBytes: () => formatBytes,
|
|
24
|
+
formatCurrency: () => formatCurrency,
|
|
25
|
+
formatNumber: () => formatNumber,
|
|
26
|
+
formatPercent: () => formatPercent
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(formatter_exports);
|
|
29
|
+
var formatNumber = (value, options = {}) => {
|
|
30
|
+
const {
|
|
31
|
+
locale = "en-US",
|
|
32
|
+
minimumFractionDigits = 0,
|
|
33
|
+
maximumFractionDigits = 20
|
|
34
|
+
} = options;
|
|
35
|
+
return new Intl.NumberFormat(locale, {
|
|
36
|
+
minimumFractionDigits,
|
|
37
|
+
maximumFractionDigits
|
|
38
|
+
}).format(value);
|
|
39
|
+
};
|
|
40
|
+
var formatCurrency = (value, currency = "USD", locale = "en-US") => {
|
|
41
|
+
return new Intl.NumberFormat(locale, {
|
|
42
|
+
style: "currency",
|
|
43
|
+
currency
|
|
44
|
+
}).format(value);
|
|
45
|
+
};
|
|
46
|
+
var formatBytes = (bytes, decimals = 2) => {
|
|
47
|
+
if (bytes === 0) return "0 Bytes";
|
|
48
|
+
const k = 1024;
|
|
49
|
+
const dm = decimals < 0 ? 0 : decimals;
|
|
50
|
+
const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
51
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
52
|
+
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
|
|
53
|
+
};
|
|
54
|
+
var formatPercent = (value, decimals = 2, locale = "en-US") => {
|
|
55
|
+
const percent = value * 100;
|
|
56
|
+
return new Intl.NumberFormat(locale, {
|
|
57
|
+
style: "percent",
|
|
58
|
+
minimumFractionDigits: 0,
|
|
59
|
+
maximumFractionDigits: Math.max(0, decimals)
|
|
60
|
+
}).format(percent / 100);
|
|
61
|
+
};
|
|
@@ -1 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
// src/lib/maths/formatter.ts
|
|
2
|
+
var formatNumber = (value, options = {}) => {
|
|
3
|
+
const {
|
|
4
|
+
locale = "en-US",
|
|
5
|
+
minimumFractionDigits = 0,
|
|
6
|
+
maximumFractionDigits = 20
|
|
7
|
+
} = options;
|
|
8
|
+
return new Intl.NumberFormat(locale, {
|
|
9
|
+
minimumFractionDigits,
|
|
10
|
+
maximumFractionDigits
|
|
11
|
+
}).format(value);
|
|
12
|
+
};
|
|
13
|
+
var formatCurrency = (value, currency = "USD", locale = "en-US") => {
|
|
14
|
+
return new Intl.NumberFormat(locale, {
|
|
15
|
+
style: "currency",
|
|
16
|
+
currency
|
|
17
|
+
}).format(value);
|
|
18
|
+
};
|
|
19
|
+
var formatBytes = (bytes, decimals = 2) => {
|
|
20
|
+
if (bytes === 0) return "0 Bytes";
|
|
21
|
+
const k = 1024;
|
|
22
|
+
const dm = decimals < 0 ? 0 : decimals;
|
|
23
|
+
const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
24
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
25
|
+
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
|
|
26
|
+
};
|
|
27
|
+
var formatPercent = (value, decimals = 2, locale = "en-US") => {
|
|
28
|
+
const percent = value * 100;
|
|
29
|
+
return new Intl.NumberFormat(locale, {
|
|
30
|
+
style: "percent",
|
|
31
|
+
minimumFractionDigits: 0,
|
|
32
|
+
maximumFractionDigits: Math.max(0, decimals)
|
|
33
|
+
}).format(percent / 100);
|
|
34
|
+
};
|
|
35
|
+
export {
|
|
36
|
+
formatBytes,
|
|
37
|
+
formatCurrency,
|
|
38
|
+
formatNumber,
|
|
39
|
+
formatPercent
|
|
40
|
+
};
|
|
@@ -1 +1,164 @@
|
|
|
1
|
-
|
|
1
|
+
/*! @fluixi/utils v1.0.0-alpha.85 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/lib/maths/guards.ts
|
|
22
|
+
var guards_exports = {};
|
|
23
|
+
__export(guards_exports, {
|
|
24
|
+
approxEqual: () => approxEqual,
|
|
25
|
+
isComplexNumber: () => isComplexNumber,
|
|
26
|
+
isEven: () => isEven,
|
|
27
|
+
isFiniteNumber: () => isFiniteNumber,
|
|
28
|
+
isFloat: () => isFloat,
|
|
29
|
+
isFraction: () => isFraction,
|
|
30
|
+
isInRange: () => isInRange,
|
|
31
|
+
isInt: () => isInt,
|
|
32
|
+
isInteger: () => isInteger,
|
|
33
|
+
isMatrix: () => isMatrix,
|
|
34
|
+
isNegative: () => isNegative,
|
|
35
|
+
isNonNegative: () => isNonNegative,
|
|
36
|
+
isNonPositive: () => isNonPositive,
|
|
37
|
+
isNumber: () => isNumber,
|
|
38
|
+
isNumeric: () => isNumeric,
|
|
39
|
+
isNumericString: () => isNumericString,
|
|
40
|
+
isOdd: () => isOdd,
|
|
41
|
+
isPositive: () => isPositive,
|
|
42
|
+
isPowerOfTwo: () => isPowerOfTwo,
|
|
43
|
+
isPrime: () => isPrime,
|
|
44
|
+
isSafeInteger: () => isSafeInteger,
|
|
45
|
+
isVector2D: () => isVector2D,
|
|
46
|
+
isVector3D: () => isVector3D,
|
|
47
|
+
isZero: () => isZero
|
|
48
|
+
});
|
|
49
|
+
module.exports = __toCommonJS(guards_exports);
|
|
50
|
+
var isNumericString = (value) => {
|
|
51
|
+
const trimmed = value.trim();
|
|
52
|
+
if (trimmed === "") return false;
|
|
53
|
+
if (!/^[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?$/.test(trimmed)) return false;
|
|
54
|
+
const num = Number(trimmed);
|
|
55
|
+
return Number.isFinite(num);
|
|
56
|
+
};
|
|
57
|
+
var isNumeric = (value) => {
|
|
58
|
+
if (typeof value === "number") return Number.isFinite(value);
|
|
59
|
+
if (typeof value === "string") return isNumericString(value);
|
|
60
|
+
return false;
|
|
61
|
+
};
|
|
62
|
+
var isInt = (value) => {
|
|
63
|
+
if (typeof value === "number") {
|
|
64
|
+
return Number.isInteger(value);
|
|
65
|
+
}
|
|
66
|
+
if (typeof value === "string") {
|
|
67
|
+
const trimmed = value.trim();
|
|
68
|
+
if (!trimmed) return false;
|
|
69
|
+
if (!/^[-+]?\d+$/.test(trimmed)) return false;
|
|
70
|
+
const num2 = Number(trimmed);
|
|
71
|
+
return Number.isInteger(num2) && Number.isFinite(num2);
|
|
72
|
+
}
|
|
73
|
+
if (typeof value === "boolean" || value == null) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
if (Array.isArray(value)) return false;
|
|
77
|
+
const num = Number(value);
|
|
78
|
+
return !Number.isNaN(num) && Number.isInteger(num) && Number.isFinite(num);
|
|
79
|
+
};
|
|
80
|
+
var isNumber = (value) => {
|
|
81
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
82
|
+
};
|
|
83
|
+
var isSafeInteger = (value) => {
|
|
84
|
+
return typeof value === "number" && Number.isSafeInteger(value);
|
|
85
|
+
};
|
|
86
|
+
var isFloat = (value) => {
|
|
87
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return false;
|
|
88
|
+
return !Number.isInteger(value);
|
|
89
|
+
};
|
|
90
|
+
function isInteger(value) {
|
|
91
|
+
return Number.isInteger(value);
|
|
92
|
+
}
|
|
93
|
+
function isFiniteNumber(value) {
|
|
94
|
+
return Number.isFinite(value);
|
|
95
|
+
}
|
|
96
|
+
function isVector2D(value) {
|
|
97
|
+
return typeof value === "object" && value !== null && "x" in value && "y" in value && typeof value.x === "number" && typeof value.y === "number";
|
|
98
|
+
}
|
|
99
|
+
function isVector3D(value) {
|
|
100
|
+
return typeof value === "object" && value !== null && "x" in value && "y" in value && "z" in value && typeof value.x === "number" && typeof value.y === "number" && typeof value.z === "number";
|
|
101
|
+
}
|
|
102
|
+
function isComplexNumber(value) {
|
|
103
|
+
return typeof value === "object" && value !== null && "real" in value && "imag" in value && typeof value.real === "number" && typeof value.imag === "number";
|
|
104
|
+
}
|
|
105
|
+
function isFraction(value) {
|
|
106
|
+
return typeof value === "object" && value !== null && "numerator" in value && "denominator" in value && typeof value.numerator === "number" && typeof value.denominator === "number" && value.denominator !== 0;
|
|
107
|
+
}
|
|
108
|
+
function isMatrix(value) {
|
|
109
|
+
return typeof value === "object" && value !== null && "rows" in value && "columns" in value && "data" in value && typeof value.rows === "number" && typeof value.columns === "number" && Array.isArray(value.data) && value.data.every((row) => Array.isArray(row));
|
|
110
|
+
}
|
|
111
|
+
var isPositive = (value) => {
|
|
112
|
+
return Number.isFinite(value) && value > 0;
|
|
113
|
+
};
|
|
114
|
+
var isNegative = (value) => {
|
|
115
|
+
return Number.isFinite(value) && value < 0;
|
|
116
|
+
};
|
|
117
|
+
function isNonNegative(value) {
|
|
118
|
+
return Number.isFinite(value) && value >= 0;
|
|
119
|
+
}
|
|
120
|
+
function isNonPositive(value) {
|
|
121
|
+
return Number.isFinite(value) && value <= 0;
|
|
122
|
+
}
|
|
123
|
+
var isZero = (value, epsilon = 1e-10) => {
|
|
124
|
+
return Number.isFinite(value) && Math.abs(value) < epsilon;
|
|
125
|
+
};
|
|
126
|
+
function isInRange(value, min, max, inclusive = true) {
|
|
127
|
+
return inclusive ? value >= min && value <= max : value > min && value < max;
|
|
128
|
+
}
|
|
129
|
+
function isEven(value) {
|
|
130
|
+
return (value & 1) === 0;
|
|
131
|
+
}
|
|
132
|
+
function isOdd(value) {
|
|
133
|
+
return (value & 1) === 1;
|
|
134
|
+
}
|
|
135
|
+
var isPrime = (n) => {
|
|
136
|
+
if (!Number.isInteger(n)) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
if (n <= 1) return false;
|
|
140
|
+
if (n <= 3) return true;
|
|
141
|
+
if (n % 2 === 0 || n % 3 === 0) return false;
|
|
142
|
+
for (let i = 5; i * i <= n; i += 6) {
|
|
143
|
+
if (n % i === 0 || n % (i + 2) === 0) return false;
|
|
144
|
+
}
|
|
145
|
+
return true;
|
|
146
|
+
};
|
|
147
|
+
var approxEqual = (a, b, epsilon = Math.E) => {
|
|
148
|
+
if (a === b) return true;
|
|
149
|
+
if (!Number.isFinite(a) || !Number.isFinite(b)) {
|
|
150
|
+
return a === b;
|
|
151
|
+
}
|
|
152
|
+
const absA = Math.abs(a);
|
|
153
|
+
const absB = Math.abs(b);
|
|
154
|
+
const diff = Math.abs(a - b);
|
|
155
|
+
if (a === 0 || b === 0 || diff < epsilon) {
|
|
156
|
+
return diff < epsilon;
|
|
157
|
+
}
|
|
158
|
+
if (diff > epsilon) return false;
|
|
159
|
+
const relativeError = diff / Math.min(absA + absB, Number.MAX_SAFE_INTEGER);
|
|
160
|
+
return relativeError < epsilon;
|
|
161
|
+
};
|
|
162
|
+
var isPowerOfTwo = (n) => {
|
|
163
|
+
return n > 0 && (n & n - 1) === 0;
|
|
164
|
+
};
|
|
@@ -1 +1,144 @@
|
|
|
1
|
-
|
|
1
|
+
/*! @fluixi/utils v1.0.0-alpha.85 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
|
+
|
|
3
|
+
// src/lib/maths/guards.ts
|
|
4
|
+
var isNumericString = (value) => {
|
|
5
|
+
const trimmed = value.trim();
|
|
6
|
+
if (trimmed === "") return false;
|
|
7
|
+
if (!/^[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?$/.test(trimmed)) return false;
|
|
8
|
+
const num = Number(trimmed);
|
|
9
|
+
return Number.isFinite(num);
|
|
10
|
+
};
|
|
11
|
+
var isNumeric = (value) => {
|
|
12
|
+
if (typeof value === "number") return Number.isFinite(value);
|
|
13
|
+
if (typeof value === "string") return isNumericString(value);
|
|
14
|
+
return false;
|
|
15
|
+
};
|
|
16
|
+
var isInt = (value) => {
|
|
17
|
+
if (typeof value === "number") {
|
|
18
|
+
return Number.isInteger(value);
|
|
19
|
+
}
|
|
20
|
+
if (typeof value === "string") {
|
|
21
|
+
const trimmed = value.trim();
|
|
22
|
+
if (!trimmed) return false;
|
|
23
|
+
if (!/^[-+]?\d+$/.test(trimmed)) return false;
|
|
24
|
+
const num2 = Number(trimmed);
|
|
25
|
+
return Number.isInteger(num2) && Number.isFinite(num2);
|
|
26
|
+
}
|
|
27
|
+
if (typeof value === "boolean" || value == null) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
if (Array.isArray(value)) return false;
|
|
31
|
+
const num = Number(value);
|
|
32
|
+
return !Number.isNaN(num) && Number.isInteger(num) && Number.isFinite(num);
|
|
33
|
+
};
|
|
34
|
+
var isNumber = (value) => {
|
|
35
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
36
|
+
};
|
|
37
|
+
var isSafeInteger = (value) => {
|
|
38
|
+
return typeof value === "number" && Number.isSafeInteger(value);
|
|
39
|
+
};
|
|
40
|
+
var isFloat = (value) => {
|
|
41
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return false;
|
|
42
|
+
return !Number.isInteger(value);
|
|
43
|
+
};
|
|
44
|
+
function isInteger(value) {
|
|
45
|
+
return Number.isInteger(value);
|
|
46
|
+
}
|
|
47
|
+
function isFiniteNumber(value) {
|
|
48
|
+
return Number.isFinite(value);
|
|
49
|
+
}
|
|
50
|
+
function isVector2D(value) {
|
|
51
|
+
return typeof value === "object" && value !== null && "x" in value && "y" in value && typeof value.x === "number" && typeof value.y === "number";
|
|
52
|
+
}
|
|
53
|
+
function isVector3D(value) {
|
|
54
|
+
return typeof value === "object" && value !== null && "x" in value && "y" in value && "z" in value && typeof value.x === "number" && typeof value.y === "number" && typeof value.z === "number";
|
|
55
|
+
}
|
|
56
|
+
function isComplexNumber(value) {
|
|
57
|
+
return typeof value === "object" && value !== null && "real" in value && "imag" in value && typeof value.real === "number" && typeof value.imag === "number";
|
|
58
|
+
}
|
|
59
|
+
function isFraction(value) {
|
|
60
|
+
return typeof value === "object" && value !== null && "numerator" in value && "denominator" in value && typeof value.numerator === "number" && typeof value.denominator === "number" && value.denominator !== 0;
|
|
61
|
+
}
|
|
62
|
+
function isMatrix(value) {
|
|
63
|
+
return typeof value === "object" && value !== null && "rows" in value && "columns" in value && "data" in value && typeof value.rows === "number" && typeof value.columns === "number" && Array.isArray(value.data) && value.data.every((row) => Array.isArray(row));
|
|
64
|
+
}
|
|
65
|
+
var isPositive = (value) => {
|
|
66
|
+
return Number.isFinite(value) && value > 0;
|
|
67
|
+
};
|
|
68
|
+
var isNegative = (value) => {
|
|
69
|
+
return Number.isFinite(value) && value < 0;
|
|
70
|
+
};
|
|
71
|
+
function isNonNegative(value) {
|
|
72
|
+
return Number.isFinite(value) && value >= 0;
|
|
73
|
+
}
|
|
74
|
+
function isNonPositive(value) {
|
|
75
|
+
return Number.isFinite(value) && value <= 0;
|
|
76
|
+
}
|
|
77
|
+
var isZero = (value, epsilon = 1e-10) => {
|
|
78
|
+
return Number.isFinite(value) && Math.abs(value) < epsilon;
|
|
79
|
+
};
|
|
80
|
+
function isInRange(value, min, max, inclusive = true) {
|
|
81
|
+
return inclusive ? value >= min && value <= max : value > min && value < max;
|
|
82
|
+
}
|
|
83
|
+
function isEven(value) {
|
|
84
|
+
return (value & 1) === 0;
|
|
85
|
+
}
|
|
86
|
+
function isOdd(value) {
|
|
87
|
+
return (value & 1) === 1;
|
|
88
|
+
}
|
|
89
|
+
var isPrime = (n) => {
|
|
90
|
+
if (!Number.isInteger(n)) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
if (n <= 1) return false;
|
|
94
|
+
if (n <= 3) return true;
|
|
95
|
+
if (n % 2 === 0 || n % 3 === 0) return false;
|
|
96
|
+
for (let i = 5; i * i <= n; i += 6) {
|
|
97
|
+
if (n % i === 0 || n % (i + 2) === 0) return false;
|
|
98
|
+
}
|
|
99
|
+
return true;
|
|
100
|
+
};
|
|
101
|
+
var approxEqual = (a, b, epsilon = Math.E) => {
|
|
102
|
+
if (a === b) return true;
|
|
103
|
+
if (!Number.isFinite(a) || !Number.isFinite(b)) {
|
|
104
|
+
return a === b;
|
|
105
|
+
}
|
|
106
|
+
const absA = Math.abs(a);
|
|
107
|
+
const absB = Math.abs(b);
|
|
108
|
+
const diff = Math.abs(a - b);
|
|
109
|
+
if (a === 0 || b === 0 || diff < epsilon) {
|
|
110
|
+
return diff < epsilon;
|
|
111
|
+
}
|
|
112
|
+
if (diff > epsilon) return false;
|
|
113
|
+
const relativeError = diff / Math.min(absA + absB, Number.MAX_SAFE_INTEGER);
|
|
114
|
+
return relativeError < epsilon;
|
|
115
|
+
};
|
|
116
|
+
var isPowerOfTwo = (n) => {
|
|
117
|
+
return n > 0 && (n & n - 1) === 0;
|
|
118
|
+
};
|
|
119
|
+
export {
|
|
120
|
+
approxEqual,
|
|
121
|
+
isComplexNumber,
|
|
122
|
+
isEven,
|
|
123
|
+
isFiniteNumber,
|
|
124
|
+
isFloat,
|
|
125
|
+
isFraction,
|
|
126
|
+
isInRange,
|
|
127
|
+
isInt,
|
|
128
|
+
isInteger,
|
|
129
|
+
isMatrix,
|
|
130
|
+
isNegative,
|
|
131
|
+
isNonNegative,
|
|
132
|
+
isNonPositive,
|
|
133
|
+
isNumber,
|
|
134
|
+
isNumeric,
|
|
135
|
+
isNumericString,
|
|
136
|
+
isOdd,
|
|
137
|
+
isPositive,
|
|
138
|
+
isPowerOfTwo,
|
|
139
|
+
isPrime,
|
|
140
|
+
isSafeInteger,
|
|
141
|
+
isVector2D,
|
|
142
|
+
isVector3D,
|
|
143
|
+
isZero
|
|
144
|
+
};
|