@helpers4/number 2.0.0-alpha.7 → 2.0.0-alpha.9
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/lib/index.d.ts +4 -0
- package/lib/index.js +4 -0
- package/lib/index.js.map +1 -1
- package/meta/api.json +159 -0
- package/{examples.json → meta/examples.json} +4 -4
- package/package.json +7 -8
- package/api.json +0 -86
- /package/{licenses.json → meta/licenses.json} +0 -0
package/lib/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* @param min - Minimum value
|
|
10
10
|
* @param max - Maximum value
|
|
11
11
|
* @returns Clamped value
|
|
12
|
+
* @since 1.9.0
|
|
12
13
|
*/
|
|
13
14
|
declare function clamp(value: number, min: number, max: number): number;
|
|
14
15
|
|
|
@@ -22,6 +23,7 @@ declare function clamp(value: number, min: number, max: number): number;
|
|
|
22
23
|
* @param min - Minimum value
|
|
23
24
|
* @param max - Maximum value
|
|
24
25
|
* @returns Random number between min and max
|
|
26
|
+
* @since 1.9.0
|
|
25
27
|
*/
|
|
26
28
|
declare function randomBetween(min: number, max: number): number;
|
|
27
29
|
/**
|
|
@@ -29,6 +31,7 @@ declare function randomBetween(min: number, max: number): number;
|
|
|
29
31
|
* @param min - Minimum value
|
|
30
32
|
* @param max - Maximum value
|
|
31
33
|
* @returns Random integer between min and max
|
|
34
|
+
* @since 1.9.0
|
|
32
35
|
*/
|
|
33
36
|
declare function randomIntBetween(min: number, max: number): number;
|
|
34
37
|
|
|
@@ -42,6 +45,7 @@ declare function randomIntBetween(min: number, max: number): number;
|
|
|
42
45
|
* @param value - The number to round
|
|
43
46
|
* @param decimals - Number of decimal places
|
|
44
47
|
* @returns Rounded number
|
|
48
|
+
* @since 1.9.0
|
|
45
49
|
*/
|
|
46
50
|
declare function roundTo(value: number, decimals: number): number;
|
|
47
51
|
|
package/lib/index.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* @param min - Minimum value
|
|
11
11
|
* @param max - Maximum value
|
|
12
12
|
* @returns Clamped value
|
|
13
|
+
* @since 1.9.0
|
|
13
14
|
*/
|
|
14
15
|
function clamp(value, min, max) {
|
|
15
16
|
return Math.min(Math.max(value, min), max);
|
|
@@ -26,6 +27,7 @@ function clamp(value, min, max) {
|
|
|
26
27
|
* @param min - Minimum value
|
|
27
28
|
* @param max - Maximum value
|
|
28
29
|
* @returns Random number between min and max
|
|
30
|
+
* @since 1.9.0
|
|
29
31
|
*/
|
|
30
32
|
function randomBetween(min, max) {
|
|
31
33
|
return Math.random() * (max - min) + min;
|
|
@@ -35,6 +37,7 @@ function randomBetween(min, max) {
|
|
|
35
37
|
* @param min - Minimum value
|
|
36
38
|
* @param max - Maximum value
|
|
37
39
|
* @returns Random integer between min and max
|
|
40
|
+
* @since 1.9.0
|
|
38
41
|
*/
|
|
39
42
|
function randomIntBetween(min, max) {
|
|
40
43
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
@@ -51,6 +54,7 @@ function randomIntBetween(min, max) {
|
|
|
51
54
|
* @param value - The number to round
|
|
52
55
|
* @param decimals - Number of decimal places
|
|
53
56
|
* @returns Rounded number
|
|
57
|
+
* @since 1.9.0
|
|
54
58
|
*/
|
|
55
59
|
function roundTo(value, decimals) {
|
|
56
60
|
const multiplier = Math.pow(10, decimals);
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../helpers/number/clamp.ts","../../../helpers/number/random.ts","../../../helpers/number/roundTo.ts"],"sourcesContent":["/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Clamps a number between min and max values\n * @param value - The value to clamp\n * @param min - Minimum value\n * @param max - Maximum value\n * @returns Clamped value\n */\nexport function clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max);\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Generates a random number between min and max (inclusive)\n * @param min - Minimum value\n * @param max - Maximum value\n * @returns Random number between min and max\n */\nexport function randomBetween(min: number, max: number): number {\n return Math.random() * (max - min) + min;\n}\n\n/**\n * Generates a random integer between min and max (inclusive)\n * @param min - Minimum value\n * @param max - Maximum value\n * @returns Random integer between min and max\n */\nexport function randomIntBetween(min: number, max: number): number {\n return Math.floor(Math.random() * (max - min + 1)) + min;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Rounds a number to specified decimal places\n * @param value - The number to round\n * @param decimals - Number of decimal places\n * @returns Rounded number\n */\nexport function roundTo(value: number, decimals: number): number {\n const multiplier = Math.pow(10, decimals);\n return Math.round(value * multiplier) / multiplier;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../helpers/number/clamp.ts","../../../helpers/number/random.ts","../../../helpers/number/roundTo.ts"],"sourcesContent":["/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Clamps a number between min and max values\n * @param value - The value to clamp\n * @param min - Minimum value\n * @param max - Maximum value\n * @returns Clamped value\n * @since 1.9.0\n */\nexport function clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max);\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Generates a random number between min and max (inclusive)\n * @param min - Minimum value\n * @param max - Maximum value\n * @returns Random number between min and max\n * @since 1.9.0\n */\nexport function randomBetween(min: number, max: number): number {\n return Math.random() * (max - min) + min;\n}\n\n/**\n * Generates a random integer between min and max (inclusive)\n * @param min - Minimum value\n * @param max - Maximum value\n * @returns Random integer between min and max\n * @since 1.9.0\n */\nexport function randomIntBetween(min: number, max: number): number {\n return Math.floor(Math.random() * (max - min + 1)) + min;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Rounds a number to specified decimal places\n * @param value - The number to round\n * @param decimals - Number of decimal places\n * @returns Rounded number\n * @since 1.9.0\n */\nexport function roundTo(value: number, decimals: number): number {\n const multiplier = Math.pow(10, decimals);\n return Math.round(value * multiplier) / multiplier;\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,SAAgB,MAAM,OAAe,KAAa,KAAqB;AACrE,QAAO,KAAK,IAAI,KAAK,IAAI,OAAO,IAAI,EAAE,IAAI;;;;;;;;;;;;;;;;ACF5C,SAAgB,cAAc,KAAa,KAAqB;AAC9D,QAAO,KAAK,QAAQ,IAAI,MAAM,OAAO;;;;;;;;;AAUvC,SAAgB,iBAAiB,KAAa,KAAqB;AACjE,QAAO,KAAK,MAAM,KAAK,QAAQ,IAAI,MAAM,MAAM,GAAG,GAAG;;;;;;;;;;;;;;;;ACZvD,SAAgB,QAAQ,OAAe,UAA0B;CAC/D,MAAM,aAAa,KAAK,IAAI,IAAI,SAAS;AACzC,QAAO,KAAK,MAAM,QAAQ,WAAW,GAAG"}
|
package/meta/api.json
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
{
|
|
2
|
+
"category": "number",
|
|
3
|
+
"version": "2.0.0-alpha.9",
|
|
4
|
+
"functions": [
|
|
5
|
+
{
|
|
6
|
+
"name": "clamp",
|
|
7
|
+
"kind": "function",
|
|
8
|
+
"description": "Clamps a number between min and max values",
|
|
9
|
+
"since": "1.9.0",
|
|
10
|
+
"signatures": [
|
|
11
|
+
{
|
|
12
|
+
"signature": "clamp(value: number, min: number, max: number): number",
|
|
13
|
+
"description": "Clamps a number between min and max values",
|
|
14
|
+
"params": [
|
|
15
|
+
{
|
|
16
|
+
"name": "value",
|
|
17
|
+
"type": "number",
|
|
18
|
+
"description": "The value to clamp"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"name": "min",
|
|
22
|
+
"type": "number",
|
|
23
|
+
"description": "Minimum value"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "max",
|
|
27
|
+
"type": "number",
|
|
28
|
+
"description": "Maximum value"
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
"returns": {
|
|
32
|
+
"type": "number",
|
|
33
|
+
"description": "Clamped value"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"examples": [
|
|
38
|
+
{
|
|
39
|
+
"title": "Clamp a value within range",
|
|
40
|
+
"description": "Restricts a number to be within a min/max range.",
|
|
41
|
+
"code": "clamp(15, 0, 10) // => 10\nclamp(-5, 0, 10) // => 0\nclamp(5, 0, 10) // => 5"
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
"sourceFile": "clamp.ts"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"name": "randomBetween",
|
|
48
|
+
"kind": "function",
|
|
49
|
+
"description": "Generates a random number between min and max (inclusive)",
|
|
50
|
+
"since": "1.9.0",
|
|
51
|
+
"signatures": [
|
|
52
|
+
{
|
|
53
|
+
"signature": "randomBetween(min: number, max: number): number",
|
|
54
|
+
"description": "Generates a random number between min and max (inclusive)",
|
|
55
|
+
"params": [
|
|
56
|
+
{
|
|
57
|
+
"name": "min",
|
|
58
|
+
"type": "number",
|
|
59
|
+
"description": "Minimum value"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"name": "max",
|
|
63
|
+
"type": "number",
|
|
64
|
+
"description": "Maximum value"
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
"returns": {
|
|
68
|
+
"type": "number",
|
|
69
|
+
"description": "Random number between min and max"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
"examples": [
|
|
74
|
+
{
|
|
75
|
+
"title": "Generate a random float in range",
|
|
76
|
+
"description": "Returns a random number between min and max (inclusive).",
|
|
77
|
+
"code": "randomBetween(1, 10)\n// => e.g. 5.327..."
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"title": "Generate a random integer in range",
|
|
81
|
+
"description": "Returns a random integer between min and max (inclusive).",
|
|
82
|
+
"code": "randomIntBetween(1, 6)\n// => e.g. 4"
|
|
83
|
+
}
|
|
84
|
+
],
|
|
85
|
+
"sourceFile": "random.ts"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"name": "randomIntBetween",
|
|
89
|
+
"kind": "function",
|
|
90
|
+
"description": "Generates a random integer between min and max (inclusive)",
|
|
91
|
+
"since": "1.9.0",
|
|
92
|
+
"signatures": [
|
|
93
|
+
{
|
|
94
|
+
"signature": "randomIntBetween(min: number, max: number): number",
|
|
95
|
+
"description": "Generates a random integer between min and max (inclusive)",
|
|
96
|
+
"params": [
|
|
97
|
+
{
|
|
98
|
+
"name": "min",
|
|
99
|
+
"type": "number",
|
|
100
|
+
"description": "Minimum value"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"name": "max",
|
|
104
|
+
"type": "number",
|
|
105
|
+
"description": "Maximum value"
|
|
106
|
+
}
|
|
107
|
+
],
|
|
108
|
+
"returns": {
|
|
109
|
+
"type": "number",
|
|
110
|
+
"description": "Random integer between min and max"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
],
|
|
114
|
+
"examples": [],
|
|
115
|
+
"sourceFile": "random.ts"
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"name": "roundTo",
|
|
119
|
+
"kind": "function",
|
|
120
|
+
"description": "Rounds a number to specified decimal places",
|
|
121
|
+
"since": "1.9.0",
|
|
122
|
+
"signatures": [
|
|
123
|
+
{
|
|
124
|
+
"signature": "roundTo(value: number, decimals: number): number",
|
|
125
|
+
"description": "Rounds a number to specified decimal places",
|
|
126
|
+
"params": [
|
|
127
|
+
{
|
|
128
|
+
"name": "value",
|
|
129
|
+
"type": "number",
|
|
130
|
+
"description": "The number to round"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"name": "decimals",
|
|
134
|
+
"type": "number",
|
|
135
|
+
"description": "Number of decimal places"
|
|
136
|
+
}
|
|
137
|
+
],
|
|
138
|
+
"returns": {
|
|
139
|
+
"type": "number",
|
|
140
|
+
"description": "Rounded number"
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
],
|
|
144
|
+
"examples": [
|
|
145
|
+
{
|
|
146
|
+
"title": "Round to 2 decimal places",
|
|
147
|
+
"description": "Rounds a floating-point number to the specified number of decimals.",
|
|
148
|
+
"code": "roundTo(3.14159, 2)\n// => 3.14"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"title": "Round to 0 decimal places",
|
|
152
|
+
"description": "Effectively rounds to the nearest integer.",
|
|
153
|
+
"code": "roundTo(3.7, 0)\n// => 4"
|
|
154
|
+
}
|
|
155
|
+
],
|
|
156
|
+
"sourceFile": "roundTo.ts"
|
|
157
|
+
}
|
|
158
|
+
]
|
|
159
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"category": "number",
|
|
3
|
-
"
|
|
3
|
+
"functions": [
|
|
4
4
|
{
|
|
5
|
-
"
|
|
5
|
+
"name": "clamp",
|
|
6
6
|
"examples": [
|
|
7
7
|
{
|
|
8
8
|
"title": "Clamp a value within range",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
]
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
|
-
"
|
|
15
|
+
"name": "randomBetween",
|
|
16
16
|
"examples": [
|
|
17
17
|
{
|
|
18
18
|
"title": "Generate a random float in range",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
]
|
|
28
28
|
},
|
|
29
29
|
{
|
|
30
|
-
"
|
|
30
|
+
"name": "roundTo",
|
|
31
31
|
"examples": [
|
|
32
32
|
{
|
|
33
33
|
"title": "Round to 2 decimal places",
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helpers4/number",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.9",
|
|
4
4
|
"description": "A set of helpers in TS/JS, compatible with tree-shaking, for number.",
|
|
5
5
|
"author": "baxyz <baxy@etik.com>",
|
|
6
6
|
"license": "LGPL-3.0",
|
|
7
|
+
"homepage": "https://helpers4.dev/typescript/categories/number/",
|
|
7
8
|
"repository": {
|
|
8
9
|
"type": "git",
|
|
9
10
|
"url": "git+https://github.com/helpers4/typescript.git"
|
|
@@ -17,9 +18,9 @@
|
|
|
17
18
|
"types": "./lib/index.d.ts",
|
|
18
19
|
"import": "./lib/index.js"
|
|
19
20
|
},
|
|
20
|
-
"./
|
|
21
|
-
"./
|
|
22
|
-
"./licenses.json": "./licenses.json",
|
|
21
|
+
"./meta/api.json": "./meta/api.json",
|
|
22
|
+
"./meta/examples.json": "./meta/examples.json",
|
|
23
|
+
"./meta/licenses.json": "./meta/licenses.json",
|
|
23
24
|
"./package.json": "./package.json"
|
|
24
25
|
},
|
|
25
26
|
"keywords": [
|
|
@@ -33,9 +34,7 @@
|
|
|
33
34
|
"lib/index.js",
|
|
34
35
|
"lib/index.d.ts",
|
|
35
36
|
"lib/index.js.map",
|
|
36
|
-
"
|
|
37
|
-
"api.json",
|
|
38
|
-
"licenses.json",
|
|
37
|
+
"meta/",
|
|
39
38
|
"LICENSE.md",
|
|
40
39
|
"package.json",
|
|
41
40
|
"README.md"
|
|
@@ -43,4 +42,4 @@
|
|
|
43
42
|
"engines": {
|
|
44
43
|
"node": ">=18.0.0"
|
|
45
44
|
}
|
|
46
|
-
}
|
|
45
|
+
}
|
package/api.json
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"category": "number",
|
|
3
|
-
"members": [
|
|
4
|
-
{
|
|
5
|
-
"name": "clamp",
|
|
6
|
-
"kind": "function",
|
|
7
|
-
"description": "Clamps a number between min and max values",
|
|
8
|
-
"signature": "clamp(value: number, min: number, max: number): number",
|
|
9
|
-
"params": [
|
|
10
|
-
{
|
|
11
|
-
"name": "value",
|
|
12
|
-
"type": "number",
|
|
13
|
-
"description": "The value to clamp"
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"name": "min",
|
|
17
|
-
"type": "number",
|
|
18
|
-
"description": "Minimum value"
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"name": "max",
|
|
22
|
-
"type": "number",
|
|
23
|
-
"description": "Maximum value"
|
|
24
|
-
}
|
|
25
|
-
],
|
|
26
|
-
"returns": "number"
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
"name": "randomBetween",
|
|
30
|
-
"kind": "function",
|
|
31
|
-
"description": "Generates a random number between min and max (inclusive)",
|
|
32
|
-
"signature": "randomBetween(min: number, max: number): number",
|
|
33
|
-
"params": [
|
|
34
|
-
{
|
|
35
|
-
"name": "min",
|
|
36
|
-
"type": "number",
|
|
37
|
-
"description": "Minimum value"
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
"name": "max",
|
|
41
|
-
"type": "number",
|
|
42
|
-
"description": "Maximum value"
|
|
43
|
-
}
|
|
44
|
-
],
|
|
45
|
-
"returns": "number"
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
"name": "randomIntBetween",
|
|
49
|
-
"kind": "function",
|
|
50
|
-
"description": "Generates a random integer between min and max (inclusive)",
|
|
51
|
-
"signature": "randomIntBetween(min: number, max: number): number",
|
|
52
|
-
"params": [
|
|
53
|
-
{
|
|
54
|
-
"name": "min",
|
|
55
|
-
"type": "number",
|
|
56
|
-
"description": "Minimum value"
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
"name": "max",
|
|
60
|
-
"type": "number",
|
|
61
|
-
"description": "Maximum value"
|
|
62
|
-
}
|
|
63
|
-
],
|
|
64
|
-
"returns": "number"
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
"name": "roundTo",
|
|
68
|
-
"kind": "function",
|
|
69
|
-
"description": "Rounds a number to specified decimal places",
|
|
70
|
-
"signature": "roundTo(value: number, decimals: number): number",
|
|
71
|
-
"params": [
|
|
72
|
-
{
|
|
73
|
-
"name": "value",
|
|
74
|
-
"type": "number",
|
|
75
|
-
"description": "The number to round"
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
"name": "decimals",
|
|
79
|
-
"type": "number",
|
|
80
|
-
"description": "Number of decimal places"
|
|
81
|
-
}
|
|
82
|
-
],
|
|
83
|
-
"returns": "number"
|
|
84
|
-
}
|
|
85
|
-
]
|
|
86
|
-
}
|
|
File without changes
|