@wavy/fn 0.0.2 → 0.0.3
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 +48 -5
- package/dist/main.d.cts +19 -9
- package/dist/main.d.ts +19 -9
- package/dist/main.js +47 -5
- package/package.json +2 -2
package/dist/main.cjs
CHANGED
|
@@ -55,6 +55,7 @@ __export(main_exports, {
|
|
|
55
55
|
isEmpty: () => isEmpty,
|
|
56
56
|
isFile: () => isFile,
|
|
57
57
|
isLetter: () => isLetter,
|
|
58
|
+
isLocalFile: () => isLocalFile,
|
|
58
59
|
isNumber: () => isNumber,
|
|
59
60
|
lastIndex: () => lastIndex,
|
|
60
61
|
map: () => map,
|
|
@@ -481,7 +482,7 @@ function format(event, ...args) {
|
|
|
481
482
|
return event;
|
|
482
483
|
}
|
|
483
484
|
}
|
|
484
|
-
function isFile(
|
|
485
|
+
function isFile(value) {
|
|
485
486
|
const fileKeys = Object.keys({
|
|
486
487
|
arrayBuffer: null,
|
|
487
488
|
bytes: null,
|
|
@@ -494,10 +495,29 @@ function isFile(obj) {
|
|
|
494
495
|
type: null,
|
|
495
496
|
webkitRelativePath: null
|
|
496
497
|
});
|
|
497
|
-
if (
|
|
498
|
+
if (value && typeof value === "object" && fileKeys.every((key) => key in value) && fileKeys.length === Object.keys(value).length)
|
|
498
499
|
return true;
|
|
499
500
|
return false;
|
|
500
501
|
}
|
|
502
|
+
function isLocalFile(value) {
|
|
503
|
+
const dummyLocalFile = {
|
|
504
|
+
name: "",
|
|
505
|
+
description: "",
|
|
506
|
+
path: "",
|
|
507
|
+
sizeInBytes: 0,
|
|
508
|
+
typeAlias: "unknown",
|
|
509
|
+
uid: "",
|
|
510
|
+
uploadDate: 0,
|
|
511
|
+
_metadata: void 0
|
|
512
|
+
};
|
|
513
|
+
const optionalKeys = ["description", "_metadata"];
|
|
514
|
+
const requiredKeys = Object.keys(dummyLocalFile).filter((key) => !optionalKeys.includes(key));
|
|
515
|
+
const allKeys = [requiredKeys, optionalKeys].flat();
|
|
516
|
+
if (value && typeof value === "object" && requiredKeys.every((key) => key in value) && Object.keys(value).every((key) => allKeys.includes(key))) {
|
|
517
|
+
return true;
|
|
518
|
+
}
|
|
519
|
+
return false;
|
|
520
|
+
}
|
|
501
521
|
var toObject = new class T {
|
|
502
522
|
fileToLocalFile(file, options) {
|
|
503
523
|
const fileName = (() => {
|
|
@@ -507,6 +527,7 @@ var toObject = new class T {
|
|
|
507
527
|
else if (options?.filename) return options.filename.trim() + fileExt;
|
|
508
528
|
return file.name;
|
|
509
529
|
})()?.trim?.();
|
|
530
|
+
const { name: _, size: __, ..._metadata } = file;
|
|
510
531
|
return {
|
|
511
532
|
uid: (0, import_uuid.v4)(),
|
|
512
533
|
description: options?.description,
|
|
@@ -525,15 +546,36 @@ var toObject = new class T {
|
|
|
525
546
|
),
|
|
526
547
|
sizeInBytes: file.size,
|
|
527
548
|
uploadDate: options?.uploadDate === "now" ? Date.now() : options?.uploadDate ?? file.lastModified,
|
|
528
|
-
name: fileName
|
|
549
|
+
name: fileName,
|
|
550
|
+
_metadata
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
localFileToFile(localFile) {
|
|
554
|
+
if ("_metadata" in localFile) {
|
|
555
|
+
return {
|
|
556
|
+
name: localFile.name,
|
|
557
|
+
size: localFile.sizeInBytes,
|
|
558
|
+
...localFile._metadata
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
return {
|
|
562
|
+
name: localFile.name,
|
|
563
|
+
size: localFile.sizeInBytes,
|
|
564
|
+
webkitRelativePath: localFile.path,
|
|
565
|
+
lastModified: localFile.uploadDate
|
|
529
566
|
};
|
|
530
567
|
}
|
|
531
568
|
invoke(...args) {
|
|
532
|
-
if (isFile(args[0]))
|
|
569
|
+
if (isFile(args[0])) {
|
|
533
570
|
return this.fileToLocalFile(
|
|
534
571
|
...args
|
|
535
572
|
);
|
|
536
|
-
|
|
573
|
+
}
|
|
574
|
+
if (isLocalFile(args[0])) {
|
|
575
|
+
return this.localFileToFile(
|
|
576
|
+
...args
|
|
577
|
+
);
|
|
578
|
+
} else throw new Error(`The arguments supplied are insufficient.`);
|
|
537
579
|
}
|
|
538
580
|
}().invoke;
|
|
539
581
|
function classNameResolver(baseClassName) {
|
|
@@ -1070,6 +1112,7 @@ var serverDataAdapter = new ServerDataAdapter().invoke;
|
|
|
1070
1112
|
isEmpty,
|
|
1071
1113
|
isFile,
|
|
1072
1114
|
isLetter,
|
|
1115
|
+
isLocalFile,
|
|
1073
1116
|
isNumber,
|
|
1074
1117
|
lastIndex,
|
|
1075
1118
|
map,
|
package/dist/main.d.cts
CHANGED
|
@@ -49,14 +49,24 @@ declare const phoneNoToString: (phoneNumber: PhoneNumber | undefined) => string;
|
|
|
49
49
|
declare const addressToString: (address: Address | undefined, inline?: boolean) => string;
|
|
50
50
|
declare const toMoney: (value: string | number, options?: NumberFormatterTypes["options"]["money"]) => string;
|
|
51
51
|
declare function format<Event extends "date" | "money" | "name" | "phone-number" | "address">(event: Event, ...args: Event extends "date" ? Parameters<typeof dateFormat> : Event extends "money" ? Parameters<typeof toMoney> : Event extends "name" ? Parameters<typeof nameToString> : Event extends "phone-number" ? Parameters<typeof phoneNoToString> : Event extends "address" ? Parameters<typeof addressToString> : never): Event extends "date" ? ReturnType<typeof dateFormat> : Event extends "money" ? ReturnType<typeof toMoney> : Event extends "name" ? ReturnType<typeof nameToString> : Event extends "phone-number" ? ReturnType<typeof phoneNoToString> : Event extends "address" ? ReturnType<typeof addressToString> : never;
|
|
52
|
-
declare function isFile(
|
|
53
|
-
declare
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
declare function isFile(value: unknown): value is File;
|
|
53
|
+
declare function isLocalFile(value: unknown): value is LocalFile;
|
|
54
|
+
declare const toObject: {
|
|
55
|
+
(file: File, options?: Partial<{
|
|
56
|
+
uploadDate: number | "now";
|
|
57
|
+
description: string;
|
|
58
|
+
filepath: string;
|
|
59
|
+
filename: string;
|
|
60
|
+
typeAlias: LocalFile["typeAlias"];
|
|
61
|
+
}> | undefined): ReturnType<(file: File, options?: Partial<{
|
|
62
|
+
uploadDate: number | "now";
|
|
63
|
+
description: string;
|
|
64
|
+
filepath: string;
|
|
65
|
+
filename: string;
|
|
66
|
+
typeAlias: LocalFile["typeAlias"];
|
|
67
|
+
}>) => LocalFile>;
|
|
68
|
+
(localFile: LocalFile | SanitizeLocalType<LocalFile>): ReturnType<(<LocalFileType extends LocalFile | SanitizeLocalType<LocalFile>>(localFile: LocalFileType) => LocalFileType extends LocalFile ? File : Partialize<File, "arrayBuffer" | "stream" | "slice" | "text" | "bytes" | "type">)>;
|
|
69
|
+
};
|
|
60
70
|
declare function classNameResolver(baseClassName: string): (className: string) => string;
|
|
61
71
|
declare function classNameExt(rootClassName: string): (className: string) => string;
|
|
62
72
|
declare function range(start: number, end: number): number[];
|
|
@@ -172,4 +182,4 @@ declare const serverDataAdapter: {
|
|
|
172
182
|
}>(event: "unzip", data: DataType): NormalizeFromServer<DataType>;
|
|
173
183
|
};
|
|
174
184
|
|
|
175
|
-
export { addArticle, arrayWithConst, asyncRun, averageOf, blankSpaces, buildArray, camelCaseToLetter, classNameExt, classNameResolver, coerceIn, copyToClipboard, count, dataSearcher, distinct, drop, dropLast, dropLastWhile, dropWhile, format, formatGCTRegNo, formatInvoiceNo, getCaps, getFileExt, group, hasIndex, ifDefined, ifEmpty, inRange, indexOf, indices, inferFilename, insertAt, isEmpty, isFile, isLetter, isNumber, lastIndex, map, mapToArray, maxOf, minOf, negate, ordinalIndicator, overwrite, pluralize, poll, random, range, readClipboardText, removeAll, repeat, run, serverDataAdapter, someValuesEmpty, sort, strictArray, stringToSearch, subObjectList, sumOf, take, takeLast, takeLastWhile, takeWhile, timeDuration, toNumber, toObject, trimString, undefinedIfEmpty, upperFirst, windowed };
|
|
185
|
+
export { addArticle, arrayWithConst, asyncRun, averageOf, blankSpaces, buildArray, camelCaseToLetter, classNameExt, classNameResolver, coerceIn, copyToClipboard, count, dataSearcher, distinct, drop, dropLast, dropLastWhile, dropWhile, format, formatGCTRegNo, formatInvoiceNo, getCaps, getFileExt, group, hasIndex, ifDefined, ifEmpty, inRange, indexOf, indices, inferFilename, insertAt, isEmpty, isFile, isLetter, isLocalFile, isNumber, lastIndex, map, mapToArray, maxOf, minOf, negate, ordinalIndicator, overwrite, pluralize, poll, random, range, readClipboardText, removeAll, repeat, run, serverDataAdapter, someValuesEmpty, sort, strictArray, stringToSearch, subObjectList, sumOf, take, takeLast, takeLastWhile, takeWhile, timeDuration, toNumber, toObject, trimString, undefinedIfEmpty, upperFirst, windowed };
|
package/dist/main.d.ts
CHANGED
|
@@ -49,14 +49,24 @@ declare const phoneNoToString: (phoneNumber: PhoneNumber | undefined) => string;
|
|
|
49
49
|
declare const addressToString: (address: Address | undefined, inline?: boolean) => string;
|
|
50
50
|
declare const toMoney: (value: string | number, options?: NumberFormatterTypes["options"]["money"]) => string;
|
|
51
51
|
declare function format<Event extends "date" | "money" | "name" | "phone-number" | "address">(event: Event, ...args: Event extends "date" ? Parameters<typeof dateFormat> : Event extends "money" ? Parameters<typeof toMoney> : Event extends "name" ? Parameters<typeof nameToString> : Event extends "phone-number" ? Parameters<typeof phoneNoToString> : Event extends "address" ? Parameters<typeof addressToString> : never): Event extends "date" ? ReturnType<typeof dateFormat> : Event extends "money" ? ReturnType<typeof toMoney> : Event extends "name" ? ReturnType<typeof nameToString> : Event extends "phone-number" ? ReturnType<typeof phoneNoToString> : Event extends "address" ? ReturnType<typeof addressToString> : never;
|
|
52
|
-
declare function isFile(
|
|
53
|
-
declare
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
declare function isFile(value: unknown): value is File;
|
|
53
|
+
declare function isLocalFile(value: unknown): value is LocalFile;
|
|
54
|
+
declare const toObject: {
|
|
55
|
+
(file: File, options?: Partial<{
|
|
56
|
+
uploadDate: number | "now";
|
|
57
|
+
description: string;
|
|
58
|
+
filepath: string;
|
|
59
|
+
filename: string;
|
|
60
|
+
typeAlias: LocalFile["typeAlias"];
|
|
61
|
+
}> | undefined): ReturnType<(file: File, options?: Partial<{
|
|
62
|
+
uploadDate: number | "now";
|
|
63
|
+
description: string;
|
|
64
|
+
filepath: string;
|
|
65
|
+
filename: string;
|
|
66
|
+
typeAlias: LocalFile["typeAlias"];
|
|
67
|
+
}>) => LocalFile>;
|
|
68
|
+
(localFile: LocalFile | SanitizeLocalType<LocalFile>): ReturnType<(<LocalFileType extends LocalFile | SanitizeLocalType<LocalFile>>(localFile: LocalFileType) => LocalFileType extends LocalFile ? File : Partialize<File, "arrayBuffer" | "stream" | "slice" | "text" | "bytes" | "type">)>;
|
|
69
|
+
};
|
|
60
70
|
declare function classNameResolver(baseClassName: string): (className: string) => string;
|
|
61
71
|
declare function classNameExt(rootClassName: string): (className: string) => string;
|
|
62
72
|
declare function range(start: number, end: number): number[];
|
|
@@ -172,4 +182,4 @@ declare const serverDataAdapter: {
|
|
|
172
182
|
}>(event: "unzip", data: DataType): NormalizeFromServer<DataType>;
|
|
173
183
|
};
|
|
174
184
|
|
|
175
|
-
export { addArticle, arrayWithConst, asyncRun, averageOf, blankSpaces, buildArray, camelCaseToLetter, classNameExt, classNameResolver, coerceIn, copyToClipboard, count, dataSearcher, distinct, drop, dropLast, dropLastWhile, dropWhile, format, formatGCTRegNo, formatInvoiceNo, getCaps, getFileExt, group, hasIndex, ifDefined, ifEmpty, inRange, indexOf, indices, inferFilename, insertAt, isEmpty, isFile, isLetter, isNumber, lastIndex, map, mapToArray, maxOf, minOf, negate, ordinalIndicator, overwrite, pluralize, poll, random, range, readClipboardText, removeAll, repeat, run, serverDataAdapter, someValuesEmpty, sort, strictArray, stringToSearch, subObjectList, sumOf, take, takeLast, takeLastWhile, takeWhile, timeDuration, toNumber, toObject, trimString, undefinedIfEmpty, upperFirst, windowed };
|
|
185
|
+
export { addArticle, arrayWithConst, asyncRun, averageOf, blankSpaces, buildArray, camelCaseToLetter, classNameExt, classNameResolver, coerceIn, copyToClipboard, count, dataSearcher, distinct, drop, dropLast, dropLastWhile, dropWhile, format, formatGCTRegNo, formatInvoiceNo, getCaps, getFileExt, group, hasIndex, ifDefined, ifEmpty, inRange, indexOf, indices, inferFilename, insertAt, isEmpty, isFile, isLetter, isLocalFile, isNumber, lastIndex, map, mapToArray, maxOf, minOf, negate, ordinalIndicator, overwrite, pluralize, poll, random, range, readClipboardText, removeAll, repeat, run, serverDataAdapter, someValuesEmpty, sort, strictArray, stringToSearch, subObjectList, sumOf, take, takeLast, takeLastWhile, takeWhile, timeDuration, toNumber, toObject, trimString, undefinedIfEmpty, upperFirst, windowed };
|
package/dist/main.js
CHANGED
|
@@ -386,7 +386,7 @@ function format(event, ...args) {
|
|
|
386
386
|
return event;
|
|
387
387
|
}
|
|
388
388
|
}
|
|
389
|
-
function isFile(
|
|
389
|
+
function isFile(value) {
|
|
390
390
|
const fileKeys = Object.keys({
|
|
391
391
|
arrayBuffer: null,
|
|
392
392
|
bytes: null,
|
|
@@ -399,10 +399,29 @@ function isFile(obj) {
|
|
|
399
399
|
type: null,
|
|
400
400
|
webkitRelativePath: null
|
|
401
401
|
});
|
|
402
|
-
if (
|
|
402
|
+
if (value && typeof value === "object" && fileKeys.every((key) => key in value) && fileKeys.length === Object.keys(value).length)
|
|
403
403
|
return true;
|
|
404
404
|
return false;
|
|
405
405
|
}
|
|
406
|
+
function isLocalFile(value) {
|
|
407
|
+
const dummyLocalFile = {
|
|
408
|
+
name: "",
|
|
409
|
+
description: "",
|
|
410
|
+
path: "",
|
|
411
|
+
sizeInBytes: 0,
|
|
412
|
+
typeAlias: "unknown",
|
|
413
|
+
uid: "",
|
|
414
|
+
uploadDate: 0,
|
|
415
|
+
_metadata: void 0
|
|
416
|
+
};
|
|
417
|
+
const optionalKeys = ["description", "_metadata"];
|
|
418
|
+
const requiredKeys = Object.keys(dummyLocalFile).filter((key) => !optionalKeys.includes(key));
|
|
419
|
+
const allKeys = [requiredKeys, optionalKeys].flat();
|
|
420
|
+
if (value && typeof value === "object" && requiredKeys.every((key) => key in value) && Object.keys(value).every((key) => allKeys.includes(key))) {
|
|
421
|
+
return true;
|
|
422
|
+
}
|
|
423
|
+
return false;
|
|
424
|
+
}
|
|
406
425
|
var toObject = new class T {
|
|
407
426
|
fileToLocalFile(file, options) {
|
|
408
427
|
const fileName = (() => {
|
|
@@ -412,6 +431,7 @@ var toObject = new class T {
|
|
|
412
431
|
else if (options?.filename) return options.filename.trim() + fileExt;
|
|
413
432
|
return file.name;
|
|
414
433
|
})()?.trim?.();
|
|
434
|
+
const { name: _, size: __, ..._metadata } = file;
|
|
415
435
|
return {
|
|
416
436
|
uid: v4(),
|
|
417
437
|
description: options?.description,
|
|
@@ -430,15 +450,36 @@ var toObject = new class T {
|
|
|
430
450
|
),
|
|
431
451
|
sizeInBytes: file.size,
|
|
432
452
|
uploadDate: options?.uploadDate === "now" ? Date.now() : options?.uploadDate ?? file.lastModified,
|
|
433
|
-
name: fileName
|
|
453
|
+
name: fileName,
|
|
454
|
+
_metadata
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
localFileToFile(localFile) {
|
|
458
|
+
if ("_metadata" in localFile) {
|
|
459
|
+
return {
|
|
460
|
+
name: localFile.name,
|
|
461
|
+
size: localFile.sizeInBytes,
|
|
462
|
+
...localFile._metadata
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
return {
|
|
466
|
+
name: localFile.name,
|
|
467
|
+
size: localFile.sizeInBytes,
|
|
468
|
+
webkitRelativePath: localFile.path,
|
|
469
|
+
lastModified: localFile.uploadDate
|
|
434
470
|
};
|
|
435
471
|
}
|
|
436
472
|
invoke(...args) {
|
|
437
|
-
if (isFile(args[0]))
|
|
473
|
+
if (isFile(args[0])) {
|
|
438
474
|
return this.fileToLocalFile(
|
|
439
475
|
...args
|
|
440
476
|
);
|
|
441
|
-
|
|
477
|
+
}
|
|
478
|
+
if (isLocalFile(args[0])) {
|
|
479
|
+
return this.localFileToFile(
|
|
480
|
+
...args
|
|
481
|
+
);
|
|
482
|
+
} else throw new Error(`The arguments supplied are insufficient.`);
|
|
442
483
|
}
|
|
443
484
|
}().invoke;
|
|
444
485
|
function classNameResolver(baseClassName) {
|
|
@@ -974,6 +1015,7 @@ export {
|
|
|
974
1015
|
isEmpty,
|
|
975
1016
|
isFile,
|
|
976
1017
|
isLetter,
|
|
1018
|
+
isLocalFile,
|
|
977
1019
|
isNumber,
|
|
978
1020
|
lastIndex,
|
|
979
1021
|
map,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wavy/fn",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"main": "./dist/main.js",
|
|
5
5
|
"module": "./dist/main.cjs",
|
|
6
6
|
"types": "./dist/main.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"description": "",
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/node": "^24.5.2",
|
|
25
|
-
"@wavy/types": "^0.0.
|
|
25
|
+
"@wavy/types": "^0.0.25",
|
|
26
26
|
"tsup": "^8.5.0",
|
|
27
27
|
"typescript": "^5.9.2"
|
|
28
28
|
}
|