@wavy/fn 0.0.26 → 0.0.28
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 +114 -234
- package/dist/main.d.cts +45 -25
- package/dist/main.d.ts +45 -25
- package/dist/main.js +110 -232
- package/package.json +4 -3
package/dist/main.cjs
CHANGED
|
@@ -56,12 +56,13 @@ __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,
|
|
65
|
+
limit: () => limit,
|
|
65
66
|
map: () => map,
|
|
66
67
|
mapToArray: () => mapToArray,
|
|
67
68
|
maxOf: () => maxOf,
|
|
@@ -71,6 +72,10 @@ __export(main_exports, {
|
|
|
71
72
|
omitNils: () => omitNils,
|
|
72
73
|
ordinalIndicator: () => ordinalIndicator,
|
|
73
74
|
overwrite: () => overwrite,
|
|
75
|
+
parseAddress: () => parseAddress,
|
|
76
|
+
parseDate: () => parseDate,
|
|
77
|
+
parseFileSize: () => parseFileSize,
|
|
78
|
+
parseMoney: () => parseMoney,
|
|
74
79
|
parseName: () => parseName,
|
|
75
80
|
pick: () => pick,
|
|
76
81
|
pluralize: () => pluralize,
|
|
@@ -81,8 +86,6 @@ __export(main_exports, {
|
|
|
81
86
|
removeAll: () => removeAll,
|
|
82
87
|
repeat: () => repeat,
|
|
83
88
|
run: () => run,
|
|
84
|
-
sanitizeLocalFile: () => sanitizeLocalFile,
|
|
85
|
-
serverDataAdapter: () => serverDataAdapter,
|
|
86
89
|
someValuesEmpty: () => someValuesEmpty,
|
|
87
90
|
sort: () => sort,
|
|
88
91
|
strictArray: () => strictArray,
|
|
@@ -104,13 +107,13 @@ __export(main_exports, {
|
|
|
104
107
|
module.exports = __toCommonJS(main_exports);
|
|
105
108
|
|
|
106
109
|
// src/helper-functions/HelperFunctions.ts
|
|
107
|
-
var
|
|
110
|
+
var import_util2 = require("@wavy/util");
|
|
108
111
|
|
|
109
112
|
// src/helper-functions/components/ObjectConverter.ts
|
|
110
113
|
var import_uuid = require("uuid");
|
|
111
|
-
var
|
|
114
|
+
var import_util = require("@wavy/util");
|
|
112
115
|
var import_console = require("console");
|
|
113
|
-
function
|
|
116
|
+
function fileToFileDetails(file, options) {
|
|
114
117
|
const fileExt = getFileExt(file.name);
|
|
115
118
|
const fileName = (() => {
|
|
116
119
|
if (options?.filename && options.filename.includes(fileExt))
|
|
@@ -118,15 +121,17 @@ function fileToLocalFile(file, options) {
|
|
|
118
121
|
else if (options?.filename) return options.filename.trim() + fileExt;
|
|
119
122
|
return file.name;
|
|
120
123
|
})()?.trim?.();
|
|
121
|
-
const { name: _, size: __
|
|
124
|
+
const { name: _, size: __ } = file;
|
|
122
125
|
return {
|
|
123
126
|
uid: options?.uid || (0, import_uuid.v4)(),
|
|
124
127
|
description: options?.description,
|
|
125
|
-
|
|
128
|
+
extension: fileExt,
|
|
126
129
|
path: options?.filepath || file?.webkitRelativePath,
|
|
127
|
-
|
|
128
|
-
Object.keys(
|
|
129
|
-
(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
|
+
)
|
|
130
135
|
),
|
|
131
136
|
(type) => {
|
|
132
137
|
if (!type) {
|
|
@@ -139,23 +144,35 @@ function fileToLocalFile(file, options) {
|
|
|
139
144
|
sizeInBytes: file.size,
|
|
140
145
|
uploadDate: options?.uploadDate === "now" ? Date.now() : options?.uploadDate ?? file?.lastModified,
|
|
141
146
|
name: fileName,
|
|
142
|
-
|
|
147
|
+
mime: file.type,
|
|
148
|
+
lastModified: file.lastModified
|
|
143
149
|
};
|
|
144
150
|
}
|
|
145
|
-
function
|
|
151
|
+
function fileDetailsToFile(details) {
|
|
146
152
|
return {
|
|
147
|
-
name:
|
|
148
|
-
size:
|
|
149
|
-
|
|
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
|
|
150
163
|
};
|
|
151
164
|
}
|
|
152
165
|
var Overloader = class {
|
|
153
166
|
invoke(...args) {
|
|
154
167
|
if (isFile(args[0])) {
|
|
155
|
-
return
|
|
168
|
+
return fileToFileDetails(
|
|
169
|
+
...args
|
|
170
|
+
);
|
|
156
171
|
}
|
|
157
|
-
if (
|
|
158
|
-
return
|
|
172
|
+
if (isFileDetails(args[0])) {
|
|
173
|
+
return fileDetailsToFile(
|
|
174
|
+
...args
|
|
175
|
+
);
|
|
159
176
|
} else throw new Error(`The arguments supplied are insufficient.`);
|
|
160
177
|
}
|
|
161
178
|
};
|
|
@@ -573,12 +590,6 @@ function format(event, ...args) {
|
|
|
573
590
|
return event;
|
|
574
591
|
}
|
|
575
592
|
}
|
|
576
|
-
function sanitizeLocalFile({
|
|
577
|
-
_metadata: _,
|
|
578
|
-
...file
|
|
579
|
-
}) {
|
|
580
|
-
return file;
|
|
581
|
-
}
|
|
582
593
|
function isFile(value) {
|
|
583
594
|
const requiredKeys = [
|
|
584
595
|
"name",
|
|
@@ -591,25 +602,14 @@ function isFile(value) {
|
|
|
591
602
|
return true;
|
|
592
603
|
return false;
|
|
593
604
|
}
|
|
594
|
-
function
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
description: "",
|
|
598
|
-
path: "",
|
|
599
|
-
sizeInBytes: 0,
|
|
600
|
-
ext: "",
|
|
601
|
-
typeAlias: "unknown",
|
|
602
|
-
uid: "",
|
|
603
|
-
uploadDate: 0,
|
|
604
|
-
_metadata: void 0
|
|
605
|
-
};
|
|
606
|
-
const optionalKeys = ["description"];
|
|
607
|
-
const requiredKeys = Object.keys(dummyLocalFile).filter((key) => !optionalKeys.includes(key));
|
|
608
|
-
const allKeys = [requiredKeys, optionalKeys].flat();
|
|
609
|
-
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);
|
|
610
608
|
return true;
|
|
609
|
+
} catch (error) {
|
|
610
|
+
console.error(error);
|
|
611
|
+
return false;
|
|
611
612
|
}
|
|
612
|
-
return false;
|
|
613
613
|
}
|
|
614
614
|
function isIterable(value) {
|
|
615
615
|
return !!value && typeof value === "object" && Symbol.iterator in value && typeof value[Symbol.iterator] === "function";
|
|
@@ -618,9 +618,59 @@ function isPromise(value) {
|
|
|
618
618
|
if (value instanceof Promise) return true;
|
|
619
619
|
return !!value && (typeof value === "object" || typeof value === "function") && "then" in value && typeof value.then === "function";
|
|
620
620
|
}
|
|
621
|
+
var parseDate = dateFormat;
|
|
621
622
|
function parseName(value) {
|
|
622
|
-
|
|
623
|
-
|
|
623
|
+
if (typeof value === "string") {
|
|
624
|
+
const [first2 = "", last2 = ""] = (value || "").trim().split(" ");
|
|
625
|
+
return { first: first2, last: last2 };
|
|
626
|
+
}
|
|
627
|
+
const { first = "", last = "" } = value || {};
|
|
628
|
+
return first.trim() + " " + last.trim();
|
|
629
|
+
}
|
|
630
|
+
function parseMoney(value) {
|
|
631
|
+
if (typeof value === "string") return StringFormatter_default.toMoney(value);
|
|
632
|
+
return NumberFormatter_default.toMoney(value);
|
|
633
|
+
}
|
|
634
|
+
function parseAddress(address, ...args) {
|
|
635
|
+
if (typeof address === "string") {
|
|
636
|
+
const [
|
|
637
|
+
options = {
|
|
638
|
+
delimiter: "|",
|
|
639
|
+
syntax: ["streetAddress", "city", "parish", "country"]
|
|
640
|
+
}
|
|
641
|
+
] = args;
|
|
642
|
+
if (typeof options === "boolean") {
|
|
643
|
+
throw new Error(
|
|
644
|
+
"Type mismatch. Expected 'object' but 'boolean' was provided."
|
|
645
|
+
);
|
|
646
|
+
}
|
|
647
|
+
const fields = address.split(options.delimiter);
|
|
648
|
+
return Object.fromEntries(
|
|
649
|
+
limit(distinct(options.syntax), 4).map((key, i) => {
|
|
650
|
+
return [key, fields[i]];
|
|
651
|
+
})
|
|
652
|
+
);
|
|
653
|
+
}
|
|
654
|
+
if (typeof address === "object") {
|
|
655
|
+
const [inline] = args;
|
|
656
|
+
return addressToString(
|
|
657
|
+
address,
|
|
658
|
+
typeof inline === "boolean" ? inline : void 0
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
return null;
|
|
662
|
+
}
|
|
663
|
+
function parseFileSize(bytes) {
|
|
664
|
+
return new FileSizeFormatter(bytes).format();
|
|
665
|
+
}
|
|
666
|
+
function limit(array, limit2) {
|
|
667
|
+
const newArray = [];
|
|
668
|
+
if (!array) return;
|
|
669
|
+
for (const item of array) {
|
|
670
|
+
if (newArray.length === limit2) break;
|
|
671
|
+
newArray.push(item);
|
|
672
|
+
}
|
|
673
|
+
return newArray;
|
|
624
674
|
}
|
|
625
675
|
function castArray(value) {
|
|
626
676
|
return Array.isArray(value) ? value : [value];
|
|
@@ -657,8 +707,18 @@ function omitNils(value) {
|
|
|
657
707
|
}
|
|
658
708
|
return result;
|
|
659
709
|
}
|
|
710
|
+
function map(arr, callback) {
|
|
711
|
+
let ended = false;
|
|
712
|
+
for (let i = 0; i < arr.length; i++) {
|
|
713
|
+
if (ended) break;
|
|
714
|
+
arr[i] = callback(arr[i], i, arr, () => {
|
|
715
|
+
ended = true;
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
return arr;
|
|
719
|
+
}
|
|
660
720
|
function getMimeTypes(typeAliases) {
|
|
661
|
-
return distinct(strictArray(typeAliases)).map((alias) =>
|
|
721
|
+
return distinct(strictArray(typeAliases)).map((alias) => import_util2.FILE_MIME_TYPES[alias]).flat();
|
|
662
722
|
}
|
|
663
723
|
function classNameResolver(baseClassName) {
|
|
664
724
|
return (className) => {
|
|
@@ -886,14 +946,6 @@ function distinct(arr) {
|
|
|
886
946
|
});
|
|
887
947
|
return newArr;
|
|
888
948
|
}
|
|
889
|
-
function map(from, mappedFields) {
|
|
890
|
-
return Object.fromEntries(
|
|
891
|
-
Object.keys(mappedFields).map((key) => {
|
|
892
|
-
const validKey = key;
|
|
893
|
-
return [mappedFields[validKey], from[validKey]];
|
|
894
|
-
})
|
|
895
|
-
);
|
|
896
|
-
}
|
|
897
949
|
function isEmpty(value) {
|
|
898
950
|
const valueLength = typeof value === "string" ? value.trim().length : value.length;
|
|
899
951
|
return valueLength === 0;
|
|
@@ -936,7 +988,7 @@ async function copyToClipboard(text) {
|
|
|
936
988
|
if (err instanceof Error) {
|
|
937
989
|
return {
|
|
938
990
|
error: {
|
|
939
|
-
|
|
991
|
+
code: "UNKNOWN",
|
|
940
992
|
title: err.name,
|
|
941
993
|
message: err.message
|
|
942
994
|
}
|
|
@@ -944,7 +996,7 @@ async function copyToClipboard(text) {
|
|
|
944
996
|
}
|
|
945
997
|
return {
|
|
946
998
|
error: {
|
|
947
|
-
|
|
999
|
+
code: "UNKNOWN",
|
|
948
1000
|
title: "Failed to copy text",
|
|
949
1001
|
message: JSON.stringify(err)
|
|
950
1002
|
}
|
|
@@ -958,7 +1010,7 @@ async function readClipboardText() {
|
|
|
958
1010
|
} catch (err) {
|
|
959
1011
|
return {
|
|
960
1012
|
error: {
|
|
961
|
-
|
|
1013
|
+
code: "UNKNOWN",
|
|
962
1014
|
title: "Failed to read clipboard contents",
|
|
963
1015
|
message: `Something went wrong while trying to read the clipboard contents. [CAUSE]: ${JSON.stringify(
|
|
964
1016
|
err
|
|
@@ -970,181 +1022,6 @@ async function readClipboardText() {
|
|
|
970
1022
|
function arrayWithConst(array) {
|
|
971
1023
|
return { value: array, asConst: [...array] };
|
|
972
1024
|
}
|
|
973
|
-
|
|
974
|
-
// src/server-adapters/ServerAdapters.ts
|
|
975
|
-
var import_types3 = require("@wavy/types");
|
|
976
|
-
var iiKeys = Object.keys({
|
|
977
|
-
name: null,
|
|
978
|
-
address: null
|
|
979
|
-
});
|
|
980
|
-
var stringArrayIdPrefix = "listOf";
|
|
981
|
-
var multiDimArrayIdPrefix = "2DListOf";
|
|
982
|
-
var multiDimArrayDelim = ":";
|
|
983
|
-
var DELIMITERS = {
|
|
984
|
-
name: " ",
|
|
985
|
-
address: "|",
|
|
986
|
-
phoneNumber: " ",
|
|
987
|
-
stringArray: " "
|
|
988
|
-
};
|
|
989
|
-
var INDEX_MAPPER = {
|
|
990
|
-
name: { first: 0, last: 1 },
|
|
991
|
-
address: {
|
|
992
|
-
streetAddress: 0,
|
|
993
|
-
city: 1,
|
|
994
|
-
parish: 2,
|
|
995
|
-
country: 3
|
|
996
|
-
}
|
|
997
|
-
};
|
|
998
|
-
function zip(data) {
|
|
999
|
-
const stringifiedData = JSON.stringify(data);
|
|
1000
|
-
const errorMessage = `Failed to execute [${zip.name}].`;
|
|
1001
|
-
return JSON.parse(stringifiedData, (key, value) => {
|
|
1002
|
-
if (iiKeys.includes(key)) {
|
|
1003
|
-
const validKey = key;
|
|
1004
|
-
const handleTypeMismatchError = (required) => {
|
|
1005
|
-
if (typeof required !== typeof value) {
|
|
1006
|
-
throw new Error(errorMessage, {
|
|
1007
|
-
cause: `[Type Mismatch] Property type {${key}:${JSON.stringify(
|
|
1008
|
-
required
|
|
1009
|
-
)}} is required, but {${key}:${JSON.stringify(
|
|
1010
|
-
value
|
|
1011
|
-
)}} was provided.`
|
|
1012
|
-
});
|
|
1013
|
-
}
|
|
1014
|
-
};
|
|
1015
|
-
switch (validKey) {
|
|
1016
|
-
case "name":
|
|
1017
|
-
handleTypeMismatchError({ first: "", last: "" });
|
|
1018
|
-
break;
|
|
1019
|
-
case "address":
|
|
1020
|
-
handleTypeMismatchError({
|
|
1021
|
-
streetAddress: "",
|
|
1022
|
-
city: "",
|
|
1023
|
-
parish: "",
|
|
1024
|
-
country: "Jamaica"
|
|
1025
|
-
});
|
|
1026
|
-
break;
|
|
1027
|
-
default:
|
|
1028
|
-
return validKey;
|
|
1029
|
-
}
|
|
1030
|
-
let group2 = [];
|
|
1031
|
-
Object.keys(INDEX_MAPPER[validKey]).forEach((prop) => {
|
|
1032
|
-
const validProp = prop;
|
|
1033
|
-
group2[INDEX_MAPPER[validKey][validProp]] = value[validProp]?.trim?.() || "";
|
|
1034
|
-
});
|
|
1035
|
-
return group2.join(DELIMITERS[validKey]).trim();
|
|
1036
|
-
}
|
|
1037
|
-
const valueIsArray = Array.isArray(value);
|
|
1038
|
-
const hasArrayId = key.includes(stringArrayIdPrefix);
|
|
1039
|
-
if (hasArrayId && valueIsArray && strictArray(value).every((v) => typeof v === "string")) {
|
|
1040
|
-
return strictArray(value).join(DELIMITERS.stringArray).trim();
|
|
1041
|
-
} else if (hasArrayId) {
|
|
1042
|
-
throw new Error(errorMessage, {
|
|
1043
|
-
cause: `[Type Mismatch] Every property with the ${stringArrayIdPrefix} prefix, must be an array of strings. However {${key}:${value}} was provided.`
|
|
1044
|
-
});
|
|
1045
|
-
}
|
|
1046
|
-
const hasMultiDimArrayId = key.includes(multiDimArrayIdPrefix);
|
|
1047
|
-
if (hasMultiDimArrayId && valueIsArray && key.includes(multiDimArrayDelim) && value.every(
|
|
1048
|
-
(d) => Array.isArray(d) && d.every((sv) => typeof sv === "object")
|
|
1049
|
-
)) {
|
|
1050
|
-
const mapName = key.split(multiDimArrayDelim)[1];
|
|
1051
|
-
return strictArray(value).map(
|
|
1052
|
-
(objArr) => strictArray(objArr).map((obj) => {
|
|
1053
|
-
if (mapName in obj) {
|
|
1054
|
-
const mapValue = obj[mapName];
|
|
1055
|
-
if (typeof mapValue !== "string") {
|
|
1056
|
-
throw new Error(errorMessage, {
|
|
1057
|
-
cause: `[Type Mismatch] Expected {${mapName}:string} but {${mapName}:${mapValue}} was provided.`
|
|
1058
|
-
});
|
|
1059
|
-
}
|
|
1060
|
-
return mapValue;
|
|
1061
|
-
} else
|
|
1062
|
-
throw new Error(errorMessage, {
|
|
1063
|
-
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.`
|
|
1064
|
-
});
|
|
1065
|
-
}).join(DELIMITERS.stringArray)
|
|
1066
|
-
);
|
|
1067
|
-
} else if (hasMultiDimArrayId && valueIsArray) {
|
|
1068
|
-
return value.map((arr) => {
|
|
1069
|
-
if (!arr.every((d) => typeof d === "string")) {
|
|
1070
|
-
throw new Error(errorMessage, {
|
|
1071
|
-
cause: `[Type Mismatch] Every sub type of the array must be a string. However ${arr} doesn't comply with this rule.`
|
|
1072
|
-
});
|
|
1073
|
-
}
|
|
1074
|
-
return arr.join(DELIMITERS.stringArray);
|
|
1075
|
-
});
|
|
1076
|
-
} else if (hasMultiDimArrayId) {
|
|
1077
|
-
throw new Error(errorMessage, {
|
|
1078
|
-
cause: `[Type Mismatch] Every property with the ${multiDimArrayIdPrefix} prefix, must be a multi dimensional array of strings. However {${key}:${value}} was provided.`
|
|
1079
|
-
});
|
|
1080
|
-
}
|
|
1081
|
-
if (typeof value === "string") return value.trim();
|
|
1082
|
-
return value;
|
|
1083
|
-
});
|
|
1084
|
-
}
|
|
1085
|
-
function unzip(data) {
|
|
1086
|
-
const stringifiedData = JSON.stringify(data);
|
|
1087
|
-
const errorMessage = `Failed to execute [${unzip.name}]`;
|
|
1088
|
-
return JSON.parse(stringifiedData, (key, value) => {
|
|
1089
|
-
const isIIKey = iiKeys.includes(key);
|
|
1090
|
-
if (isIIKey && typeof value === "string") {
|
|
1091
|
-
const validKey = key;
|
|
1092
|
-
const splitProp = value.split(DELIMITERS[validKey]);
|
|
1093
|
-
return Object.fromEntries(
|
|
1094
|
-
Object.entries(INDEX_MAPPER[validKey]).map(([mapperKey, idx]) => {
|
|
1095
|
-
return [mapperKey, splitProp[idx]?.trim?.() || ""];
|
|
1096
|
-
})
|
|
1097
|
-
);
|
|
1098
|
-
} else if (isIIKey) {
|
|
1099
|
-
throw new Error(errorMessage, {
|
|
1100
|
-
cause: `[Type Mismatch] {${key}:string} expected, but {${key}:${value}} was provided.`
|
|
1101
|
-
});
|
|
1102
|
-
}
|
|
1103
|
-
const hasArrayId = key.includes(stringArrayIdPrefix);
|
|
1104
|
-
if (hasArrayId && typeof value === "string") {
|
|
1105
|
-
return strictArray(value.split(DELIMITERS.stringArray));
|
|
1106
|
-
} else if (hasArrayId) {
|
|
1107
|
-
throw new Error(errorMessage, {
|
|
1108
|
-
cause: `[Type Mismatch] {${key}:string} is required but {${key}:${value}} was provided.`
|
|
1109
|
-
});
|
|
1110
|
-
}
|
|
1111
|
-
const hasMultiDimArrayId = key.includes(multiDimArrayIdPrefix);
|
|
1112
|
-
if (hasMultiDimArrayId && Array.isArray(value)) {
|
|
1113
|
-
const mapName = key.split(multiDimArrayDelim)?.[1];
|
|
1114
|
-
return strictArray(value).map((delimString) => {
|
|
1115
|
-
const splitStr = strictArray(delimString.split(DELIMITERS.stringArray));
|
|
1116
|
-
if (!splitStr.every((d) => typeof d === "string"))
|
|
1117
|
-
throw new Error(errorMessage, {
|
|
1118
|
-
cause: `[Type Mismatch] Expected string[] but found ${splitStr}.`
|
|
1119
|
-
});
|
|
1120
|
-
if (mapName) return splitStr.map((value2) => ({ [mapName]: value2 }));
|
|
1121
|
-
return splitStr;
|
|
1122
|
-
});
|
|
1123
|
-
} else if (hasMultiDimArrayId) {
|
|
1124
|
-
throw new Error(errorMessage, {
|
|
1125
|
-
cause: `[Type Mismatch] {${key}:string[]} is required but {${key}:${value}} was provided.`
|
|
1126
|
-
});
|
|
1127
|
-
}
|
|
1128
|
-
return value;
|
|
1129
|
-
});
|
|
1130
|
-
}
|
|
1131
|
-
var EVENTS = ["zip", "unzip"];
|
|
1132
|
-
var ServerDataAdapter = class {
|
|
1133
|
-
invoke(event, data) {
|
|
1134
|
-
switch (event) {
|
|
1135
|
-
case "unzip":
|
|
1136
|
-
return unzip(data);
|
|
1137
|
-
case "zip":
|
|
1138
|
-
return zip(data);
|
|
1139
|
-
default:
|
|
1140
|
-
event;
|
|
1141
|
-
throw new Error(
|
|
1142
|
-
`"${event}" is an unrecognized event. Try again using one of the following events ${EVENTS}.`
|
|
1143
|
-
);
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
|
-
};
|
|
1147
|
-
var serverDataAdapter = new ServerDataAdapter().invoke;
|
|
1148
1025
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1149
1026
|
0 && (module.exports = {
|
|
1150
1027
|
addArticle,
|
|
@@ -1183,12 +1060,13 @@ var serverDataAdapter = new ServerDataAdapter().invoke;
|
|
|
1183
1060
|
insertAt,
|
|
1184
1061
|
isEmpty,
|
|
1185
1062
|
isFile,
|
|
1063
|
+
isFileDetails,
|
|
1186
1064
|
isIterable,
|
|
1187
1065
|
isLetter,
|
|
1188
|
-
isLocalFile,
|
|
1189
1066
|
isNumber,
|
|
1190
1067
|
isPromise,
|
|
1191
1068
|
lastIndex,
|
|
1069
|
+
limit,
|
|
1192
1070
|
map,
|
|
1193
1071
|
mapToArray,
|
|
1194
1072
|
maxOf,
|
|
@@ -1198,6 +1076,10 @@ var serverDataAdapter = new ServerDataAdapter().invoke;
|
|
|
1198
1076
|
omitNils,
|
|
1199
1077
|
ordinalIndicator,
|
|
1200
1078
|
overwrite,
|
|
1079
|
+
parseAddress,
|
|
1080
|
+
parseDate,
|
|
1081
|
+
parseFileSize,
|
|
1082
|
+
parseMoney,
|
|
1201
1083
|
parseName,
|
|
1202
1084
|
pick,
|
|
1203
1085
|
pluralize,
|
|
@@ -1208,8 +1090,6 @@ var serverDataAdapter = new ServerDataAdapter().invoke;
|
|
|
1208
1090
|
removeAll,
|
|
1209
1091
|
repeat,
|
|
1210
1092
|
run,
|
|
1211
|
-
sanitizeLocalFile,
|
|
1212
|
-
serverDataAdapter,
|
|
1213
1093
|
someValuesEmpty,
|
|
1214
1094
|
sort,
|
|
1215
1095
|
strictArray,
|
package/dist/main.d.cts
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
|
-
import "@wavy/
|
|
2
|
-
import
|
|
3
|
-
import { LocalFile, Name, SanitizeFile, NonFunction, KnownFileTypeAlias, TaskResult, FromServer, NormalizeFromServer } from '@wavy/types';
|
|
1
|
+
import "@wavy/util"
|
|
2
|
+
import { FileDetails, Name, Address, NonFunction, KnownFileAlias, TaskResult } from '@wavy/util';
|
|
4
3
|
|
|
5
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";
|
|
6
5
|
|
|
7
6
|
declare const toObject: {
|
|
8
|
-
(file: File
|
|
7
|
+
(file: File, options?: Partial<{
|
|
9
8
|
uid?: string;
|
|
10
9
|
uploadDate: number | "now";
|
|
11
10
|
description: string;
|
|
12
11
|
filepath: string;
|
|
13
12
|
filename: string;
|
|
14
|
-
|
|
15
|
-
}> | undefined):
|
|
16
|
-
(
|
|
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;
|
|
17
27
|
};
|
|
18
28
|
|
|
19
29
|
type NumberFormatterTypes = {
|
|
@@ -61,21 +71,41 @@ declare const toNumber: typeof StringFormatter.toNumber;
|
|
|
61
71
|
declare const addArticle: typeof StringFormatter.addArticle;
|
|
62
72
|
declare const pluralize: typeof StringFormatter.pluralize;
|
|
63
73
|
declare const nameToString: (name: Name | undefined) => string;
|
|
64
|
-
declare const addressToString: (address:
|
|
74
|
+
declare const addressToString: (address: Address | undefined, inline?: boolean) => string;
|
|
65
75
|
declare const toMoney: (value: string | number, options?: NumberFormatterTypes["options"]["money"]) => string;
|
|
76
|
+
/**
|
|
77
|
+
* @deprecated Migrate to individual function calls.
|
|
78
|
+
* @example parseDate, parseMoney, parseName, parseAddress, parseFileSize
|
|
79
|
+
*/
|
|
66
80
|
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;
|
|
67
|
-
declare function sanitizeLocalFile({ _metadata: _, ...file }: LocalFile): SanitizeFile<LocalFile>;
|
|
68
81
|
declare function isFile(value: unknown): value is File;
|
|
69
|
-
declare function
|
|
82
|
+
declare function isFileDetails(value: unknown): value is FileDetails;
|
|
70
83
|
declare function isIterable<T>(value: unknown): value is Iterable<T>;
|
|
71
84
|
declare function isPromise<T>(value: unknown): value is Promise<T>;
|
|
72
|
-
declare
|
|
85
|
+
declare const parseDate: (time: number | Date | "now", format?: DateFormat) => string;
|
|
86
|
+
declare function parseName<Value extends string | Name>(value: Value): Value extends string ? Name : Value extends Name ? string : never;
|
|
87
|
+
declare function parseMoney(value: string | number): string;
|
|
88
|
+
declare function parseAddress<T extends Address | string>(address: T, ...args: T extends string ? [
|
|
89
|
+
options?: Partial<{
|
|
90
|
+
/**The value used to separate each field in the string
|
|
91
|
+
* @default "|"
|
|
92
|
+
*/
|
|
93
|
+
delimiter?: string;
|
|
94
|
+
/**The order in which the fields appear
|
|
95
|
+
* @default ["streetAddress", "city", "parish", "country"]
|
|
96
|
+
*/
|
|
97
|
+
syntax?: (keyof Address)[];
|
|
98
|
+
}>
|
|
99
|
+
] : T extends Address ? [inline?: boolean] : []): (T extends Address ? string : T extends string ? Address : never) | null;
|
|
100
|
+
declare function parseFileSize(bytes: number): string;
|
|
101
|
+
declare function limit<T>(array: T[], limit: number): T[] | undefined;
|
|
73
102
|
declare function castArray<T>(value: T | T[]): T[];
|
|
74
103
|
declare function castReturn<T extends NonFunction<any>>(value: T | (() => T)): T;
|
|
75
|
-
declare function pick<O extends object, K extends keyof O>(value: O, keys: K[]): { [Key in K]: O[Key] | null; };
|
|
76
|
-
declare function omit<O extends object, K extends keyof O>(value: O, keys: K[]): { [Key in Exclude<keyof O, K>]: O[Key] | null; };
|
|
104
|
+
declare function pick<O extends object, K extends keyof O = keyof O>(value: O, keys: K[]): { [Key in K]: O[Key] | null; };
|
|
105
|
+
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; };
|
|
77
106
|
declare function omitNils<O extends object>(value: O): O;
|
|
78
|
-
declare function
|
|
107
|
+
declare function map<T>(arr: T[], callback: (value: T, index: number, array: T[], end: () => void) => T): T[];
|
|
108
|
+
declare function getMimeTypes(typeAliases: KnownFileAlias[]): string[];
|
|
79
109
|
declare function classNameResolver(baseClassName: string): (className: string) => string;
|
|
80
110
|
declare function classNameExt(rootClassName: string): (className: string) => string;
|
|
81
111
|
declare function range(start: number, end: number): number[];
|
|
@@ -162,7 +192,6 @@ declare function mapToArray<K extends string | number | symbol, V>(map: Map<K, V
|
|
|
162
192
|
[Key in K]: V;
|
|
163
193
|
}[];
|
|
164
194
|
declare function distinct<T>(arr: T[]): T[];
|
|
165
|
-
declare function map<To extends object, From extends object>(from: From, mappedFields: Record<keyof From, keyof To>): To;
|
|
166
195
|
declare function isEmpty(value: string | unknown[]): boolean;
|
|
167
196
|
declare function ifDefined<T, R>(value: T | undefined, cb: (value: T) => R): R | undefined;
|
|
168
197
|
declare function someValuesEmpty<O extends {
|
|
@@ -184,13 +213,4 @@ declare function arrayWithConst<T>(array: T[]): {
|
|
|
184
213
|
asConst: readonly T[];
|
|
185
214
|
};
|
|
186
215
|
|
|
187
|
-
|
|
188
|
-
<DataType extends {
|
|
189
|
-
[key: string]: any;
|
|
190
|
-
}>(event: "zip", data: DataType): FromServer<DataType>;
|
|
191
|
-
<DataType extends {
|
|
192
|
-
[key: string]: any;
|
|
193
|
-
}>(event: "unzip", data: DataType): NormalizeFromServer<DataType>;
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
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, map, mapToArray, maxOf, minOf, negate, omit, omitNils, ordinalIndicator, overwrite, 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 };
|
|
216
|
+
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,19 +1,29 @@
|
|
|
1
|
-
import "@wavy/
|
|
2
|
-
import
|
|
3
|
-
import { LocalFile, Name, SanitizeFile, NonFunction, KnownFileTypeAlias, TaskResult, FromServer, NormalizeFromServer } from '@wavy/types';
|
|
1
|
+
import "@wavy/util"
|
|
2
|
+
import { FileDetails, Name, Address, NonFunction, KnownFileAlias, TaskResult } from '@wavy/util';
|
|
4
3
|
|
|
5
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";
|
|
6
5
|
|
|
7
6
|
declare const toObject: {
|
|
8
|
-
(file: File
|
|
7
|
+
(file: File, options?: Partial<{
|
|
9
8
|
uid?: string;
|
|
10
9
|
uploadDate: number | "now";
|
|
11
10
|
description: string;
|
|
12
11
|
filepath: string;
|
|
13
12
|
filename: string;
|
|
14
|
-
|
|
15
|
-
}> | undefined):
|
|
16
|
-
(
|
|
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;
|
|
17
27
|
};
|
|
18
28
|
|
|
19
29
|
type NumberFormatterTypes = {
|
|
@@ -61,21 +71,41 @@ declare const toNumber: typeof StringFormatter.toNumber;
|
|
|
61
71
|
declare const addArticle: typeof StringFormatter.addArticle;
|
|
62
72
|
declare const pluralize: typeof StringFormatter.pluralize;
|
|
63
73
|
declare const nameToString: (name: Name | undefined) => string;
|
|
64
|
-
declare const addressToString: (address:
|
|
74
|
+
declare const addressToString: (address: Address | undefined, inline?: boolean) => string;
|
|
65
75
|
declare const toMoney: (value: string | number, options?: NumberFormatterTypes["options"]["money"]) => string;
|
|
76
|
+
/**
|
|
77
|
+
* @deprecated Migrate to individual function calls.
|
|
78
|
+
* @example parseDate, parseMoney, parseName, parseAddress, parseFileSize
|
|
79
|
+
*/
|
|
66
80
|
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;
|
|
67
|
-
declare function sanitizeLocalFile({ _metadata: _, ...file }: LocalFile): SanitizeFile<LocalFile>;
|
|
68
81
|
declare function isFile(value: unknown): value is File;
|
|
69
|
-
declare function
|
|
82
|
+
declare function isFileDetails(value: unknown): value is FileDetails;
|
|
70
83
|
declare function isIterable<T>(value: unknown): value is Iterable<T>;
|
|
71
84
|
declare function isPromise<T>(value: unknown): value is Promise<T>;
|
|
72
|
-
declare
|
|
85
|
+
declare const parseDate: (time: number | Date | "now", format?: DateFormat) => string;
|
|
86
|
+
declare function parseName<Value extends string | Name>(value: Value): Value extends string ? Name : Value extends Name ? string : never;
|
|
87
|
+
declare function parseMoney(value: string | number): string;
|
|
88
|
+
declare function parseAddress<T extends Address | string>(address: T, ...args: T extends string ? [
|
|
89
|
+
options?: Partial<{
|
|
90
|
+
/**The value used to separate each field in the string
|
|
91
|
+
* @default "|"
|
|
92
|
+
*/
|
|
93
|
+
delimiter?: string;
|
|
94
|
+
/**The order in which the fields appear
|
|
95
|
+
* @default ["streetAddress", "city", "parish", "country"]
|
|
96
|
+
*/
|
|
97
|
+
syntax?: (keyof Address)[];
|
|
98
|
+
}>
|
|
99
|
+
] : T extends Address ? [inline?: boolean] : []): (T extends Address ? string : T extends string ? Address : never) | null;
|
|
100
|
+
declare function parseFileSize(bytes: number): string;
|
|
101
|
+
declare function limit<T>(array: T[], limit: number): T[] | undefined;
|
|
73
102
|
declare function castArray<T>(value: T | T[]): T[];
|
|
74
103
|
declare function castReturn<T extends NonFunction<any>>(value: T | (() => T)): T;
|
|
75
|
-
declare function pick<O extends object, K extends keyof O>(value: O, keys: K[]): { [Key in K]: O[Key] | null; };
|
|
76
|
-
declare function omit<O extends object, K extends keyof O>(value: O, keys: K[]): { [Key in Exclude<keyof O, K>]: O[Key] | null; };
|
|
104
|
+
declare function pick<O extends object, K extends keyof O = keyof O>(value: O, keys: K[]): { [Key in K]: O[Key] | null; };
|
|
105
|
+
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; };
|
|
77
106
|
declare function omitNils<O extends object>(value: O): O;
|
|
78
|
-
declare function
|
|
107
|
+
declare function map<T>(arr: T[], callback: (value: T, index: number, array: T[], end: () => void) => T): T[];
|
|
108
|
+
declare function getMimeTypes(typeAliases: KnownFileAlias[]): string[];
|
|
79
109
|
declare function classNameResolver(baseClassName: string): (className: string) => string;
|
|
80
110
|
declare function classNameExt(rootClassName: string): (className: string) => string;
|
|
81
111
|
declare function range(start: number, end: number): number[];
|
|
@@ -162,7 +192,6 @@ declare function mapToArray<K extends string | number | symbol, V>(map: Map<K, V
|
|
|
162
192
|
[Key in K]: V;
|
|
163
193
|
}[];
|
|
164
194
|
declare function distinct<T>(arr: T[]): T[];
|
|
165
|
-
declare function map<To extends object, From extends object>(from: From, mappedFields: Record<keyof From, keyof To>): To;
|
|
166
195
|
declare function isEmpty(value: string | unknown[]): boolean;
|
|
167
196
|
declare function ifDefined<T, R>(value: T | undefined, cb: (value: T) => R): R | undefined;
|
|
168
197
|
declare function someValuesEmpty<O extends {
|
|
@@ -184,13 +213,4 @@ declare function arrayWithConst<T>(array: T[]): {
|
|
|
184
213
|
asConst: readonly T[];
|
|
185
214
|
};
|
|
186
215
|
|
|
187
|
-
|
|
188
|
-
<DataType extends {
|
|
189
|
-
[key: string]: any;
|
|
190
|
-
}>(event: "zip", data: DataType): FromServer<DataType>;
|
|
191
|
-
<DataType extends {
|
|
192
|
-
[key: string]: any;
|
|
193
|
-
}>(event: "unzip", data: DataType): NormalizeFromServer<DataType>;
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
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, map, mapToArray, maxOf, minOf, negate, omit, omitNils, ordinalIndicator, overwrite, 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 };
|
|
216
|
+
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";
|
|
@@ -515,9 +513,59 @@ function isPromise(value) {
|
|
|
515
513
|
if (value instanceof Promise) return true;
|
|
516
514
|
return !!value && (typeof value === "object" || typeof value === "function") && "then" in value && typeof value.then === "function";
|
|
517
515
|
}
|
|
516
|
+
var parseDate = dateFormat;
|
|
518
517
|
function parseName(value) {
|
|
519
|
-
|
|
520
|
-
|
|
518
|
+
if (typeof value === "string") {
|
|
519
|
+
const [first2 = "", last2 = ""] = (value || "").trim().split(" ");
|
|
520
|
+
return { first: first2, last: last2 };
|
|
521
|
+
}
|
|
522
|
+
const { first = "", last = "" } = value || {};
|
|
523
|
+
return first.trim() + " " + last.trim();
|
|
524
|
+
}
|
|
525
|
+
function parseMoney(value) {
|
|
526
|
+
if (typeof value === "string") return StringFormatter_default.toMoney(value);
|
|
527
|
+
return NumberFormatter_default.toMoney(value);
|
|
528
|
+
}
|
|
529
|
+
function parseAddress(address, ...args) {
|
|
530
|
+
if (typeof address === "string") {
|
|
531
|
+
const [
|
|
532
|
+
options = {
|
|
533
|
+
delimiter: "|",
|
|
534
|
+
syntax: ["streetAddress", "city", "parish", "country"]
|
|
535
|
+
}
|
|
536
|
+
] = args;
|
|
537
|
+
if (typeof options === "boolean") {
|
|
538
|
+
throw new Error(
|
|
539
|
+
"Type mismatch. Expected 'object' but 'boolean' was provided."
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
const fields = address.split(options.delimiter);
|
|
543
|
+
return Object.fromEntries(
|
|
544
|
+
limit(distinct(options.syntax), 4).map((key, i) => {
|
|
545
|
+
return [key, fields[i]];
|
|
546
|
+
})
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
if (typeof address === "object") {
|
|
550
|
+
const [inline] = args;
|
|
551
|
+
return addressToString(
|
|
552
|
+
address,
|
|
553
|
+
typeof inline === "boolean" ? inline : void 0
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
return null;
|
|
557
|
+
}
|
|
558
|
+
function parseFileSize(bytes) {
|
|
559
|
+
return new FileSizeFormatter(bytes).format();
|
|
560
|
+
}
|
|
561
|
+
function limit(array, limit2) {
|
|
562
|
+
const newArray = [];
|
|
563
|
+
if (!array) return;
|
|
564
|
+
for (const item of array) {
|
|
565
|
+
if (newArray.length === limit2) break;
|
|
566
|
+
newArray.push(item);
|
|
567
|
+
}
|
|
568
|
+
return newArray;
|
|
521
569
|
}
|
|
522
570
|
function castArray(value) {
|
|
523
571
|
return Array.isArray(value) ? value : [value];
|
|
@@ -554,8 +602,18 @@ function omitNils(value) {
|
|
|
554
602
|
}
|
|
555
603
|
return result;
|
|
556
604
|
}
|
|
605
|
+
function map(arr, callback) {
|
|
606
|
+
let ended = false;
|
|
607
|
+
for (let i = 0; i < arr.length; i++) {
|
|
608
|
+
if (ended) break;
|
|
609
|
+
arr[i] = callback(arr[i], i, arr, () => {
|
|
610
|
+
ended = true;
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
return arr;
|
|
614
|
+
}
|
|
557
615
|
function getMimeTypes(typeAliases) {
|
|
558
|
-
return distinct(strictArray(typeAliases)).map((alias) =>
|
|
616
|
+
return distinct(strictArray(typeAliases)).map((alias) => FILE_MIME_TYPES2[alias]).flat();
|
|
559
617
|
}
|
|
560
618
|
function classNameResolver(baseClassName) {
|
|
561
619
|
return (className) => {
|
|
@@ -783,14 +841,6 @@ function distinct(arr) {
|
|
|
783
841
|
});
|
|
784
842
|
return newArr;
|
|
785
843
|
}
|
|
786
|
-
function map(from, mappedFields) {
|
|
787
|
-
return Object.fromEntries(
|
|
788
|
-
Object.keys(mappedFields).map((key) => {
|
|
789
|
-
const validKey = key;
|
|
790
|
-
return [mappedFields[validKey], from[validKey]];
|
|
791
|
-
})
|
|
792
|
-
);
|
|
793
|
-
}
|
|
794
844
|
function isEmpty(value) {
|
|
795
845
|
const valueLength = typeof value === "string" ? value.trim().length : value.length;
|
|
796
846
|
return valueLength === 0;
|
|
@@ -833,7 +883,7 @@ async function copyToClipboard(text) {
|
|
|
833
883
|
if (err instanceof Error) {
|
|
834
884
|
return {
|
|
835
885
|
error: {
|
|
836
|
-
|
|
886
|
+
code: "UNKNOWN",
|
|
837
887
|
title: err.name,
|
|
838
888
|
message: err.message
|
|
839
889
|
}
|
|
@@ -841,7 +891,7 @@ async function copyToClipboard(text) {
|
|
|
841
891
|
}
|
|
842
892
|
return {
|
|
843
893
|
error: {
|
|
844
|
-
|
|
894
|
+
code: "UNKNOWN",
|
|
845
895
|
title: "Failed to copy text",
|
|
846
896
|
message: JSON.stringify(err)
|
|
847
897
|
}
|
|
@@ -855,7 +905,7 @@ async function readClipboardText() {
|
|
|
855
905
|
} catch (err) {
|
|
856
906
|
return {
|
|
857
907
|
error: {
|
|
858
|
-
|
|
908
|
+
code: "UNKNOWN",
|
|
859
909
|
title: "Failed to read clipboard contents",
|
|
860
910
|
message: `Something went wrong while trying to read the clipboard contents. [CAUSE]: ${JSON.stringify(
|
|
861
911
|
err
|
|
@@ -867,181 +917,6 @@ async function readClipboardText() {
|
|
|
867
917
|
function arrayWithConst(array) {
|
|
868
918
|
return { value: array, asConst: [...array] };
|
|
869
919
|
}
|
|
870
|
-
|
|
871
|
-
// src/server-adapters/ServerAdapters.ts
|
|
872
|
-
import "@wavy/types";
|
|
873
|
-
var iiKeys = Object.keys({
|
|
874
|
-
name: null,
|
|
875
|
-
address: null
|
|
876
|
-
});
|
|
877
|
-
var stringArrayIdPrefix = "listOf";
|
|
878
|
-
var multiDimArrayIdPrefix = "2DListOf";
|
|
879
|
-
var multiDimArrayDelim = ":";
|
|
880
|
-
var DELIMITERS = {
|
|
881
|
-
name: " ",
|
|
882
|
-
address: "|",
|
|
883
|
-
phoneNumber: " ",
|
|
884
|
-
stringArray: " "
|
|
885
|
-
};
|
|
886
|
-
var INDEX_MAPPER = {
|
|
887
|
-
name: { first: 0, last: 1 },
|
|
888
|
-
address: {
|
|
889
|
-
streetAddress: 0,
|
|
890
|
-
city: 1,
|
|
891
|
-
parish: 2,
|
|
892
|
-
country: 3
|
|
893
|
-
}
|
|
894
|
-
};
|
|
895
|
-
function zip(data) {
|
|
896
|
-
const stringifiedData = JSON.stringify(data);
|
|
897
|
-
const errorMessage = `Failed to execute [${zip.name}].`;
|
|
898
|
-
return JSON.parse(stringifiedData, (key, value) => {
|
|
899
|
-
if (iiKeys.includes(key)) {
|
|
900
|
-
const validKey = key;
|
|
901
|
-
const handleTypeMismatchError = (required) => {
|
|
902
|
-
if (typeof required !== typeof value) {
|
|
903
|
-
throw new Error(errorMessage, {
|
|
904
|
-
cause: `[Type Mismatch] Property type {${key}:${JSON.stringify(
|
|
905
|
-
required
|
|
906
|
-
)}} is required, but {${key}:${JSON.stringify(
|
|
907
|
-
value
|
|
908
|
-
)}} was provided.`
|
|
909
|
-
});
|
|
910
|
-
}
|
|
911
|
-
};
|
|
912
|
-
switch (validKey) {
|
|
913
|
-
case "name":
|
|
914
|
-
handleTypeMismatchError({ first: "", last: "" });
|
|
915
|
-
break;
|
|
916
|
-
case "address":
|
|
917
|
-
handleTypeMismatchError({
|
|
918
|
-
streetAddress: "",
|
|
919
|
-
city: "",
|
|
920
|
-
parish: "",
|
|
921
|
-
country: "Jamaica"
|
|
922
|
-
});
|
|
923
|
-
break;
|
|
924
|
-
default:
|
|
925
|
-
return validKey;
|
|
926
|
-
}
|
|
927
|
-
let group2 = [];
|
|
928
|
-
Object.keys(INDEX_MAPPER[validKey]).forEach((prop) => {
|
|
929
|
-
const validProp = prop;
|
|
930
|
-
group2[INDEX_MAPPER[validKey][validProp]] = value[validProp]?.trim?.() || "";
|
|
931
|
-
});
|
|
932
|
-
return group2.join(DELIMITERS[validKey]).trim();
|
|
933
|
-
}
|
|
934
|
-
const valueIsArray = Array.isArray(value);
|
|
935
|
-
const hasArrayId = key.includes(stringArrayIdPrefix);
|
|
936
|
-
if (hasArrayId && valueIsArray && strictArray(value).every((v) => typeof v === "string")) {
|
|
937
|
-
return strictArray(value).join(DELIMITERS.stringArray).trim();
|
|
938
|
-
} else if (hasArrayId) {
|
|
939
|
-
throw new Error(errorMessage, {
|
|
940
|
-
cause: `[Type Mismatch] Every property with the ${stringArrayIdPrefix} prefix, must be an array of strings. However {${key}:${value}} was provided.`
|
|
941
|
-
});
|
|
942
|
-
}
|
|
943
|
-
const hasMultiDimArrayId = key.includes(multiDimArrayIdPrefix);
|
|
944
|
-
if (hasMultiDimArrayId && valueIsArray && key.includes(multiDimArrayDelim) && value.every(
|
|
945
|
-
(d) => Array.isArray(d) && d.every((sv) => typeof sv === "object")
|
|
946
|
-
)) {
|
|
947
|
-
const mapName = key.split(multiDimArrayDelim)[1];
|
|
948
|
-
return strictArray(value).map(
|
|
949
|
-
(objArr) => strictArray(objArr).map((obj) => {
|
|
950
|
-
if (mapName in obj) {
|
|
951
|
-
const mapValue = obj[mapName];
|
|
952
|
-
if (typeof mapValue !== "string") {
|
|
953
|
-
throw new Error(errorMessage, {
|
|
954
|
-
cause: `[Type Mismatch] Expected {${mapName}:string} but {${mapName}:${mapValue}} was provided.`
|
|
955
|
-
});
|
|
956
|
-
}
|
|
957
|
-
return mapValue;
|
|
958
|
-
} else
|
|
959
|
-
throw new Error(errorMessage, {
|
|
960
|
-
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.`
|
|
961
|
-
});
|
|
962
|
-
}).join(DELIMITERS.stringArray)
|
|
963
|
-
);
|
|
964
|
-
} else if (hasMultiDimArrayId && valueIsArray) {
|
|
965
|
-
return value.map((arr) => {
|
|
966
|
-
if (!arr.every((d) => typeof d === "string")) {
|
|
967
|
-
throw new Error(errorMessage, {
|
|
968
|
-
cause: `[Type Mismatch] Every sub type of the array must be a string. However ${arr} doesn't comply with this rule.`
|
|
969
|
-
});
|
|
970
|
-
}
|
|
971
|
-
return arr.join(DELIMITERS.stringArray);
|
|
972
|
-
});
|
|
973
|
-
} else if (hasMultiDimArrayId) {
|
|
974
|
-
throw new Error(errorMessage, {
|
|
975
|
-
cause: `[Type Mismatch] Every property with the ${multiDimArrayIdPrefix} prefix, must be a multi dimensional array of strings. However {${key}:${value}} was provided.`
|
|
976
|
-
});
|
|
977
|
-
}
|
|
978
|
-
if (typeof value === "string") return value.trim();
|
|
979
|
-
return value;
|
|
980
|
-
});
|
|
981
|
-
}
|
|
982
|
-
function unzip(data) {
|
|
983
|
-
const stringifiedData = JSON.stringify(data);
|
|
984
|
-
const errorMessage = `Failed to execute [${unzip.name}]`;
|
|
985
|
-
return JSON.parse(stringifiedData, (key, value) => {
|
|
986
|
-
const isIIKey = iiKeys.includes(key);
|
|
987
|
-
if (isIIKey && typeof value === "string") {
|
|
988
|
-
const validKey = key;
|
|
989
|
-
const splitProp = value.split(DELIMITERS[validKey]);
|
|
990
|
-
return Object.fromEntries(
|
|
991
|
-
Object.entries(INDEX_MAPPER[validKey]).map(([mapperKey, idx]) => {
|
|
992
|
-
return [mapperKey, splitProp[idx]?.trim?.() || ""];
|
|
993
|
-
})
|
|
994
|
-
);
|
|
995
|
-
} else if (isIIKey) {
|
|
996
|
-
throw new Error(errorMessage, {
|
|
997
|
-
cause: `[Type Mismatch] {${key}:string} expected, but {${key}:${value}} was provided.`
|
|
998
|
-
});
|
|
999
|
-
}
|
|
1000
|
-
const hasArrayId = key.includes(stringArrayIdPrefix);
|
|
1001
|
-
if (hasArrayId && typeof value === "string") {
|
|
1002
|
-
return strictArray(value.split(DELIMITERS.stringArray));
|
|
1003
|
-
} else if (hasArrayId) {
|
|
1004
|
-
throw new Error(errorMessage, {
|
|
1005
|
-
cause: `[Type Mismatch] {${key}:string} is required but {${key}:${value}} was provided.`
|
|
1006
|
-
});
|
|
1007
|
-
}
|
|
1008
|
-
const hasMultiDimArrayId = key.includes(multiDimArrayIdPrefix);
|
|
1009
|
-
if (hasMultiDimArrayId && Array.isArray(value)) {
|
|
1010
|
-
const mapName = key.split(multiDimArrayDelim)?.[1];
|
|
1011
|
-
return strictArray(value).map((delimString) => {
|
|
1012
|
-
const splitStr = strictArray(delimString.split(DELIMITERS.stringArray));
|
|
1013
|
-
if (!splitStr.every((d) => typeof d === "string"))
|
|
1014
|
-
throw new Error(errorMessage, {
|
|
1015
|
-
cause: `[Type Mismatch] Expected string[] but found ${splitStr}.`
|
|
1016
|
-
});
|
|
1017
|
-
if (mapName) return splitStr.map((value2) => ({ [mapName]: value2 }));
|
|
1018
|
-
return splitStr;
|
|
1019
|
-
});
|
|
1020
|
-
} else if (hasMultiDimArrayId) {
|
|
1021
|
-
throw new Error(errorMessage, {
|
|
1022
|
-
cause: `[Type Mismatch] {${key}:string[]} is required but {${key}:${value}} was provided.`
|
|
1023
|
-
});
|
|
1024
|
-
}
|
|
1025
|
-
return value;
|
|
1026
|
-
});
|
|
1027
|
-
}
|
|
1028
|
-
var EVENTS = ["zip", "unzip"];
|
|
1029
|
-
var ServerDataAdapter = class {
|
|
1030
|
-
invoke(event, data) {
|
|
1031
|
-
switch (event) {
|
|
1032
|
-
case "unzip":
|
|
1033
|
-
return unzip(data);
|
|
1034
|
-
case "zip":
|
|
1035
|
-
return zip(data);
|
|
1036
|
-
default:
|
|
1037
|
-
event;
|
|
1038
|
-
throw new Error(
|
|
1039
|
-
`"${event}" is an unrecognized event. Try again using one of the following events ${EVENTS}.`
|
|
1040
|
-
);
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
};
|
|
1044
|
-
var serverDataAdapter = new ServerDataAdapter().invoke;
|
|
1045
920
|
export {
|
|
1046
921
|
addArticle,
|
|
1047
922
|
arrayWithConst,
|
|
@@ -1079,12 +954,13 @@ export {
|
|
|
1079
954
|
insertAt,
|
|
1080
955
|
isEmpty,
|
|
1081
956
|
isFile,
|
|
957
|
+
isFileDetails,
|
|
1082
958
|
isIterable,
|
|
1083
959
|
isLetter,
|
|
1084
|
-
isLocalFile,
|
|
1085
960
|
isNumber,
|
|
1086
961
|
isPromise,
|
|
1087
962
|
lastIndex,
|
|
963
|
+
limit,
|
|
1088
964
|
map,
|
|
1089
965
|
mapToArray,
|
|
1090
966
|
maxOf,
|
|
@@ -1094,6 +970,10 @@ export {
|
|
|
1094
970
|
omitNils,
|
|
1095
971
|
ordinalIndicator,
|
|
1096
972
|
overwrite,
|
|
973
|
+
parseAddress,
|
|
974
|
+
parseDate,
|
|
975
|
+
parseFileSize,
|
|
976
|
+
parseMoney,
|
|
1097
977
|
parseName,
|
|
1098
978
|
pick,
|
|
1099
979
|
pluralize,
|
|
@@ -1104,8 +984,6 @@ export {
|
|
|
1104
984
|
removeAll,
|
|
1105
985
|
repeat,
|
|
1106
986
|
run,
|
|
1107
|
-
sanitizeLocalFile,
|
|
1108
|
-
serverDataAdapter,
|
|
1109
987
|
someValuesEmpty,
|
|
1110
988
|
sort,
|
|
1111
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.28",
|
|
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"
|