@wavy/fn 0.0.16 → 0.0.18
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 +88 -81
- package/dist/main.d.cts +13 -14
- package/dist/main.d.ts +13 -14
- package/dist/main.js +88 -81
- package/package.json +5 -3
package/dist/main.cjs
CHANGED
|
@@ -98,6 +98,91 @@ module.exports = __toCommonJS(main_exports);
|
|
|
98
98
|
// src/helper-functions/HelperFunctions.ts
|
|
99
99
|
var import_types2 = require("@wavy/types");
|
|
100
100
|
|
|
101
|
+
// src/helper-functions/components/ObjectConverter.ts
|
|
102
|
+
var import_uuid = require("uuid");
|
|
103
|
+
var import_types = require("@wavy/types");
|
|
104
|
+
var import_console = require("console");
|
|
105
|
+
function fileToLocalFile(file, options) {
|
|
106
|
+
const fileExt = getFileExt(file.name);
|
|
107
|
+
const fileName = (() => {
|
|
108
|
+
if (options?.filename && options.filename.includes(fileExt))
|
|
109
|
+
return options.filename;
|
|
110
|
+
else if (options?.filename) return options.filename.trim() + fileExt;
|
|
111
|
+
return file.name;
|
|
112
|
+
})()?.trim?.();
|
|
113
|
+
const { name: _, size: __, ..._metadata } = file;
|
|
114
|
+
return {
|
|
115
|
+
uid: options?.uid || (0, import_uuid.v4)(),
|
|
116
|
+
description: options?.description,
|
|
117
|
+
ext: fileExt,
|
|
118
|
+
path: options?.filepath || file?.webkitRelativePath,
|
|
119
|
+
typeAlias: options?.typeAlias || run(
|
|
120
|
+
Object.keys(import_types.LOCAL_FILE_MIME_TYPES).find(
|
|
121
|
+
(key) => import_types.LOCAL_FILE_MIME_TYPES[key].includes(file.type)
|
|
122
|
+
),
|
|
123
|
+
(type) => {
|
|
124
|
+
if (!type) {
|
|
125
|
+
(0, import_console.log)("An unknown file type was found ", file.type);
|
|
126
|
+
return "unknown";
|
|
127
|
+
}
|
|
128
|
+
return type;
|
|
129
|
+
}
|
|
130
|
+
),
|
|
131
|
+
sizeInBytes: file.size,
|
|
132
|
+
uploadDate: options?.uploadDate === "now" ? Date.now() : options?.uploadDate ?? file?.lastModified,
|
|
133
|
+
name: fileName,
|
|
134
|
+
_metadata
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function localFileToFile(localFile) {
|
|
138
|
+
return {
|
|
139
|
+
name: localFile.name,
|
|
140
|
+
size: localFile.sizeInBytes,
|
|
141
|
+
...localFile._metadata
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
var Overloader = class {
|
|
145
|
+
invoke(...args) {
|
|
146
|
+
if (isFile(args[0])) {
|
|
147
|
+
return fileToLocalFile(...args);
|
|
148
|
+
}
|
|
149
|
+
if (isLocalFile(args[0])) {
|
|
150
|
+
return localFileToFile(...args);
|
|
151
|
+
} else throw new Error(`The arguments supplied are insufficient.`);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
var toObject = new Overloader().invoke;
|
|
155
|
+
var ObjectConverter_default = toObject;
|
|
156
|
+
|
|
157
|
+
// src/helper-functions/components/formatter/FileSizeFormatter.ts
|
|
158
|
+
var FileSizeFormatter = class {
|
|
159
|
+
constructor(bytes) {
|
|
160
|
+
this.bytes = bytes;
|
|
161
|
+
}
|
|
162
|
+
bytes;
|
|
163
|
+
toKb() {
|
|
164
|
+
return { amount: this.scaleUp(this.bytes), unit: "KB" };
|
|
165
|
+
}
|
|
166
|
+
toMb() {
|
|
167
|
+
return { amount: this.scaleUp(this.toKb().amount), unit: "MB" };
|
|
168
|
+
}
|
|
169
|
+
toGb() {
|
|
170
|
+
return { amount: this.scaleUp(this.toMb().amount), unit: "GB" };
|
|
171
|
+
}
|
|
172
|
+
toTb() {
|
|
173
|
+
return { amount: this.scaleUp(this.toGb().amount), unit: "TB" };
|
|
174
|
+
}
|
|
175
|
+
format() {
|
|
176
|
+
const size = [this.toTb(), this.toGb(), this.toMb(), this.toKb()].map(
|
|
177
|
+
(size2) => ({ ...size2, amount: Math.floor(size2.amount) })
|
|
178
|
+
).find((size2) => size2.amount >= 1);
|
|
179
|
+
return size ? `${size.amount} ${size.unit}` : `${this.bytes} B`;
|
|
180
|
+
}
|
|
181
|
+
scaleUp(bytes) {
|
|
182
|
+
return bytes / 1e3;
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
101
186
|
// src/helper-functions/components/formatter/number/NumberFormatter.ts
|
|
102
187
|
var NumberFormatter = class _NumberFormatter {
|
|
103
188
|
static format(value, format2, options) {
|
|
@@ -153,14 +238,6 @@ var NumberFormatter_default = NumberFormatter;
|
|
|
153
238
|
var ObjectFormatter = class {
|
|
154
239
|
static toString = {
|
|
155
240
|
name: (name) => name ? `${name.first} ${name.last}`.trim() : "no_name",
|
|
156
|
-
phoneNumber: (phoneNumber) => {
|
|
157
|
-
if (!phoneNumber) return "no_phone_number";
|
|
158
|
-
return `${phoneNumber.countryCode} (${phoneNumber.areaCode}) ${insertAt(
|
|
159
|
-
phoneNumber.localNumber.split(""),
|
|
160
|
-
3,
|
|
161
|
-
"-"
|
|
162
|
-
).join("")}`;
|
|
163
|
-
},
|
|
164
241
|
address: (address, inline) => {
|
|
165
242
|
if (address === void 0) return "no_address";
|
|
166
243
|
const addressKeys = Object.keys(address).map((k) => k);
|
|
@@ -449,62 +526,6 @@ var TimeManager = class _TimeManager {
|
|
|
449
526
|
};
|
|
450
527
|
var TimeManager_default = TimeManager;
|
|
451
528
|
|
|
452
|
-
// src/helper-functions/components/ObjectConverter.ts
|
|
453
|
-
var import_uuid = require("uuid");
|
|
454
|
-
var import_types = require("@wavy/types");
|
|
455
|
-
var import_console = require("console");
|
|
456
|
-
function fileToLocalFile(file, options) {
|
|
457
|
-
const fileExt = getFileExt(file.name);
|
|
458
|
-
const fileName = (() => {
|
|
459
|
-
if (options?.filename && options.filename.includes(fileExt))
|
|
460
|
-
return options.filename;
|
|
461
|
-
else if (options?.filename) return options.filename.trim() + fileExt;
|
|
462
|
-
return file.name;
|
|
463
|
-
})()?.trim?.();
|
|
464
|
-
const { name: _, size: __, ..._metadata } = file;
|
|
465
|
-
return {
|
|
466
|
-
uid: options?.uid || (0, import_uuid.v4)(),
|
|
467
|
-
description: options?.description,
|
|
468
|
-
ext: fileExt,
|
|
469
|
-
path: options?.filepath || file?.webkitRelativePath,
|
|
470
|
-
typeAlias: options?.typeAlias || run(
|
|
471
|
-
Object.keys(import_types.LOCAL_FILE_MIME_TYPES).find(
|
|
472
|
-
(key) => import_types.LOCAL_FILE_MIME_TYPES[key].includes(file.type)
|
|
473
|
-
),
|
|
474
|
-
(type) => {
|
|
475
|
-
if (!type) {
|
|
476
|
-
(0, import_console.log)("An unknown file type was found ", file.type);
|
|
477
|
-
return "unknown";
|
|
478
|
-
}
|
|
479
|
-
return type;
|
|
480
|
-
}
|
|
481
|
-
),
|
|
482
|
-
sizeInBytes: file.size,
|
|
483
|
-
uploadDate: options?.uploadDate === "now" ? Date.now() : options?.uploadDate ?? file?.lastModified,
|
|
484
|
-
name: fileName,
|
|
485
|
-
_metadata
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
function localFileToFile(localFile) {
|
|
489
|
-
return {
|
|
490
|
-
name: localFile.name,
|
|
491
|
-
size: localFile.sizeInBytes,
|
|
492
|
-
...localFile._metadata
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
var Overloader = class {
|
|
496
|
-
invoke(...args) {
|
|
497
|
-
if (isFile(args[0])) {
|
|
498
|
-
return fileToLocalFile(...args);
|
|
499
|
-
}
|
|
500
|
-
if (isLocalFile(args[0])) {
|
|
501
|
-
return localFileToFile(...args);
|
|
502
|
-
} else throw new Error(`The arguments supplied are insufficient.`);
|
|
503
|
-
}
|
|
504
|
-
};
|
|
505
|
-
var toObject = new Overloader().invoke;
|
|
506
|
-
var ObjectConverter_default = toObject;
|
|
507
|
-
|
|
508
529
|
// src/helper-functions/HelperFunctions.ts
|
|
509
530
|
var dateFormat = new TimeManager_default().format;
|
|
510
531
|
var timeDuration = new TimeManager_default().getDuration;
|
|
@@ -518,7 +539,6 @@ var addArticle = StringFormatter_default.addArticle;
|
|
|
518
539
|
var pluralize = StringFormatter_default.pluralize;
|
|
519
540
|
var objToString = ObjectFormatter_default.toString;
|
|
520
541
|
var nameToString = objToString.name;
|
|
521
|
-
var phoneNoToString = objToString.phoneNumber;
|
|
522
542
|
var addressToString = objToString.address;
|
|
523
543
|
var toMoney = (value, options) => typeof value === "string" ? StringFormatter_default.toMoney(value, options) : NumberFormatter_default.toMoney(value, options);
|
|
524
544
|
function format(event, ...args) {
|
|
@@ -534,8 +554,8 @@ function format(event, ...args) {
|
|
|
534
554
|
return getCaller(toMoney);
|
|
535
555
|
case "name":
|
|
536
556
|
return getCaller(nameToString);
|
|
537
|
-
case "
|
|
538
|
-
return
|
|
557
|
+
case "file-size":
|
|
558
|
+
return new FileSizeFormatter(args[0]).format();
|
|
539
559
|
default:
|
|
540
560
|
return event;
|
|
541
561
|
}
|
|
@@ -898,8 +918,7 @@ function arrayWithConst(array) {
|
|
|
898
918
|
var import_types3 = require("@wavy/types");
|
|
899
919
|
var iiKeys = Object.keys({
|
|
900
920
|
name: null,
|
|
901
|
-
address: null
|
|
902
|
-
phoneNumber: null
|
|
921
|
+
address: null
|
|
903
922
|
});
|
|
904
923
|
var stringArrayIdPrefix = "listOf";
|
|
905
924
|
var multiDimArrayIdPrefix = "2DListOf";
|
|
@@ -917,11 +936,6 @@ var INDEX_MAPPER = {
|
|
|
917
936
|
city: 1,
|
|
918
937
|
parish: 2,
|
|
919
938
|
country: 3
|
|
920
|
-
},
|
|
921
|
-
phoneNumber: {
|
|
922
|
-
countryCode: 0,
|
|
923
|
-
areaCode: 1,
|
|
924
|
-
localNumber: 2
|
|
925
939
|
}
|
|
926
940
|
};
|
|
927
941
|
function zip(data) {
|
|
@@ -953,13 +967,6 @@ function zip(data) {
|
|
|
953
967
|
country: "Jamaica"
|
|
954
968
|
});
|
|
955
969
|
break;
|
|
956
|
-
case "phoneNumber":
|
|
957
|
-
handleTypeMismatchError({
|
|
958
|
-
countryCode: "1",
|
|
959
|
-
areaCode: "876",
|
|
960
|
-
localNumber: ""
|
|
961
|
-
});
|
|
962
|
-
break;
|
|
963
970
|
default:
|
|
964
971
|
return validKey;
|
|
965
972
|
}
|
package/dist/main.d.cts
CHANGED
|
@@ -4,6 +4,18 @@ import { LocalFile, SanitizeFile, KnownFileTypeAlias, TaskResult, FromServer, No
|
|
|
4
4
|
|
|
5
5
|
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
6
|
|
|
7
|
+
declare const toObject: {
|
|
8
|
+
(file: File | Pick<File, "size" | "name" | "type" | "webkitRelativePath" | "lastModified">, options?: Partial<{
|
|
9
|
+
uid?: string;
|
|
10
|
+
uploadDate: number | "now";
|
|
11
|
+
description: string;
|
|
12
|
+
filepath: string;
|
|
13
|
+
filename: string;
|
|
14
|
+
typeAlias: LocalFile["typeAlias"];
|
|
15
|
+
}> | undefined): LocalFile;
|
|
16
|
+
(localFile: LocalFile): File;
|
|
17
|
+
};
|
|
18
|
+
|
|
7
19
|
type NumberFormatterTypes = {
|
|
8
20
|
formats: "money";
|
|
9
21
|
options: {
|
|
@@ -34,18 +46,6 @@ declare class StringFormatter {
|
|
|
34
46
|
static upperFirst(value: string): string;
|
|
35
47
|
}
|
|
36
48
|
|
|
37
|
-
declare const toObject: {
|
|
38
|
-
(file: File | Pick<File, "name" | "size" | "type" | "webkitRelativePath" | "lastModified">, options?: Partial<{
|
|
39
|
-
uid?: string;
|
|
40
|
-
uploadDate: number | "now";
|
|
41
|
-
description: string;
|
|
42
|
-
filepath: string;
|
|
43
|
-
filename: string;
|
|
44
|
-
typeAlias: LocalFile["typeAlias"];
|
|
45
|
-
}> | undefined): LocalFile;
|
|
46
|
-
(localFile: LocalFile): File;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
49
|
declare const dateFormat: (time: number | Date | "now", format?: DateFormat) => string;
|
|
50
50
|
declare const timeDuration: (from: number | "now" | Date, to: number | "now" | Date, options?: {
|
|
51
51
|
disableRemainder?: boolean;
|
|
@@ -60,10 +60,9 @@ declare const toNumber: typeof StringFormatter.toNumber;
|
|
|
60
60
|
declare const addArticle: typeof StringFormatter.addArticle;
|
|
61
61
|
declare const pluralize: typeof StringFormatter.pluralize;
|
|
62
62
|
declare const nameToString: (name: _wavy_types.Name | undefined) => string;
|
|
63
|
-
declare const phoneNoToString: (phoneNumber: _wavy_types.PhoneNumber | undefined) => string;
|
|
64
63
|
declare const addressToString: (address: _wavy_types.Address | undefined, inline?: boolean) => string;
|
|
65
64
|
declare const toMoney: (value: string | number, options?: NumberFormatterTypes["options"]["money"]) => string;
|
|
66
|
-
declare function format<Event extends "date" | "money" | "name" | "
|
|
65
|
+
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
66
|
declare function sanitizeLocalFile({ _metadata: _, ...file }: LocalFile): SanitizeFile<LocalFile>;
|
|
68
67
|
declare function isFile(value: unknown): value is File;
|
|
69
68
|
declare function isLocalFile(value: unknown): value is LocalFile;
|
package/dist/main.d.ts
CHANGED
|
@@ -4,6 +4,18 @@ import { LocalFile, SanitizeFile, KnownFileTypeAlias, TaskResult, FromServer, No
|
|
|
4
4
|
|
|
5
5
|
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
6
|
|
|
7
|
+
declare const toObject: {
|
|
8
|
+
(file: File | Pick<File, "size" | "name" | "type" | "webkitRelativePath" | "lastModified">, options?: Partial<{
|
|
9
|
+
uid?: string;
|
|
10
|
+
uploadDate: number | "now";
|
|
11
|
+
description: string;
|
|
12
|
+
filepath: string;
|
|
13
|
+
filename: string;
|
|
14
|
+
typeAlias: LocalFile["typeAlias"];
|
|
15
|
+
}> | undefined): LocalFile;
|
|
16
|
+
(localFile: LocalFile): File;
|
|
17
|
+
};
|
|
18
|
+
|
|
7
19
|
type NumberFormatterTypes = {
|
|
8
20
|
formats: "money";
|
|
9
21
|
options: {
|
|
@@ -34,18 +46,6 @@ declare class StringFormatter {
|
|
|
34
46
|
static upperFirst(value: string): string;
|
|
35
47
|
}
|
|
36
48
|
|
|
37
|
-
declare const toObject: {
|
|
38
|
-
(file: File | Pick<File, "name" | "size" | "type" | "webkitRelativePath" | "lastModified">, options?: Partial<{
|
|
39
|
-
uid?: string;
|
|
40
|
-
uploadDate: number | "now";
|
|
41
|
-
description: string;
|
|
42
|
-
filepath: string;
|
|
43
|
-
filename: string;
|
|
44
|
-
typeAlias: LocalFile["typeAlias"];
|
|
45
|
-
}> | undefined): LocalFile;
|
|
46
|
-
(localFile: LocalFile): File;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
49
|
declare const dateFormat: (time: number | Date | "now", format?: DateFormat) => string;
|
|
50
50
|
declare const timeDuration: (from: number | "now" | Date, to: number | "now" | Date, options?: {
|
|
51
51
|
disableRemainder?: boolean;
|
|
@@ -60,10 +60,9 @@ declare const toNumber: typeof StringFormatter.toNumber;
|
|
|
60
60
|
declare const addArticle: typeof StringFormatter.addArticle;
|
|
61
61
|
declare const pluralize: typeof StringFormatter.pluralize;
|
|
62
62
|
declare const nameToString: (name: _wavy_types.Name | undefined) => string;
|
|
63
|
-
declare const phoneNoToString: (phoneNumber: _wavy_types.PhoneNumber | undefined) => string;
|
|
64
63
|
declare const addressToString: (address: _wavy_types.Address | undefined, inline?: boolean) => string;
|
|
65
64
|
declare const toMoney: (value: string | number, options?: NumberFormatterTypes["options"]["money"]) => string;
|
|
66
|
-
declare function format<Event extends "date" | "money" | "name" | "
|
|
65
|
+
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
66
|
declare function sanitizeLocalFile({ _metadata: _, ...file }: LocalFile): SanitizeFile<LocalFile>;
|
|
68
67
|
declare function isFile(value: unknown): value is File;
|
|
69
68
|
declare function isLocalFile(value: unknown): value is LocalFile;
|
package/dist/main.js
CHANGED
|
@@ -3,6 +3,91 @@ import {
|
|
|
3
3
|
LOCAL_FILE_MIME_TYPES as LOCAL_FILE_MIME_TYPES2
|
|
4
4
|
} from "@wavy/types";
|
|
5
5
|
|
|
6
|
+
// src/helper-functions/components/ObjectConverter.ts
|
|
7
|
+
import { v4 } from "uuid";
|
|
8
|
+
import { LOCAL_FILE_MIME_TYPES } from "@wavy/types";
|
|
9
|
+
import { log } from "console";
|
|
10
|
+
function fileToLocalFile(file, options) {
|
|
11
|
+
const fileExt = getFileExt(file.name);
|
|
12
|
+
const fileName = (() => {
|
|
13
|
+
if (options?.filename && options.filename.includes(fileExt))
|
|
14
|
+
return options.filename;
|
|
15
|
+
else if (options?.filename) return options.filename.trim() + fileExt;
|
|
16
|
+
return file.name;
|
|
17
|
+
})()?.trim?.();
|
|
18
|
+
const { name: _, size: __, ..._metadata } = file;
|
|
19
|
+
return {
|
|
20
|
+
uid: options?.uid || v4(),
|
|
21
|
+
description: options?.description,
|
|
22
|
+
ext: fileExt,
|
|
23
|
+
path: options?.filepath || file?.webkitRelativePath,
|
|
24
|
+
typeAlias: options?.typeAlias || run(
|
|
25
|
+
Object.keys(LOCAL_FILE_MIME_TYPES).find(
|
|
26
|
+
(key) => LOCAL_FILE_MIME_TYPES[key].includes(file.type)
|
|
27
|
+
),
|
|
28
|
+
(type) => {
|
|
29
|
+
if (!type) {
|
|
30
|
+
log("An unknown file type was found ", file.type);
|
|
31
|
+
return "unknown";
|
|
32
|
+
}
|
|
33
|
+
return type;
|
|
34
|
+
}
|
|
35
|
+
),
|
|
36
|
+
sizeInBytes: file.size,
|
|
37
|
+
uploadDate: options?.uploadDate === "now" ? Date.now() : options?.uploadDate ?? file?.lastModified,
|
|
38
|
+
name: fileName,
|
|
39
|
+
_metadata
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function localFileToFile(localFile) {
|
|
43
|
+
return {
|
|
44
|
+
name: localFile.name,
|
|
45
|
+
size: localFile.sizeInBytes,
|
|
46
|
+
...localFile._metadata
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
var Overloader = class {
|
|
50
|
+
invoke(...args) {
|
|
51
|
+
if (isFile(args[0])) {
|
|
52
|
+
return fileToLocalFile(...args);
|
|
53
|
+
}
|
|
54
|
+
if (isLocalFile(args[0])) {
|
|
55
|
+
return localFileToFile(...args);
|
|
56
|
+
} else throw new Error(`The arguments supplied are insufficient.`);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var toObject = new Overloader().invoke;
|
|
60
|
+
var ObjectConverter_default = toObject;
|
|
61
|
+
|
|
62
|
+
// src/helper-functions/components/formatter/FileSizeFormatter.ts
|
|
63
|
+
var FileSizeFormatter = class {
|
|
64
|
+
constructor(bytes) {
|
|
65
|
+
this.bytes = bytes;
|
|
66
|
+
}
|
|
67
|
+
bytes;
|
|
68
|
+
toKb() {
|
|
69
|
+
return { amount: this.scaleUp(this.bytes), unit: "KB" };
|
|
70
|
+
}
|
|
71
|
+
toMb() {
|
|
72
|
+
return { amount: this.scaleUp(this.toKb().amount), unit: "MB" };
|
|
73
|
+
}
|
|
74
|
+
toGb() {
|
|
75
|
+
return { amount: this.scaleUp(this.toMb().amount), unit: "GB" };
|
|
76
|
+
}
|
|
77
|
+
toTb() {
|
|
78
|
+
return { amount: this.scaleUp(this.toGb().amount), unit: "TB" };
|
|
79
|
+
}
|
|
80
|
+
format() {
|
|
81
|
+
const size = [this.toTb(), this.toGb(), this.toMb(), this.toKb()].map(
|
|
82
|
+
(size2) => ({ ...size2, amount: Math.floor(size2.amount) })
|
|
83
|
+
).find((size2) => size2.amount >= 1);
|
|
84
|
+
return size ? `${size.amount} ${size.unit}` : `${this.bytes} B`;
|
|
85
|
+
}
|
|
86
|
+
scaleUp(bytes) {
|
|
87
|
+
return bytes / 1e3;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
6
91
|
// src/helper-functions/components/formatter/number/NumberFormatter.ts
|
|
7
92
|
var NumberFormatter = class _NumberFormatter {
|
|
8
93
|
static format(value, format2, options) {
|
|
@@ -58,14 +143,6 @@ var NumberFormatter_default = NumberFormatter;
|
|
|
58
143
|
var ObjectFormatter = class {
|
|
59
144
|
static toString = {
|
|
60
145
|
name: (name) => name ? `${name.first} ${name.last}`.trim() : "no_name",
|
|
61
|
-
phoneNumber: (phoneNumber) => {
|
|
62
|
-
if (!phoneNumber) return "no_phone_number";
|
|
63
|
-
return `${phoneNumber.countryCode} (${phoneNumber.areaCode}) ${insertAt(
|
|
64
|
-
phoneNumber.localNumber.split(""),
|
|
65
|
-
3,
|
|
66
|
-
"-"
|
|
67
|
-
).join("")}`;
|
|
68
|
-
},
|
|
69
146
|
address: (address, inline) => {
|
|
70
147
|
if (address === void 0) return "no_address";
|
|
71
148
|
const addressKeys = Object.keys(address).map((k) => k);
|
|
@@ -354,62 +431,6 @@ var TimeManager = class _TimeManager {
|
|
|
354
431
|
};
|
|
355
432
|
var TimeManager_default = TimeManager;
|
|
356
433
|
|
|
357
|
-
// src/helper-functions/components/ObjectConverter.ts
|
|
358
|
-
import { v4 } from "uuid";
|
|
359
|
-
import { LOCAL_FILE_MIME_TYPES } from "@wavy/types";
|
|
360
|
-
import { log } from "console";
|
|
361
|
-
function fileToLocalFile(file, options) {
|
|
362
|
-
const fileExt = getFileExt(file.name);
|
|
363
|
-
const fileName = (() => {
|
|
364
|
-
if (options?.filename && options.filename.includes(fileExt))
|
|
365
|
-
return options.filename;
|
|
366
|
-
else if (options?.filename) return options.filename.trim() + fileExt;
|
|
367
|
-
return file.name;
|
|
368
|
-
})()?.trim?.();
|
|
369
|
-
const { name: _, size: __, ..._metadata } = file;
|
|
370
|
-
return {
|
|
371
|
-
uid: options?.uid || v4(),
|
|
372
|
-
description: options?.description,
|
|
373
|
-
ext: fileExt,
|
|
374
|
-
path: options?.filepath || file?.webkitRelativePath,
|
|
375
|
-
typeAlias: options?.typeAlias || run(
|
|
376
|
-
Object.keys(LOCAL_FILE_MIME_TYPES).find(
|
|
377
|
-
(key) => LOCAL_FILE_MIME_TYPES[key].includes(file.type)
|
|
378
|
-
),
|
|
379
|
-
(type) => {
|
|
380
|
-
if (!type) {
|
|
381
|
-
log("An unknown file type was found ", file.type);
|
|
382
|
-
return "unknown";
|
|
383
|
-
}
|
|
384
|
-
return type;
|
|
385
|
-
}
|
|
386
|
-
),
|
|
387
|
-
sizeInBytes: file.size,
|
|
388
|
-
uploadDate: options?.uploadDate === "now" ? Date.now() : options?.uploadDate ?? file?.lastModified,
|
|
389
|
-
name: fileName,
|
|
390
|
-
_metadata
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
function localFileToFile(localFile) {
|
|
394
|
-
return {
|
|
395
|
-
name: localFile.name,
|
|
396
|
-
size: localFile.sizeInBytes,
|
|
397
|
-
...localFile._metadata
|
|
398
|
-
};
|
|
399
|
-
}
|
|
400
|
-
var Overloader = class {
|
|
401
|
-
invoke(...args) {
|
|
402
|
-
if (isFile(args[0])) {
|
|
403
|
-
return fileToLocalFile(...args);
|
|
404
|
-
}
|
|
405
|
-
if (isLocalFile(args[0])) {
|
|
406
|
-
return localFileToFile(...args);
|
|
407
|
-
} else throw new Error(`The arguments supplied are insufficient.`);
|
|
408
|
-
}
|
|
409
|
-
};
|
|
410
|
-
var toObject = new Overloader().invoke;
|
|
411
|
-
var ObjectConverter_default = toObject;
|
|
412
|
-
|
|
413
434
|
// src/helper-functions/HelperFunctions.ts
|
|
414
435
|
var dateFormat = new TimeManager_default().format;
|
|
415
436
|
var timeDuration = new TimeManager_default().getDuration;
|
|
@@ -423,7 +444,6 @@ var addArticle = StringFormatter_default.addArticle;
|
|
|
423
444
|
var pluralize = StringFormatter_default.pluralize;
|
|
424
445
|
var objToString = ObjectFormatter_default.toString;
|
|
425
446
|
var nameToString = objToString.name;
|
|
426
|
-
var phoneNoToString = objToString.phoneNumber;
|
|
427
447
|
var addressToString = objToString.address;
|
|
428
448
|
var toMoney = (value, options) => typeof value === "string" ? StringFormatter_default.toMoney(value, options) : NumberFormatter_default.toMoney(value, options);
|
|
429
449
|
function format(event, ...args) {
|
|
@@ -439,8 +459,8 @@ function format(event, ...args) {
|
|
|
439
459
|
return getCaller(toMoney);
|
|
440
460
|
case "name":
|
|
441
461
|
return getCaller(nameToString);
|
|
442
|
-
case "
|
|
443
|
-
return
|
|
462
|
+
case "file-size":
|
|
463
|
+
return new FileSizeFormatter(args[0]).format();
|
|
444
464
|
default:
|
|
445
465
|
return event;
|
|
446
466
|
}
|
|
@@ -803,8 +823,7 @@ function arrayWithConst(array) {
|
|
|
803
823
|
import "@wavy/types";
|
|
804
824
|
var iiKeys = Object.keys({
|
|
805
825
|
name: null,
|
|
806
|
-
address: null
|
|
807
|
-
phoneNumber: null
|
|
826
|
+
address: null
|
|
808
827
|
});
|
|
809
828
|
var stringArrayIdPrefix = "listOf";
|
|
810
829
|
var multiDimArrayIdPrefix = "2DListOf";
|
|
@@ -822,11 +841,6 @@ var INDEX_MAPPER = {
|
|
|
822
841
|
city: 1,
|
|
823
842
|
parish: 2,
|
|
824
843
|
country: 3
|
|
825
|
-
},
|
|
826
|
-
phoneNumber: {
|
|
827
|
-
countryCode: 0,
|
|
828
|
-
areaCode: 1,
|
|
829
|
-
localNumber: 2
|
|
830
844
|
}
|
|
831
845
|
};
|
|
832
846
|
function zip(data) {
|
|
@@ -858,13 +872,6 @@ function zip(data) {
|
|
|
858
872
|
country: "Jamaica"
|
|
859
873
|
});
|
|
860
874
|
break;
|
|
861
|
-
case "phoneNumber":
|
|
862
|
-
handleTypeMismatchError({
|
|
863
|
-
countryCode: "1",
|
|
864
|
-
areaCode: "876",
|
|
865
|
-
localNumber: ""
|
|
866
|
-
});
|
|
867
|
-
break;
|
|
868
875
|
default:
|
|
869
876
|
return validKey;
|
|
870
877
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wavy/fn",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"main": "./dist/main.js",
|
|
5
5
|
"module": "./dist/main.cjs",
|
|
6
6
|
"types": "./dist/main.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "tsup && node prepend"
|
|
8
|
+
"build": "tsup && node prepend",
|
|
9
|
+
"success": "echo ✨ Successfully published package! ✨",
|
|
10
|
+
"publisher": "npm run build && npm version patch && npm publish && npm run success"
|
|
9
11
|
},
|
|
10
12
|
"repository": {
|
|
11
13
|
"type": "git",
|
|
@@ -22,7 +24,7 @@
|
|
|
22
24
|
"description": "",
|
|
23
25
|
"devDependencies": {
|
|
24
26
|
"@types/node": "^24.5.2",
|
|
25
|
-
"@wavy/types": "^0.0.
|
|
27
|
+
"@wavy/types": "^0.0.46",
|
|
26
28
|
"tsup": "^8.5.0",
|
|
27
29
|
"typescript": "^5.9.2"
|
|
28
30
|
},
|