Skip to content

Commit f1bc8f1

Browse files
committed
docs: ✏️ Add documentation for Number module
Create comprehensive documentation for the HandyScript Number module, including method descriptions, examples, and error handling details. The documentation is based on the TypeScript implementation in lib/number.ts and associated test cases in test/number.test.ts. ✅ Closes: #70
1 parent 0df87fc commit f1bc8f1

1 file changed

Lines changed: 110 additions & 2 deletions

File tree

‎static/documentation/number.md‎

Lines changed: 110 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,118 @@
22

33
The `Number` module extends the `Number` object for more functionality and ease of use. when dealing with Number objects in JavaScript.
44

5-
**© HandyScript Number 6/16/23 - Last Update: 9/25/23:**
5+
**© HandyScript Number 6/16/23 - Last Update: 11/22/23:**
66

77
## Table of Contents
88

9+
- [Handy Script Number](#handy-script-number)
10+
- [Table of Contents](#table-of-contents)
11+
- [Utility Methods](#utility-methods)
12+
- [toHuman()](#tohuman)
13+
- [toReadable(separator?)](#toreadableseparator)
14+
- [toWords()](#towords)
15+
- [isFinite()](#isfinite)
16+
- [isSafeNumber()](#issafenumber)
17+
18+
## Utility Methods
19+
20+
### toHuman
21+
22+
The `toHuman` method returns a string representation of a number in a human-readable format. It formats numbers using abbreviations such as K (thousand), M (million), B (billion), T (trillion), etc.
23+
24+
```typescript
25+
Number.prototype.toHuman(): string
26+
```
27+
28+
**Returns:** `string` - The Representation of a number in a human-readable format.
29+
30+
**Example:**
31+
32+
```javascript
33+
(999).toHuman(); // Returns "999"
34+
(1000).toHuman(); // Returns "1K"
35+
(1500000000).toHuman(); // Returns "1.5B"
36+
```
37+
38+
### toReadable
39+
40+
The `toReadable` method returns a string representation of a number in a readable format. It adds separators to the number, making it easier to read. The default separator is `-`, but you can specify a custom separator.
41+
42+
```typescript
43+
Number.prototype.toReadable (separator = "-"): string
44+
```
45+
46+
**Parameters:**
47+
48+
- `separator` - The separator to be used. (Optional), defaults to `-`.
49+
50+
**Returns:** `string` - Representation of a number in a readable format.
51+
52+
**Example:**
53+
54+
```javascript
55+
(999).toReadable(); // Returns "999"
56+
(1000).toReadable(); // Returns "1-000"
57+
(1500000000).toReadable("_"); // Returns "1_500_000_000"
58+
```
59+
60+
### toWords
61+
62+
The `toWords` method converts an integer into words. It provides a textual representation of the number in English words.
63+
64+
```typescript
65+
Number.prototype.toWords(): string
66+
```
67+
68+
**Returns:** `string` - the textual representation of the number in English words.
69+
70+
**Error Handling:**
71+
72+
- Throws a `TypeError` for non-finite numbers.
73+
- Throws a `RangeError` for numbers outside the safe range.
74+
75+
**Example:**
76+
77+
```javascript
78+
(0).toWords(); // Returns "zero"
79+
(22).toWords(); // Returns "twenty-two"
80+
(8888).toWords(); // Returns "eight thousand, eight hundred eighty-eight"
81+
```
82+
83+
### isFinite:
84+
85+
The `isFinite` method checks if a number is finite.
86+
87+
```typescript
88+
Number.prototype.isFinite(): boolean
89+
```
90+
91+
**Returns:** `boolean` - Is finite number
92+
93+
**Example:**
94+
95+
```javascript
96+
(10).isFinite(); // Returns true
97+
Infinity.isFinite(); // Returns false
98+
```
99+
100+
### isSafeNumber
101+
102+
The `isSafeNumber` method checks if a number is within the safe integer range.
103+
104+
```typescript
105+
Number.prototype.isSafeNumber(): boolean
106+
```
107+
108+
**Returns:** `boolean` - Is the number within the safe integer range.
109+
110+
**Example:**
111+
112+
```javascript
113+
(10).isSafeNumber(); // Returns true
114+
(Number.MAX_SAFE_INTEGER + 1).isSafeNumber(); // Returns false
115+
```
116+
9117
<p align="center"><b>© HandyScript Number 6/16/23</b></p>
10118

11-
This Markdown documentation is detailed and extensive to use the `Number` module to its full potential, along with their descriptions and TypeScript function signatures. The table of contents at the beginning [Back To Top](#table-of-contents) of the document allows for easy navigation. If you have any questions or suggestions, please contact us at <vvhybe@hotmail.com>.
119+
This documentation provides a comprehensive guide to the Number module in HandyScript. The module extends the native JavaScript Number object, offering additional functionality and ease of use when dealing with numbers. The table of contents at the beginning [Back To Top](#table-of-contents) of the document allows for easy navigation. If you have any questions or suggestions, please contact us at <vvhybe@hotmail.com>.

0 commit comments

Comments
 (0)