@wavy/fn 0.0.1 → 0.0.2

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 CHANGED
@@ -498,38 +498,44 @@ function isFile(obj) {
498
498
  return true;
499
499
  return false;
500
500
  }
501
- function toObject(object, ...args) {
502
- if (isFile(object)) {
503
- const options = args[0];
501
+ var toObject = new class T {
502
+ fileToLocalFile(file, options) {
504
503
  const fileName = (() => {
505
- const fileExt = getFileExt(object.name);
504
+ const fileExt = getFileExt(file.name);
506
505
  if (options?.filename && options.filename.includes(fileExt))
507
506
  return options.filename;
508
507
  else if (options?.filename) return options.filename.trim() + fileExt;
509
- return object.name;
508
+ return file.name;
510
509
  })()?.trim?.();
511
510
  return {
512
511
  uid: (0, import_uuid.v4)(),
513
512
  description: options?.description,
514
- path: options?.filepath || object.webkitRelativePath,
513
+ path: options?.filepath || file.webkitRelativePath,
515
514
  typeAlias: options?.typeAlias || run(
516
515
  Object.keys(import_types.LOCAL_FILE_MIME_TYPES).find(
517
- (key) => import_types.LOCAL_FILE_MIME_TYPES[key].includes(object.type)
516
+ (key) => import_types.LOCAL_FILE_MIME_TYPES[key].includes(file.type)
518
517
  ),
519
518
  (type) => {
520
519
  if (!type) {
521
- (0, import_console.log)("An unknown file type was found ", object.type);
520
+ (0, import_console.log)("An unknown file type was found ", file.type);
522
521
  return "unknown";
523
522
  }
524
523
  return type;
525
524
  }
526
525
  ),
527
- sizeInBytes: object.size,
528
- uploadDate: options?.uploadDate === "now" ? Date.now() : options?.uploadDate ?? object.lastModified,
526
+ sizeInBytes: file.size,
527
+ uploadDate: options?.uploadDate === "now" ? Date.now() : options?.uploadDate ?? file.lastModified,
529
528
  name: fileName
530
529
  };
531
530
  }
532
- }
531
+ invoke(...args) {
532
+ if (isFile(args[0]))
533
+ return this.fileToLocalFile(
534
+ ...args
535
+ );
536
+ else throw new Error(`The arguments supplied are insufficient.`);
537
+ }
538
+ }().invoke;
533
539
  function classNameResolver(baseClassName) {
534
540
  return (className) => {
535
541
  return `${baseClassName}-${className}`;
package/dist/main.d.cts CHANGED
@@ -50,15 +50,13 @@ declare const addressToString: (address: Address | undefined, inline?: boolean)
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
52
  declare function isFile(obj: unknown): obj is File;
53
- declare function toObject<O extends File>(object: O, ...args: O extends File ? [
54
- options?: Partial<{
55
- uploadDate: number | "now";
56
- description: string;
57
- filepath: string;
58
- filename: string;
59
- typeAlias: LocalFile["typeAlias"];
60
- }>
61
- ] : []): O extends File ? LocalFile | undefined : void;
53
+ declare const toObject: (file: File, options?: Partial<{
54
+ uploadDate: number | "now";
55
+ description: string;
56
+ filepath: string;
57
+ filename: string;
58
+ typeAlias: LocalFile["typeAlias"];
59
+ }> | undefined) => LocalFile;
62
60
  declare function classNameResolver(baseClassName: string): (className: string) => string;
63
61
  declare function classNameExt(rootClassName: string): (className: string) => string;
64
62
  declare function range(start: number, end: number): number[];
package/dist/main.d.ts CHANGED
@@ -50,15 +50,13 @@ declare const addressToString: (address: Address | undefined, inline?: boolean)
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
52
  declare function isFile(obj: unknown): obj is File;
53
- declare function toObject<O extends File>(object: O, ...args: O extends File ? [
54
- options?: Partial<{
55
- uploadDate: number | "now";
56
- description: string;
57
- filepath: string;
58
- filename: string;
59
- typeAlias: LocalFile["typeAlias"];
60
- }>
61
- ] : []): O extends File ? LocalFile | undefined : void;
53
+ declare const toObject: (file: File, options?: Partial<{
54
+ uploadDate: number | "now";
55
+ description: string;
56
+ filepath: string;
57
+ filename: string;
58
+ typeAlias: LocalFile["typeAlias"];
59
+ }> | undefined) => LocalFile;
62
60
  declare function classNameResolver(baseClassName: string): (className: string) => string;
63
61
  declare function classNameExt(rootClassName: string): (className: string) => string;
64
62
  declare function range(start: number, end: number): number[];
package/dist/main.js CHANGED
@@ -403,38 +403,44 @@ function isFile(obj) {
403
403
  return true;
404
404
  return false;
405
405
  }
406
- function toObject(object, ...args) {
407
- if (isFile(object)) {
408
- const options = args[0];
406
+ var toObject = new class T {
407
+ fileToLocalFile(file, options) {
409
408
  const fileName = (() => {
410
- const fileExt = getFileExt(object.name);
409
+ const fileExt = getFileExt(file.name);
411
410
  if (options?.filename && options.filename.includes(fileExt))
412
411
  return options.filename;
413
412
  else if (options?.filename) return options.filename.trim() + fileExt;
414
- return object.name;
413
+ return file.name;
415
414
  })()?.trim?.();
416
415
  return {
417
416
  uid: v4(),
418
417
  description: options?.description,
419
- path: options?.filepath || object.webkitRelativePath,
418
+ path: options?.filepath || file.webkitRelativePath,
420
419
  typeAlias: options?.typeAlias || run(
421
420
  Object.keys(LOCAL_FILE_MIME_TYPES).find(
422
- (key) => LOCAL_FILE_MIME_TYPES[key].includes(object.type)
421
+ (key) => LOCAL_FILE_MIME_TYPES[key].includes(file.type)
423
422
  ),
424
423
  (type) => {
425
424
  if (!type) {
426
- log("An unknown file type was found ", object.type);
425
+ log("An unknown file type was found ", file.type);
427
426
  return "unknown";
428
427
  }
429
428
  return type;
430
429
  }
431
430
  ),
432
- sizeInBytes: object.size,
433
- uploadDate: options?.uploadDate === "now" ? Date.now() : options?.uploadDate ?? object.lastModified,
431
+ sizeInBytes: file.size,
432
+ uploadDate: options?.uploadDate === "now" ? Date.now() : options?.uploadDate ?? file.lastModified,
434
433
  name: fileName
435
434
  };
436
435
  }
437
- }
436
+ invoke(...args) {
437
+ if (isFile(args[0]))
438
+ return this.fileToLocalFile(
439
+ ...args
440
+ );
441
+ else throw new Error(`The arguments supplied are insufficient.`);
442
+ }
443
+ }().invoke;
438
444
  function classNameResolver(baseClassName) {
439
445
  return (className) => {
440
446
  return `${baseClassName}-${className}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wavy/fn",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "main": "./dist/main.js",
5
5
  "module": "./dist/main.cjs",
6
6
  "types": "./dist/main.d.ts",
package/prepend.js CHANGED
@@ -11,3 +11,4 @@ import("fs").then((fs) => {
11
11
 
12
12
  handlePrepend('import "@wavy/types"');
13
13
  });
14
+