Skip to content

Commit 7d98cff

Browse files
committed
feat(docs): improve documentation
1 parent 14e6da8 commit 7d98cff

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,27 @@ const { cap } = cap;
5858
### Example:
5959

6060
```javascript
61-
cap(23, 0, 1); // returns: 1
61+
const min = 1;
62+
const max = 5;
63+
cap(7, min, max); // returns: 5
6264

65+
cap(3, 0, 6); // returns: 3
6366
cap(-5, 1, -4); // returns: -4
6467
```
6568

69+
### Function declaration
70+
71+
```ts
72+
/**
73+
* Limits value to range from min to max.
74+
* If max is omitted min will be used as max, without a min range limit.
75+
* @value value to limit
76+
* @min minimum value
77+
* @max maximum value (optional)
78+
*/
79+
function cap(value: number, min: number, max?: number): number;
80+
```
81+
6682
## Run tests
6783

6884
```sh

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
/**
2-
* Limits value to range from min to max
2+
* Limits value to range from min to max.
3+
* If max is omitted min will be used as max, without a min range limit.
4+
* @value value to limit
5+
* @min minimum value
6+
* @max maximum value (optional)
37
*/
48
export function cap(value: number, min: number, max?: number): number {
59
if (max === undefined) return Math.min(value, min);

0 commit comments

Comments
 (0)