@accitdg/web-helpers 0.0.2 → 0.0.3
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 +134 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1 +1,134 @@
|
|
|
1
|
-
|
|
1
|
+
# Web Helpers
|
|
2
|
+
|
|
3
|
+
A collection of utility functions for web development, including currency conversion, Base64 encoding/decoding, and file handling.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install web-helpers
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Import the package
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
import webHelpers from 'web-helpers';
|
|
17
|
+
// or
|
|
18
|
+
import { convertNumberToCurrency, arrayBufferToBase64, /* ... */ } from 'web-helpers';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Functions
|
|
22
|
+
|
|
23
|
+
### `convertNumberToCurrency(numberValue: number): string`
|
|
24
|
+
|
|
25
|
+
Converts a number to Philippine Peso (PHP) currency format.
|
|
26
|
+
|
|
27
|
+
**Parameters:**
|
|
28
|
+
- `numberValue` (number): The number to convert
|
|
29
|
+
|
|
30
|
+
**Returns:** Formatted currency string
|
|
31
|
+
|
|
32
|
+
**Example:**
|
|
33
|
+
```javascript
|
|
34
|
+
webHelpers.convertNumberToCurrency(1000);
|
|
35
|
+
// Output: "₱1,000.00"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
### `arrayBufferToBase64(buffer: ArrayBuffer): string`
|
|
41
|
+
|
|
42
|
+
Converts an ArrayBuffer to a Base64-encoded string.
|
|
43
|
+
|
|
44
|
+
**Parameters:**
|
|
45
|
+
- `buffer` (ArrayBuffer): The buffer to encode
|
|
46
|
+
|
|
47
|
+
**Returns:** Base64 encoded string
|
|
48
|
+
|
|
49
|
+
**Example:**
|
|
50
|
+
```javascript
|
|
51
|
+
const buffer = new ArrayBuffer(8);
|
|
52
|
+
const base64 = webHelpers.arrayBufferToBase64(buffer);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
### `cleanBase64(base64: string): string`
|
|
58
|
+
|
|
59
|
+
Removes the data URL prefix from a Base64 string, leaving only the encoded data.
|
|
60
|
+
|
|
61
|
+
**Parameters:**
|
|
62
|
+
- `base64` (string): The Base64 string with or without prefix
|
|
63
|
+
|
|
64
|
+
**Returns:** Cleaned Base64 string without prefix
|
|
65
|
+
|
|
66
|
+
**Example:**
|
|
67
|
+
```javascript
|
|
68
|
+
const cleaned = webHelpers.cleanBase64('data:image/png;base64,iVBORw0KG...');
|
|
69
|
+
// Output: "iVBORw0KG..."
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
### `restoreBase64(cleanedBase64: string, imageType?: string): string`
|
|
75
|
+
|
|
76
|
+
Restores a clean Base64 string to a complete data URL format.
|
|
77
|
+
|
|
78
|
+
**Parameters:**
|
|
79
|
+
- `cleanedBase64` (string): The Base64 string without prefix
|
|
80
|
+
- `imageType` (string, optional): Image type (default: "png")
|
|
81
|
+
|
|
82
|
+
**Returns:** Complete data URL string
|
|
83
|
+
|
|
84
|
+
**Example:**
|
|
85
|
+
```javascript
|
|
86
|
+
const dataUrl = webHelpers.restoreBase64('iVBORw0KG...', 'jpeg');
|
|
87
|
+
// Output: "data:image/jpeg;base64,iVBORw0KG..."
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
### `downloadBase64File(base64Data: string, filename: string): void`
|
|
93
|
+
|
|
94
|
+
Triggers a download of a file from Base64-encoded data.
|
|
95
|
+
|
|
96
|
+
**Parameters:**
|
|
97
|
+
- `base64Data` (string): The Base64 encoded file data
|
|
98
|
+
- `filename` (string): The name of the file to download
|
|
99
|
+
|
|
100
|
+
**Example:**
|
|
101
|
+
```javascript
|
|
102
|
+
webHelpers.downloadBase64File('data:image/png;base64,iVBORw0KG...', 'image.png');
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
### `getFileExtensionFromBase64(base64String: string): string | null`
|
|
108
|
+
|
|
109
|
+
Extracts the file extension from a Base64 data URL.
|
|
110
|
+
|
|
111
|
+
**Parameters:**
|
|
112
|
+
- `base64String` (string): The Base64 data URL
|
|
113
|
+
|
|
114
|
+
**Returns:** File extension (e.g., "png", "pdf") or null if parsing fails
|
|
115
|
+
|
|
116
|
+
**Example:**
|
|
117
|
+
```javascript
|
|
118
|
+
const ext = webHelpers.getFileExtensionFromBase64('data:image/png;base64,iVBORw0KG...');
|
|
119
|
+
// Output: "png"
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Supported File Types
|
|
125
|
+
|
|
126
|
+
The `cleanBase64` function supports:
|
|
127
|
+
- Images: png, jpg, jpeg, gif, webp, etc.
|
|
128
|
+
- PDF documents
|
|
129
|
+
- Word documents (.docx, .dotx)
|
|
130
|
+
- Excel spreadsheets (.xlsx)
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
See LICENSE file for details.
|