@wavy/fn 0.0.1
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/dist/main.cjs +1102 -0
- package/dist/main.d.cts +177 -0
- package/dist/main.d.ts +177 -0
- package/dist/main.js +1006 -0
- package/package.json +29 -0
- package/prepend.js +13 -0
package/dist/main.cjs
ADDED
|
@@ -0,0 +1,1102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/main.ts
|
|
21
|
+
var main_exports = {};
|
|
22
|
+
__export(main_exports, {
|
|
23
|
+
addArticle: () => addArticle,
|
|
24
|
+
arrayWithConst: () => arrayWithConst,
|
|
25
|
+
asyncRun: () => asyncRun,
|
|
26
|
+
averageOf: () => averageOf,
|
|
27
|
+
blankSpaces: () => blankSpaces,
|
|
28
|
+
buildArray: () => buildArray,
|
|
29
|
+
camelCaseToLetter: () => camelCaseToLetter,
|
|
30
|
+
classNameExt: () => classNameExt,
|
|
31
|
+
classNameResolver: () => classNameResolver,
|
|
32
|
+
coerceIn: () => coerceIn,
|
|
33
|
+
copyToClipboard: () => copyToClipboard,
|
|
34
|
+
count: () => count,
|
|
35
|
+
dataSearcher: () => dataSearcher,
|
|
36
|
+
distinct: () => distinct,
|
|
37
|
+
drop: () => drop,
|
|
38
|
+
dropLast: () => dropLast,
|
|
39
|
+
dropLastWhile: () => dropLastWhile,
|
|
40
|
+
dropWhile: () => dropWhile,
|
|
41
|
+
format: () => format,
|
|
42
|
+
formatGCTRegNo: () => formatGCTRegNo,
|
|
43
|
+
formatInvoiceNo: () => formatInvoiceNo,
|
|
44
|
+
getCaps: () => getCaps,
|
|
45
|
+
getFileExt: () => getFileExt,
|
|
46
|
+
group: () => group,
|
|
47
|
+
hasIndex: () => hasIndex,
|
|
48
|
+
ifDefined: () => ifDefined,
|
|
49
|
+
ifEmpty: () => ifEmpty,
|
|
50
|
+
inRange: () => inRange,
|
|
51
|
+
indexOf: () => indexOf,
|
|
52
|
+
indices: () => indices,
|
|
53
|
+
inferFilename: () => inferFilename,
|
|
54
|
+
insertAt: () => insertAt,
|
|
55
|
+
isEmpty: () => isEmpty,
|
|
56
|
+
isFile: () => isFile,
|
|
57
|
+
isLetter: () => isLetter,
|
|
58
|
+
isNumber: () => isNumber,
|
|
59
|
+
lastIndex: () => lastIndex,
|
|
60
|
+
map: () => map,
|
|
61
|
+
mapToArray: () => mapToArray,
|
|
62
|
+
maxOf: () => maxOf,
|
|
63
|
+
minOf: () => minOf,
|
|
64
|
+
negate: () => negate,
|
|
65
|
+
ordinalIndicator: () => ordinalIndicator,
|
|
66
|
+
overwrite: () => overwrite,
|
|
67
|
+
pluralize: () => pluralize,
|
|
68
|
+
poll: () => poll,
|
|
69
|
+
random: () => random,
|
|
70
|
+
range: () => range,
|
|
71
|
+
readClipboardText: () => readClipboardText,
|
|
72
|
+
removeAll: () => removeAll,
|
|
73
|
+
repeat: () => repeat,
|
|
74
|
+
run: () => run,
|
|
75
|
+
serverDataAdapter: () => serverDataAdapter,
|
|
76
|
+
someValuesEmpty: () => someValuesEmpty,
|
|
77
|
+
sort: () => sort,
|
|
78
|
+
strictArray: () => strictArray,
|
|
79
|
+
stringToSearch: () => stringToSearch,
|
|
80
|
+
subObjectList: () => subObjectList,
|
|
81
|
+
sumOf: () => sumOf,
|
|
82
|
+
take: () => take,
|
|
83
|
+
takeLast: () => takeLast,
|
|
84
|
+
takeLastWhile: () => takeLastWhile,
|
|
85
|
+
takeWhile: () => takeWhile,
|
|
86
|
+
timeDuration: () => timeDuration,
|
|
87
|
+
toNumber: () => toNumber,
|
|
88
|
+
toObject: () => toObject,
|
|
89
|
+
trimString: () => trimString,
|
|
90
|
+
undefinedIfEmpty: () => undefinedIfEmpty,
|
|
91
|
+
upperFirst: () => upperFirst,
|
|
92
|
+
windowed: () => windowed
|
|
93
|
+
});
|
|
94
|
+
module.exports = __toCommonJS(main_exports);
|
|
95
|
+
|
|
96
|
+
// src/helper-functions/components/time/TimeManager.ts
|
|
97
|
+
var TimeManager = class _TimeManager {
|
|
98
|
+
constructor(locale = "en-jm") {
|
|
99
|
+
this.locale = locale;
|
|
100
|
+
}
|
|
101
|
+
periods = {
|
|
102
|
+
overview: {
|
|
103
|
+
getPrevious: (period) => {
|
|
104
|
+
if (period === "Today") return "Yesterday";
|
|
105
|
+
if (period === "All") return "None";
|
|
106
|
+
return period.replace("This", "Last");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
metrics = {
|
|
111
|
+
second: {
|
|
112
|
+
pluginVals: [1e3],
|
|
113
|
+
unit: { fmt: "second", abv: "sec" },
|
|
114
|
+
get inMillis() {
|
|
115
|
+
return _TimeManager.calcInMillis(this.pluginVals);
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
get minute() {
|
|
119
|
+
return {
|
|
120
|
+
pluginVals: [...this.second.pluginVals, 60],
|
|
121
|
+
unit: { fmt: "minute", abv: "min" },
|
|
122
|
+
get inMillis() {
|
|
123
|
+
return _TimeManager.calcInMillis(this.pluginVals);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
},
|
|
127
|
+
get hour() {
|
|
128
|
+
return {
|
|
129
|
+
pluginVals: [...this.minute.pluginVals, 60],
|
|
130
|
+
unit: { fmt: "hour", abv: "hr" },
|
|
131
|
+
get inMillis() {
|
|
132
|
+
return _TimeManager.calcInMillis(this.pluginVals);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
},
|
|
136
|
+
get day() {
|
|
137
|
+
return {
|
|
138
|
+
pluginVals: [...this.hour.pluginVals, 24],
|
|
139
|
+
unit: { fmt: "day", abv: "d" },
|
|
140
|
+
get inMillis() {
|
|
141
|
+
return _TimeManager.calcInMillis(this.pluginVals);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
},
|
|
145
|
+
get week() {
|
|
146
|
+
return {
|
|
147
|
+
pluginVals: [...this.day.pluginVals, 7],
|
|
148
|
+
unit: { fmt: "week", abv: "wk" },
|
|
149
|
+
get inMillis() {
|
|
150
|
+
return _TimeManager.calcInMillis(this.pluginVals);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
},
|
|
154
|
+
get month() {
|
|
155
|
+
return {
|
|
156
|
+
pluginVals: [...this.day.pluginVals, 30.44],
|
|
157
|
+
unit: { fmt: "month", abv: "mo" },
|
|
158
|
+
inMillis: this.year.inMillis * (1 / 12)
|
|
159
|
+
};
|
|
160
|
+
},
|
|
161
|
+
get year() {
|
|
162
|
+
return {
|
|
163
|
+
pluginVals: [...this.day.pluginVals, 365],
|
|
164
|
+
unit: { fmt: "year", abv: "y" },
|
|
165
|
+
get inMillis() {
|
|
166
|
+
return _TimeManager.calcInMillis(this.pluginVals);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
format(time, format2) {
|
|
172
|
+
if (!time) return "";
|
|
173
|
+
const convertedDate = typeof time === "number" ? new Date(time) : time === "now" ? new Date(Date.now()) : time;
|
|
174
|
+
let options = {};
|
|
175
|
+
switch (format2) {
|
|
176
|
+
case "HH:mm A":
|
|
177
|
+
options = { hour: "numeric", minute: "2-digit" };
|
|
178
|
+
break;
|
|
179
|
+
case "mm/dd/yyyy":
|
|
180
|
+
options = {
|
|
181
|
+
year: "numeric",
|
|
182
|
+
month: "2-digit",
|
|
183
|
+
day: "2-digit"
|
|
184
|
+
};
|
|
185
|
+
break;
|
|
186
|
+
case "mm/dd/yyyy HH:mm A":
|
|
187
|
+
options = {
|
|
188
|
+
year: "numeric",
|
|
189
|
+
month: "2-digit",
|
|
190
|
+
day: "2-digit",
|
|
191
|
+
hour: "numeric",
|
|
192
|
+
minute: "2-digit"
|
|
193
|
+
};
|
|
194
|
+
break;
|
|
195
|
+
default:
|
|
196
|
+
options = {
|
|
197
|
+
year: "numeric",
|
|
198
|
+
month: format2 === "MMMM" ? "long" : "short",
|
|
199
|
+
day: "numeric"
|
|
200
|
+
};
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
const fmtDate = convertedDate.toLocaleDateString(this.locale, options);
|
|
204
|
+
if (format2 === "MMMM")
|
|
205
|
+
return takeWhile(fmtDate.split(""), (char) => char !== " ").join("");
|
|
206
|
+
if (format2 === "yyyy") return takeLast(fmtDate.split(""), 4).join("");
|
|
207
|
+
if (format2 === "MMM yyyy") {
|
|
208
|
+
const month = this.format(convertedDate, "MMMM");
|
|
209
|
+
const year = this.format(convertedDate, "yyyy");
|
|
210
|
+
return `${month} ${year}`;
|
|
211
|
+
}
|
|
212
|
+
if (format2 === "HH:mm A")
|
|
213
|
+
return takeLastWhile(fmtDate.split(""), (char) => char !== ",").join("").trim();
|
|
214
|
+
if (format2 === "MMM dd, yyyy | HH:mm A" || format2 === "MMM dd, yyyy at HH:mm A") {
|
|
215
|
+
const delimiter = format2 === "MMM dd, yyyy at HH:mm A" ? "at" : "|";
|
|
216
|
+
const time2 = this.format(convertedDate, "HH:mm A");
|
|
217
|
+
return [fmtDate, time2].join(` ${delimiter} `);
|
|
218
|
+
}
|
|
219
|
+
return fmtDate;
|
|
220
|
+
}
|
|
221
|
+
getDuration(from, to, options) {
|
|
222
|
+
const difference = new Date(to).getTime() - new Date(from).getTime();
|
|
223
|
+
const metrics = this.metrics;
|
|
224
|
+
const getFmtDuration = (duration2, unit) => `${duration2} ${options?.abvUnits ? unit.abv : unit.fmt}${duration2 > 1 ? "s" : ""}`;
|
|
225
|
+
const getDuration = (plugins) => plugins.reduce((prev, curr) => prev / curr);
|
|
226
|
+
const metric = (timeDifference = difference) => Object.keys(metrics).reduce((prev, curr) => {
|
|
227
|
+
const validPrev = prev;
|
|
228
|
+
const validCurr = curr;
|
|
229
|
+
if (!prev) return curr;
|
|
230
|
+
if (timeDifference >= metrics[validPrev].inMillis && timeDifference < metrics[validCurr].inMillis)
|
|
231
|
+
return prev;
|
|
232
|
+
return curr;
|
|
233
|
+
});
|
|
234
|
+
const duration = getDuration([difference, ...metrics[metric()].pluginVals]);
|
|
235
|
+
const flooredDuration = Math.floor(duration);
|
|
236
|
+
const fmtDuration = getFmtDuration(
|
|
237
|
+
flooredDuration,
|
|
238
|
+
flooredDuration ? metrics[metric()].unit : metrics.second.unit
|
|
239
|
+
);
|
|
240
|
+
if (!options?.disableRemainder) {
|
|
241
|
+
const remaindingDifference = difference % metrics[metric()].inMillis;
|
|
242
|
+
const remaindingMetric = metrics[metric(remaindingDifference)];
|
|
243
|
+
const remaindingDuration = getDuration([
|
|
244
|
+
remaindingDifference,
|
|
245
|
+
...remaindingMetric.pluginVals
|
|
246
|
+
]);
|
|
247
|
+
const roundedRemaindingDuration = Math.floor(remaindingDuration);
|
|
248
|
+
const fmtRoundedRemaindingDuration = getFmtDuration(
|
|
249
|
+
roundedRemaindingDuration,
|
|
250
|
+
remaindingMetric.unit
|
|
251
|
+
);
|
|
252
|
+
return roundedRemaindingDuration ? `${fmtDuration} ${fmtRoundedRemaindingDuration}` : fmtDuration;
|
|
253
|
+
}
|
|
254
|
+
return fmtDuration;
|
|
255
|
+
}
|
|
256
|
+
getTimeOfDay() {
|
|
257
|
+
const time = this.format("now", "HH:mm A");
|
|
258
|
+
const amOrPm = takeLast(time.split(""), 2).join("");
|
|
259
|
+
const hour = parseInt(
|
|
260
|
+
takeWhile(time.split(""), (value) => value !== ":").join("")
|
|
261
|
+
);
|
|
262
|
+
return amOrPm === "am" ? "morning" : hour < 5 ? "afternoon" : "evening";
|
|
263
|
+
}
|
|
264
|
+
static calcInMillis = (plugins) => plugins.reduce((prev, curr) => prev * curr);
|
|
265
|
+
};
|
|
266
|
+
var TimeManager_default = TimeManager;
|
|
267
|
+
|
|
268
|
+
// src/helper-functions/components/formatter/number/NumberFormatter.ts
|
|
269
|
+
var NumberFormatter = class _NumberFormatter {
|
|
270
|
+
static format(value, format2, options) {
|
|
271
|
+
switch (format2) {
|
|
272
|
+
case "money":
|
|
273
|
+
return _NumberFormatter.toMoney(value, options);
|
|
274
|
+
default:
|
|
275
|
+
return value.toLocaleString("en-us");
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
static toMoney(amount, options) {
|
|
279
|
+
const dollarSign = options?.excludeDollarSign ? "" : "$";
|
|
280
|
+
if (!amount) return dollarSign + (options?.dropDecimals ? "0" : "0.00");
|
|
281
|
+
if (options?.truncate) {
|
|
282
|
+
const strAmt = takeWhile(
|
|
283
|
+
`${amount}`.split(""),
|
|
284
|
+
(char) => char !== "."
|
|
285
|
+
).join("");
|
|
286
|
+
const fmtMoney = (value, decimal) => {
|
|
287
|
+
const getTruncatedSuffix = () => {
|
|
288
|
+
if (strAmt.length <= 3) return "";
|
|
289
|
+
if (range(4, 7).includes(strAmt.length)) return "k";
|
|
290
|
+
if (range(7, 10).includes(strAmt.length)) return "m";
|
|
291
|
+
if (range(10, 13).includes(strAmt.length)) return "b";
|
|
292
|
+
if (range(13, 16).includes(strAmt.length)) return "t";
|
|
293
|
+
};
|
|
294
|
+
const fmtValue = parseInt(decimal) > 0 ? `${value}.${decimal}` : value;
|
|
295
|
+
return dollarSign + fmtValue + getTruncatedSuffix();
|
|
296
|
+
};
|
|
297
|
+
if (strAmt.length <= 3) return fmtMoney(strAmt, "0");
|
|
298
|
+
else {
|
|
299
|
+
const relevantDigits = takeLast(
|
|
300
|
+
windowed([...strAmt.split("")].reverse(), 3).map(
|
|
301
|
+
(arr) => arr.reverse()
|
|
302
|
+
),
|
|
303
|
+
2
|
|
304
|
+
).reverse();
|
|
305
|
+
return fmtMoney(relevantDigits[0].join(""), relevantDigits[1][0]);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return (amount < 0 ? "-" : options?.showSigns ? "+" : "") + dollarSign + amount.toLocaleString("en-US", {
|
|
309
|
+
minimumFractionDigits: options?.dropDecimals ? 0 : 2,
|
|
310
|
+
currency: "USD",
|
|
311
|
+
currencyDisplay: "symbol",
|
|
312
|
+
currencySign: "accounting",
|
|
313
|
+
signDisplay: "never"
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
var NumberFormatter_default = NumberFormatter;
|
|
318
|
+
|
|
319
|
+
// src/helper-functions/components/input/InputManager.ts
|
|
320
|
+
var InputManager = class {
|
|
321
|
+
static manualValidators = {
|
|
322
|
+
percent: (value) => StringFormatter_default.toNumber(value) <= 100 && run(value.split(".")?.[1], (dec) => dec ? dec.length <= 2 : true)
|
|
323
|
+
};
|
|
324
|
+
static formatters = {
|
|
325
|
+
money: {
|
|
326
|
+
format: (value) => take(
|
|
327
|
+
value.split(".").map(
|
|
328
|
+
(sect, idx) => idx === 0 ? `${NumberFormatter_default.format(StringFormatter_default.toNumber(sect))}` : take(sect.split(""), 2).join("")
|
|
329
|
+
),
|
|
330
|
+
2
|
|
331
|
+
).join("."),
|
|
332
|
+
unformat: (value) => `${StringFormatter_default.toNumber(value)}`
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
static separateNumbersFormatter(options = {
|
|
336
|
+
numbersPerGroup: 3,
|
|
337
|
+
separator: "-"
|
|
338
|
+
}) {
|
|
339
|
+
return {
|
|
340
|
+
format: (value) => {
|
|
341
|
+
let groupedValues = windowed(
|
|
342
|
+
value.split(""),
|
|
343
|
+
options.numbersPerGroup
|
|
344
|
+
).map((v) => v.join(""));
|
|
345
|
+
if (options.groupCount) {
|
|
346
|
+
groupedValues = [
|
|
347
|
+
...take(groupedValues, options.groupCount),
|
|
348
|
+
drop(groupedValues, options.groupCount).join("").replace(options.separator, "")
|
|
349
|
+
].filter((v) => !isEmpty(v));
|
|
350
|
+
}
|
|
351
|
+
return groupedValues.join(options.separator);
|
|
352
|
+
},
|
|
353
|
+
unformat: (value) => {
|
|
354
|
+
const unformatted = value.replaceAll(options.separator, "");
|
|
355
|
+
return unformatted;
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
var InputManager_default = InputManager;
|
|
361
|
+
|
|
362
|
+
// src/helper-functions/components/formatter/string/StringFormatter.ts
|
|
363
|
+
var VOWELS = "aeiouy";
|
|
364
|
+
var StringFormatter = class _StringFormatter {
|
|
365
|
+
static vowels = VOWELS;
|
|
366
|
+
static caseConverter = {
|
|
367
|
+
camelToLetter: (camelCase) => {
|
|
368
|
+
return camelCase.split("").map(
|
|
369
|
+
(char, charIdx) => charIdx === 0 ? char.toUpperCase() : char === char.toUpperCase() && char !== char.toLowerCase() ? ` ${char}` : char
|
|
370
|
+
).join("");
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
static extract = {
|
|
374
|
+
capitalLetters: (value, count2) => {
|
|
375
|
+
return value.split("", count2).filter(
|
|
376
|
+
(char) => char === char.toUpperCase() && char !== char.toLowerCase()
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
static trimString(value, trim) {
|
|
381
|
+
let newValue = value;
|
|
382
|
+
while (newValue.endsWith(trim)) {
|
|
383
|
+
newValue = value.split("").reverse().join("").replace(trim, "").split("").reverse().join("");
|
|
384
|
+
}
|
|
385
|
+
return newValue;
|
|
386
|
+
}
|
|
387
|
+
static pluralize(value) {
|
|
388
|
+
return value[value.length - 1] === "s" ? value + "es" : value + "s";
|
|
389
|
+
}
|
|
390
|
+
static addArticle(value, article) {
|
|
391
|
+
let fmtArticle = "";
|
|
392
|
+
switch (article) {
|
|
393
|
+
case "a/an":
|
|
394
|
+
fmtArticle = VOWELS.includes(value?.[0].toLowerCase()) ? "An" : "A";
|
|
395
|
+
break;
|
|
396
|
+
default:
|
|
397
|
+
return article;
|
|
398
|
+
}
|
|
399
|
+
return `${fmtArticle.toLowerCase()} ${value}`;
|
|
400
|
+
}
|
|
401
|
+
static toSearch(from) {
|
|
402
|
+
return from.split("").filter((char) => char !== " ").join("").toLowerCase().trim();
|
|
403
|
+
}
|
|
404
|
+
static toMoney(from, options) {
|
|
405
|
+
return NumberFormatter_default.toMoney(_StringFormatter.toNumber(from), options);
|
|
406
|
+
}
|
|
407
|
+
static toTRN(from) {
|
|
408
|
+
return InputManager_default.separateNumbersFormatter().format(from);
|
|
409
|
+
}
|
|
410
|
+
static toNumber(value) {
|
|
411
|
+
const potentialNumber = take(value.split("."), 2).join(".").split("").map(
|
|
412
|
+
(char, idx) => idx === 0 && char === "-" ? char : "0123456789.".includes(char) ? char : ""
|
|
413
|
+
).join("");
|
|
414
|
+
return isEmpty(potentialNumber.trim()) ? 0 : parseFloat(potentialNumber);
|
|
415
|
+
}
|
|
416
|
+
static upperFirst(value) {
|
|
417
|
+
return value.split("").map((char, idx) => idx === 0 ? char.toUpperCase() : char).join("");
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
var StringFormatter_default = StringFormatter;
|
|
421
|
+
|
|
422
|
+
// src/helper-functions/components/formatter/object/ObjectFormatter.ts
|
|
423
|
+
var ObjectFormatter = class {
|
|
424
|
+
static toString = {
|
|
425
|
+
name: (name) => name ? `${name.first} ${name.last}`.trim() : "no_name",
|
|
426
|
+
phoneNumber: (phoneNumber) => {
|
|
427
|
+
if (!phoneNumber) return "no_phone_number";
|
|
428
|
+
return `${phoneNumber.countryCode} (${phoneNumber.areaCode}) ${insertAt(
|
|
429
|
+
phoneNumber.localNumber.split(""),
|
|
430
|
+
3,
|
|
431
|
+
"-"
|
|
432
|
+
).join("")}`;
|
|
433
|
+
},
|
|
434
|
+
address: (address, inline) => {
|
|
435
|
+
if (address === void 0) return "no_address";
|
|
436
|
+
const addressKeys = Object.keys(address).map((k) => k);
|
|
437
|
+
const delimiter = (isLast) => !isLast ? "," + (!inline ? "\n" : "") : "";
|
|
438
|
+
return addressKeys.map(
|
|
439
|
+
(key, idx) => address[key] + delimiter(idx === lastIndex(addressKeys))
|
|
440
|
+
).join("") || "no_address";
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
};
|
|
444
|
+
var ObjectFormatter_default = ObjectFormatter;
|
|
445
|
+
|
|
446
|
+
// src/helper-functions/HelperFunctions.ts
|
|
447
|
+
var import_uuid = require("uuid");
|
|
448
|
+
var import_types = require("@wavy/types");
|
|
449
|
+
var import_console = require("console");
|
|
450
|
+
var dateFormat = new TimeManager_default().format;
|
|
451
|
+
var timeDuration = new TimeManager_default().getDuration;
|
|
452
|
+
var upperFirst = StringFormatter_default.upperFirst;
|
|
453
|
+
var camelCaseToLetter = StringFormatter_default.caseConverter.camelToLetter;
|
|
454
|
+
var trimString = StringFormatter_default.trimString;
|
|
455
|
+
var stringToSearch = StringFormatter_default.toSearch;
|
|
456
|
+
var getCaps = StringFormatter_default.extract.capitalLetters;
|
|
457
|
+
var toNumber = StringFormatter_default.toNumber;
|
|
458
|
+
var addArticle = StringFormatter_default.addArticle;
|
|
459
|
+
var pluralize = StringFormatter_default.pluralize;
|
|
460
|
+
var objToString = ObjectFormatter_default.toString;
|
|
461
|
+
var nameToString = objToString.name;
|
|
462
|
+
var phoneNoToString = objToString.phoneNumber;
|
|
463
|
+
var addressToString = objToString.address;
|
|
464
|
+
var toMoney = (value, options) => typeof value === "string" ? StringFormatter_default.toMoney(value, options) : NumberFormatter_default.toMoney(value, options);
|
|
465
|
+
function format(event, ...args) {
|
|
466
|
+
const getCaller = (caller) => {
|
|
467
|
+
return caller(...args);
|
|
468
|
+
};
|
|
469
|
+
switch (event) {
|
|
470
|
+
case "date":
|
|
471
|
+
return getCaller(dateFormat);
|
|
472
|
+
case "address":
|
|
473
|
+
return getCaller(addressToString);
|
|
474
|
+
case "money":
|
|
475
|
+
return getCaller(toMoney);
|
|
476
|
+
case "name":
|
|
477
|
+
return getCaller(nameToString);
|
|
478
|
+
case "phone-number":
|
|
479
|
+
return getCaller(phoneNoToString);
|
|
480
|
+
default:
|
|
481
|
+
return event;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
function isFile(obj) {
|
|
485
|
+
const fileKeys = Object.keys({
|
|
486
|
+
arrayBuffer: null,
|
|
487
|
+
bytes: null,
|
|
488
|
+
lastModified: null,
|
|
489
|
+
name: null,
|
|
490
|
+
size: null,
|
|
491
|
+
slice: null,
|
|
492
|
+
stream: null,
|
|
493
|
+
text: null,
|
|
494
|
+
type: null,
|
|
495
|
+
webkitRelativePath: null
|
|
496
|
+
});
|
|
497
|
+
if (obj && typeof obj === "object" && fileKeys.every((key) => key in obj))
|
|
498
|
+
return true;
|
|
499
|
+
return false;
|
|
500
|
+
}
|
|
501
|
+
function toObject(object, ...args) {
|
|
502
|
+
if (isFile(object)) {
|
|
503
|
+
const options = args[0];
|
|
504
|
+
const fileName = (() => {
|
|
505
|
+
const fileExt = getFileExt(object.name);
|
|
506
|
+
if (options?.filename && options.filename.includes(fileExt))
|
|
507
|
+
return options.filename;
|
|
508
|
+
else if (options?.filename) return options.filename.trim() + fileExt;
|
|
509
|
+
return object.name;
|
|
510
|
+
})()?.trim?.();
|
|
511
|
+
return {
|
|
512
|
+
uid: (0, import_uuid.v4)(),
|
|
513
|
+
description: options?.description,
|
|
514
|
+
path: options?.filepath || object.webkitRelativePath,
|
|
515
|
+
typeAlias: options?.typeAlias || run(
|
|
516
|
+
Object.keys(import_types.LOCAL_FILE_MIME_TYPES).find(
|
|
517
|
+
(key) => import_types.LOCAL_FILE_MIME_TYPES[key].includes(object.type)
|
|
518
|
+
),
|
|
519
|
+
(type) => {
|
|
520
|
+
if (!type) {
|
|
521
|
+
(0, import_console.log)("An unknown file type was found ", object.type);
|
|
522
|
+
return "unknown";
|
|
523
|
+
}
|
|
524
|
+
return type;
|
|
525
|
+
}
|
|
526
|
+
),
|
|
527
|
+
sizeInBytes: object.size,
|
|
528
|
+
uploadDate: options?.uploadDate === "now" ? Date.now() : options?.uploadDate ?? object.lastModified,
|
|
529
|
+
name: fileName
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
function classNameResolver(baseClassName) {
|
|
534
|
+
return (className) => {
|
|
535
|
+
return `${baseClassName}-${className}`;
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
function classNameExt(rootClassName) {
|
|
539
|
+
return (className) => {
|
|
540
|
+
return `${rootClassName} ${className}`;
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
function range(start, end) {
|
|
544
|
+
return buildArray(end - start, (i) => i + start);
|
|
545
|
+
}
|
|
546
|
+
function lastIndex(value) {
|
|
547
|
+
return value.length - 1;
|
|
548
|
+
}
|
|
549
|
+
function buildArray(length, func) {
|
|
550
|
+
return Array.from(Array(length)).map((_, idx) => func(idx));
|
|
551
|
+
}
|
|
552
|
+
function blankSpaces(count2) {
|
|
553
|
+
return buildArray(count2, () => "\u200C").join(" ");
|
|
554
|
+
}
|
|
555
|
+
function ordinalIndicator(amount) {
|
|
556
|
+
const stringifiedAmount = `${amount}`;
|
|
557
|
+
const lastIdx = lastIndex(stringifiedAmount);
|
|
558
|
+
const lastChar = stringifiedAmount[lastIdx];
|
|
559
|
+
const secondToLastChar = stringifiedAmount[lastIdx - 1];
|
|
560
|
+
let indicator;
|
|
561
|
+
if (secondToLastChar === "1") indicator = "th";
|
|
562
|
+
else if (lastChar === "1") indicator = "st";
|
|
563
|
+
else if (lastChar === "2") indicator = "nd";
|
|
564
|
+
else if (lastChar === "3") indicator = "rd";
|
|
565
|
+
else indicator = "th";
|
|
566
|
+
return stringifiedAmount + indicator;
|
|
567
|
+
}
|
|
568
|
+
function indexOf(arr, key, value) {
|
|
569
|
+
const queriedValue = arr.find((obj) => obj[key] === value);
|
|
570
|
+
if (!queriedValue) return;
|
|
571
|
+
return arr.indexOf(queriedValue);
|
|
572
|
+
}
|
|
573
|
+
function formatInvoiceNo(invoiceNo) {
|
|
574
|
+
return `INV-${invoiceNo}`;
|
|
575
|
+
}
|
|
576
|
+
function formatGCTRegNo(regNo) {
|
|
577
|
+
return `GCT-${regNo}`;
|
|
578
|
+
}
|
|
579
|
+
function indices(arr) {
|
|
580
|
+
return arr.map((_, idx) => idx);
|
|
581
|
+
}
|
|
582
|
+
function hasIndex(arr, index) {
|
|
583
|
+
return indices(arr).includes(index);
|
|
584
|
+
}
|
|
585
|
+
function repeat(count2, func) {
|
|
586
|
+
for (let idx = 0; idx < count2; idx++) {
|
|
587
|
+
func(idx);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
function isLetter(value) {
|
|
591
|
+
return "abcdefghijklmnopqrstuvwxyz".includes(value.toLowerCase());
|
|
592
|
+
}
|
|
593
|
+
function isNumber(value) {
|
|
594
|
+
return "0123456789".includes(value);
|
|
595
|
+
}
|
|
596
|
+
function count(searchFor, arrayish) {
|
|
597
|
+
const fmtArr = typeof arrayish === "string" ? arrayish.split("") : arrayish;
|
|
598
|
+
return fmtArr.filter((v) => v === searchFor).length;
|
|
599
|
+
}
|
|
600
|
+
function subObjectList(value, array) {
|
|
601
|
+
const newArray = [];
|
|
602
|
+
array.forEach((item) => {
|
|
603
|
+
if (item[value.key] === value.value) {
|
|
604
|
+
newArray.push(item);
|
|
605
|
+
}
|
|
606
|
+
});
|
|
607
|
+
return newArray;
|
|
608
|
+
}
|
|
609
|
+
function random(max, min) {
|
|
610
|
+
const randNum = Math.floor(Math.random() * max);
|
|
611
|
+
return min !== void 0 && randNum < min ? random(max, min) : randNum;
|
|
612
|
+
}
|
|
613
|
+
function undefinedIfEmpty(value) {
|
|
614
|
+
if (value.length > 0) return value;
|
|
615
|
+
}
|
|
616
|
+
function ifEmpty(value, fallback) {
|
|
617
|
+
return isEmpty(value) ? fallback : value;
|
|
618
|
+
}
|
|
619
|
+
function windowed(arr, count2) {
|
|
620
|
+
const newArr = Array.from(
|
|
621
|
+
Array(Math.floor(arr.length / count2 + arr.length % count2))
|
|
622
|
+
).map(() => []);
|
|
623
|
+
arr.forEach((val, idx) => newArr[Math.floor(idx / count2)]?.push(val));
|
|
624
|
+
return newArr.filter((arr2) => arr2.length > 0);
|
|
625
|
+
}
|
|
626
|
+
function group(arr, isGroup) {
|
|
627
|
+
const groups = [];
|
|
628
|
+
arr.forEach((value) => {
|
|
629
|
+
const groupIdx = groups.findIndex(
|
|
630
|
+
(group2) => group2.every((groupVal) => isGroup(value, groupVal))
|
|
631
|
+
);
|
|
632
|
+
if (groupIdx !== -1) {
|
|
633
|
+
groups[groupIdx].push(value);
|
|
634
|
+
} else {
|
|
635
|
+
groups[groups.length] = [value];
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
return groups;
|
|
639
|
+
}
|
|
640
|
+
function strictArray(arr) {
|
|
641
|
+
return arr.filter(
|
|
642
|
+
(val) => typeof val === "string" ? val.trim().length > 0 : val !== void 0 && val !== null
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
function maxOf(arr) {
|
|
646
|
+
const fmtArr = strictArray(arr);
|
|
647
|
+
return isEmpty(arr) ? 0 : fmtArr.reduce((prev, current) => current > prev ? current : prev);
|
|
648
|
+
}
|
|
649
|
+
function minOf(arr) {
|
|
650
|
+
const fmtArr = strictArray(arr);
|
|
651
|
+
return isEmpty(arr) ? 0 : fmtArr.reduce((prev, current) => current < prev ? current : prev);
|
|
652
|
+
}
|
|
653
|
+
function averageOf(arr) {
|
|
654
|
+
const fmtArr = strictArray(arr);
|
|
655
|
+
return isEmpty(fmtArr) ? 0 : sumOf(fmtArr) / fmtArr.length;
|
|
656
|
+
}
|
|
657
|
+
function run(value, fn) {
|
|
658
|
+
return fn(value);
|
|
659
|
+
}
|
|
660
|
+
async function asyncRun(value, fn) {
|
|
661
|
+
return fn(value);
|
|
662
|
+
}
|
|
663
|
+
function coerceIn(arr, min, max) {
|
|
664
|
+
return arr.map((num) => num > max ? max : num < min ? min : num);
|
|
665
|
+
}
|
|
666
|
+
function sort(arr, sortBy, order = "asc") {
|
|
667
|
+
const queryObj = (obj) => {
|
|
668
|
+
const value = obj[sortBy];
|
|
669
|
+
return typeof value === "string" ? value.toLowerCase() : value;
|
|
670
|
+
};
|
|
671
|
+
const sortOrder = (a, b) => {
|
|
672
|
+
const queryA = queryObj(a);
|
|
673
|
+
const queryB = queryObj(b);
|
|
674
|
+
if (typeof queryA === "string") {
|
|
675
|
+
const comparedQuery = queryA.localeCompare(queryB, void 0, {
|
|
676
|
+
numeric: queryA.split("").some((char) => isNumber(char)),
|
|
677
|
+
sensitivity: "base"
|
|
678
|
+
});
|
|
679
|
+
return order === "asc" ? comparedQuery === -1 : comparedQuery === 1;
|
|
680
|
+
}
|
|
681
|
+
return order === "asc" ? queryA < queryB : queryA > queryB;
|
|
682
|
+
};
|
|
683
|
+
return arr.toSorted(
|
|
684
|
+
(a, b) => sortOrder(a, b) ? -1 : queryObj(a) === queryObj(b) ? 0 : 1
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
function sumOf(value) {
|
|
688
|
+
return !isEmpty(value) ? value.reduce((acc, amt) => acc + amt) : 0;
|
|
689
|
+
}
|
|
690
|
+
function insertAt(arr, index, value) {
|
|
691
|
+
return arr.toSpliced(index, 0, value);
|
|
692
|
+
}
|
|
693
|
+
function overwrite(arr, index, newValue) {
|
|
694
|
+
return arr.with(index, newValue);
|
|
695
|
+
}
|
|
696
|
+
function take(value, amount) {
|
|
697
|
+
return [...value].splice(0, amount);
|
|
698
|
+
}
|
|
699
|
+
function takeWhile(value, fn) {
|
|
700
|
+
const newValue = [];
|
|
701
|
+
for (let idx = 0; idx < value.length; idx++) {
|
|
702
|
+
if (!fn(value[idx], idx)) break;
|
|
703
|
+
newValue.push(value[idx]);
|
|
704
|
+
}
|
|
705
|
+
return newValue;
|
|
706
|
+
}
|
|
707
|
+
function takeLast(arr, amount = 1) {
|
|
708
|
+
if (amount <= 1) return [arr[arr.length - 1]];
|
|
709
|
+
return [...arr].splice(arr.length - amount);
|
|
710
|
+
}
|
|
711
|
+
function takeLastWhile(value, fn) {
|
|
712
|
+
const newValue = [];
|
|
713
|
+
for (let idx = 0; idx < value.length; idx++) {
|
|
714
|
+
const lastIdx = value.length - 1 - idx;
|
|
715
|
+
if (!fn(value[lastIdx], lastIdx)) break;
|
|
716
|
+
newValue.push(value[lastIdx]);
|
|
717
|
+
}
|
|
718
|
+
return newValue.reverse();
|
|
719
|
+
}
|
|
720
|
+
function drop(arr, count2) {
|
|
721
|
+
return arr.slice(count2 || 1);
|
|
722
|
+
}
|
|
723
|
+
function dropWhile(arr, fn) {
|
|
724
|
+
return arr.filter((v, idx) => fn(v, idx) ? false : true);
|
|
725
|
+
}
|
|
726
|
+
function dropLast(arr, count2 = 1) {
|
|
727
|
+
return arr.slice(0, arr.length - count2);
|
|
728
|
+
}
|
|
729
|
+
function dropLastWhile(arr, fn) {
|
|
730
|
+
return dropWhile(arr.toReversed(), fn).toReversed();
|
|
731
|
+
}
|
|
732
|
+
function dataSearcher(dataSource, queryProperty, searchFor, options) {
|
|
733
|
+
const toSearch = (value) => stringToSearch(JSON.stringify(value)).replaceAll('"', "");
|
|
734
|
+
return dataSource.filter((value) => {
|
|
735
|
+
const propVal = toSearch(value[queryProperty]);
|
|
736
|
+
const searcher = toSearch(searchFor);
|
|
737
|
+
return options?.strictEquality ? propVal === searcher : propVal.includes(searcher);
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
function inRange(value, min, max, options) {
|
|
741
|
+
if (options?.excludeBoth) return value > min && value < max;
|
|
742
|
+
if (options?.excludeMax) return value >= min && value < max;
|
|
743
|
+
if (options?.excludeMin) return value > min && value <= max;
|
|
744
|
+
return value >= min && value <= max;
|
|
745
|
+
}
|
|
746
|
+
function negate(condition, negate2) {
|
|
747
|
+
return negate2 ? !condition : condition;
|
|
748
|
+
}
|
|
749
|
+
function removeAll(str, remove) {
|
|
750
|
+
return str.split("").filter((char) => char !== remove).join("");
|
|
751
|
+
}
|
|
752
|
+
function mapToArray(map2) {
|
|
753
|
+
return map2.entries().toArray().map(([key, value]) => ({ [key]: value }));
|
|
754
|
+
}
|
|
755
|
+
function distinct(arr) {
|
|
756
|
+
const newArr = [];
|
|
757
|
+
arr.forEach((value) => {
|
|
758
|
+
if (!newArr.includes(value)) newArr.push(value);
|
|
759
|
+
});
|
|
760
|
+
return newArr;
|
|
761
|
+
}
|
|
762
|
+
function map(from, mappedFields) {
|
|
763
|
+
return Object.fromEntries(
|
|
764
|
+
Object.keys(mappedFields).map((key) => {
|
|
765
|
+
const validKey = key;
|
|
766
|
+
return [mappedFields[validKey], from[validKey]];
|
|
767
|
+
})
|
|
768
|
+
);
|
|
769
|
+
}
|
|
770
|
+
function isEmpty(value) {
|
|
771
|
+
const valueLength = typeof value === "string" ? value.trim().length : value.length;
|
|
772
|
+
return valueLength === 0;
|
|
773
|
+
}
|
|
774
|
+
function ifDefined(value, cb) {
|
|
775
|
+
return !value ? void 0 : cb(value);
|
|
776
|
+
}
|
|
777
|
+
function someValuesEmpty(obj) {
|
|
778
|
+
return Object.keys(obj).some((key) => isEmpty(obj[key]));
|
|
779
|
+
}
|
|
780
|
+
async function poll(getValue, interval = 100) {
|
|
781
|
+
while (true) {
|
|
782
|
+
const value = await getValue();
|
|
783
|
+
if (value !== void 0) {
|
|
784
|
+
return value;
|
|
785
|
+
}
|
|
786
|
+
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
function inferFilename(filePath) {
|
|
790
|
+
return takeLastWhile(
|
|
791
|
+
filePath.split(""),
|
|
792
|
+
(char) => !"/\\".includes(char)
|
|
793
|
+
).join("");
|
|
794
|
+
}
|
|
795
|
+
function getFileExt(filePath) {
|
|
796
|
+
return "." + takeLastWhile(filePath.split(""), (v) => v !== ".").join("");
|
|
797
|
+
}
|
|
798
|
+
async function copyToClipboard(text) {
|
|
799
|
+
try {
|
|
800
|
+
await navigator.clipboard.writeText(text);
|
|
801
|
+
return { data: "success" };
|
|
802
|
+
} catch (err) {
|
|
803
|
+
console.error("Failed to copy text: ", err);
|
|
804
|
+
if (err instanceof Error) {
|
|
805
|
+
return {
|
|
806
|
+
error: {
|
|
807
|
+
errorCode: "UNKNOWN",
|
|
808
|
+
title: err.name,
|
|
809
|
+
message: err.message
|
|
810
|
+
}
|
|
811
|
+
};
|
|
812
|
+
}
|
|
813
|
+
return {
|
|
814
|
+
error: {
|
|
815
|
+
errorCode: "UNKNOWN",
|
|
816
|
+
title: "Failed to copy text",
|
|
817
|
+
message: JSON.stringify(err)
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
async function readClipboardText() {
|
|
823
|
+
try {
|
|
824
|
+
const text = await navigator.clipboard.readText();
|
|
825
|
+
return { data: { text: text.trim() } };
|
|
826
|
+
} catch (err) {
|
|
827
|
+
console.error("Failed to read clipboard contents: ", err);
|
|
828
|
+
return {
|
|
829
|
+
error: {
|
|
830
|
+
errorCode: "UNKNOWN",
|
|
831
|
+
title: "Failed to read clipboard contents",
|
|
832
|
+
message: `Something went wrong while trying to read the clipboard contents. [CAUSE]: ${JSON.stringify(
|
|
833
|
+
err
|
|
834
|
+
)}.`
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
function arrayWithConst(array) {
|
|
840
|
+
return { value: array, asConst: [...array] };
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
// src/server-adapters/ServerAdapters.ts
|
|
844
|
+
var import_types2 = require("@wavy/types");
|
|
845
|
+
var iiKeys = Object.keys({
|
|
846
|
+
name: null,
|
|
847
|
+
address: null,
|
|
848
|
+
phoneNumber: null
|
|
849
|
+
});
|
|
850
|
+
var stringArrayIdPrefix = "listOf";
|
|
851
|
+
var multiDimArrayIdPrefix = "2DListOf";
|
|
852
|
+
var multiDimArrayDelim = ":";
|
|
853
|
+
var DELIMITERS = {
|
|
854
|
+
name: " ",
|
|
855
|
+
address: "|",
|
|
856
|
+
phoneNumber: " ",
|
|
857
|
+
stringArray: " "
|
|
858
|
+
};
|
|
859
|
+
var INDEX_MAPPER = {
|
|
860
|
+
name: { first: 0, last: 1 },
|
|
861
|
+
address: {
|
|
862
|
+
streetAddress: 0,
|
|
863
|
+
city: 1,
|
|
864
|
+
parish: 2,
|
|
865
|
+
country: 3
|
|
866
|
+
},
|
|
867
|
+
phoneNumber: {
|
|
868
|
+
countryCode: 0,
|
|
869
|
+
areaCode: 1,
|
|
870
|
+
localNumber: 2
|
|
871
|
+
}
|
|
872
|
+
};
|
|
873
|
+
function zip(data) {
|
|
874
|
+
const stringifiedData = JSON.stringify(data);
|
|
875
|
+
const errorMessage = `Failed to execute [${zip.name}].`;
|
|
876
|
+
return JSON.parse(stringifiedData, (key, value) => {
|
|
877
|
+
if (iiKeys.includes(key)) {
|
|
878
|
+
const validKey = key;
|
|
879
|
+
const handleTypeMismatchError = (required) => {
|
|
880
|
+
if (typeof required !== typeof value) {
|
|
881
|
+
throw new Error(errorMessage, {
|
|
882
|
+
cause: `[Type Mismatch] Property type {${key}:${JSON.stringify(
|
|
883
|
+
required
|
|
884
|
+
)}} is required, but {${key}:${JSON.stringify(
|
|
885
|
+
value
|
|
886
|
+
)}} was provided.`
|
|
887
|
+
});
|
|
888
|
+
}
|
|
889
|
+
};
|
|
890
|
+
switch (validKey) {
|
|
891
|
+
case "name":
|
|
892
|
+
handleTypeMismatchError({ first: "", last: "" });
|
|
893
|
+
break;
|
|
894
|
+
case "address":
|
|
895
|
+
handleTypeMismatchError({
|
|
896
|
+
streetAddress: "",
|
|
897
|
+
city: "",
|
|
898
|
+
parish: "",
|
|
899
|
+
country: "Jamaica"
|
|
900
|
+
});
|
|
901
|
+
break;
|
|
902
|
+
case "phoneNumber":
|
|
903
|
+
handleTypeMismatchError({
|
|
904
|
+
countryCode: "1",
|
|
905
|
+
areaCode: "876",
|
|
906
|
+
localNumber: ""
|
|
907
|
+
});
|
|
908
|
+
break;
|
|
909
|
+
default:
|
|
910
|
+
return validKey;
|
|
911
|
+
}
|
|
912
|
+
let group2 = [];
|
|
913
|
+
Object.keys(INDEX_MAPPER[validKey]).forEach((prop) => {
|
|
914
|
+
const validProp = prop;
|
|
915
|
+
group2[INDEX_MAPPER[validKey][validProp]] = value[validProp]?.trim?.() || "";
|
|
916
|
+
});
|
|
917
|
+
return group2.join(DELIMITERS[validKey]).trim();
|
|
918
|
+
}
|
|
919
|
+
const valueIsArray = Array.isArray(value);
|
|
920
|
+
const hasArrayId = key.includes(stringArrayIdPrefix);
|
|
921
|
+
if (hasArrayId && valueIsArray && strictArray(value).every((v) => typeof v === "string")) {
|
|
922
|
+
return strictArray(value).join(DELIMITERS.stringArray).trim();
|
|
923
|
+
} else if (hasArrayId) {
|
|
924
|
+
throw new Error(errorMessage, {
|
|
925
|
+
cause: `[Type Mismatch] Every property with the ${stringArrayIdPrefix} prefix, must be an array of strings. However {${key}:${value}} was provided.`
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
const hasMultiDimArrayId = key.includes(multiDimArrayIdPrefix);
|
|
929
|
+
if (hasMultiDimArrayId && valueIsArray && key.includes(multiDimArrayDelim) && value.every(
|
|
930
|
+
(d) => Array.isArray(d) && d.every((sv) => typeof sv === "object")
|
|
931
|
+
)) {
|
|
932
|
+
const mapName = key.split(multiDimArrayDelim)[1];
|
|
933
|
+
return strictArray(value).map(
|
|
934
|
+
(objArr) => strictArray(objArr).map((obj) => {
|
|
935
|
+
if (mapName in obj) {
|
|
936
|
+
const mapValue = obj[mapName];
|
|
937
|
+
if (typeof mapValue !== "string") {
|
|
938
|
+
throw new Error(errorMessage, {
|
|
939
|
+
cause: `[Type Mismatch] Expected {${mapName}:string} but {${mapName}:${mapValue}} was provided.`
|
|
940
|
+
});
|
|
941
|
+
}
|
|
942
|
+
return mapValue;
|
|
943
|
+
} else
|
|
944
|
+
throw new Error(errorMessage, {
|
|
945
|
+
cause: `[Type Mismatch] Every object in the multi dimensional array must have a property with the name ${mapName}. However ${obj} doesn't adhere to this rule.`
|
|
946
|
+
});
|
|
947
|
+
}).join(DELIMITERS.stringArray)
|
|
948
|
+
);
|
|
949
|
+
} else if (hasMultiDimArrayId && valueIsArray) {
|
|
950
|
+
return value.map((arr) => {
|
|
951
|
+
if (!arr.every((d) => typeof d === "string")) {
|
|
952
|
+
throw new Error(errorMessage, {
|
|
953
|
+
cause: `[Type Mismatch] Every sub type of the array must be a string. However ${arr} doesn't comply with this rule.`
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
return arr.join(DELIMITERS.stringArray);
|
|
957
|
+
});
|
|
958
|
+
} else if (hasMultiDimArrayId) {
|
|
959
|
+
throw new Error(errorMessage, {
|
|
960
|
+
cause: `[Type Mismatch] Every property with the ${multiDimArrayIdPrefix} prefix, must be a multi dimensional array of strings. However {${key}:${value}} was provided.`
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
if (typeof value === "string") return value.trim();
|
|
964
|
+
return value;
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
function unzip(data) {
|
|
968
|
+
const stringifiedData = JSON.stringify(data);
|
|
969
|
+
const errorMessage = `Failed to execute [${unzip.name}]`;
|
|
970
|
+
return JSON.parse(stringifiedData, (key, value) => {
|
|
971
|
+
const isIIKey = iiKeys.includes(key);
|
|
972
|
+
if (isIIKey && typeof value === "string") {
|
|
973
|
+
const validKey = key;
|
|
974
|
+
const splitProp = value.split(DELIMITERS[validKey]);
|
|
975
|
+
return Object.fromEntries(
|
|
976
|
+
Object.entries(INDEX_MAPPER[validKey]).map(([mapperKey, idx]) => {
|
|
977
|
+
return [mapperKey, splitProp[idx]?.trim?.() || ""];
|
|
978
|
+
})
|
|
979
|
+
);
|
|
980
|
+
} else if (isIIKey) {
|
|
981
|
+
throw new Error(errorMessage, {
|
|
982
|
+
cause: `[Type Mismatch] {${key}:string} expected, but {${key}:${value}} was provided.`
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
const hasArrayId = key.includes(stringArrayIdPrefix);
|
|
986
|
+
if (hasArrayId && typeof value === "string") {
|
|
987
|
+
return strictArray(value.split(DELIMITERS.stringArray));
|
|
988
|
+
} else if (hasArrayId) {
|
|
989
|
+
throw new Error(errorMessage, {
|
|
990
|
+
cause: `[Type Mismatch] {${key}:string} is required but {${key}:${value}} was provided.`
|
|
991
|
+
});
|
|
992
|
+
}
|
|
993
|
+
const hasMultiDimArrayId = key.includes(multiDimArrayIdPrefix);
|
|
994
|
+
if (hasMultiDimArrayId && Array.isArray(value)) {
|
|
995
|
+
const mapName = key.split(multiDimArrayDelim)?.[1];
|
|
996
|
+
return strictArray(value).map((delimString) => {
|
|
997
|
+
const splitStr = strictArray(delimString.split(DELIMITERS.stringArray));
|
|
998
|
+
if (!splitStr.every((d) => typeof d === "string"))
|
|
999
|
+
throw new Error(errorMessage, {
|
|
1000
|
+
cause: `[Type Mismatch] Expected string[] but found ${splitStr}.`
|
|
1001
|
+
});
|
|
1002
|
+
if (mapName) return splitStr.map((value2) => ({ [mapName]: value2 }));
|
|
1003
|
+
return splitStr;
|
|
1004
|
+
});
|
|
1005
|
+
} else if (hasMultiDimArrayId) {
|
|
1006
|
+
throw new Error(errorMessage, {
|
|
1007
|
+
cause: `[Type Mismatch] {${key}:string[]} is required but {${key}:${value}} was provided.`
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
return value;
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
var EVENTS = ["zip", "unzip"];
|
|
1014
|
+
var ServerDataAdapter = class {
|
|
1015
|
+
invoke(event, data) {
|
|
1016
|
+
switch (event) {
|
|
1017
|
+
case "unzip":
|
|
1018
|
+
return unzip(data);
|
|
1019
|
+
case "zip":
|
|
1020
|
+
return zip(data);
|
|
1021
|
+
default:
|
|
1022
|
+
event;
|
|
1023
|
+
throw new Error(
|
|
1024
|
+
`"${event}" is an unrecognized event. Try again using one of the following events ${EVENTS}.`
|
|
1025
|
+
);
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
};
|
|
1029
|
+
var serverDataAdapter = new ServerDataAdapter().invoke;
|
|
1030
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1031
|
+
0 && (module.exports = {
|
|
1032
|
+
addArticle,
|
|
1033
|
+
arrayWithConst,
|
|
1034
|
+
asyncRun,
|
|
1035
|
+
averageOf,
|
|
1036
|
+
blankSpaces,
|
|
1037
|
+
buildArray,
|
|
1038
|
+
camelCaseToLetter,
|
|
1039
|
+
classNameExt,
|
|
1040
|
+
classNameResolver,
|
|
1041
|
+
coerceIn,
|
|
1042
|
+
copyToClipboard,
|
|
1043
|
+
count,
|
|
1044
|
+
dataSearcher,
|
|
1045
|
+
distinct,
|
|
1046
|
+
drop,
|
|
1047
|
+
dropLast,
|
|
1048
|
+
dropLastWhile,
|
|
1049
|
+
dropWhile,
|
|
1050
|
+
format,
|
|
1051
|
+
formatGCTRegNo,
|
|
1052
|
+
formatInvoiceNo,
|
|
1053
|
+
getCaps,
|
|
1054
|
+
getFileExt,
|
|
1055
|
+
group,
|
|
1056
|
+
hasIndex,
|
|
1057
|
+
ifDefined,
|
|
1058
|
+
ifEmpty,
|
|
1059
|
+
inRange,
|
|
1060
|
+
indexOf,
|
|
1061
|
+
indices,
|
|
1062
|
+
inferFilename,
|
|
1063
|
+
insertAt,
|
|
1064
|
+
isEmpty,
|
|
1065
|
+
isFile,
|
|
1066
|
+
isLetter,
|
|
1067
|
+
isNumber,
|
|
1068
|
+
lastIndex,
|
|
1069
|
+
map,
|
|
1070
|
+
mapToArray,
|
|
1071
|
+
maxOf,
|
|
1072
|
+
minOf,
|
|
1073
|
+
negate,
|
|
1074
|
+
ordinalIndicator,
|
|
1075
|
+
overwrite,
|
|
1076
|
+
pluralize,
|
|
1077
|
+
poll,
|
|
1078
|
+
random,
|
|
1079
|
+
range,
|
|
1080
|
+
readClipboardText,
|
|
1081
|
+
removeAll,
|
|
1082
|
+
repeat,
|
|
1083
|
+
run,
|
|
1084
|
+
serverDataAdapter,
|
|
1085
|
+
someValuesEmpty,
|
|
1086
|
+
sort,
|
|
1087
|
+
strictArray,
|
|
1088
|
+
stringToSearch,
|
|
1089
|
+
subObjectList,
|
|
1090
|
+
sumOf,
|
|
1091
|
+
take,
|
|
1092
|
+
takeLast,
|
|
1093
|
+
takeLastWhile,
|
|
1094
|
+
takeWhile,
|
|
1095
|
+
timeDuration,
|
|
1096
|
+
toNumber,
|
|
1097
|
+
toObject,
|
|
1098
|
+
trimString,
|
|
1099
|
+
undefinedIfEmpty,
|
|
1100
|
+
upperFirst,
|
|
1101
|
+
windowed
|
|
1102
|
+
});
|