@wavy/fn 0.0.27 → 0.0.29
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 +45 -227
- package/dist/main.d.cts +26 -20
- package/dist/main.d.ts +26 -20
- package/dist/main.js +46 -225
- package/package.json +4 -3
package/dist/main.cjs
CHANGED
|
@@ -56,9 +56,9 @@ __export(main_exports, {
|
|
|
56
56
|
insertAt: () => insertAt,
|
|
57
57
|
isEmpty: () => isEmpty,
|
|
58
58
|
isFile: () => isFile,
|
|
59
|
+
isFileDetails: () => isFileDetails,
|
|
59
60
|
isIterable: () => isIterable,
|
|
60
61
|
isLetter: () => isLetter,
|
|
61
|
-
isLocalFile: () => isLocalFile,
|
|
62
62
|
isNumber: () => isNumber,
|
|
63
63
|
isPromise: () => isPromise,
|
|
64
64
|
lastIndex: () => lastIndex,
|
|
@@ -86,8 +86,6 @@ __export(main_exports, {
|
|
|
86
86
|
removeAll: () => removeAll,
|
|
87
87
|
repeat: () => repeat,
|
|
88
88
|
run: () => run,
|
|
89
|
-
sanitizeLocalFile: () => sanitizeLocalFile,
|
|
90
|
-
serverDataAdapter: () => serverDataAdapter,
|
|
91
89
|
someValuesEmpty: () => someValuesEmpty,
|
|
92
90
|
sort: () => sort,
|
|
93
91
|
strictArray: () => strictArray,
|
|
@@ -109,13 +107,13 @@ __export(main_exports, {
|
|
|
109
107
|
module.exports = __toCommonJS(main_exports);
|
|
110
108
|
|
|
111
109
|
// src/helper-functions/HelperFunctions.ts
|
|
112
|
-
var
|
|
110
|
+
var import_util2 = require("@wavy/util");
|
|
113
111
|
|
|
114
112
|
// src/helper-functions/components/ObjectConverter.ts
|
|
115
113
|
var import_uuid = require("uuid");
|
|
116
|
-
var
|
|
114
|
+
var import_util = require("@wavy/util");
|
|
117
115
|
var import_console = require("console");
|
|
118
|
-
function
|
|
116
|
+
function fileToFileDetails(file, options) {
|
|
119
117
|
const fileExt = getFileExt(file.name);
|
|
120
118
|
const fileName = (() => {
|
|
121
119
|
if (options?.filename && options.filename.includes(fileExt))
|
|
@@ -123,15 +121,17 @@ function fileToLocalFile(file, options) {
|
|
|
123
121
|
else if (options?.filename) return options.filename.trim() + fileExt;
|
|
124
122
|
return file.name;
|
|
125
123
|
})()?.trim?.();
|
|
126
|
-
const { name: _, size: __
|
|
124
|
+
const { name: _, size: __ } = file;
|
|
127
125
|
return {
|
|
128
126
|
uid: options?.uid || (0, import_uuid.v4)(),
|
|
129
127
|
description: options?.description,
|
|
130
|
-
|
|
128
|
+
extension: fileExt,
|
|
131
129
|
path: options?.filepath || file?.webkitRelativePath,
|
|
132
|
-
|
|
133
|
-
Object.keys(
|
|
134
|
-
(key) =>
|
|
130
|
+
alias: options?.alias || run(
|
|
131
|
+
Object.keys(import_util.FILE_MIME_TYPES).find(
|
|
132
|
+
(key) => import_util.FILE_MIME_TYPES[key].includes(
|
|
133
|
+
file.type
|
|
134
|
+
)
|
|
135
135
|
),
|
|
136
136
|
(type) => {
|
|
137
137
|
if (!type) {
|
|
@@ -144,23 +144,35 @@ function fileToLocalFile(file, options) {
|
|
|
144
144
|
sizeInBytes: file.size,
|
|
145
145
|
uploadDate: options?.uploadDate === "now" ? Date.now() : options?.uploadDate ?? file?.lastModified,
|
|
146
146
|
name: fileName,
|
|
147
|
-
|
|
147
|
+
mime: file.type,
|
|
148
|
+
lastModified: file.lastModified
|
|
148
149
|
};
|
|
149
150
|
}
|
|
150
|
-
function
|
|
151
|
+
function fileDetailsToFile(details) {
|
|
151
152
|
return {
|
|
152
|
-
name:
|
|
153
|
-
size:
|
|
154
|
-
|
|
153
|
+
name: details.name,
|
|
154
|
+
size: details.sizeInBytes,
|
|
155
|
+
webkitRelativePath: details.path,
|
|
156
|
+
lastModified: details.lastModified,
|
|
157
|
+
type: details.mime,
|
|
158
|
+
arrayBuffer: null,
|
|
159
|
+
bytes: null,
|
|
160
|
+
slice: null,
|
|
161
|
+
stream: null,
|
|
162
|
+
text: null
|
|
155
163
|
};
|
|
156
164
|
}
|
|
157
165
|
var Overloader = class {
|
|
158
166
|
invoke(...args) {
|
|
159
167
|
if (isFile(args[0])) {
|
|
160
|
-
return
|
|
168
|
+
return fileToFileDetails(
|
|
169
|
+
...args
|
|
170
|
+
);
|
|
161
171
|
}
|
|
162
|
-
if (
|
|
163
|
-
return
|
|
172
|
+
if (isFileDetails(args[0])) {
|
|
173
|
+
return fileDetailsToFile(
|
|
174
|
+
...args
|
|
175
|
+
);
|
|
164
176
|
} else throw new Error(`The arguments supplied are insufficient.`);
|
|
165
177
|
}
|
|
166
178
|
};
|
|
@@ -578,12 +590,6 @@ function format(event, ...args) {
|
|
|
578
590
|
return event;
|
|
579
591
|
}
|
|
580
592
|
}
|
|
581
|
-
function sanitizeLocalFile({
|
|
582
|
-
_metadata: _,
|
|
583
|
-
...file
|
|
584
|
-
}) {
|
|
585
|
-
return file;
|
|
586
|
-
}
|
|
587
593
|
function isFile(value) {
|
|
588
594
|
const requiredKeys = [
|
|
589
595
|
"name",
|
|
@@ -596,25 +602,14 @@ function isFile(value) {
|
|
|
596
602
|
return true;
|
|
597
603
|
return false;
|
|
598
604
|
}
|
|
599
|
-
function
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
description: "",
|
|
603
|
-
path: "",
|
|
604
|
-
sizeInBytes: 0,
|
|
605
|
-
ext: "",
|
|
606
|
-
typeAlias: "unknown",
|
|
607
|
-
uid: "",
|
|
608
|
-
uploadDate: 0,
|
|
609
|
-
_metadata: void 0
|
|
610
|
-
};
|
|
611
|
-
const optionalKeys = ["description"];
|
|
612
|
-
const requiredKeys = Object.keys(dummyLocalFile).filter((key) => !optionalKeys.includes(key));
|
|
613
|
-
const allKeys = [requiredKeys, optionalKeys].flat();
|
|
614
|
-
if (value && typeof value === "object" && requiredKeys.every((key) => key in value) && Object.keys(value).every((key) => allKeys.includes(key))) {
|
|
605
|
+
function isFileDetails(value) {
|
|
606
|
+
try {
|
|
607
|
+
import_util2.FileDetails.parse(value);
|
|
615
608
|
return true;
|
|
609
|
+
} catch (error) {
|
|
610
|
+
console.error(error);
|
|
611
|
+
return false;
|
|
616
612
|
}
|
|
617
|
-
return false;
|
|
618
613
|
}
|
|
619
614
|
function isIterable(value) {
|
|
620
615
|
return !!value && typeof value === "object" && Symbol.iterator in value && typeof value[Symbol.iterator] === "function";
|
|
@@ -632,9 +627,9 @@ function parseName(value) {
|
|
|
632
627
|
const { first = "", last = "" } = value || {};
|
|
633
628
|
return first.trim() + " " + last.trim();
|
|
634
629
|
}
|
|
635
|
-
function parseMoney(value) {
|
|
636
|
-
if (typeof value === "string") return StringFormatter_default.toMoney(value);
|
|
637
|
-
return NumberFormatter_default.toMoney(value);
|
|
630
|
+
function parseMoney(value, options) {
|
|
631
|
+
if (typeof value === "string") return StringFormatter_default.toMoney(value, options);
|
|
632
|
+
return NumberFormatter_default.toMoney(value, options);
|
|
638
633
|
}
|
|
639
634
|
function parseAddress(address, ...args) {
|
|
640
635
|
if (typeof address === "string") {
|
|
@@ -723,7 +718,7 @@ function map(arr, callback) {
|
|
|
723
718
|
return arr;
|
|
724
719
|
}
|
|
725
720
|
function getMimeTypes(typeAliases) {
|
|
726
|
-
return distinct(strictArray(typeAliases)).map((alias) =>
|
|
721
|
+
return distinct(strictArray(typeAliases)).map((alias) => import_util2.FILE_MIME_TYPES[alias]).flat();
|
|
727
722
|
}
|
|
728
723
|
function classNameResolver(baseClassName) {
|
|
729
724
|
return (className) => {
|
|
@@ -993,7 +988,7 @@ async function copyToClipboard(text) {
|
|
|
993
988
|
if (err instanceof Error) {
|
|
994
989
|
return {
|
|
995
990
|
error: {
|
|
996
|
-
|
|
991
|
+
code: "UNKNOWN",
|
|
997
992
|
title: err.name,
|
|
998
993
|
message: err.message
|
|
999
994
|
}
|
|
@@ -1001,7 +996,7 @@ async function copyToClipboard(text) {
|
|
|
1001
996
|
}
|
|
1002
997
|
return {
|
|
1003
998
|
error: {
|
|
1004
|
-
|
|
999
|
+
code: "UNKNOWN",
|
|
1005
1000
|
title: "Failed to copy text",
|
|
1006
1001
|
message: JSON.stringify(err)
|
|
1007
1002
|
}
|
|
@@ -1015,7 +1010,7 @@ async function readClipboardText() {
|
|
|
1015
1010
|
} catch (err) {
|
|
1016
1011
|
return {
|
|
1017
1012
|
error: {
|
|
1018
|
-
|
|
1013
|
+
code: "UNKNOWN",
|
|
1019
1014
|
title: "Failed to read clipboard contents",
|
|
1020
1015
|
message: `Something went wrong while trying to read the clipboard contents. [CAUSE]: ${JSON.stringify(
|
|
1021
1016
|
err
|
|
@@ -1027,181 +1022,6 @@ async function readClipboardText() {
|
|
|
1027
1022
|
function arrayWithConst(array) {
|
|
1028
1023
|
return { value: array, asConst: [...array] };
|
|
1029
1024
|
}
|
|
1030
|
-
|
|
1031
|
-
// src/server-adapters/ServerAdapters.ts
|
|
1032
|
-
var import_types3 = require("@wavy/types");
|
|
1033
|
-
var iiKeys = Object.keys({
|
|
1034
|
-
name: null,
|
|
1035
|
-
address: null
|
|
1036
|
-
});
|
|
1037
|
-
var stringArrayIdPrefix = "listOf";
|
|
1038
|
-
var multiDimArrayIdPrefix = "2DListOf";
|
|
1039
|
-
var multiDimArrayDelim = ":";
|
|
1040
|
-
var DELIMITERS = {
|
|
1041
|
-
name: " ",
|
|
1042
|
-
address: "|",
|
|
1043
|
-
phoneNumber: " ",
|
|
1044
|
-
stringArray: " "
|
|
1045
|
-
};
|
|
1046
|
-
var INDEX_MAPPER = {
|
|
1047
|
-
name: { first: 0, last: 1 },
|
|
1048
|
-
address: {
|
|
1049
|
-
streetAddress: 0,
|
|
1050
|
-
city: 1,
|
|
1051
|
-
parish: 2,
|
|
1052
|
-
country: 3
|
|
1053
|
-
}
|
|
1054
|
-
};
|
|
1055
|
-
function zip(data) {
|
|
1056
|
-
const stringifiedData = JSON.stringify(data);
|
|
1057
|
-
const errorMessage = `Failed to execute [${zip.name}].`;
|
|
1058
|
-
return JSON.parse(stringifiedData, (key, value) => {
|
|
1059
|
-
if (iiKeys.includes(key)) {
|
|
1060
|
-
const validKey = key;
|
|
1061
|
-
const handleTypeMismatchError = (required) => {
|
|
1062
|
-
if (typeof required !== typeof value) {
|
|
1063
|
-
throw new Error(errorMessage, {
|
|
1064
|
-
cause: `[Type Mismatch] Property type {${key}:${JSON.stringify(
|
|
1065
|
-
required
|
|
1066
|
-
)}} is required, but {${key}:${JSON.stringify(
|
|
1067
|
-
value
|
|
1068
|
-
)}} was provided.`
|
|
1069
|
-
});
|
|
1070
|
-
}
|
|
1071
|
-
};
|
|
1072
|
-
switch (validKey) {
|
|
1073
|
-
case "name":
|
|
1074
|
-
handleTypeMismatchError({ first: "", last: "" });
|
|
1075
|
-
break;
|
|
1076
|
-
case "address":
|
|
1077
|
-
handleTypeMismatchError({
|
|
1078
|
-
streetAddress: "",
|
|
1079
|
-
city: "",
|
|
1080
|
-
parish: "",
|
|
1081
|
-
country: "Jamaica"
|
|
1082
|
-
});
|
|
1083
|
-
break;
|
|
1084
|
-
default:
|
|
1085
|
-
return validKey;
|
|
1086
|
-
}
|
|
1087
|
-
let group2 = [];
|
|
1088
|
-
Object.keys(INDEX_MAPPER[validKey]).forEach((prop) => {
|
|
1089
|
-
const validProp = prop;
|
|
1090
|
-
group2[INDEX_MAPPER[validKey][validProp]] = value[validProp]?.trim?.() || "";
|
|
1091
|
-
});
|
|
1092
|
-
return group2.join(DELIMITERS[validKey]).trim();
|
|
1093
|
-
}
|
|
1094
|
-
const valueIsArray = Array.isArray(value);
|
|
1095
|
-
const hasArrayId = key.includes(stringArrayIdPrefix);
|
|
1096
|
-
if (hasArrayId && valueIsArray && strictArray(value).every((v) => typeof v === "string")) {
|
|
1097
|
-
return strictArray(value).join(DELIMITERS.stringArray).trim();
|
|
1098
|
-
} else if (hasArrayId) {
|
|
1099
|
-
throw new Error(errorMessage, {
|
|
1100
|
-
cause: `[Type Mismatch] Every property with the ${stringArrayIdPrefix} prefix, must be an array of strings. However {${key}:${value}} was provided.`
|
|
1101
|
-
});
|
|
1102
|
-
}
|
|
1103
|
-
const hasMultiDimArrayId = key.includes(multiDimArrayIdPrefix);
|
|
1104
|
-
if (hasMultiDimArrayId && valueIsArray && key.includes(multiDimArrayDelim) && value.every(
|
|
1105
|
-
(d) => Array.isArray(d) && d.every((sv) => typeof sv === "object")
|
|
1106
|
-
)) {
|
|
1107
|
-
const mapName = key.split(multiDimArrayDelim)[1];
|
|
1108
|
-
return strictArray(value).map(
|
|
1109
|
-
(objArr) => strictArray(objArr).map((obj) => {
|
|
1110
|
-
if (mapName in obj) {
|
|
1111
|
-
const mapValue = obj[mapName];
|
|
1112
|
-
if (typeof mapValue !== "string") {
|
|
1113
|
-
throw new Error(errorMessage, {
|
|
1114
|
-
cause: `[Type Mismatch] Expected {${mapName}:string} but {${mapName}:${mapValue}} was provided.`
|
|
1115
|
-
});
|
|
1116
|
-
}
|
|
1117
|
-
return mapValue;
|
|
1118
|
-
} else
|
|
1119
|
-
throw new Error(errorMessage, {
|
|
1120
|
-
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.`
|
|
1121
|
-
});
|
|
1122
|
-
}).join(DELIMITERS.stringArray)
|
|
1123
|
-
);
|
|
1124
|
-
} else if (hasMultiDimArrayId && valueIsArray) {
|
|
1125
|
-
return value.map((arr) => {
|
|
1126
|
-
if (!arr.every((d) => typeof d === "string")) {
|
|
1127
|
-
throw new Error(errorMessage, {
|
|
1128
|
-
cause: `[Type Mismatch] Every sub type of the array must be a string. However ${arr} doesn't comply with this rule.`
|
|
1129
|
-
});
|
|
1130
|
-
}
|
|
1131
|
-
return arr.join(DELIMITERS.stringArray);
|
|
1132
|
-
});
|
|
1133
|
-
} else if (hasMultiDimArrayId) {
|
|
1134
|
-
throw new Error(errorMessage, {
|
|
1135
|
-
cause: `[Type Mismatch] Every property with the ${multiDimArrayIdPrefix} prefix, must be a multi dimensional array of strings. However {${key}:${value}} was provided.`
|
|
1136
|
-
});
|
|
1137
|
-
}
|
|
1138
|
-
if (typeof value === "string") return value.trim();
|
|
1139
|
-
return value;
|
|
1140
|
-
});
|
|
1141
|
-
}
|
|
1142
|
-
function unzip(data) {
|
|
1143
|
-
const stringifiedData = JSON.stringify(data);
|
|
1144
|
-
const errorMessage = `Failed to execute [${unzip.name}]`;
|
|
1145
|
-
return JSON.parse(stringifiedData, (key, value) => {
|
|
1146
|
-
const isIIKey = iiKeys.includes(key);
|
|
1147
|
-
if (isIIKey && typeof value === "string") {
|
|
1148
|
-
const validKey = key;
|
|
1149
|
-
const splitProp = value.split(DELIMITERS[validKey]);
|
|
1150
|
-
return Object.fromEntries(
|
|
1151
|
-
Object.entries(INDEX_MAPPER[validKey]).map(([mapperKey, idx]) => {
|
|
1152
|
-
return [mapperKey, splitProp[idx]?.trim?.() || ""];
|
|
1153
|
-
})
|
|
1154
|
-
);
|
|
1155
|
-
} else if (isIIKey) {
|
|
1156
|
-
throw new Error(errorMessage, {
|
|
1157
|
-
cause: `[Type Mismatch] {${key}:string} expected, but {${key}:${value}} was provided.`
|
|
1158
|
-
});
|
|
1159
|
-
}
|
|
1160
|
-
const hasArrayId = key.includes(stringArrayIdPrefix);
|
|
1161
|
-
if (hasArrayId && typeof value === "string") {
|
|
1162
|
-
return strictArray(value.split(DELIMITERS.stringArray));
|
|
1163
|
-
} else if (hasArrayId) {
|
|
1164
|
-
throw new Error(errorMessage, {
|
|
1165
|
-
cause: `[Type Mismatch] {${key}:string} is required but {${key}:${value}} was provided.`
|
|
1166
|
-
});
|
|
1167
|
-
}
|
|
1168
|
-
const hasMultiDimArrayId = key.includes(multiDimArrayIdPrefix);
|
|
1169
|
-
if (hasMultiDimArrayId && Array.isArray(value)) {
|
|
1170
|
-
const mapName = key.split(multiDimArrayDelim)?.[1];
|
|
1171
|
-
return strictArray(value).map((delimString) => {
|
|
1172
|
-
const splitStr = strictArray(delimString.split(DELIMITERS.stringArray));
|
|
1173
|
-
if (!splitStr.every((d) => typeof d === "string"))
|
|
1174
|
-
throw new Error(errorMessage, {
|
|
1175
|
-
cause: `[Type Mismatch] Expected string[] but found ${splitStr}.`
|
|
1176
|
-
});
|
|
1177
|
-
if (mapName) return splitStr.map((value2) => ({ [mapName]: value2 }));
|
|
1178
|
-
return splitStr;
|
|
1179
|
-
});
|
|
1180
|
-
} else if (hasMultiDimArrayId) {
|
|
1181
|
-
throw new Error(errorMessage, {
|
|
1182
|
-
cause: `[Type Mismatch] {${key}:string[]} is required but {${key}:${value}} was provided.`
|
|
1183
|
-
});
|
|
1184
|
-
}
|
|
1185
|
-
return value;
|
|
1186
|
-
});
|
|
1187
|
-
}
|
|
1188
|
-
var EVENTS = ["zip", "unzip"];
|
|
1189
|
-
var ServerDataAdapter = class {
|
|
1190
|
-
invoke(event, data) {
|
|
1191
|
-
switch (event) {
|
|
1192
|
-
case "unzip":
|
|
1193
|
-
return unzip(data);
|
|
1194
|
-
case "zip":
|
|
1195
|
-
return zip(data);
|
|
1196
|
-
default:
|
|
1197
|
-
event;
|
|
1198
|
-
throw new Error(
|
|
1199
|
-
`"${event}" is an unrecognized event. Try again using one of the following events ${EVENTS}.`
|
|
1200
|
-
);
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
};
|
|
1204
|
-
var serverDataAdapter = new ServerDataAdapter().invoke;
|
|
1205
1025
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1206
1026
|
0 && (module.exports = {
|
|
1207
1027
|
addArticle,
|
|
@@ -1240,9 +1060,9 @@ var serverDataAdapter = new ServerDataAdapter().invoke;
|
|
|
1240
1060
|
insertAt,
|
|
1241
1061
|
isEmpty,
|
|
1242
1062
|
isFile,
|
|
1063
|
+
isFileDetails,
|
|
1243
1064
|
isIterable,
|
|
1244
1065
|
isLetter,
|
|
1245
|
-
isLocalFile,
|
|
1246
1066
|
isNumber,
|
|
1247
1067
|
isPromise,
|
|
1248
1068
|
lastIndex,
|
|
@@ -1270,8 +1090,6 @@ var serverDataAdapter = new ServerDataAdapter().invoke;
|
|
|
1270
1090
|
removeAll,
|
|
1271
1091
|
repeat,
|
|
1272
1092
|
run,
|
|
1273
|
-
sanitizeLocalFile,
|
|
1274
|
-
serverDataAdapter,
|
|
1275
1093
|
someValuesEmpty,
|
|
1276
1094
|
sort,
|
|
1277
1095
|
strictArray,
|
package/dist/main.d.cts
CHANGED
|
@@ -1,18 +1,29 @@
|
|
|
1
|
-
import "@wavy/
|
|
2
|
-
import {
|
|
1
|
+
import "@wavy/util"
|
|
2
|
+
import { FileDetails, Name, Address, NonFunction, KnownFileAlias, TaskResult } from '@wavy/util';
|
|
3
3
|
|
|
4
4
|
type DateFormat = "MMM dd, yyyy" | "MMM dd, yyyy | hh:mm A" | "MMM dd, yyyy at hh:mm A" | "MMMM" | "yyyy" | "MMM yyyy" | "mm/dd/yyyy" | "mm/dd/yyyy hh:mm A" | "hh:mm A" | "hh:mm:ss A";
|
|
5
5
|
|
|
6
6
|
declare const toObject: {
|
|
7
|
-
(file: File
|
|
7
|
+
(file: File, options?: Partial<{
|
|
8
8
|
uid?: string;
|
|
9
9
|
uploadDate: number | "now";
|
|
10
10
|
description: string;
|
|
11
11
|
filepath: string;
|
|
12
12
|
filename: string;
|
|
13
|
-
|
|
14
|
-
}> | undefined):
|
|
15
|
-
(
|
|
13
|
+
alias: FileDetails["alias"];
|
|
14
|
+
}> | undefined): FileDetails;
|
|
15
|
+
(details: {
|
|
16
|
+
lastModified: number | null;
|
|
17
|
+
sizeInBytes: number;
|
|
18
|
+
name: string;
|
|
19
|
+
path: string;
|
|
20
|
+
extension: string;
|
|
21
|
+
mime: string;
|
|
22
|
+
alias: "pdf" | "word" | "excel" | "img" | "txt" | "unknown";
|
|
23
|
+
uid?: string | undefined;
|
|
24
|
+
uploadDate?: number | undefined;
|
|
25
|
+
description?: string | undefined;
|
|
26
|
+
}): File;
|
|
16
27
|
};
|
|
17
28
|
|
|
18
29
|
type NumberFormatterTypes = {
|
|
@@ -27,6 +38,11 @@ type NumberFormatterTypes = {
|
|
|
27
38
|
};
|
|
28
39
|
};
|
|
29
40
|
|
|
41
|
+
declare class NumberFormatter {
|
|
42
|
+
static format(value: number, format?: NumberFormatterTypes["formats"], options?: NumberFormatterTypes["options"]["money"]): string;
|
|
43
|
+
static toMoney(amount: number | undefined, options?: NumberFormatterTypes["options"]["money"]): string;
|
|
44
|
+
}
|
|
45
|
+
|
|
30
46
|
declare class StringFormatter {
|
|
31
47
|
static vowels: string;
|
|
32
48
|
static caseConverter: {
|
|
@@ -67,14 +83,13 @@ declare const toMoney: (value: string | number, options?: NumberFormatterTypes["
|
|
|
67
83
|
* @example parseDate, parseMoney, parseName, parseAddress, parseFileSize
|
|
68
84
|
*/
|
|
69
85
|
declare function format<Event extends "date" | "money" | "name" | "address" | "file-size">(event: Event, ...args: Event extends "date" ? Parameters<typeof dateFormat> : Event extends "money" ? Parameters<typeof toMoney> : Event extends "name" ? Parameters<typeof nameToString> : Event extends "address" ? Parameters<typeof addressToString> : Event extends "file-size" ? [bytes: number] : never): Event extends "date" | "money" | "name" | "address" | "file-size" ? string : never;
|
|
70
|
-
declare function sanitizeLocalFile({ _metadata: _, ...file }: LocalFile): SanitizeFile<LocalFile>;
|
|
71
86
|
declare function isFile(value: unknown): value is File;
|
|
72
|
-
declare function
|
|
87
|
+
declare function isFileDetails(value: unknown): value is FileDetails;
|
|
73
88
|
declare function isIterable<T>(value: unknown): value is Iterable<T>;
|
|
74
89
|
declare function isPromise<T>(value: unknown): value is Promise<T>;
|
|
75
90
|
declare const parseDate: (time: number | Date | "now", format?: DateFormat) => string;
|
|
76
91
|
declare function parseName<Value extends string | Name>(value: Value): Value extends string ? Name : Value extends Name ? string : never;
|
|
77
|
-
declare function parseMoney(value: string | number): string;
|
|
92
|
+
declare function parseMoney(value: string | number, options?: Parameters<typeof NumberFormatter.toMoney>[1]): string;
|
|
78
93
|
declare function parseAddress<T extends Address | string>(address: T, ...args: T extends string ? [
|
|
79
94
|
options?: Partial<{
|
|
80
95
|
/**The value used to separate each field in the string
|
|
@@ -95,7 +110,7 @@ declare function pick<O extends object, K extends keyof O = keyof O>(value: O, k
|
|
|
95
110
|
declare function omit<O extends object, K extends keyof O = keyof O>(value: O, keys: K[]): { [Key in Exclude<keyof O, K>]: O[Key] | null; };
|
|
96
111
|
declare function omitNils<O extends object>(value: O): O;
|
|
97
112
|
declare function map<T>(arr: T[], callback: (value: T, index: number, array: T[], end: () => void) => T): T[];
|
|
98
|
-
declare function getMimeTypes(typeAliases:
|
|
113
|
+
declare function getMimeTypes(typeAliases: KnownFileAlias[]): string[];
|
|
99
114
|
declare function classNameResolver(baseClassName: string): (className: string) => string;
|
|
100
115
|
declare function classNameExt(rootClassName: string): (className: string) => string;
|
|
101
116
|
declare function range(start: number, end: number): number[];
|
|
@@ -203,13 +218,4 @@ declare function arrayWithConst<T>(array: T[]): {
|
|
|
203
218
|
asConst: readonly T[];
|
|
204
219
|
};
|
|
205
220
|
|
|
206
|
-
|
|
207
|
-
<DataType extends {
|
|
208
|
-
[key: string]: any;
|
|
209
|
-
}>(event: "zip", data: DataType): FromServer<DataType>;
|
|
210
|
-
<DataType extends {
|
|
211
|
-
[key: string]: any;
|
|
212
|
-
}>(event: "unzip", data: DataType): NormalizeFromServer<DataType>;
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
export { addArticle, arrayWithConst, asyncRun, averageOf, blankSpaces, buildArray, camelCaseToLetter, castArray, castReturn, classNameExt, classNameResolver, coerceIn, copyToClipboard, count, dataSearcher, distinct, drop, dropLast, dropLastWhile, dropWhile, format, getCaps, getFileExt, getFilename, getMimeTypes, group, hasIndex, ifDefined, ifEmpty, inRange, indexOf, indices, inferFilename, insertAt, isEmpty, isFile, isIterable, isLetter, isLocalFile, isNumber, isPromise, lastIndex, limit, map, mapToArray, maxOf, minOf, negate, omit, omitNils, ordinalIndicator, overwrite, parseAddress, parseDate, parseFileSize, parseMoney, parseName, pick, pluralize, poll, random, range, readClipboardText, removeAll, repeat, run, sanitizeLocalFile, serverDataAdapter, someValuesEmpty, sort, strictArray, stringToSearch, subObjectList, sumOf, take, takeLast, takeLastWhile, takeWhile, timeDuration, toNumber, toObject, trimString, undefinedIfEmpty, upperFirst, windowed };
|
|
221
|
+
export { addArticle, arrayWithConst, asyncRun, averageOf, blankSpaces, buildArray, camelCaseToLetter, castArray, castReturn, classNameExt, classNameResolver, coerceIn, copyToClipboard, count, dataSearcher, distinct, drop, dropLast, dropLastWhile, dropWhile, format, getCaps, getFileExt, getFilename, getMimeTypes, group, hasIndex, ifDefined, ifEmpty, inRange, indexOf, indices, inferFilename, insertAt, isEmpty, isFile, isFileDetails, isIterable, isLetter, isNumber, isPromise, lastIndex, limit, map, mapToArray, maxOf, minOf, negate, omit, omitNils, ordinalIndicator, overwrite, parseAddress, parseDate, parseFileSize, parseMoney, parseName, pick, pluralize, poll, random, range, readClipboardText, removeAll, repeat, run, someValuesEmpty, sort, strictArray, stringToSearch, subObjectList, sumOf, take, takeLast, takeLastWhile, takeWhile, timeDuration, toNumber, toObject, trimString, undefinedIfEmpty, upperFirst, windowed };
|
package/dist/main.d.ts
CHANGED
|
@@ -1,18 +1,29 @@
|
|
|
1
|
-
import "@wavy/
|
|
2
|
-
import {
|
|
1
|
+
import "@wavy/util"
|
|
2
|
+
import { FileDetails, Name, Address, NonFunction, KnownFileAlias, TaskResult } from '@wavy/util';
|
|
3
3
|
|
|
4
4
|
type DateFormat = "MMM dd, yyyy" | "MMM dd, yyyy | hh:mm A" | "MMM dd, yyyy at hh:mm A" | "MMMM" | "yyyy" | "MMM yyyy" | "mm/dd/yyyy" | "mm/dd/yyyy hh:mm A" | "hh:mm A" | "hh:mm:ss A";
|
|
5
5
|
|
|
6
6
|
declare const toObject: {
|
|
7
|
-
(file: File
|
|
7
|
+
(file: File, options?: Partial<{
|
|
8
8
|
uid?: string;
|
|
9
9
|
uploadDate: number | "now";
|
|
10
10
|
description: string;
|
|
11
11
|
filepath: string;
|
|
12
12
|
filename: string;
|
|
13
|
-
|
|
14
|
-
}> | undefined):
|
|
15
|
-
(
|
|
13
|
+
alias: FileDetails["alias"];
|
|
14
|
+
}> | undefined): FileDetails;
|
|
15
|
+
(details: {
|
|
16
|
+
lastModified: number | null;
|
|
17
|
+
sizeInBytes: number;
|
|
18
|
+
name: string;
|
|
19
|
+
path: string;
|
|
20
|
+
extension: string;
|
|
21
|
+
mime: string;
|
|
22
|
+
alias: "pdf" | "word" | "excel" | "img" | "txt" | "unknown";
|
|
23
|
+
uid?: string | undefined;
|
|
24
|
+
uploadDate?: number | undefined;
|
|
25
|
+
description?: string | undefined;
|
|
26
|
+
}): File;
|
|
16
27
|
};
|
|
17
28
|
|
|
18
29
|
type NumberFormatterTypes = {
|
|
@@ -27,6 +38,11 @@ type NumberFormatterTypes = {
|
|
|
27
38
|
};
|
|
28
39
|
};
|
|
29
40
|
|
|
41
|
+
declare class NumberFormatter {
|
|
42
|
+
static format(value: number, format?: NumberFormatterTypes["formats"], options?: NumberFormatterTypes["options"]["money"]): string;
|
|
43
|
+
static toMoney(amount: number | undefined, options?: NumberFormatterTypes["options"]["money"]): string;
|
|
44
|
+
}
|
|
45
|
+
|
|
30
46
|
declare class StringFormatter {
|
|
31
47
|
static vowels: string;
|
|
32
48
|
static caseConverter: {
|
|
@@ -67,14 +83,13 @@ declare const toMoney: (value: string | number, options?: NumberFormatterTypes["
|
|
|
67
83
|
* @example parseDate, parseMoney, parseName, parseAddress, parseFileSize
|
|
68
84
|
*/
|
|
69
85
|
declare function format<Event extends "date" | "money" | "name" | "address" | "file-size">(event: Event, ...args: Event extends "date" ? Parameters<typeof dateFormat> : Event extends "money" ? Parameters<typeof toMoney> : Event extends "name" ? Parameters<typeof nameToString> : Event extends "address" ? Parameters<typeof addressToString> : Event extends "file-size" ? [bytes: number] : never): Event extends "date" | "money" | "name" | "address" | "file-size" ? string : never;
|
|
70
|
-
declare function sanitizeLocalFile({ _metadata: _, ...file }: LocalFile): SanitizeFile<LocalFile>;
|
|
71
86
|
declare function isFile(value: unknown): value is File;
|
|
72
|
-
declare function
|
|
87
|
+
declare function isFileDetails(value: unknown): value is FileDetails;
|
|
73
88
|
declare function isIterable<T>(value: unknown): value is Iterable<T>;
|
|
74
89
|
declare function isPromise<T>(value: unknown): value is Promise<T>;
|
|
75
90
|
declare const parseDate: (time: number | Date | "now", format?: DateFormat) => string;
|
|
76
91
|
declare function parseName<Value extends string | Name>(value: Value): Value extends string ? Name : Value extends Name ? string : never;
|
|
77
|
-
declare function parseMoney(value: string | number): string;
|
|
92
|
+
declare function parseMoney(value: string | number, options?: Parameters<typeof NumberFormatter.toMoney>[1]): string;
|
|
78
93
|
declare function parseAddress<T extends Address | string>(address: T, ...args: T extends string ? [
|
|
79
94
|
options?: Partial<{
|
|
80
95
|
/**The value used to separate each field in the string
|
|
@@ -95,7 +110,7 @@ declare function pick<O extends object, K extends keyof O = keyof O>(value: O, k
|
|
|
95
110
|
declare function omit<O extends object, K extends keyof O = keyof O>(value: O, keys: K[]): { [Key in Exclude<keyof O, K>]: O[Key] | null; };
|
|
96
111
|
declare function omitNils<O extends object>(value: O): O;
|
|
97
112
|
declare function map<T>(arr: T[], callback: (value: T, index: number, array: T[], end: () => void) => T): T[];
|
|
98
|
-
declare function getMimeTypes(typeAliases:
|
|
113
|
+
declare function getMimeTypes(typeAliases: KnownFileAlias[]): string[];
|
|
99
114
|
declare function classNameResolver(baseClassName: string): (className: string) => string;
|
|
100
115
|
declare function classNameExt(rootClassName: string): (className: string) => string;
|
|
101
116
|
declare function range(start: number, end: number): number[];
|
|
@@ -203,13 +218,4 @@ declare function arrayWithConst<T>(array: T[]): {
|
|
|
203
218
|
asConst: readonly T[];
|
|
204
219
|
};
|
|
205
220
|
|
|
206
|
-
|
|
207
|
-
<DataType extends {
|
|
208
|
-
[key: string]: any;
|
|
209
|
-
}>(event: "zip", data: DataType): FromServer<DataType>;
|
|
210
|
-
<DataType extends {
|
|
211
|
-
[key: string]: any;
|
|
212
|
-
}>(event: "unzip", data: DataType): NormalizeFromServer<DataType>;
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
export { addArticle, arrayWithConst, asyncRun, averageOf, blankSpaces, buildArray, camelCaseToLetter, castArray, castReturn, classNameExt, classNameResolver, coerceIn, copyToClipboard, count, dataSearcher, distinct, drop, dropLast, dropLastWhile, dropWhile, format, getCaps, getFileExt, getFilename, getMimeTypes, group, hasIndex, ifDefined, ifEmpty, inRange, indexOf, indices, inferFilename, insertAt, isEmpty, isFile, isIterable, isLetter, isLocalFile, isNumber, isPromise, lastIndex, limit, map, mapToArray, maxOf, minOf, negate, omit, omitNils, ordinalIndicator, overwrite, parseAddress, parseDate, parseFileSize, parseMoney, parseName, pick, pluralize, poll, random, range, readClipboardText, removeAll, repeat, run, sanitizeLocalFile, serverDataAdapter, someValuesEmpty, sort, strictArray, stringToSearch, subObjectList, sumOf, take, takeLast, takeLastWhile, takeWhile, timeDuration, toNumber, toObject, trimString, undefinedIfEmpty, upperFirst, windowed };
|
|
221
|
+
export { addArticle, arrayWithConst, asyncRun, averageOf, blankSpaces, buildArray, camelCaseToLetter, castArray, castReturn, classNameExt, classNameResolver, coerceIn, copyToClipboard, count, dataSearcher, distinct, drop, dropLast, dropLastWhile, dropWhile, format, getCaps, getFileExt, getFilename, getMimeTypes, group, hasIndex, ifDefined, ifEmpty, inRange, indexOf, indices, inferFilename, insertAt, isEmpty, isFile, isFileDetails, isIterable, isLetter, isNumber, isPromise, lastIndex, limit, map, mapToArray, maxOf, minOf, negate, omit, omitNils, ordinalIndicator, overwrite, parseAddress, parseDate, parseFileSize, parseMoney, parseName, pick, pluralize, poll, random, range, readClipboardText, removeAll, repeat, run, someValuesEmpty, sort, strictArray, stringToSearch, subObjectList, sumOf, take, takeLast, takeLastWhile, takeWhile, timeDuration, toNumber, toObject, trimString, undefinedIfEmpty, upperFirst, windowed };
|
package/dist/main.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
// src/helper-functions/HelperFunctions.ts
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
FILE_MIME_TYPES as FILE_MIME_TYPES2,
|
|
4
|
+
FileDetails as FileDetails2
|
|
5
|
+
} from "@wavy/util";
|
|
5
6
|
|
|
6
7
|
// src/helper-functions/components/ObjectConverter.ts
|
|
7
8
|
import { v4 } from "uuid";
|
|
8
|
-
import {
|
|
9
|
+
import { FILE_MIME_TYPES } from "@wavy/util";
|
|
9
10
|
import { log } from "console";
|
|
10
|
-
function
|
|
11
|
+
function fileToFileDetails(file, options) {
|
|
11
12
|
const fileExt = getFileExt(file.name);
|
|
12
13
|
const fileName = (() => {
|
|
13
14
|
if (options?.filename && options.filename.includes(fileExt))
|
|
@@ -15,15 +16,17 @@ function fileToLocalFile(file, options) {
|
|
|
15
16
|
else if (options?.filename) return options.filename.trim() + fileExt;
|
|
16
17
|
return file.name;
|
|
17
18
|
})()?.trim?.();
|
|
18
|
-
const { name: _, size: __
|
|
19
|
+
const { name: _, size: __ } = file;
|
|
19
20
|
return {
|
|
20
21
|
uid: options?.uid || v4(),
|
|
21
22
|
description: options?.description,
|
|
22
|
-
|
|
23
|
+
extension: fileExt,
|
|
23
24
|
path: options?.filepath || file?.webkitRelativePath,
|
|
24
|
-
|
|
25
|
-
Object.keys(
|
|
26
|
-
(key) =>
|
|
25
|
+
alias: options?.alias || run(
|
|
26
|
+
Object.keys(FILE_MIME_TYPES).find(
|
|
27
|
+
(key) => FILE_MIME_TYPES[key].includes(
|
|
28
|
+
file.type
|
|
29
|
+
)
|
|
27
30
|
),
|
|
28
31
|
(type) => {
|
|
29
32
|
if (!type) {
|
|
@@ -36,23 +39,35 @@ function fileToLocalFile(file, options) {
|
|
|
36
39
|
sizeInBytes: file.size,
|
|
37
40
|
uploadDate: options?.uploadDate === "now" ? Date.now() : options?.uploadDate ?? file?.lastModified,
|
|
38
41
|
name: fileName,
|
|
39
|
-
|
|
42
|
+
mime: file.type,
|
|
43
|
+
lastModified: file.lastModified
|
|
40
44
|
};
|
|
41
45
|
}
|
|
42
|
-
function
|
|
46
|
+
function fileDetailsToFile(details) {
|
|
43
47
|
return {
|
|
44
|
-
name:
|
|
45
|
-
size:
|
|
46
|
-
|
|
48
|
+
name: details.name,
|
|
49
|
+
size: details.sizeInBytes,
|
|
50
|
+
webkitRelativePath: details.path,
|
|
51
|
+
lastModified: details.lastModified,
|
|
52
|
+
type: details.mime,
|
|
53
|
+
arrayBuffer: null,
|
|
54
|
+
bytes: null,
|
|
55
|
+
slice: null,
|
|
56
|
+
stream: null,
|
|
57
|
+
text: null
|
|
47
58
|
};
|
|
48
59
|
}
|
|
49
60
|
var Overloader = class {
|
|
50
61
|
invoke(...args) {
|
|
51
62
|
if (isFile(args[0])) {
|
|
52
|
-
return
|
|
63
|
+
return fileToFileDetails(
|
|
64
|
+
...args
|
|
65
|
+
);
|
|
53
66
|
}
|
|
54
|
-
if (
|
|
55
|
-
return
|
|
67
|
+
if (isFileDetails(args[0])) {
|
|
68
|
+
return fileDetailsToFile(
|
|
69
|
+
...args
|
|
70
|
+
);
|
|
56
71
|
} else throw new Error(`The arguments supplied are insufficient.`);
|
|
57
72
|
}
|
|
58
73
|
};
|
|
@@ -470,12 +485,6 @@ function format(event, ...args) {
|
|
|
470
485
|
return event;
|
|
471
486
|
}
|
|
472
487
|
}
|
|
473
|
-
function sanitizeLocalFile({
|
|
474
|
-
_metadata: _,
|
|
475
|
-
...file
|
|
476
|
-
}) {
|
|
477
|
-
return file;
|
|
478
|
-
}
|
|
479
488
|
function isFile(value) {
|
|
480
489
|
const requiredKeys = [
|
|
481
490
|
"name",
|
|
@@ -488,25 +497,14 @@ function isFile(value) {
|
|
|
488
497
|
return true;
|
|
489
498
|
return false;
|
|
490
499
|
}
|
|
491
|
-
function
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
description: "",
|
|
495
|
-
path: "",
|
|
496
|
-
sizeInBytes: 0,
|
|
497
|
-
ext: "",
|
|
498
|
-
typeAlias: "unknown",
|
|
499
|
-
uid: "",
|
|
500
|
-
uploadDate: 0,
|
|
501
|
-
_metadata: void 0
|
|
502
|
-
};
|
|
503
|
-
const optionalKeys = ["description"];
|
|
504
|
-
const requiredKeys = Object.keys(dummyLocalFile).filter((key) => !optionalKeys.includes(key));
|
|
505
|
-
const allKeys = [requiredKeys, optionalKeys].flat();
|
|
506
|
-
if (value && typeof value === "object" && requiredKeys.every((key) => key in value) && Object.keys(value).every((key) => allKeys.includes(key))) {
|
|
500
|
+
function isFileDetails(value) {
|
|
501
|
+
try {
|
|
502
|
+
FileDetails2.parse(value);
|
|
507
503
|
return true;
|
|
504
|
+
} catch (error) {
|
|
505
|
+
console.error(error);
|
|
506
|
+
return false;
|
|
508
507
|
}
|
|
509
|
-
return false;
|
|
510
508
|
}
|
|
511
509
|
function isIterable(value) {
|
|
512
510
|
return !!value && typeof value === "object" && Symbol.iterator in value && typeof value[Symbol.iterator] === "function";
|
|
@@ -524,9 +522,9 @@ function parseName(value) {
|
|
|
524
522
|
const { first = "", last = "" } = value || {};
|
|
525
523
|
return first.trim() + " " + last.trim();
|
|
526
524
|
}
|
|
527
|
-
function parseMoney(value) {
|
|
528
|
-
if (typeof value === "string") return StringFormatter_default.toMoney(value);
|
|
529
|
-
return NumberFormatter_default.toMoney(value);
|
|
525
|
+
function parseMoney(value, options) {
|
|
526
|
+
if (typeof value === "string") return StringFormatter_default.toMoney(value, options);
|
|
527
|
+
return NumberFormatter_default.toMoney(value, options);
|
|
530
528
|
}
|
|
531
529
|
function parseAddress(address, ...args) {
|
|
532
530
|
if (typeof address === "string") {
|
|
@@ -615,7 +613,7 @@ function map(arr, callback) {
|
|
|
615
613
|
return arr;
|
|
616
614
|
}
|
|
617
615
|
function getMimeTypes(typeAliases) {
|
|
618
|
-
return distinct(strictArray(typeAliases)).map((alias) =>
|
|
616
|
+
return distinct(strictArray(typeAliases)).map((alias) => FILE_MIME_TYPES2[alias]).flat();
|
|
619
617
|
}
|
|
620
618
|
function classNameResolver(baseClassName) {
|
|
621
619
|
return (className) => {
|
|
@@ -885,7 +883,7 @@ async function copyToClipboard(text) {
|
|
|
885
883
|
if (err instanceof Error) {
|
|
886
884
|
return {
|
|
887
885
|
error: {
|
|
888
|
-
|
|
886
|
+
code: "UNKNOWN",
|
|
889
887
|
title: err.name,
|
|
890
888
|
message: err.message
|
|
891
889
|
}
|
|
@@ -893,7 +891,7 @@ async function copyToClipboard(text) {
|
|
|
893
891
|
}
|
|
894
892
|
return {
|
|
895
893
|
error: {
|
|
896
|
-
|
|
894
|
+
code: "UNKNOWN",
|
|
897
895
|
title: "Failed to copy text",
|
|
898
896
|
message: JSON.stringify(err)
|
|
899
897
|
}
|
|
@@ -907,7 +905,7 @@ async function readClipboardText() {
|
|
|
907
905
|
} catch (err) {
|
|
908
906
|
return {
|
|
909
907
|
error: {
|
|
910
|
-
|
|
908
|
+
code: "UNKNOWN",
|
|
911
909
|
title: "Failed to read clipboard contents",
|
|
912
910
|
message: `Something went wrong while trying to read the clipboard contents. [CAUSE]: ${JSON.stringify(
|
|
913
911
|
err
|
|
@@ -919,181 +917,6 @@ async function readClipboardText() {
|
|
|
919
917
|
function arrayWithConst(array) {
|
|
920
918
|
return { value: array, asConst: [...array] };
|
|
921
919
|
}
|
|
922
|
-
|
|
923
|
-
// src/server-adapters/ServerAdapters.ts
|
|
924
|
-
import "@wavy/types";
|
|
925
|
-
var iiKeys = Object.keys({
|
|
926
|
-
name: null,
|
|
927
|
-
address: null
|
|
928
|
-
});
|
|
929
|
-
var stringArrayIdPrefix = "listOf";
|
|
930
|
-
var multiDimArrayIdPrefix = "2DListOf";
|
|
931
|
-
var multiDimArrayDelim = ":";
|
|
932
|
-
var DELIMITERS = {
|
|
933
|
-
name: " ",
|
|
934
|
-
address: "|",
|
|
935
|
-
phoneNumber: " ",
|
|
936
|
-
stringArray: " "
|
|
937
|
-
};
|
|
938
|
-
var INDEX_MAPPER = {
|
|
939
|
-
name: { first: 0, last: 1 },
|
|
940
|
-
address: {
|
|
941
|
-
streetAddress: 0,
|
|
942
|
-
city: 1,
|
|
943
|
-
parish: 2,
|
|
944
|
-
country: 3
|
|
945
|
-
}
|
|
946
|
-
};
|
|
947
|
-
function zip(data) {
|
|
948
|
-
const stringifiedData = JSON.stringify(data);
|
|
949
|
-
const errorMessage = `Failed to execute [${zip.name}].`;
|
|
950
|
-
return JSON.parse(stringifiedData, (key, value) => {
|
|
951
|
-
if (iiKeys.includes(key)) {
|
|
952
|
-
const validKey = key;
|
|
953
|
-
const handleTypeMismatchError = (required) => {
|
|
954
|
-
if (typeof required !== typeof value) {
|
|
955
|
-
throw new Error(errorMessage, {
|
|
956
|
-
cause: `[Type Mismatch] Property type {${key}:${JSON.stringify(
|
|
957
|
-
required
|
|
958
|
-
)}} is required, but {${key}:${JSON.stringify(
|
|
959
|
-
value
|
|
960
|
-
)}} was provided.`
|
|
961
|
-
});
|
|
962
|
-
}
|
|
963
|
-
};
|
|
964
|
-
switch (validKey) {
|
|
965
|
-
case "name":
|
|
966
|
-
handleTypeMismatchError({ first: "", last: "" });
|
|
967
|
-
break;
|
|
968
|
-
case "address":
|
|
969
|
-
handleTypeMismatchError({
|
|
970
|
-
streetAddress: "",
|
|
971
|
-
city: "",
|
|
972
|
-
parish: "",
|
|
973
|
-
country: "Jamaica"
|
|
974
|
-
});
|
|
975
|
-
break;
|
|
976
|
-
default:
|
|
977
|
-
return validKey;
|
|
978
|
-
}
|
|
979
|
-
let group2 = [];
|
|
980
|
-
Object.keys(INDEX_MAPPER[validKey]).forEach((prop) => {
|
|
981
|
-
const validProp = prop;
|
|
982
|
-
group2[INDEX_MAPPER[validKey][validProp]] = value[validProp]?.trim?.() || "";
|
|
983
|
-
});
|
|
984
|
-
return group2.join(DELIMITERS[validKey]).trim();
|
|
985
|
-
}
|
|
986
|
-
const valueIsArray = Array.isArray(value);
|
|
987
|
-
const hasArrayId = key.includes(stringArrayIdPrefix);
|
|
988
|
-
if (hasArrayId && valueIsArray && strictArray(value).every((v) => typeof v === "string")) {
|
|
989
|
-
return strictArray(value).join(DELIMITERS.stringArray).trim();
|
|
990
|
-
} else if (hasArrayId) {
|
|
991
|
-
throw new Error(errorMessage, {
|
|
992
|
-
cause: `[Type Mismatch] Every property with the ${stringArrayIdPrefix} prefix, must be an array of strings. However {${key}:${value}} was provided.`
|
|
993
|
-
});
|
|
994
|
-
}
|
|
995
|
-
const hasMultiDimArrayId = key.includes(multiDimArrayIdPrefix);
|
|
996
|
-
if (hasMultiDimArrayId && valueIsArray && key.includes(multiDimArrayDelim) && value.every(
|
|
997
|
-
(d) => Array.isArray(d) && d.every((sv) => typeof sv === "object")
|
|
998
|
-
)) {
|
|
999
|
-
const mapName = key.split(multiDimArrayDelim)[1];
|
|
1000
|
-
return strictArray(value).map(
|
|
1001
|
-
(objArr) => strictArray(objArr).map((obj) => {
|
|
1002
|
-
if (mapName in obj) {
|
|
1003
|
-
const mapValue = obj[mapName];
|
|
1004
|
-
if (typeof mapValue !== "string") {
|
|
1005
|
-
throw new Error(errorMessage, {
|
|
1006
|
-
cause: `[Type Mismatch] Expected {${mapName}:string} but {${mapName}:${mapValue}} was provided.`
|
|
1007
|
-
});
|
|
1008
|
-
}
|
|
1009
|
-
return mapValue;
|
|
1010
|
-
} else
|
|
1011
|
-
throw new Error(errorMessage, {
|
|
1012
|
-
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.`
|
|
1013
|
-
});
|
|
1014
|
-
}).join(DELIMITERS.stringArray)
|
|
1015
|
-
);
|
|
1016
|
-
} else if (hasMultiDimArrayId && valueIsArray) {
|
|
1017
|
-
return value.map((arr) => {
|
|
1018
|
-
if (!arr.every((d) => typeof d === "string")) {
|
|
1019
|
-
throw new Error(errorMessage, {
|
|
1020
|
-
cause: `[Type Mismatch] Every sub type of the array must be a string. However ${arr} doesn't comply with this rule.`
|
|
1021
|
-
});
|
|
1022
|
-
}
|
|
1023
|
-
return arr.join(DELIMITERS.stringArray);
|
|
1024
|
-
});
|
|
1025
|
-
} else if (hasMultiDimArrayId) {
|
|
1026
|
-
throw new Error(errorMessage, {
|
|
1027
|
-
cause: `[Type Mismatch] Every property with the ${multiDimArrayIdPrefix} prefix, must be a multi dimensional array of strings. However {${key}:${value}} was provided.`
|
|
1028
|
-
});
|
|
1029
|
-
}
|
|
1030
|
-
if (typeof value === "string") return value.trim();
|
|
1031
|
-
return value;
|
|
1032
|
-
});
|
|
1033
|
-
}
|
|
1034
|
-
function unzip(data) {
|
|
1035
|
-
const stringifiedData = JSON.stringify(data);
|
|
1036
|
-
const errorMessage = `Failed to execute [${unzip.name}]`;
|
|
1037
|
-
return JSON.parse(stringifiedData, (key, value) => {
|
|
1038
|
-
const isIIKey = iiKeys.includes(key);
|
|
1039
|
-
if (isIIKey && typeof value === "string") {
|
|
1040
|
-
const validKey = key;
|
|
1041
|
-
const splitProp = value.split(DELIMITERS[validKey]);
|
|
1042
|
-
return Object.fromEntries(
|
|
1043
|
-
Object.entries(INDEX_MAPPER[validKey]).map(([mapperKey, idx]) => {
|
|
1044
|
-
return [mapperKey, splitProp[idx]?.trim?.() || ""];
|
|
1045
|
-
})
|
|
1046
|
-
);
|
|
1047
|
-
} else if (isIIKey) {
|
|
1048
|
-
throw new Error(errorMessage, {
|
|
1049
|
-
cause: `[Type Mismatch] {${key}:string} expected, but {${key}:${value}} was provided.`
|
|
1050
|
-
});
|
|
1051
|
-
}
|
|
1052
|
-
const hasArrayId = key.includes(stringArrayIdPrefix);
|
|
1053
|
-
if (hasArrayId && typeof value === "string") {
|
|
1054
|
-
return strictArray(value.split(DELIMITERS.stringArray));
|
|
1055
|
-
} else if (hasArrayId) {
|
|
1056
|
-
throw new Error(errorMessage, {
|
|
1057
|
-
cause: `[Type Mismatch] {${key}:string} is required but {${key}:${value}} was provided.`
|
|
1058
|
-
});
|
|
1059
|
-
}
|
|
1060
|
-
const hasMultiDimArrayId = key.includes(multiDimArrayIdPrefix);
|
|
1061
|
-
if (hasMultiDimArrayId && Array.isArray(value)) {
|
|
1062
|
-
const mapName = key.split(multiDimArrayDelim)?.[1];
|
|
1063
|
-
return strictArray(value).map((delimString) => {
|
|
1064
|
-
const splitStr = strictArray(delimString.split(DELIMITERS.stringArray));
|
|
1065
|
-
if (!splitStr.every((d) => typeof d === "string"))
|
|
1066
|
-
throw new Error(errorMessage, {
|
|
1067
|
-
cause: `[Type Mismatch] Expected string[] but found ${splitStr}.`
|
|
1068
|
-
});
|
|
1069
|
-
if (mapName) return splitStr.map((value2) => ({ [mapName]: value2 }));
|
|
1070
|
-
return splitStr;
|
|
1071
|
-
});
|
|
1072
|
-
} else if (hasMultiDimArrayId) {
|
|
1073
|
-
throw new Error(errorMessage, {
|
|
1074
|
-
cause: `[Type Mismatch] {${key}:string[]} is required but {${key}:${value}} was provided.`
|
|
1075
|
-
});
|
|
1076
|
-
}
|
|
1077
|
-
return value;
|
|
1078
|
-
});
|
|
1079
|
-
}
|
|
1080
|
-
var EVENTS = ["zip", "unzip"];
|
|
1081
|
-
var ServerDataAdapter = class {
|
|
1082
|
-
invoke(event, data) {
|
|
1083
|
-
switch (event) {
|
|
1084
|
-
case "unzip":
|
|
1085
|
-
return unzip(data);
|
|
1086
|
-
case "zip":
|
|
1087
|
-
return zip(data);
|
|
1088
|
-
default:
|
|
1089
|
-
event;
|
|
1090
|
-
throw new Error(
|
|
1091
|
-
`"${event}" is an unrecognized event. Try again using one of the following events ${EVENTS}.`
|
|
1092
|
-
);
|
|
1093
|
-
}
|
|
1094
|
-
}
|
|
1095
|
-
};
|
|
1096
|
-
var serverDataAdapter = new ServerDataAdapter().invoke;
|
|
1097
920
|
export {
|
|
1098
921
|
addArticle,
|
|
1099
922
|
arrayWithConst,
|
|
@@ -1131,9 +954,9 @@ export {
|
|
|
1131
954
|
insertAt,
|
|
1132
955
|
isEmpty,
|
|
1133
956
|
isFile,
|
|
957
|
+
isFileDetails,
|
|
1134
958
|
isIterable,
|
|
1135
959
|
isLetter,
|
|
1136
|
-
isLocalFile,
|
|
1137
960
|
isNumber,
|
|
1138
961
|
isPromise,
|
|
1139
962
|
lastIndex,
|
|
@@ -1161,8 +984,6 @@ export {
|
|
|
1161
984
|
removeAll,
|
|
1162
985
|
repeat,
|
|
1163
986
|
run,
|
|
1164
|
-
sanitizeLocalFile,
|
|
1165
|
-
serverDataAdapter,
|
|
1166
987
|
someValuesEmpty,
|
|
1167
988
|
sort,
|
|
1168
989
|
strictArray,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wavy/fn",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.29",
|
|
4
4
|
"main": "./dist/main.js",
|
|
5
5
|
"module": "./dist/main.cjs",
|
|
6
6
|
"types": "./dist/main.d.ts",
|
|
@@ -25,9 +25,10 @@
|
|
|
25
25
|
"description": "",
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/node": "^24.5.2",
|
|
28
|
-
"@wavy/
|
|
28
|
+
"@wavy/util": "^0.0.6",
|
|
29
29
|
"tsup": "^8.5.0",
|
|
30
|
-
"typescript": "^5.9.2"
|
|
30
|
+
"typescript": "^5.9.2",
|
|
31
|
+
"zod": "^4.2.1"
|
|
31
32
|
},
|
|
32
33
|
"dependencies": {
|
|
33
34
|
"uuid": "^13.0.0"
|