@accitdg/web-helpers 0.0.3 → 0.0.4
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 +127 -7
- package/dist/index.esm.ts +58 -1
- package/dist/index.ts +58 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,9 +13,12 @@ npm install web-helpers
|
|
|
13
13
|
### Import the package
|
|
14
14
|
|
|
15
15
|
```javascript
|
|
16
|
-
import webHelpers from
|
|
16
|
+
import webHelpers from "web-helpers";
|
|
17
17
|
// or
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
convertNumberToCurrency,
|
|
20
|
+
arrayBufferToBase64 /* ... */,
|
|
21
|
+
} from "web-helpers";
|
|
19
22
|
```
|
|
20
23
|
|
|
21
24
|
## Functions
|
|
@@ -25,11 +28,13 @@ import { convertNumberToCurrency, arrayBufferToBase64, /* ... */ } from 'web-hel
|
|
|
25
28
|
Converts a number to Philippine Peso (PHP) currency format.
|
|
26
29
|
|
|
27
30
|
**Parameters:**
|
|
31
|
+
|
|
28
32
|
- `numberValue` (number): The number to convert
|
|
29
33
|
|
|
30
34
|
**Returns:** Formatted currency string
|
|
31
35
|
|
|
32
36
|
**Example:**
|
|
37
|
+
|
|
33
38
|
```javascript
|
|
34
39
|
webHelpers.convertNumberToCurrency(1000);
|
|
35
40
|
// Output: "₱1,000.00"
|
|
@@ -42,11 +47,13 @@ webHelpers.convertNumberToCurrency(1000);
|
|
|
42
47
|
Converts an ArrayBuffer to a Base64-encoded string.
|
|
43
48
|
|
|
44
49
|
**Parameters:**
|
|
50
|
+
|
|
45
51
|
- `buffer` (ArrayBuffer): The buffer to encode
|
|
46
52
|
|
|
47
53
|
**Returns:** Base64 encoded string
|
|
48
54
|
|
|
49
55
|
**Example:**
|
|
56
|
+
|
|
50
57
|
```javascript
|
|
51
58
|
const buffer = new ArrayBuffer(8);
|
|
52
59
|
const base64 = webHelpers.arrayBufferToBase64(buffer);
|
|
@@ -59,13 +66,15 @@ const base64 = webHelpers.arrayBufferToBase64(buffer);
|
|
|
59
66
|
Removes the data URL prefix from a Base64 string, leaving only the encoded data.
|
|
60
67
|
|
|
61
68
|
**Parameters:**
|
|
69
|
+
|
|
62
70
|
- `base64` (string): The Base64 string with or without prefix
|
|
63
71
|
|
|
64
72
|
**Returns:** Cleaned Base64 string without prefix
|
|
65
73
|
|
|
66
74
|
**Example:**
|
|
75
|
+
|
|
67
76
|
```javascript
|
|
68
|
-
const cleaned = webHelpers.cleanBase64(
|
|
77
|
+
const cleaned = webHelpers.cleanBase64("data:image/png;base64,iVBORw0KG...");
|
|
69
78
|
// Output: "iVBORw0KG..."
|
|
70
79
|
```
|
|
71
80
|
|
|
@@ -76,14 +85,16 @@ const cleaned = webHelpers.cleanBase64('data:image/png;base64,iVBORw0KG...');
|
|
|
76
85
|
Restores a clean Base64 string to a complete data URL format.
|
|
77
86
|
|
|
78
87
|
**Parameters:**
|
|
88
|
+
|
|
79
89
|
- `cleanedBase64` (string): The Base64 string without prefix
|
|
80
90
|
- `imageType` (string, optional): Image type (default: "png")
|
|
81
91
|
|
|
82
92
|
**Returns:** Complete data URL string
|
|
83
93
|
|
|
84
94
|
**Example:**
|
|
95
|
+
|
|
85
96
|
```javascript
|
|
86
|
-
const dataUrl = webHelpers.restoreBase64(
|
|
97
|
+
const dataUrl = webHelpers.restoreBase64("iVBORw0KG...", "jpeg");
|
|
87
98
|
// Output: "data:image/jpeg;base64,iVBORw0KG..."
|
|
88
99
|
```
|
|
89
100
|
|
|
@@ -94,12 +105,17 @@ const dataUrl = webHelpers.restoreBase64('iVBORw0KG...', 'jpeg');
|
|
|
94
105
|
Triggers a download of a file from Base64-encoded data.
|
|
95
106
|
|
|
96
107
|
**Parameters:**
|
|
108
|
+
|
|
97
109
|
- `base64Data` (string): The Base64 encoded file data
|
|
98
110
|
- `filename` (string): The name of the file to download
|
|
99
111
|
|
|
100
112
|
**Example:**
|
|
113
|
+
|
|
101
114
|
```javascript
|
|
102
|
-
webHelpers.downloadBase64File(
|
|
115
|
+
webHelpers.downloadBase64File(
|
|
116
|
+
"data:image/png;base64,iVBORw0KG...",
|
|
117
|
+
"image.png"
|
|
118
|
+
);
|
|
103
119
|
```
|
|
104
120
|
|
|
105
121
|
---
|
|
@@ -109,21 +125,125 @@ webHelpers.downloadBase64File('data:image/png;base64,iVBORw0KG...', 'image.png')
|
|
|
109
125
|
Extracts the file extension from a Base64 data URL.
|
|
110
126
|
|
|
111
127
|
**Parameters:**
|
|
128
|
+
|
|
112
129
|
- `base64String` (string): The Base64 data URL
|
|
113
130
|
|
|
114
131
|
**Returns:** File extension (e.g., "png", "pdf") or null if parsing fails
|
|
115
132
|
|
|
116
133
|
**Example:**
|
|
134
|
+
|
|
117
135
|
```javascript
|
|
118
|
-
const ext = webHelpers.getFileExtensionFromBase64(
|
|
136
|
+
const ext = webHelpers.getFileExtensionFromBase64(
|
|
137
|
+
"data:image/png;base64,iVBORw0KG..."
|
|
138
|
+
);
|
|
119
139
|
// Output: "png"
|
|
120
140
|
```
|
|
121
141
|
|
|
122
142
|
---
|
|
123
143
|
|
|
144
|
+
## Configuration
|
|
145
|
+
|
|
146
|
+
createPayload and createPayload2 read applicationId and notificationId from a global config object. Call configureHelpers once during app initialization to set global defaults:
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
configureHelpers({
|
|
150
|
+
applicationId: "app-123",
|
|
151
|
+
notificationId: "notif-abc",
|
|
152
|
+
});
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
- These global values are stored on globalThis.\_\_WEB_HELPERS_CONFIG.
|
|
156
|
+
- Individual calls to createPayload / createPayload2 can override these values by passing notifId / applicationId in the arguments.
|
|
157
|
+
|
|
158
|
+
## Payload factories
|
|
159
|
+
|
|
160
|
+
### createPayload(args?)
|
|
161
|
+
|
|
162
|
+
Returns a full, readable payload shape suitable for APIs that expect verbose keys.
|
|
163
|
+
|
|
164
|
+
Signature (TypeScript):
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
createPayload(args?: {
|
|
168
|
+
pagination?: { count: number; page: number };
|
|
169
|
+
payload?: Record<string, any>;
|
|
170
|
+
notifId?: string | null;
|
|
171
|
+
})
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Returns:
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
{
|
|
178
|
+
isLazyLoading: boolean;
|
|
179
|
+
notificationId: string | null;
|
|
180
|
+
applicationId: string | null;
|
|
181
|
+
geoLocation: {
|
|
182
|
+
latitude: string;
|
|
183
|
+
longitude: string;
|
|
184
|
+
dateTime: string;
|
|
185
|
+
}
|
|
186
|
+
pagination: {
|
|
187
|
+
count: number;
|
|
188
|
+
page: number;
|
|
189
|
+
}
|
|
190
|
+
payload: Record<string, any>;
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Example:
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
const result = createPayload({ payload: { foo: "bar" } });
|
|
198
|
+
// uses configured notificationId/applicationId unless notifId is provided
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### createPayload2(options?)
|
|
202
|
+
|
|
203
|
+
Returns a compact payload shape (short keys) for services that use abbreviated keys.
|
|
204
|
+
|
|
205
|
+
Signature (TypeScript):
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
createPayload2({
|
|
209
|
+
pagination?: { c: number; p: number },
|
|
210
|
+
payload?: Record<string, any>,
|
|
211
|
+
notifId?: string | null,
|
|
212
|
+
applicationId?: string | null,
|
|
213
|
+
} = {})
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Returns:
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
{
|
|
220
|
+
isLl: boolean;
|
|
221
|
+
nId: string | null;
|
|
222
|
+
aId: string | null;
|
|
223
|
+
gL: {
|
|
224
|
+
lt: string;
|
|
225
|
+
long: string;
|
|
226
|
+
date: string;
|
|
227
|
+
}
|
|
228
|
+
pg: {
|
|
229
|
+
c: number;
|
|
230
|
+
p: number;
|
|
231
|
+
}
|
|
232
|
+
p: Record<string, any>;
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Example:
|
|
237
|
+
|
|
238
|
+
```ts
|
|
239
|
+
const short = createPayload2({ payload: { x: 1 } });
|
|
240
|
+
// uses configured applicationId/notificationId unless overridden in the call
|
|
241
|
+
```
|
|
242
|
+
|
|
124
243
|
## Supported File Types
|
|
125
244
|
|
|
126
245
|
The `cleanBase64` function supports:
|
|
246
|
+
|
|
127
247
|
- Images: png, jpg, jpeg, gif, webp, etc.
|
|
128
248
|
- PDF documents
|
|
129
249
|
- Word documents (.docx, .dotx)
|
|
@@ -131,4 +251,4 @@ The `cleanBase64` function supports:
|
|
|
131
251
|
|
|
132
252
|
## License
|
|
133
253
|
|
|
134
|
-
|
|
254
|
+
@allcardtech2025
|
package/dist/index.esm.ts
CHANGED
|
@@ -43,6 +43,60 @@ const getFileExtensionFromBase64 = base64String => {
|
|
|
43
43
|
return null;
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
|
+
const createPayload = args => {
|
|
47
|
+
// ...existing code...
|
|
48
|
+
let param = typeof globalThis.objTrim === "function" ? globalThis.objTrim(args.payload ?? {}) : args.payload ?? {};
|
|
49
|
+
var data = {
|
|
50
|
+
isLazyLoading: false,
|
|
51
|
+
notificationId: args.notifId ?? globalThis.__WEB_HELPERS_CONFIG?.notificationId ?? null,
|
|
52
|
+
applicationId: globalThis.__WEB_HELPERS_CONFIG?.applicationId ?? null,
|
|
53
|
+
geoLocation: {
|
|
54
|
+
latitude: "0",
|
|
55
|
+
longitude: "0",
|
|
56
|
+
dateTime: new Date().toISOString()
|
|
57
|
+
},
|
|
58
|
+
pagination: args.pagination ?? {
|
|
59
|
+
count: 0,
|
|
60
|
+
page: 0
|
|
61
|
+
},
|
|
62
|
+
payload: param
|
|
63
|
+
};
|
|
64
|
+
return data;
|
|
65
|
+
};
|
|
66
|
+
const createPayload2 = ({
|
|
67
|
+
pagination = {
|
|
68
|
+
c: 0,
|
|
69
|
+
p: 0
|
|
70
|
+
},
|
|
71
|
+
payload = {},
|
|
72
|
+
notifId,
|
|
73
|
+
applicationId
|
|
74
|
+
} = {}) => {
|
|
75
|
+
const cfg = globalThis.__WEB_HELPERS_CONFIG || {};
|
|
76
|
+
const nId = notifId ?? cfg.notificationId ?? null;
|
|
77
|
+
const aId = applicationId ?? cfg.applicationId ?? null;
|
|
78
|
+
const objTrimFn = typeof globalThis.objTrim === "function" ? globalThis.objTrim : o => o;
|
|
79
|
+
const param = objTrimFn(payload);
|
|
80
|
+
return {
|
|
81
|
+
isLl: false,
|
|
82
|
+
nId,
|
|
83
|
+
aId,
|
|
84
|
+
gL: {
|
|
85
|
+
lt: "0",
|
|
86
|
+
long: "0",
|
|
87
|
+
date: new Date().toISOString()
|
|
88
|
+
},
|
|
89
|
+
pg: pagination,
|
|
90
|
+
p: param
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
// Add this helper to configure global values (call once during app init)
|
|
94
|
+
const configureHelpers = config => {
|
|
95
|
+
globalThis.__WEB_HELPERS_CONFIG = {
|
|
96
|
+
...(globalThis.__WEB_HELPERS_CONFIG || {}),
|
|
97
|
+
...config
|
|
98
|
+
};
|
|
99
|
+
};
|
|
46
100
|
|
|
47
101
|
const webHelpers = {
|
|
48
102
|
convertNumberToCurrency,
|
|
@@ -50,7 +104,10 @@ const webHelpers = {
|
|
|
50
104
|
cleanBase64,
|
|
51
105
|
downloadBase64File,
|
|
52
106
|
restoreBase64,
|
|
53
|
-
getFileExtensionFromBase64
|
|
107
|
+
getFileExtensionFromBase64,
|
|
108
|
+
configureHelpers,
|
|
109
|
+
createPayload,
|
|
110
|
+
createPayload2
|
|
54
111
|
};
|
|
55
112
|
|
|
56
113
|
export { webHelpers as default, webHelpers };
|
package/dist/index.ts
CHANGED
|
@@ -47,6 +47,60 @@ const getFileExtensionFromBase64 = base64String => {
|
|
|
47
47
|
return null;
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
|
+
const createPayload = args => {
|
|
51
|
+
// ...existing code...
|
|
52
|
+
let param = typeof globalThis.objTrim === "function" ? globalThis.objTrim(args.payload ?? {}) : args.payload ?? {};
|
|
53
|
+
var data = {
|
|
54
|
+
isLazyLoading: false,
|
|
55
|
+
notificationId: args.notifId ?? globalThis.__WEB_HELPERS_CONFIG?.notificationId ?? null,
|
|
56
|
+
applicationId: globalThis.__WEB_HELPERS_CONFIG?.applicationId ?? null,
|
|
57
|
+
geoLocation: {
|
|
58
|
+
latitude: "0",
|
|
59
|
+
longitude: "0",
|
|
60
|
+
dateTime: new Date().toISOString()
|
|
61
|
+
},
|
|
62
|
+
pagination: args.pagination ?? {
|
|
63
|
+
count: 0,
|
|
64
|
+
page: 0
|
|
65
|
+
},
|
|
66
|
+
payload: param
|
|
67
|
+
};
|
|
68
|
+
return data;
|
|
69
|
+
};
|
|
70
|
+
const createPayload2 = ({
|
|
71
|
+
pagination = {
|
|
72
|
+
c: 0,
|
|
73
|
+
p: 0
|
|
74
|
+
},
|
|
75
|
+
payload = {},
|
|
76
|
+
notifId,
|
|
77
|
+
applicationId
|
|
78
|
+
} = {}) => {
|
|
79
|
+
const cfg = globalThis.__WEB_HELPERS_CONFIG || {};
|
|
80
|
+
const nId = notifId ?? cfg.notificationId ?? null;
|
|
81
|
+
const aId = applicationId ?? cfg.applicationId ?? null;
|
|
82
|
+
const objTrimFn = typeof globalThis.objTrim === "function" ? globalThis.objTrim : o => o;
|
|
83
|
+
const param = objTrimFn(payload);
|
|
84
|
+
return {
|
|
85
|
+
isLl: false,
|
|
86
|
+
nId,
|
|
87
|
+
aId,
|
|
88
|
+
gL: {
|
|
89
|
+
lt: "0",
|
|
90
|
+
long: "0",
|
|
91
|
+
date: new Date().toISOString()
|
|
92
|
+
},
|
|
93
|
+
pg: pagination,
|
|
94
|
+
p: param
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
// Add this helper to configure global values (call once during app init)
|
|
98
|
+
const configureHelpers = config => {
|
|
99
|
+
globalThis.__WEB_HELPERS_CONFIG = {
|
|
100
|
+
...(globalThis.__WEB_HELPERS_CONFIG || {}),
|
|
101
|
+
...config
|
|
102
|
+
};
|
|
103
|
+
};
|
|
50
104
|
|
|
51
105
|
const webHelpers = {
|
|
52
106
|
convertNumberToCurrency,
|
|
@@ -54,7 +108,10 @@ const webHelpers = {
|
|
|
54
108
|
cleanBase64,
|
|
55
109
|
downloadBase64File,
|
|
56
110
|
restoreBase64,
|
|
57
|
-
getFileExtensionFromBase64
|
|
111
|
+
getFileExtensionFromBase64,
|
|
112
|
+
configureHelpers,
|
|
113
|
+
createPayload,
|
|
114
|
+
createPayload2
|
|
58
115
|
};
|
|
59
116
|
|
|
60
117
|
exports["default"] = webHelpers;
|