@wavy/fn 0.0.13 → 0.0.15

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
@@ -39,8 +39,6 @@ __export(main_exports, {
39
39
  dropLastWhile: () => dropLastWhile,
40
40
  dropWhile: () => dropWhile,
41
41
  format: () => format,
42
- formatGCTRegNo: () => formatGCTRegNo,
43
- formatInvoiceNo: () => formatInvoiceNo,
44
42
  getCaps: () => getCaps,
45
43
  getFileExt: () => getFileExt,
46
44
  getFilename: () => getFilename,
@@ -75,6 +73,7 @@ __export(main_exports, {
75
73
  removeAll: () => removeAll,
76
74
  repeat: () => repeat,
77
75
  run: () => run,
76
+ sanitizeLocalFile: () => sanitizeLocalFile,
78
77
  serverDataAdapter: () => serverDataAdapter,
79
78
  someValuesEmpty: () => someValuesEmpty,
80
79
  sort: () => sort,
@@ -279,9 +278,6 @@ var StringFormatter_default = StringFormatter;
279
278
 
280
279
  // src/helper-functions/components/time/TimeManager.ts
281
280
  var TimeManager = class _TimeManager {
282
- constructor(locale = "en-jm") {
283
- this.locale = locale;
284
- }
285
281
  static periods = {
286
282
  overview: {
287
283
  getPrevious: (period) => {
@@ -387,7 +383,7 @@ var TimeManager = class _TimeManager {
387
383
  };
388
384
  break;
389
385
  }
390
- const fmtDate = convertedDate.toLocaleDateString(this.locale, options);
386
+ const fmtDate = convertedDate.toLocaleDateString(void 0, options);
391
387
  if (format2 === "MMMM")
392
388
  return takeWhile(fmtDate.split(""), (char) => char !== " ").join("");
393
389
  if (format2 === "yyyy") return takeLast(fmtDate.split(""), 4).join("");
@@ -543,6 +539,12 @@ function format(event, ...args) {
543
539
  return event;
544
540
  }
545
541
  }
542
+ function sanitizeLocalFile({
543
+ _metadata: _,
544
+ ...file
545
+ }) {
546
+ return file;
547
+ }
546
548
  function isFile(value) {
547
549
  const requiredKeys = [
548
550
  "name",
@@ -617,12 +619,6 @@ function indexOf(arr, key, value) {
617
619
  if (!queriedValue) return;
618
620
  return arr.indexOf(queriedValue);
619
621
  }
620
- function formatInvoiceNo(invoiceNo) {
621
- return `INV-${invoiceNo}`;
622
- }
623
- function formatGCTRegNo(regNo) {
624
- return `GCT-${regNo}`;
625
- }
626
622
  function indices(arr) {
627
623
  return arr.map((_, idx) => idx);
628
624
  }
@@ -635,10 +631,12 @@ function repeat(count2, func) {
635
631
  }
636
632
  }
637
633
  function isLetter(value) {
638
- return "abcdefghijklmnopqrstuvwxyz".includes(value.toLowerCase());
634
+ if (value.length !== 1)
635
+ throw new Error(`Expected a single character but ${value} was provided.`);
636
+ return /[a-zA-A]/.test(value);
639
637
  }
640
638
  function isNumber(value) {
641
- return "0123456789".includes(value);
639
+ return !!parseFloat(value);
642
640
  }
643
641
  function count(searchFor, arrayish) {
644
642
  const fmtArr = typeof arrayish === "string" ? arrayish.split("") : arrayish;
@@ -661,9 +659,10 @@ function undefinedIfEmpty(value) {
661
659
  if (value.length > 0) return value;
662
660
  }
663
661
  function ifEmpty(value, fallback) {
664
- return isEmpty(value) ? fallback : value;
662
+ return isEmpty(value) || !value ? fallback : value;
665
663
  }
666
664
  function windowed(arr, count2) {
665
+ if (!arr) return arr;
667
666
  const newArr = Array.from(
668
667
  Array(Math.floor(arr.length / count2 + arr.length % count2))
669
668
  ).map(() => []);
@@ -672,7 +671,7 @@ function windowed(arr, count2) {
672
671
  }
673
672
  function group(arr, isGroup) {
674
673
  const groups = [];
675
- arr.forEach((value) => {
674
+ arr?.forEach?.((value) => {
676
675
  const groupIdx = groups.findIndex(
677
676
  (group2) => group2.every((groupVal) => isGroup(value, groupVal))
678
677
  );
@@ -685,20 +684,20 @@ function group(arr, isGroup) {
685
684
  return groups;
686
685
  }
687
686
  function strictArray(arr) {
688
- return arr.filter(
687
+ return arr?.filter?.(
689
688
  (val) => typeof val === "string" ? val.trim().length > 0 : val !== void 0 && val !== null
690
689
  );
691
690
  }
692
691
  function maxOf(arr) {
693
- const fmtArr = strictArray(arr);
692
+ const fmtArr = strictArray(arr || []);
694
693
  return isEmpty(arr) ? 0 : fmtArr.reduce((prev, current) => current > prev ? current : prev);
695
694
  }
696
695
  function minOf(arr) {
697
- const fmtArr = strictArray(arr);
696
+ const fmtArr = strictArray(arr || []);
698
697
  return isEmpty(arr) ? 0 : fmtArr.reduce((prev, current) => current < prev ? current : prev);
699
698
  }
700
699
  function averageOf(arr) {
701
- const fmtArr = strictArray(arr);
700
+ const fmtArr = strictArray(arr || []);
702
701
  return isEmpty(fmtArr) ? 0 : sumOf(fmtArr) / fmtArr.length;
703
702
  }
704
703
  function run(value, fn) {
@@ -1101,8 +1100,6 @@ var serverDataAdapter = new ServerDataAdapter().invoke;
1101
1100
  dropLastWhile,
1102
1101
  dropWhile,
1103
1102
  format,
1104
- formatGCTRegNo,
1105
- formatInvoiceNo,
1106
1103
  getCaps,
1107
1104
  getFileExt,
1108
1105
  getFilename,
@@ -1137,6 +1134,7 @@ var serverDataAdapter = new ServerDataAdapter().invoke;
1137
1134
  removeAll,
1138
1135
  repeat,
1139
1136
  run,
1137
+ sanitizeLocalFile,
1140
1138
  serverDataAdapter,
1141
1139
  someValuesEmpty,
1142
1140
  sort,
package/dist/main.d.cts CHANGED
@@ -61,6 +61,7 @@ declare const phoneNoToString: (phoneNumber: PhoneNumber | undefined) => string;
61
61
  declare const addressToString: (address: Address | undefined, inline?: boolean) => string;
62
62
  declare const toMoney: (value: string | number, options?: NumberFormatterTypes["options"]["money"]) => string;
63
63
  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
+ declare function sanitizeLocalFile({ _metadata: _, ...file }: LocalFile): SanitizeFile<LocalFile>;
64
65
  declare function isFile(value: unknown): value is File;
65
66
  declare function isLocalFile(value: unknown): value is LocalFile;
66
67
  declare function getMimeTypes(typeAliases: KnownFileTypeAlias[]): string[];
@@ -81,8 +82,6 @@ declare function ordinalIndicator(amount: number): string;
81
82
  *
82
83
  */
83
84
  declare function indexOf<O extends object, K extends keyof O>(arr: O[], key: K, value: O[K]): number | undefined;
84
- declare function formatInvoiceNo(invoiceNo: string): string;
85
- declare function formatGCTRegNo(regNo: string): string;
86
85
  declare function indices(arr: unknown[]): number[];
87
86
  declare function hasIndex(arr: unknown[], index: number): boolean;
88
87
  declare function repeat<T>(count: number, func: (idx: number) => T): void;
@@ -183,4 +182,4 @@ declare const serverDataAdapter: {
183
182
  }>(event: "unzip", data: DataType): NormalizeFromServer<DataType>;
184
183
  };
185
184
 
186
- export { addArticle, arrayWithConst, asyncRun, averageOf, blankSpaces, buildArray, camelCaseToLetter, classNameExt, classNameResolver, coerceIn, copyToClipboard, count, dataSearcher, distinct, drop, dropLast, dropLastWhile, dropWhile, format, formatGCTRegNo, formatInvoiceNo, getCaps, getFileExt, getFilename, getMimeTypes, 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 };
185
+ export { addArticle, arrayWithConst, asyncRun, averageOf, blankSpaces, buildArray, camelCaseToLetter, classNameExt, classNameResolver, coerceIn, copyToClipboard, count, dataSearcher, distinct, drop, dropLast, dropLastWhile, dropWhile, format, getCaps, getFileExt, getFilename, getMimeTypes, 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, sanitizeLocalFile, serverDataAdapter, someValuesEmpty, sort, strictArray, stringToSearch, subObjectList, sumOf, take, takeLast, takeLastWhile, takeWhile, timeDuration, toNumber, toObject, trimString, undefinedIfEmpty, upperFirst, windowed };
package/dist/main.d.ts CHANGED
@@ -61,6 +61,7 @@ declare const phoneNoToString: (phoneNumber: PhoneNumber | undefined) => string;
61
61
  declare const addressToString: (address: Address | undefined, inline?: boolean) => string;
62
62
  declare const toMoney: (value: string | number, options?: NumberFormatterTypes["options"]["money"]) => string;
63
63
  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
+ declare function sanitizeLocalFile({ _metadata: _, ...file }: LocalFile): SanitizeFile<LocalFile>;
64
65
  declare function isFile(value: unknown): value is File;
65
66
  declare function isLocalFile(value: unknown): value is LocalFile;
66
67
  declare function getMimeTypes(typeAliases: KnownFileTypeAlias[]): string[];
@@ -81,8 +82,6 @@ declare function ordinalIndicator(amount: number): string;
81
82
  *
82
83
  */
83
84
  declare function indexOf<O extends object, K extends keyof O>(arr: O[], key: K, value: O[K]): number | undefined;
84
- declare function formatInvoiceNo(invoiceNo: string): string;
85
- declare function formatGCTRegNo(regNo: string): string;
86
85
  declare function indices(arr: unknown[]): number[];
87
86
  declare function hasIndex(arr: unknown[], index: number): boolean;
88
87
  declare function repeat<T>(count: number, func: (idx: number) => T): void;
@@ -183,4 +182,4 @@ declare const serverDataAdapter: {
183
182
  }>(event: "unzip", data: DataType): NormalizeFromServer<DataType>;
184
183
  };
185
184
 
186
- export { addArticle, arrayWithConst, asyncRun, averageOf, blankSpaces, buildArray, camelCaseToLetter, classNameExt, classNameResolver, coerceIn, copyToClipboard, count, dataSearcher, distinct, drop, dropLast, dropLastWhile, dropWhile, format, formatGCTRegNo, formatInvoiceNo, getCaps, getFileExt, getFilename, getMimeTypes, 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 };
185
+ export { addArticle, arrayWithConst, asyncRun, averageOf, blankSpaces, buildArray, camelCaseToLetter, classNameExt, classNameResolver, coerceIn, copyToClipboard, count, dataSearcher, distinct, drop, dropLast, dropLastWhile, dropWhile, format, getCaps, getFileExt, getFilename, getMimeTypes, 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, sanitizeLocalFile, serverDataAdapter, someValuesEmpty, sort, strictArray, stringToSearch, subObjectList, sumOf, take, takeLast, takeLastWhile, takeWhile, timeDuration, toNumber, toObject, trimString, undefinedIfEmpty, upperFirst, windowed };
package/dist/main.js CHANGED
@@ -181,9 +181,6 @@ var StringFormatter_default = StringFormatter;
181
181
 
182
182
  // src/helper-functions/components/time/TimeManager.ts
183
183
  var TimeManager = class _TimeManager {
184
- constructor(locale = "en-jm") {
185
- this.locale = locale;
186
- }
187
184
  static periods = {
188
185
  overview: {
189
186
  getPrevious: (period) => {
@@ -289,7 +286,7 @@ var TimeManager = class _TimeManager {
289
286
  };
290
287
  break;
291
288
  }
292
- const fmtDate = convertedDate.toLocaleDateString(this.locale, options);
289
+ const fmtDate = convertedDate.toLocaleDateString(void 0, options);
293
290
  if (format2 === "MMMM")
294
291
  return takeWhile(fmtDate.split(""), (char) => char !== " ").join("");
295
292
  if (format2 === "yyyy") return takeLast(fmtDate.split(""), 4).join("");
@@ -445,6 +442,12 @@ function format(event, ...args) {
445
442
  return event;
446
443
  }
447
444
  }
445
+ function sanitizeLocalFile({
446
+ _metadata: _,
447
+ ...file
448
+ }) {
449
+ return file;
450
+ }
448
451
  function isFile(value) {
449
452
  const requiredKeys = [
450
453
  "name",
@@ -519,12 +522,6 @@ function indexOf(arr, key, value) {
519
522
  if (!queriedValue) return;
520
523
  return arr.indexOf(queriedValue);
521
524
  }
522
- function formatInvoiceNo(invoiceNo) {
523
- return `INV-${invoiceNo}`;
524
- }
525
- function formatGCTRegNo(regNo) {
526
- return `GCT-${regNo}`;
527
- }
528
525
  function indices(arr) {
529
526
  return arr.map((_, idx) => idx);
530
527
  }
@@ -537,10 +534,12 @@ function repeat(count2, func) {
537
534
  }
538
535
  }
539
536
  function isLetter(value) {
540
- return "abcdefghijklmnopqrstuvwxyz".includes(value.toLowerCase());
537
+ if (value.length !== 1)
538
+ throw new Error(`Expected a single character but ${value} was provided.`);
539
+ return /[a-zA-A]/.test(value);
541
540
  }
542
541
  function isNumber(value) {
543
- return "0123456789".includes(value);
542
+ return !!parseFloat(value);
544
543
  }
545
544
  function count(searchFor, arrayish) {
546
545
  const fmtArr = typeof arrayish === "string" ? arrayish.split("") : arrayish;
@@ -563,9 +562,10 @@ function undefinedIfEmpty(value) {
563
562
  if (value.length > 0) return value;
564
563
  }
565
564
  function ifEmpty(value, fallback) {
566
- return isEmpty(value) ? fallback : value;
565
+ return isEmpty(value) || !value ? fallback : value;
567
566
  }
568
567
  function windowed(arr, count2) {
568
+ if (!arr) return arr;
569
569
  const newArr = Array.from(
570
570
  Array(Math.floor(arr.length / count2 + arr.length % count2))
571
571
  ).map(() => []);
@@ -574,7 +574,7 @@ function windowed(arr, count2) {
574
574
  }
575
575
  function group(arr, isGroup) {
576
576
  const groups = [];
577
- arr.forEach((value) => {
577
+ arr?.forEach?.((value) => {
578
578
  const groupIdx = groups.findIndex(
579
579
  (group2) => group2.every((groupVal) => isGroup(value, groupVal))
580
580
  );
@@ -587,20 +587,20 @@ function group(arr, isGroup) {
587
587
  return groups;
588
588
  }
589
589
  function strictArray(arr) {
590
- return arr.filter(
590
+ return arr?.filter?.(
591
591
  (val) => typeof val === "string" ? val.trim().length > 0 : val !== void 0 && val !== null
592
592
  );
593
593
  }
594
594
  function maxOf(arr) {
595
- const fmtArr = strictArray(arr);
595
+ const fmtArr = strictArray(arr || []);
596
596
  return isEmpty(arr) ? 0 : fmtArr.reduce((prev, current) => current > prev ? current : prev);
597
597
  }
598
598
  function minOf(arr) {
599
- const fmtArr = strictArray(arr);
599
+ const fmtArr = strictArray(arr || []);
600
600
  return isEmpty(arr) ? 0 : fmtArr.reduce((prev, current) => current < prev ? current : prev);
601
601
  }
602
602
  function averageOf(arr) {
603
- const fmtArr = strictArray(arr);
603
+ const fmtArr = strictArray(arr || []);
604
604
  return isEmpty(fmtArr) ? 0 : sumOf(fmtArr) / fmtArr.length;
605
605
  }
606
606
  function run(value, fn) {
@@ -1002,8 +1002,6 @@ export {
1002
1002
  dropLastWhile,
1003
1003
  dropWhile,
1004
1004
  format,
1005
- formatGCTRegNo,
1006
- formatInvoiceNo,
1007
1005
  getCaps,
1008
1006
  getFileExt,
1009
1007
  getFilename,
@@ -1038,6 +1036,7 @@ export {
1038
1036
  removeAll,
1039
1037
  repeat,
1040
1038
  run,
1039
+ sanitizeLocalFile,
1041
1040
  serverDataAdapter,
1042
1041
  someValuesEmpty,
1043
1042
  sort,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wavy/fn",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "main": "./dist/main.js",
5
5
  "module": "./dist/main.cjs",
6
6
  "types": "./dist/main.d.ts",
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
- });