@wavy/fn 0.0.14 → 0.0.16

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
@@ -454,8 +454,8 @@ var import_uuid = require("uuid");
454
454
  var import_types = require("@wavy/types");
455
455
  var import_console = require("console");
456
456
  function fileToLocalFile(file, options) {
457
+ const fileExt = getFileExt(file.name);
457
458
  const fileName = (() => {
458
- const fileExt = getFileExt(file.name);
459
459
  if (options?.filename && options.filename.includes(fileExt))
460
460
  return options.filename;
461
461
  else if (options?.filename) return options.filename.trim() + fileExt;
@@ -465,6 +465,7 @@ function fileToLocalFile(file, options) {
465
465
  return {
466
466
  uid: options?.uid || (0, import_uuid.v4)(),
467
467
  description: options?.description,
468
+ ext: fileExt,
468
469
  path: options?.filepath || file?.webkitRelativePath,
469
470
  typeAlias: options?.typeAlias || run(
470
471
  Object.keys(import_types.LOCAL_FILE_MIME_TYPES).find(
@@ -563,6 +564,7 @@ function isLocalFile(value) {
563
564
  description: "",
564
565
  path: "",
565
566
  sizeInBytes: 0,
567
+ ext: "",
566
568
  typeAlias: "unknown",
567
569
  uid: "",
568
570
  uploadDate: 0,
@@ -659,9 +661,10 @@ function undefinedIfEmpty(value) {
659
661
  if (value.length > 0) return value;
660
662
  }
661
663
  function ifEmpty(value, fallback) {
662
- return isEmpty(value) ? fallback : value;
664
+ return isEmpty(value) || !value ? fallback : value;
663
665
  }
664
666
  function windowed(arr, count2) {
667
+ if (!arr) return arr;
665
668
  const newArr = Array.from(
666
669
  Array(Math.floor(arr.length / count2 + arr.length % count2))
667
670
  ).map(() => []);
@@ -670,7 +673,7 @@ function windowed(arr, count2) {
670
673
  }
671
674
  function group(arr, isGroup) {
672
675
  const groups = [];
673
- arr.forEach((value) => {
676
+ arr?.forEach?.((value) => {
674
677
  const groupIdx = groups.findIndex(
675
678
  (group2) => group2.every((groupVal) => isGroup(value, groupVal))
676
679
  );
@@ -683,20 +686,20 @@ function group(arr, isGroup) {
683
686
  return groups;
684
687
  }
685
688
  function strictArray(arr) {
686
- return arr.filter(
689
+ return (arr || []).filter(
687
690
  (val) => typeof val === "string" ? val.trim().length > 0 : val !== void 0 && val !== null
688
691
  );
689
692
  }
690
693
  function maxOf(arr) {
691
694
  const fmtArr = strictArray(arr);
692
- return isEmpty(arr) ? 0 : fmtArr.reduce((prev, current) => current > prev ? current : prev);
695
+ return isEmpty(fmtArr) ? 0 : fmtArr.reduce((prev, current) => current > prev ? current : prev);
693
696
  }
694
697
  function minOf(arr) {
695
- const fmtArr = strictArray(arr);
696
- return isEmpty(arr) ? 0 : fmtArr.reduce((prev, current) => current < prev ? current : prev);
698
+ const fmtArr = strictArray(arr || []);
699
+ return isEmpty(fmtArr) ? 0 : fmtArr.reduce((prev, current) => current < prev ? current : prev);
697
700
  }
698
701
  function averageOf(arr) {
699
- const fmtArr = strictArray(arr);
702
+ const fmtArr = strictArray(arr || []);
700
703
  return isEmpty(fmtArr) ? 0 : sumOf(fmtArr) / fmtArr.length;
701
704
  }
702
705
  function run(value, fn) {
@@ -725,7 +728,7 @@ function sort(arr, sortBy, order = "asc") {
725
728
  }
726
729
  return order === "asc" ? queryA < queryB : queryA > queryB;
727
730
  };
728
- return arr.toSorted(
731
+ return (arr || []).toSorted(
729
732
  (a, b) => sortOrder(a, b) ? -1 : queryObj(a) === queryObj(b) ? 0 : 1
730
733
  );
731
734
  }
@@ -736,7 +739,7 @@ function insertAt(arr, index, value) {
736
739
  return arr.toSpliced(index, 0, value);
737
740
  }
738
741
  function overwrite(arr, index, newValue) {
739
- return arr.with(index, newValue);
742
+ return (arr || []).with(index, newValue);
740
743
  }
741
744
  function take(value, amount) {
742
745
  return [...value].splice(0, amount);
@@ -799,7 +802,7 @@ function mapToArray(map2) {
799
802
  }
800
803
  function distinct(arr) {
801
804
  const newArr = [];
802
- arr.forEach((value) => {
805
+ (arr || []).forEach((value) => {
803
806
  if (!newArr.includes(value)) newArr.push(value);
804
807
  });
805
808
  return newArr;
package/dist/main.d.cts CHANGED
@@ -1,4 +1,7 @@
1
1
  import "@wavy/types"
2
+ import * as _wavy_types from '@wavy/types';
3
+ import { LocalFile, SanitizeFile, KnownFileTypeAlias, TaskResult, FromServer, NormalizeFromServer } from '@wavy/types';
4
+
2
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";
3
6
 
4
7
  type NumberFormatterTypes = {
@@ -56,9 +59,9 @@ declare const getCaps: (value: string, count?: number) => string[];
56
59
  declare const toNumber: typeof StringFormatter.toNumber;
57
60
  declare const addArticle: typeof StringFormatter.addArticle;
58
61
  declare const pluralize: typeof StringFormatter.pluralize;
59
- declare const nameToString: (name: Name | undefined) => string;
60
- declare const phoneNoToString: (phoneNumber: PhoneNumber | undefined) => string;
61
- declare const addressToString: (address: Address | undefined, inline?: boolean) => string;
62
+ declare const nameToString: (name: _wavy_types.Name | undefined) => string;
63
+ declare const phoneNoToString: (phoneNumber: _wavy_types.PhoneNumber | undefined) => string;
64
+ declare const addressToString: (address: _wavy_types.Address | undefined, inline?: boolean) => string;
62
65
  declare const toMoney: (value: string | number, options?: NumberFormatterTypes["options"]["money"]) => string;
63
66
  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;
64
67
  declare function sanitizeLocalFile({ _metadata: _, ...file }: LocalFile): SanitizeFile<LocalFile>;
package/dist/main.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  import "@wavy/types"
2
+ import * as _wavy_types from '@wavy/types';
3
+ import { LocalFile, SanitizeFile, KnownFileTypeAlias, TaskResult, FromServer, NormalizeFromServer } from '@wavy/types';
4
+
2
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";
3
6
 
4
7
  type NumberFormatterTypes = {
@@ -56,9 +59,9 @@ declare const getCaps: (value: string, count?: number) => string[];
56
59
  declare const toNumber: typeof StringFormatter.toNumber;
57
60
  declare const addArticle: typeof StringFormatter.addArticle;
58
61
  declare const pluralize: typeof StringFormatter.pluralize;
59
- declare const nameToString: (name: Name | undefined) => string;
60
- declare const phoneNoToString: (phoneNumber: PhoneNumber | undefined) => string;
61
- declare const addressToString: (address: Address | undefined, inline?: boolean) => string;
62
+ declare const nameToString: (name: _wavy_types.Name | undefined) => string;
63
+ declare const phoneNoToString: (phoneNumber: _wavy_types.PhoneNumber | undefined) => string;
64
+ declare const addressToString: (address: _wavy_types.Address | undefined, inline?: boolean) => string;
62
65
  declare const toMoney: (value: string | number, options?: NumberFormatterTypes["options"]["money"]) => string;
63
66
  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;
64
67
  declare function sanitizeLocalFile({ _metadata: _, ...file }: LocalFile): SanitizeFile<LocalFile>;
package/dist/main.js CHANGED
@@ -1,5 +1,7 @@
1
1
  // src/helper-functions/HelperFunctions.ts
2
- import { LOCAL_FILE_MIME_TYPES as LOCAL_FILE_MIME_TYPES2 } from "@wavy/types";
2
+ import {
3
+ LOCAL_FILE_MIME_TYPES as LOCAL_FILE_MIME_TYPES2
4
+ } from "@wavy/types";
3
5
 
4
6
  // src/helper-functions/components/formatter/number/NumberFormatter.ts
5
7
  var NumberFormatter = class _NumberFormatter {
@@ -357,8 +359,8 @@ import { v4 } from "uuid";
357
359
  import { LOCAL_FILE_MIME_TYPES } from "@wavy/types";
358
360
  import { log } from "console";
359
361
  function fileToLocalFile(file, options) {
362
+ const fileExt = getFileExt(file.name);
360
363
  const fileName = (() => {
361
- const fileExt = getFileExt(file.name);
362
364
  if (options?.filename && options.filename.includes(fileExt))
363
365
  return options.filename;
364
366
  else if (options?.filename) return options.filename.trim() + fileExt;
@@ -368,6 +370,7 @@ function fileToLocalFile(file, options) {
368
370
  return {
369
371
  uid: options?.uid || v4(),
370
372
  description: options?.description,
373
+ ext: fileExt,
371
374
  path: options?.filepath || file?.webkitRelativePath,
372
375
  typeAlias: options?.typeAlias || run(
373
376
  Object.keys(LOCAL_FILE_MIME_TYPES).find(
@@ -466,6 +469,7 @@ function isLocalFile(value) {
466
469
  description: "",
467
470
  path: "",
468
471
  sizeInBytes: 0,
472
+ ext: "",
469
473
  typeAlias: "unknown",
470
474
  uid: "",
471
475
  uploadDate: 0,
@@ -562,9 +566,10 @@ function undefinedIfEmpty(value) {
562
566
  if (value.length > 0) return value;
563
567
  }
564
568
  function ifEmpty(value, fallback) {
565
- return isEmpty(value) ? fallback : value;
569
+ return isEmpty(value) || !value ? fallback : value;
566
570
  }
567
571
  function windowed(arr, count2) {
572
+ if (!arr) return arr;
568
573
  const newArr = Array.from(
569
574
  Array(Math.floor(arr.length / count2 + arr.length % count2))
570
575
  ).map(() => []);
@@ -573,7 +578,7 @@ function windowed(arr, count2) {
573
578
  }
574
579
  function group(arr, isGroup) {
575
580
  const groups = [];
576
- arr.forEach((value) => {
581
+ arr?.forEach?.((value) => {
577
582
  const groupIdx = groups.findIndex(
578
583
  (group2) => group2.every((groupVal) => isGroup(value, groupVal))
579
584
  );
@@ -586,20 +591,20 @@ function group(arr, isGroup) {
586
591
  return groups;
587
592
  }
588
593
  function strictArray(arr) {
589
- return arr.filter(
594
+ return (arr || []).filter(
590
595
  (val) => typeof val === "string" ? val.trim().length > 0 : val !== void 0 && val !== null
591
596
  );
592
597
  }
593
598
  function maxOf(arr) {
594
599
  const fmtArr = strictArray(arr);
595
- return isEmpty(arr) ? 0 : fmtArr.reduce((prev, current) => current > prev ? current : prev);
600
+ return isEmpty(fmtArr) ? 0 : fmtArr.reduce((prev, current) => current > prev ? current : prev);
596
601
  }
597
602
  function minOf(arr) {
598
- const fmtArr = strictArray(arr);
599
- return isEmpty(arr) ? 0 : fmtArr.reduce((prev, current) => current < prev ? current : prev);
603
+ const fmtArr = strictArray(arr || []);
604
+ return isEmpty(fmtArr) ? 0 : fmtArr.reduce((prev, current) => current < prev ? current : prev);
600
605
  }
601
606
  function averageOf(arr) {
602
- const fmtArr = strictArray(arr);
607
+ const fmtArr = strictArray(arr || []);
603
608
  return isEmpty(fmtArr) ? 0 : sumOf(fmtArr) / fmtArr.length;
604
609
  }
605
610
  function run(value, fn) {
@@ -628,7 +633,7 @@ function sort(arr, sortBy, order = "asc") {
628
633
  }
629
634
  return order === "asc" ? queryA < queryB : queryA > queryB;
630
635
  };
631
- return arr.toSorted(
636
+ return (arr || []).toSorted(
632
637
  (a, b) => sortOrder(a, b) ? -1 : queryObj(a) === queryObj(b) ? 0 : 1
633
638
  );
634
639
  }
@@ -639,7 +644,7 @@ function insertAt(arr, index, value) {
639
644
  return arr.toSpliced(index, 0, value);
640
645
  }
641
646
  function overwrite(arr, index, newValue) {
642
- return arr.with(index, newValue);
647
+ return (arr || []).with(index, newValue);
643
648
  }
644
649
  function take(value, amount) {
645
650
  return [...value].splice(0, amount);
@@ -702,7 +707,7 @@ function mapToArray(map2) {
702
707
  }
703
708
  function distinct(arr) {
704
709
  const newArr = [];
705
- arr.forEach((value) => {
710
+ (arr || []).forEach((value) => {
706
711
  if (!newArr.includes(value)) newArr.push(value);
707
712
  });
708
713
  return newArr;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wavy/fn",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
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.32",
25
+ "@wavy/types": "^0.0.43",
26
26
  "tsup": "^8.5.0",
27
27
  "typescript": "^5.9.2"
28
28
  },
package/prepend.js DELETED
@@ -1,14 +0,0 @@
1
- import("fs").then((fs) => {
2
- const paths = ["./dist/main.d.ts", "./dist/main.d.cts"];
3
- const handlePrepend = (...args) => {
4
- const text = args.join("\n");
5
-
6
- paths.forEach((path) => {
7
- const data = fs.readFileSync(path)
8
- fs.writeFileSync(path, text + "\n" + data);
9
- });
10
- };
11
-
12
- handlePrepend('import "@wavy/types"');
13
- });
14
-
package/publish.js DELETED
@@ -1,37 +0,0 @@
1
- import("child_process").then(async ({ exec }) => {
2
- const fs = await import("fs");
3
- const console = await import("console");
4
- const jsonPackage = JSON.parse(
5
- fs.readFileSync("./package.json").toString("utf-8")
6
- );
7
- const version = jsonPackage.version;
8
- let newVersion = "";
9
- const updateVersion = async () => {
10
- return new Promise((res, rej) => {
11
- exec("npm version patch", (err, stdout, stderr) => {
12
- if (err) rej(err);
13
- res({ stdout, stderr });
14
- });
15
- });
16
- };
17
- updateVersion();
18
- exec("npm run build && npm publish", async (err) => {
19
- const overwriteVersionError = `Cannot implicitly apply the "latest" tag because published version ${version} is higher than the new version ${version}.`;
20
- const getSuccessMessage = (tries = 1) =>
21
- `✨ Successfully published package (${
22
- newVersion ? `v${version}-v${newVersion}` : `v${version}`
23
- }) after ${tries} tries 😁! ✨`;
24
-
25
- if (err && err.message.includes(overwriteVersionError)) {
26
- updateVersion();
27
- exec("npm publish", (err) => {
28
- if (err) console.error(err);
29
- else console.log(getSuccessMessage(2));
30
- });
31
- } else if (err) {
32
- console.log(err);
33
- } else {
34
- console.log(getSuccessMessage());
35
- }
36
- });
37
- });