@js-utils-kit/number 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Sriman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ function e(e,t,n){return Math.min(Math.max(e,t),n)}function t(e=0,t=0,n=0,r=0){if([e,t,n,r].some(e=>e<0))throw Error(`All time values must be non-negative numbers.`);return(e*24*60*60+t*60*60+n*60+r)*1e3}function n(e){return e%2==0}function r(e){return e%2!=0}function i(e,t){return Math.random()*(t-e)+e}function a(e,t){return Math.floor(Math.random()*(t-e+1))+e}exports.clamp=e,exports.getMilliseconds=t,exports.isEven=n,exports.isOdd=r,exports.randomFloat=i,exports.randomInt=a;var o=require(`@js-utils-kit/types`);Object.keys(o).forEach(function(e){e!==`default`&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return o[e]}})});
@@ -0,0 +1,108 @@
1
+ import { Hour, MinuteOrSecond } from "@js-utils-kit/types";
2
+ export * from "@js-utils-kit/types";
3
+
4
+ //#region src/clamp.d.ts
5
+
6
+ /**
7
+ * Clamps a number between a minimum and maximum value.
8
+ *
9
+ * Ensures that the returned number is not less than `min` and not more than `max`.
10
+ *
11
+ * @returns The clamped number.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * clamp(5, 1, 10); // 5
16
+ * clamp(0, 1, 10); // 1
17
+ * clamp(15, 1, 10); // 10
18
+ * ```
19
+ */
20
+ declare function clamp(/** The number to clamp */
21
+ value: number, /** The minimum allowed value */
22
+ min: number, /** The maximum allowed value */
23
+ max: number): number;
24
+ //#endregion
25
+ //#region src/getMilliseconds.d.ts
26
+ /**
27
+ * Converts a time duration (days, hours, minutes, seconds) into total milliseconds.
28
+ *
29
+ * @returns The equivalent duration in milliseconds.
30
+ *
31
+ * @throws Will throw an error if any parameter is negative.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * getMilliseconds(1); // 86400000 (1 day)
36
+ * getMilliseconds(0, 1); // 3600000 (1 hour)
37
+ * getMilliseconds(0, 0, 30, 15); // 1815000 (30 minutes 15 seconds)
38
+ * ```
39
+ */
40
+ declare function getMilliseconds(/** Number of days. */
41
+ days?: number, /** Hour of the day (`0–23`). */
42
+ hours?: Hour, /** Minute value (`0–59`). */
43
+ minutes?: MinuteOrSecond, /** Second value (`0–59`). */
44
+ seconds?: MinuteOrSecond): number;
45
+ //#endregion
46
+ //#region src/isEven.d.ts
47
+ /**
48
+ * Checks if a number is even.
49
+ *
50
+ * @returns True if the number is even, false otherwise.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * isEven(4); // true
55
+ * isEven(3); // false
56
+ * ```
57
+ */
58
+ declare function isEven(/** The number to check */
59
+ value: number): boolean;
60
+ //#endregion
61
+ //#region src/isOdd.d.ts
62
+ /**
63
+ * Checks if a number is odd.
64
+ *
65
+ * @returns True if the number is odd, false otherwise.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * isOdd(3); // true
70
+ * isOdd(4); // false
71
+ * ```
72
+ */
73
+ declare function isOdd(/** The number to check */
74
+ value: number): boolean;
75
+ //#endregion
76
+ //#region src/randomFloat.d.ts
77
+ /**
78
+ * Returns a random floating-point number between `min` and `max`.
79
+ *
80
+ * @returns A random float between min and max.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * randomFloat(0, 1); // 0.624...
85
+ * randomFloat(1.5, 5.2); // 3.1415...
86
+ * ```
87
+ */
88
+ declare function randomFloat(/** Minimum value */
89
+ min: number, /** Maximum value */
90
+ max: number): number;
91
+ //#endregion
92
+ //#region src/randomInt.d.ts
93
+ /**
94
+ * Returns a random integer between `min` and `max`, inclusive.
95
+ *
96
+ * @returns A random integer between min and max.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * randomInt(1, 5); // 3
101
+ * randomInt(10, 20); // 17
102
+ * ```
103
+ */
104
+ declare function randomInt(/** Minimum value */
105
+ min: number, /** Maximum value */
106
+ max: number): number;
107
+ //#endregion
108
+ export { clamp, getMilliseconds, isEven, isOdd, randomFloat, randomInt };
@@ -0,0 +1,108 @@
1
+ import { Hour, MinuteOrSecond } from "@js-utils-kit/types";
2
+ export * from "@js-utils-kit/types";
3
+
4
+ //#region src/clamp.d.ts
5
+
6
+ /**
7
+ * Clamps a number between a minimum and maximum value.
8
+ *
9
+ * Ensures that the returned number is not less than `min` and not more than `max`.
10
+ *
11
+ * @returns The clamped number.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * clamp(5, 1, 10); // 5
16
+ * clamp(0, 1, 10); // 1
17
+ * clamp(15, 1, 10); // 10
18
+ * ```
19
+ */
20
+ declare function clamp(/** The number to clamp */
21
+ value: number, /** The minimum allowed value */
22
+ min: number, /** The maximum allowed value */
23
+ max: number): number;
24
+ //#endregion
25
+ //#region src/getMilliseconds.d.ts
26
+ /**
27
+ * Converts a time duration (days, hours, minutes, seconds) into total milliseconds.
28
+ *
29
+ * @returns The equivalent duration in milliseconds.
30
+ *
31
+ * @throws Will throw an error if any parameter is negative.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * getMilliseconds(1); // 86400000 (1 day)
36
+ * getMilliseconds(0, 1); // 3600000 (1 hour)
37
+ * getMilliseconds(0, 0, 30, 15); // 1815000 (30 minutes 15 seconds)
38
+ * ```
39
+ */
40
+ declare function getMilliseconds(/** Number of days. */
41
+ days?: number, /** Hour of the day (`0–23`). */
42
+ hours?: Hour, /** Minute value (`0–59`). */
43
+ minutes?: MinuteOrSecond, /** Second value (`0–59`). */
44
+ seconds?: MinuteOrSecond): number;
45
+ //#endregion
46
+ //#region src/isEven.d.ts
47
+ /**
48
+ * Checks if a number is even.
49
+ *
50
+ * @returns True if the number is even, false otherwise.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * isEven(4); // true
55
+ * isEven(3); // false
56
+ * ```
57
+ */
58
+ declare function isEven(/** The number to check */
59
+ value: number): boolean;
60
+ //#endregion
61
+ //#region src/isOdd.d.ts
62
+ /**
63
+ * Checks if a number is odd.
64
+ *
65
+ * @returns True if the number is odd, false otherwise.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * isOdd(3); // true
70
+ * isOdd(4); // false
71
+ * ```
72
+ */
73
+ declare function isOdd(/** The number to check */
74
+ value: number): boolean;
75
+ //#endregion
76
+ //#region src/randomFloat.d.ts
77
+ /**
78
+ * Returns a random floating-point number between `min` and `max`.
79
+ *
80
+ * @returns A random float between min and max.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * randomFloat(0, 1); // 0.624...
85
+ * randomFloat(1.5, 5.2); // 3.1415...
86
+ * ```
87
+ */
88
+ declare function randomFloat(/** Minimum value */
89
+ min: number, /** Maximum value */
90
+ max: number): number;
91
+ //#endregion
92
+ //#region src/randomInt.d.ts
93
+ /**
94
+ * Returns a random integer between `min` and `max`, inclusive.
95
+ *
96
+ * @returns A random integer between min and max.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * randomInt(1, 5); // 3
101
+ * randomInt(10, 20); // 17
102
+ * ```
103
+ */
104
+ declare function randomInt(/** Minimum value */
105
+ min: number, /** Maximum value */
106
+ max: number): number;
107
+ //#endregion
108
+ export { clamp, getMilliseconds, isEven, isOdd, randomFloat, randomInt };
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ export*from"@js-utils-kit/types";function e(e,t,n){return Math.min(Math.max(e,t),n)}function t(e=0,t=0,n=0,r=0){if([e,t,n,r].some(e=>e<0))throw Error(`All time values must be non-negative numbers.`);return(e*24*60*60+t*60*60+n*60+r)*1e3}function n(e){return e%2==0}function r(e){return e%2!=0}function i(e,t){return Math.random()*(t-e)+e}function a(e,t){return Math.floor(Math.random()*(t-e+1))+e}export{e as clamp,t as getMilliseconds,n as isEven,r as isOdd,i as randomFloat,a as randomInt};
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@js-utils-kit/number",
3
+ "version": "1.0.0",
4
+ "description": "Number utilities",
5
+ "private": false,
6
+ "license": "MIT",
7
+ "author": {
8
+ "name": "Sriman",
9
+ "email": "136729116+TenEplaysOfficial@users.noreply.github.com",
10
+ "url": "https://tene.vercel.app"
11
+ },
12
+ "homepage": "https://js-utils.js.org",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/teneplaysofficial/js-utils-kit",
16
+ "directory": "packages/number"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/teneplaysofficial/js-utils-kit/issues"
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "engines": {
25
+ "node": ">=22"
26
+ },
27
+ "type": "module",
28
+ "main": "./dist/index.cjs",
29
+ "module": "./dist/index.mjs",
30
+ "types": "./dist/index.d.cts",
31
+ "exports": {
32
+ ".": {
33
+ "import": "./dist/index.mjs",
34
+ "require": "./dist/index.cjs"
35
+ }
36
+ },
37
+ "dependencies": {
38
+ "@js-utils-kit/types": "1.0.0"
39
+ },
40
+ "scripts": {
41
+ "build": "tsdown",
42
+ "test": "vitest run"
43
+ }
44
+ }