@wavy/fn 0.0.1 → 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 +63 -14
- package/dist/main.d.cts +14 -6
- package/dist/main.d.ts +14 -6
- package/dist/main.js +62 -14
- package/package.json +2 -2
- package/prepend.js +1 -0
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,42 +495,89 @@ 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
|
}
|
|
501
|
-
function
|
|
502
|
-
|
|
503
|
-
|
|
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
|
+
}
|
|
521
|
+
var toObject = new class T {
|
|
522
|
+
fileToLocalFile(file, options) {
|
|
504
523
|
const fileName = (() => {
|
|
505
|
-
const fileExt = getFileExt(
|
|
524
|
+
const fileExt = getFileExt(file.name);
|
|
506
525
|
if (options?.filename && options.filename.includes(fileExt))
|
|
507
526
|
return options.filename;
|
|
508
527
|
else if (options?.filename) return options.filename.trim() + fileExt;
|
|
509
|
-
return
|
|
528
|
+
return file.name;
|
|
510
529
|
})()?.trim?.();
|
|
530
|
+
const { name: _, size: __, ..._metadata } = file;
|
|
511
531
|
return {
|
|
512
532
|
uid: (0, import_uuid.v4)(),
|
|
513
533
|
description: options?.description,
|
|
514
|
-
path: options?.filepath ||
|
|
534
|
+
path: options?.filepath || file.webkitRelativePath,
|
|
515
535
|
typeAlias: options?.typeAlias || run(
|
|
516
536
|
Object.keys(import_types.LOCAL_FILE_MIME_TYPES).find(
|
|
517
|
-
(key) => import_types.LOCAL_FILE_MIME_TYPES[key].includes(
|
|
537
|
+
(key) => import_types.LOCAL_FILE_MIME_TYPES[key].includes(file.type)
|
|
518
538
|
),
|
|
519
539
|
(type) => {
|
|
520
540
|
if (!type) {
|
|
521
|
-
(0, import_console.log)("An unknown file type was found ",
|
|
541
|
+
(0, import_console.log)("An unknown file type was found ", file.type);
|
|
522
542
|
return "unknown";
|
|
523
543
|
}
|
|
524
544
|
return type;
|
|
525
545
|
}
|
|
526
546
|
),
|
|
527
|
-
sizeInBytes:
|
|
528
|
-
uploadDate: options?.uploadDate === "now" ? Date.now() : options?.uploadDate ??
|
|
529
|
-
name: fileName
|
|
547
|
+
sizeInBytes: file.size,
|
|
548
|
+
uploadDate: options?.uploadDate === "now" ? Date.now() : options?.uploadDate ?? file.lastModified,
|
|
549
|
+
name: fileName,
|
|
550
|
+
_metadata
|
|
530
551
|
};
|
|
531
552
|
}
|
|
532
|
-
|
|
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
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
invoke(...args) {
|
|
569
|
+
if (isFile(args[0])) {
|
|
570
|
+
return this.fileToLocalFile(
|
|
571
|
+
...args
|
|
572
|
+
);
|
|
573
|
+
}
|
|
574
|
+
if (isLocalFile(args[0])) {
|
|
575
|
+
return this.localFileToFile(
|
|
576
|
+
...args
|
|
577
|
+
);
|
|
578
|
+
} else throw new Error(`The arguments supplied are insufficient.`);
|
|
579
|
+
}
|
|
580
|
+
}().invoke;
|
|
533
581
|
function classNameResolver(baseClassName) {
|
|
534
582
|
return (className) => {
|
|
535
583
|
return `${baseClassName}-${className}`;
|
|
@@ -1064,6 +1112,7 @@ var serverDataAdapter = new ServerDataAdapter().invoke;
|
|
|
1064
1112
|
isEmpty,
|
|
1065
1113
|
isFile,
|
|
1066
1114
|
isLetter,
|
|
1115
|
+
isLocalFile,
|
|
1067
1116
|
isNumber,
|
|
1068
1117
|
lastIndex,
|
|
1069
1118
|
map,
|
package/dist/main.d.cts
CHANGED
|
@@ -49,16 +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 function
|
|
54
|
-
|
|
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<{
|
|
55
56
|
uploadDate: number | "now";
|
|
56
57
|
description: string;
|
|
57
58
|
filepath: string;
|
|
58
59
|
filename: string;
|
|
59
60
|
typeAlias: LocalFile["typeAlias"];
|
|
60
|
-
}>
|
|
61
|
-
|
|
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
|
+
};
|
|
62
70
|
declare function classNameResolver(baseClassName: string): (className: string) => string;
|
|
63
71
|
declare function classNameExt(rootClassName: string): (className: string) => string;
|
|
64
72
|
declare function range(start: number, end: number): number[];
|
|
@@ -174,4 +182,4 @@ declare const serverDataAdapter: {
|
|
|
174
182
|
}>(event: "unzip", data: DataType): NormalizeFromServer<DataType>;
|
|
175
183
|
};
|
|
176
184
|
|
|
177
|
-
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,16 +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 function
|
|
54
|
-
|
|
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<{
|
|
55
56
|
uploadDate: number | "now";
|
|
56
57
|
description: string;
|
|
57
58
|
filepath: string;
|
|
58
59
|
filename: string;
|
|
59
60
|
typeAlias: LocalFile["typeAlias"];
|
|
60
|
-
}>
|
|
61
|
-
|
|
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
|
+
};
|
|
62
70
|
declare function classNameResolver(baseClassName: string): (className: string) => string;
|
|
63
71
|
declare function classNameExt(rootClassName: string): (className: string) => string;
|
|
64
72
|
declare function range(start: number, end: number): number[];
|
|
@@ -174,4 +182,4 @@ declare const serverDataAdapter: {
|
|
|
174
182
|
}>(event: "unzip", data: DataType): NormalizeFromServer<DataType>;
|
|
175
183
|
};
|
|
176
184
|
|
|
177
|
-
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,42 +399,89 @@ 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
|
|
407
|
-
|
|
408
|
-
|
|
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
|
+
}
|
|
425
|
+
var toObject = new class T {
|
|
426
|
+
fileToLocalFile(file, options) {
|
|
409
427
|
const fileName = (() => {
|
|
410
|
-
const fileExt = getFileExt(
|
|
428
|
+
const fileExt = getFileExt(file.name);
|
|
411
429
|
if (options?.filename && options.filename.includes(fileExt))
|
|
412
430
|
return options.filename;
|
|
413
431
|
else if (options?.filename) return options.filename.trim() + fileExt;
|
|
414
|
-
return
|
|
432
|
+
return file.name;
|
|
415
433
|
})()?.trim?.();
|
|
434
|
+
const { name: _, size: __, ..._metadata } = file;
|
|
416
435
|
return {
|
|
417
436
|
uid: v4(),
|
|
418
437
|
description: options?.description,
|
|
419
|
-
path: options?.filepath ||
|
|
438
|
+
path: options?.filepath || file.webkitRelativePath,
|
|
420
439
|
typeAlias: options?.typeAlias || run(
|
|
421
440
|
Object.keys(LOCAL_FILE_MIME_TYPES).find(
|
|
422
|
-
(key) => LOCAL_FILE_MIME_TYPES[key].includes(
|
|
441
|
+
(key) => LOCAL_FILE_MIME_TYPES[key].includes(file.type)
|
|
423
442
|
),
|
|
424
443
|
(type) => {
|
|
425
444
|
if (!type) {
|
|
426
|
-
log("An unknown file type was found ",
|
|
445
|
+
log("An unknown file type was found ", file.type);
|
|
427
446
|
return "unknown";
|
|
428
447
|
}
|
|
429
448
|
return type;
|
|
430
449
|
}
|
|
431
450
|
),
|
|
432
|
-
sizeInBytes:
|
|
433
|
-
uploadDate: options?.uploadDate === "now" ? Date.now() : options?.uploadDate ??
|
|
434
|
-
name: fileName
|
|
451
|
+
sizeInBytes: file.size,
|
|
452
|
+
uploadDate: options?.uploadDate === "now" ? Date.now() : options?.uploadDate ?? file.lastModified,
|
|
453
|
+
name: fileName,
|
|
454
|
+
_metadata
|
|
435
455
|
};
|
|
436
456
|
}
|
|
437
|
-
|
|
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
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
invoke(...args) {
|
|
473
|
+
if (isFile(args[0])) {
|
|
474
|
+
return this.fileToLocalFile(
|
|
475
|
+
...args
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
if (isLocalFile(args[0])) {
|
|
479
|
+
return this.localFileToFile(
|
|
480
|
+
...args
|
|
481
|
+
);
|
|
482
|
+
} else throw new Error(`The arguments supplied are insufficient.`);
|
|
483
|
+
}
|
|
484
|
+
}().invoke;
|
|
438
485
|
function classNameResolver(baseClassName) {
|
|
439
486
|
return (className) => {
|
|
440
487
|
return `${baseClassName}-${className}`;
|
|
@@ -968,6 +1015,7 @@ export {
|
|
|
968
1015
|
isEmpty,
|
|
969
1016
|
isFile,
|
|
970
1017
|
isLetter,
|
|
1018
|
+
isLocalFile,
|
|
971
1019
|
isNumber,
|
|
972
1020
|
lastIndex,
|
|
973
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
|
}
|
package/prepend.js
CHANGED