@helpers4/number 2.0.0-alpha.2 → 2.0.0-alpha.21
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.md +150 -650
- package/README.md +11 -5
- package/lib/index.d.ts +92 -4
- package/lib/index.js +119 -15
- package/lib/index.js.map +1 -0
- package/llms.txt +236 -0
- package/meta/api.json +226 -0
- package/meta/category.json +6 -0
- package/meta/examples.json +70 -0
- package/meta/licenses.json +4 -0
- package/meta/native-alternatives.json +37 -0
- package/package.json +20 -6
package/meta/api.json
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
{
|
|
2
|
+
"category": "number",
|
|
3
|
+
"version": "2.0.0-alpha.21",
|
|
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": "formatSize",
|
|
48
|
+
"kind": "function",
|
|
49
|
+
"description": "Format a byte count into a human-readable string with the appropriate unit.\n\nEach unit is 1024 of the previous (binary prefix). The result is formatted\nwith one decimal place.",
|
|
50
|
+
"since": "next",
|
|
51
|
+
"signatures": [
|
|
52
|
+
{
|
|
53
|
+
"signature": "formatSize(bytes: number): string",
|
|
54
|
+
"description": "Format a byte count into a human-readable string with the appropriate unit.\n\nEach unit is 1024 of the previous (binary prefix). The result is formatted\nwith one decimal place.",
|
|
55
|
+
"params": [
|
|
56
|
+
{
|
|
57
|
+
"name": "bytes",
|
|
58
|
+
"type": "number",
|
|
59
|
+
"description": "A non-negative integer representing a byte count."
|
|
60
|
+
}
|
|
61
|
+
],
|
|
62
|
+
"returns": {
|
|
63
|
+
"type": "string",
|
|
64
|
+
"description": "A human-readable string such as `'0.0B'`, `'1.5KB'`, `'3.2MB'`."
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
"examples": [
|
|
69
|
+
{
|
|
70
|
+
"title": "Format bytes to human-readable size",
|
|
71
|
+
"description": "Converts a raw byte count to a human-readable string using binary prefixes.",
|
|
72
|
+
"code": "formatSize(0) // '0.0B'\nformatSize(512) // '512.0B'\nformatSize(1024) // '1.0KB'\nformatSize(1_048_576) // '1.0MB'\nformatSize(1_073_741_824) // '1.0GB'"
|
|
73
|
+
}
|
|
74
|
+
],
|
|
75
|
+
"sourceFile": "formatSize.ts"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"name": "randomBetween",
|
|
79
|
+
"kind": "function",
|
|
80
|
+
"description": "Generates a random number between min and max (inclusive)",
|
|
81
|
+
"since": "1.9.0",
|
|
82
|
+
"signatures": [
|
|
83
|
+
{
|
|
84
|
+
"signature": "randomBetween(min: number, max: number): number",
|
|
85
|
+
"description": "Generates a random number between min and max (inclusive)",
|
|
86
|
+
"params": [
|
|
87
|
+
{
|
|
88
|
+
"name": "min",
|
|
89
|
+
"type": "number",
|
|
90
|
+
"description": "Minimum value"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"name": "max",
|
|
94
|
+
"type": "number",
|
|
95
|
+
"description": "Maximum value"
|
|
96
|
+
}
|
|
97
|
+
],
|
|
98
|
+
"returns": {
|
|
99
|
+
"type": "number",
|
|
100
|
+
"description": "Random number between min and max"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
],
|
|
104
|
+
"examples": [
|
|
105
|
+
{
|
|
106
|
+
"title": "Generate a random float in range",
|
|
107
|
+
"description": "Returns a random number between min and max (inclusive).",
|
|
108
|
+
"code": "randomBetween(1, 10)\n// => e.g. 5.327..."
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"title": "Generate a random integer in range",
|
|
112
|
+
"description": "Returns a random integer between min and max (inclusive).",
|
|
113
|
+
"code": "randomIntBetween(1, 6)\n// => e.g. 4"
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
"sourceFile": "random.ts"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"name": "randomIntBetween",
|
|
120
|
+
"kind": "function",
|
|
121
|
+
"description": "Generates a random integer between min and max (inclusive)",
|
|
122
|
+
"since": "1.9.0",
|
|
123
|
+
"signatures": [
|
|
124
|
+
{
|
|
125
|
+
"signature": "randomIntBetween(min: number, max: number): number",
|
|
126
|
+
"description": "Generates a random integer between min and max (inclusive)",
|
|
127
|
+
"params": [
|
|
128
|
+
{
|
|
129
|
+
"name": "min",
|
|
130
|
+
"type": "number",
|
|
131
|
+
"description": "Minimum value"
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"name": "max",
|
|
135
|
+
"type": "number",
|
|
136
|
+
"description": "Maximum value"
|
|
137
|
+
}
|
|
138
|
+
],
|
|
139
|
+
"returns": {
|
|
140
|
+
"type": "number",
|
|
141
|
+
"description": "Random integer between min and max"
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
],
|
|
145
|
+
"examples": [],
|
|
146
|
+
"sourceFile": "random.ts"
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
"name": "roundTo",
|
|
150
|
+
"kind": "function",
|
|
151
|
+
"description": "Rounds a number to specified decimal places",
|
|
152
|
+
"since": "1.9.0",
|
|
153
|
+
"signatures": [
|
|
154
|
+
{
|
|
155
|
+
"signature": "roundTo(value: number, decimals: number): number",
|
|
156
|
+
"description": "Rounds a number to specified decimal places",
|
|
157
|
+
"params": [
|
|
158
|
+
{
|
|
159
|
+
"name": "value",
|
|
160
|
+
"type": "number",
|
|
161
|
+
"description": "The number to round"
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
"name": "decimals",
|
|
165
|
+
"type": "number",
|
|
166
|
+
"description": "Number of decimal places"
|
|
167
|
+
}
|
|
168
|
+
],
|
|
169
|
+
"returns": {
|
|
170
|
+
"type": "number",
|
|
171
|
+
"description": "Rounded number"
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
],
|
|
175
|
+
"examples": [
|
|
176
|
+
{
|
|
177
|
+
"title": "Round to 2 decimal places",
|
|
178
|
+
"description": "Rounds a floating-point number to the specified number of decimals.",
|
|
179
|
+
"code": "roundTo(3.14159, 2)\n// => 3.14"
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
"title": "Round to 0 decimal places",
|
|
183
|
+
"description": "Effectively rounds to the nearest integer.",
|
|
184
|
+
"code": "roundTo(3.7, 0)\n// => 4"
|
|
185
|
+
}
|
|
186
|
+
],
|
|
187
|
+
"sourceFile": "roundTo.ts"
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
"name": "sum",
|
|
191
|
+
"kind": "function",
|
|
192
|
+
"description": "Calculates the sum of an array of numbers.",
|
|
193
|
+
"since": "2.0.0",
|
|
194
|
+
"signatures": [
|
|
195
|
+
{
|
|
196
|
+
"signature": "sum(array: readonly number[]): number",
|
|
197
|
+
"description": "Calculates the sum of an array of numbers.",
|
|
198
|
+
"params": [
|
|
199
|
+
{
|
|
200
|
+
"name": "array",
|
|
201
|
+
"type": "readonly number[]",
|
|
202
|
+
"description": "The array of numbers to sum"
|
|
203
|
+
}
|
|
204
|
+
],
|
|
205
|
+
"returns": {
|
|
206
|
+
"type": "number",
|
|
207
|
+
"description": "The sum of all values"
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
],
|
|
211
|
+
"examples": [
|
|
212
|
+
{
|
|
213
|
+
"title": "Sum numbers",
|
|
214
|
+
"description": "Calculates the sum of an array of numbers.",
|
|
215
|
+
"code": "sum([1, 2, 3, 4])\n// => 10"
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
"title": "Sum with negative numbers",
|
|
219
|
+
"description": "Handles negative numbers correctly.",
|
|
220
|
+
"code": "sum([10, -3, 5, -2])\n// => 10"
|
|
221
|
+
}
|
|
222
|
+
],
|
|
223
|
+
"sourceFile": "sum.ts"
|
|
224
|
+
}
|
|
225
|
+
]
|
|
226
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"category": "number",
|
|
3
|
+
"functions": [
|
|
4
|
+
{
|
|
5
|
+
"name": "clamp",
|
|
6
|
+
"examples": [
|
|
7
|
+
{
|
|
8
|
+
"title": "Clamp a value within range",
|
|
9
|
+
"description": "Restricts a number to be within a min/max range.",
|
|
10
|
+
"code": "clamp(15, 0, 10) // => 10\nclamp(-5, 0, 10) // => 0\nclamp(5, 0, 10) // => 5"
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": "formatSize",
|
|
16
|
+
"examples": [
|
|
17
|
+
{
|
|
18
|
+
"title": "Format bytes to human-readable size",
|
|
19
|
+
"description": "Converts a raw byte count to a human-readable string using binary prefixes.",
|
|
20
|
+
"code": "formatSize(0) // '0.0B'\nformatSize(512) // '512.0B'\nformatSize(1024) // '1.0KB'\nformatSize(1_048_576) // '1.0MB'\nformatSize(1_073_741_824) // '1.0GB'"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"name": "randomBetween",
|
|
26
|
+
"examples": [
|
|
27
|
+
{
|
|
28
|
+
"title": "Generate a random float in range",
|
|
29
|
+
"description": "Returns a random number between min and max (inclusive).",
|
|
30
|
+
"code": "randomBetween(1, 10)\n// => e.g. 5.327..."
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"title": "Generate a random integer in range",
|
|
34
|
+
"description": "Returns a random integer between min and max (inclusive).",
|
|
35
|
+
"code": "randomIntBetween(1, 6)\n// => e.g. 4"
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"name": "roundTo",
|
|
41
|
+
"examples": [
|
|
42
|
+
{
|
|
43
|
+
"title": "Round to 2 decimal places",
|
|
44
|
+
"description": "Rounds a floating-point number to the specified number of decimals.",
|
|
45
|
+
"code": "roundTo(3.14159, 2)\n// => 3.14"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"title": "Round to 0 decimal places",
|
|
49
|
+
"description": "Effectively rounds to the nearest integer.",
|
|
50
|
+
"code": "roundTo(3.7, 0)\n// => 4"
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"name": "sum",
|
|
56
|
+
"examples": [
|
|
57
|
+
{
|
|
58
|
+
"title": "Sum numbers",
|
|
59
|
+
"description": "Calculates the sum of an array of numbers.",
|
|
60
|
+
"code": "sum([1, 2, 3, 4])\n// => 10"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"title": "Sum with negative numbers",
|
|
64
|
+
"description": "Handles negative numbers correctly.",
|
|
65
|
+
"code": "sum([10, -3, 5, -2])\n// => 10"
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"category": "number",
|
|
3
|
+
"functions": [
|
|
4
|
+
{
|
|
5
|
+
"name": "min / max",
|
|
6
|
+
"libraries": [
|
|
7
|
+
"lodash",
|
|
8
|
+
"radashi",
|
|
9
|
+
"ramda"
|
|
10
|
+
],
|
|
11
|
+
"native": "Math.min(...arr) / Math.max(...arr)",
|
|
12
|
+
"since": "ES1",
|
|
13
|
+
"example": "Math.min(...numbers)\nMath.max(...numbers)",
|
|
14
|
+
"notes": "For large arrays, prefer reduce to avoid stack overflow"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"name": "ceil / floor",
|
|
18
|
+
"libraries": [
|
|
19
|
+
"lodash"
|
|
20
|
+
],
|
|
21
|
+
"native": "Math.ceil() / Math.floor()",
|
|
22
|
+
"since": "ES1",
|
|
23
|
+
"example": "Math.ceil(4.2) // 5\nMath.floor(4.8) // 4",
|
|
24
|
+
"notes": "No precision param natively; use roundTo from helpers4 for decimal precision"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"name": "toInt / toFloat",
|
|
28
|
+
"libraries": [
|
|
29
|
+
"radashi"
|
|
30
|
+
],
|
|
31
|
+
"native": "parseInt(str, 10) / parseFloat(str)",
|
|
32
|
+
"since": "ES1",
|
|
33
|
+
"example": "parseInt('42px', 10) // 42\nparseFloat('3.14') // 3.14",
|
|
34
|
+
"notes": "Radashi adds default-value fallback on NaN"
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
package/package.json
CHANGED
|
@@ -1,35 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helpers4/number",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.21",
|
|
4
4
|
"description": "A set of helpers in TS/JS, compatible with tree-shaking, for number.",
|
|
5
5
|
"author": "baxyz <baxy@etik.com>",
|
|
6
|
-
"license": "
|
|
6
|
+
"license": "LGPL-3.0",
|
|
7
|
+
"homepage": "https://helpers4.dev/typescript/categories/number/",
|
|
7
8
|
"repository": {
|
|
8
9
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/helpers4/
|
|
10
|
+
"url": "git+https://github.com/helpers4/typescript.git"
|
|
10
11
|
},
|
|
11
12
|
"type": "module",
|
|
13
|
+
"sideEffects": false,
|
|
12
14
|
"main": "lib/index.js",
|
|
13
15
|
"types": "lib/index.d.ts",
|
|
14
16
|
"exports": {
|
|
15
17
|
".": {
|
|
16
18
|
"types": "./lib/index.d.ts",
|
|
17
19
|
"import": "./lib/index.js"
|
|
18
|
-
}
|
|
20
|
+
},
|
|
21
|
+
"./meta/api.json": "./meta/api.json",
|
|
22
|
+
"./meta/examples.json": "./meta/examples.json",
|
|
23
|
+
"./meta/licenses.json": "./meta/licenses.json",
|
|
24
|
+
"./llms.txt": "./llms.txt",
|
|
25
|
+
"./package.json": "./package.json"
|
|
19
26
|
},
|
|
20
27
|
"keywords": [
|
|
21
28
|
"helpers",
|
|
22
29
|
"number",
|
|
23
30
|
"clamp",
|
|
31
|
+
"formatSize",
|
|
32
|
+
"random",
|
|
24
33
|
"roundTo",
|
|
25
|
-
"
|
|
34
|
+
"sum"
|
|
26
35
|
],
|
|
27
36
|
"files": [
|
|
28
37
|
"lib/index.js",
|
|
29
38
|
"lib/index.d.ts",
|
|
30
39
|
"lib/index.js.map",
|
|
40
|
+
"meta/",
|
|
41
|
+
"llms.txt",
|
|
31
42
|
"LICENSE.md",
|
|
32
43
|
"package.json",
|
|
33
44
|
"README.md"
|
|
34
|
-
]
|
|
45
|
+
],
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=18.0.0"
|
|
48
|
+
}
|
|
35
49
|
}
|