@helpers4/number 2.0.0-alpha.11 → 2.0.0-alpha.15
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/README.md +4 -4
- package/llms.txt +200 -0
- package/meta/api.json +1 -1
- package/meta/category.json +6 -0
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -40,15 +40,15 @@ A set of helpers for working with URLs.
|
|
|
40
40
|
| Name | Package | Source Code | Description |
|
|
41
41
|
|------|---------|-------------|-------------|
|
|
42
42
|
| array | [@helpers4/array](https://www.npmjs.com/package/@helpers4/array) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/array) | Array manipulation utilities |
|
|
43
|
-
| date | [@helpers4/date](https://www.npmjs.com/package/@helpers4/date) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/date) |
|
|
43
|
+
| date | [@helpers4/date](https://www.npmjs.com/package/@helpers4/date) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/date) | Date and time utility functions |
|
|
44
44
|
| function | [@helpers4/function](https://www.npmjs.com/package/@helpers4/function) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/function) | Function utilities and type guards |
|
|
45
|
-
| math | [@helpers4/math](https://www.npmjs.com/package/@helpers4/math) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/math) |
|
|
46
|
-
| number | [@helpers4/number](https://www.npmjs.com/package/@helpers4/number) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/number) |
|
|
45
|
+
| math | [@helpers4/math](https://www.npmjs.com/package/@helpers4/math) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/math) | Mathematical utility functions and calculations |
|
|
46
|
+
| number | [@helpers4/number](https://www.npmjs.com/package/@helpers4/number) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/number) | Number utility functions and validation |
|
|
47
47
|
| object | [@helpers4/object](https://www.npmjs.com/package/@helpers4/object) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/object) | Object manipulation utilities |
|
|
48
48
|
| observable | [@helpers4/observable](https://www.npmjs.com/package/@helpers4/observable) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/observable) | Observable utilities and combinators |
|
|
49
49
|
| promise | [@helpers4/promise](https://www.npmjs.com/package/@helpers4/promise) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/promise) | Promise utilities and error handling |
|
|
50
50
|
| string | [@helpers4/string](https://www.npmjs.com/package/@helpers4/string) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/string) | String manipulation and formatting utilities |
|
|
51
|
-
| type | [@helpers4/type](https://www.npmjs.com/package/@helpers4/type) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/type) |
|
|
51
|
+
| type | [@helpers4/type](https://www.npmjs.com/package/@helpers4/type) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/type) | Type checking and validation utilities |
|
|
52
52
|
| url | [@helpers4/url](https://www.npmjs.com/package/@helpers4/url) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/url) | URL parsing and manipulation utilities |
|
|
53
53
|
| version | [@helpers4/version](https://www.npmjs.com/package/@helpers4/version) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/version) | Version string manipulation utilities |
|
|
54
54
|
<!-- /AUTOMATIC-CATEGORIES-TABLE -->
|
package/llms.txt
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# @helpers4/number
|
|
2
|
+
|
|
3
|
+
> Tree-shakable TypeScript utility functions for the `number` domain.
|
|
4
|
+
> Package: `@helpers4/number` — Version: 2.0.0-alpha.15
|
|
5
|
+
> License: LGPL-3.0-or-later
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @helpers4/number
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @helpers4/number
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { clamp, randomBetween, randomIntBetween, ... } from '@helpers4/number';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Functions
|
|
22
|
+
|
|
23
|
+
| Function | Description |
|
|
24
|
+
|---|---|
|
|
25
|
+
| `clamp` | Clamps a number between min and max values |
|
|
26
|
+
| `randomBetween` | Generates a random number between min and max (inclusive) |
|
|
27
|
+
| `randomIntBetween` | Generates a random integer between min and max (inclusive) |
|
|
28
|
+
| `roundTo` | Rounds a number to specified decimal places |
|
|
29
|
+
| `sum` | Calculates the sum of an array of numbers. |
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## API Reference
|
|
34
|
+
|
|
35
|
+
### `clamp`
|
|
36
|
+
|
|
37
|
+
Clamps a number between min and max values
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { clamp } from '@helpers4/number';
|
|
41
|
+
|
|
42
|
+
clamp(value: number, min: number, max: number): number
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Parameters:**
|
|
46
|
+
|
|
47
|
+
- `value: number` — The value to clamp
|
|
48
|
+
- `min: number` — Minimum value
|
|
49
|
+
- `max: number` — Maximum value
|
|
50
|
+
|
|
51
|
+
**Returns:** `number` — Clamped value
|
|
52
|
+
|
|
53
|
+
**Examples:**
|
|
54
|
+
|
|
55
|
+
*Clamp a value within range*
|
|
56
|
+
|
|
57
|
+
Restricts a number to be within a min/max range.
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
clamp(15, 0, 10) // => 10
|
|
61
|
+
clamp(-5, 0, 10) // => 0
|
|
62
|
+
clamp(5, 0, 10) // => 5
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
### `randomBetween`
|
|
68
|
+
|
|
69
|
+
Generates a random number between min and max (inclusive)
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { randomBetween } from '@helpers4/number';
|
|
73
|
+
|
|
74
|
+
randomBetween(min: number, max: number): number
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**Parameters:**
|
|
78
|
+
|
|
79
|
+
- `min: number` — Minimum value
|
|
80
|
+
- `max: number` — Maximum value
|
|
81
|
+
|
|
82
|
+
**Returns:** `number` — Random number between min and max
|
|
83
|
+
|
|
84
|
+
**Examples:**
|
|
85
|
+
|
|
86
|
+
*Generate a random float in range*
|
|
87
|
+
|
|
88
|
+
Returns a random number between min and max (inclusive).
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
randomBetween(1, 10)
|
|
92
|
+
// => e.g. 5.327...
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
*Generate a random integer in range*
|
|
96
|
+
|
|
97
|
+
Returns a random integer between min and max (inclusive).
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
randomIntBetween(1, 6)
|
|
101
|
+
// => e.g. 4
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
### `randomIntBetween`
|
|
107
|
+
|
|
108
|
+
Generates a random integer between min and max (inclusive)
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
import { randomIntBetween } from '@helpers4/number';
|
|
112
|
+
|
|
113
|
+
randomIntBetween(min: number, max: number): number
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**Parameters:**
|
|
117
|
+
|
|
118
|
+
- `min: number` — Minimum value
|
|
119
|
+
- `max: number` — Maximum value
|
|
120
|
+
|
|
121
|
+
**Returns:** `number` — Random integer between min and max
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
### `roundTo`
|
|
126
|
+
|
|
127
|
+
Rounds a number to specified decimal places
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
import { roundTo } from '@helpers4/number';
|
|
131
|
+
|
|
132
|
+
roundTo(value: number, decimals: number): number
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
**Parameters:**
|
|
136
|
+
|
|
137
|
+
- `value: number` — The number to round
|
|
138
|
+
- `decimals: number` — Number of decimal places
|
|
139
|
+
|
|
140
|
+
**Returns:** `number` — Rounded number
|
|
141
|
+
|
|
142
|
+
**Examples:**
|
|
143
|
+
|
|
144
|
+
*Round to 2 decimal places*
|
|
145
|
+
|
|
146
|
+
Rounds a floating-point number to the specified number of decimals.
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
roundTo(3.14159, 2)
|
|
150
|
+
// => 3.14
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
*Round to 0 decimal places*
|
|
154
|
+
|
|
155
|
+
Effectively rounds to the nearest integer.
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
roundTo(3.7, 0)
|
|
159
|
+
// => 4
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
### `sum`
|
|
165
|
+
|
|
166
|
+
Calculates the sum of an array of numbers.
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
import { sum } from '@helpers4/number';
|
|
170
|
+
|
|
171
|
+
sum(array: readonly number[]): number
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**Parameters:**
|
|
175
|
+
|
|
176
|
+
- `array: readonly number[]` — The array of numbers to sum
|
|
177
|
+
|
|
178
|
+
**Returns:** `number` — The sum of all values
|
|
179
|
+
|
|
180
|
+
**Examples:**
|
|
181
|
+
|
|
182
|
+
*Sum numbers*
|
|
183
|
+
|
|
184
|
+
Calculates the sum of an array of numbers.
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
sum([1, 2, 3, 4])
|
|
188
|
+
// => 10
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
*Sum with negative numbers*
|
|
192
|
+
|
|
193
|
+
Handles negative numbers correctly.
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
sum([10, -3, 5, -2])
|
|
197
|
+
// => 10
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
---
|
package/meta/api.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helpers4/number",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.15",
|
|
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",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"./meta/api.json": "./meta/api.json",
|
|
22
22
|
"./meta/examples.json": "./meta/examples.json",
|
|
23
23
|
"./meta/licenses.json": "./meta/licenses.json",
|
|
24
|
+
"./llms.txt": "./llms.txt",
|
|
24
25
|
"./package.json": "./package.json"
|
|
25
26
|
},
|
|
26
27
|
"keywords": [
|
|
@@ -36,6 +37,7 @@
|
|
|
36
37
|
"lib/index.d.ts",
|
|
37
38
|
"lib/index.js.map",
|
|
38
39
|
"meta/",
|
|
40
|
+
"llms.txt",
|
|
39
41
|
"LICENSE.md",
|
|
40
42
|
"package.json",
|
|
41
43
|
"README.md"
|