@wavy/fn 0.0.6 → 0.0.8

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
@@ -87,7 +87,6 @@ __export(main_exports, {
87
87
  takeWhile: () => takeWhile,
88
88
  timeDuration: () => timeDuration,
89
89
  toNumber: () => toNumber,
90
- toObject: () => toObject,
91
90
  trimString: () => trimString,
92
91
  undefinedIfEmpty: () => undefinedIfEmpty,
93
92
  upperFirst: () => upperFirst,
@@ -95,6 +94,187 @@ __export(main_exports, {
95
94
  });
96
95
  module.exports = __toCommonJS(main_exports);
97
96
 
97
+ // src/helper-functions/HelperFunctions.ts
98
+ var import_types2 = require("@wavy/types");
99
+
100
+ // src/helper-functions/components/formatter/number/NumberFormatter.ts
101
+ var NumberFormatter = class _NumberFormatter {
102
+ static format(value, format2, options) {
103
+ switch (format2) {
104
+ case "money":
105
+ return _NumberFormatter.toMoney(value, options);
106
+ default:
107
+ return value.toLocaleString("en-us");
108
+ }
109
+ }
110
+ static toMoney(amount, options) {
111
+ const dollarSign = options?.excludeDollarSign ? "" : "$";
112
+ if (!amount) return dollarSign + (options?.dropDecimals ? "0" : "0.00");
113
+ if (options?.truncate) {
114
+ const strAmt = takeWhile(
115
+ `${amount}`.split(""),
116
+ (char) => char !== "."
117
+ ).join("");
118
+ const fmtMoney = (value, decimal) => {
119
+ const getTruncatedSuffix = () => {
120
+ if (strAmt.length <= 3) return "";
121
+ if (range(4, 7).includes(strAmt.length)) return "k";
122
+ if (range(7, 10).includes(strAmt.length)) return "m";
123
+ if (range(10, 13).includes(strAmt.length)) return "b";
124
+ if (range(13, 16).includes(strAmt.length)) return "t";
125
+ };
126
+ const fmtValue = parseInt(decimal) > 0 ? `${value}.${decimal}` : value;
127
+ return dollarSign + fmtValue + getTruncatedSuffix();
128
+ };
129
+ if (strAmt.length <= 3) return fmtMoney(strAmt, "0");
130
+ else {
131
+ const relevantDigits = takeLast(
132
+ windowed([...strAmt.split("")].reverse(), 3).map(
133
+ (arr) => arr.reverse()
134
+ ),
135
+ 2
136
+ ).reverse();
137
+ return fmtMoney(relevantDigits[0].join(""), relevantDigits[1][0]);
138
+ }
139
+ }
140
+ return (amount < 0 ? "-" : options?.showSigns ? "+" : "") + dollarSign + amount.toLocaleString("en-US", {
141
+ minimumFractionDigits: options?.dropDecimals ? 0 : 2,
142
+ currency: "USD",
143
+ currencyDisplay: "symbol",
144
+ currencySign: "accounting",
145
+ signDisplay: "never"
146
+ });
147
+ }
148
+ };
149
+ var NumberFormatter_default = NumberFormatter;
150
+
151
+ // src/helper-functions/components/formatter/object/ObjectFormatter.ts
152
+ var ObjectFormatter = class {
153
+ static toString = {
154
+ name: (name) => name ? `${name.first} ${name.last}`.trim() : "no_name",
155
+ phoneNumber: (phoneNumber) => {
156
+ if (!phoneNumber) return "no_phone_number";
157
+ return `${phoneNumber.countryCode} (${phoneNumber.areaCode}) ${insertAt(
158
+ phoneNumber.localNumber.split(""),
159
+ 3,
160
+ "-"
161
+ ).join("")}`;
162
+ },
163
+ address: (address, inline) => {
164
+ if (address === void 0) return "no_address";
165
+ const addressKeys = Object.keys(address).map((k) => k);
166
+ const delimiter = (isLast) => !isLast ? "," + (!inline ? "\n" : "") : "";
167
+ return addressKeys.map(
168
+ (key, idx) => address[key] + delimiter(idx === lastIndex(addressKeys))
169
+ ).join("") || "no_address";
170
+ }
171
+ };
172
+ };
173
+ var ObjectFormatter_default = ObjectFormatter;
174
+
175
+ // src/helper-functions/components/input/InputManager.ts
176
+ var InputManager = class {
177
+ static manualValidators = {
178
+ percent: (value) => StringFormatter_default.toNumber(value) <= 100 && run(value.split(".")?.[1], (dec) => dec ? dec.length <= 2 : true)
179
+ };
180
+ static formatters = {
181
+ money: {
182
+ format: (value) => take(
183
+ value.split(".").map(
184
+ (sect, idx) => idx === 0 ? `${NumberFormatter_default.format(StringFormatter_default.toNumber(sect))}` : take(sect.split(""), 2).join("")
185
+ ),
186
+ 2
187
+ ).join("."),
188
+ unformat: (value) => `${StringFormatter_default.toNumber(value)}`
189
+ }
190
+ };
191
+ static separateNumbersFormatter(options = {
192
+ numbersPerGroup: 3,
193
+ separator: "-"
194
+ }) {
195
+ return {
196
+ format: (value) => {
197
+ let groupedValues = windowed(
198
+ value.split(""),
199
+ options.numbersPerGroup
200
+ ).map((v) => v.join(""));
201
+ if (options.groupCount) {
202
+ groupedValues = [
203
+ ...take(groupedValues, options.groupCount),
204
+ drop(groupedValues, options.groupCount).join("").replace(options.separator, "")
205
+ ].filter((v) => !isEmpty(v));
206
+ }
207
+ return groupedValues.join(options.separator);
208
+ },
209
+ unformat: (value) => {
210
+ const unformatted = value.replaceAll(options.separator, "");
211
+ return unformatted;
212
+ }
213
+ };
214
+ }
215
+ };
216
+ var InputManager_default = InputManager;
217
+
218
+ // src/helper-functions/components/formatter/string/StringFormatter.ts
219
+ var VOWELS = "aeiouy";
220
+ var StringFormatter = class _StringFormatter {
221
+ static vowels = VOWELS;
222
+ static caseConverter = {
223
+ camelToLetter: (camelCase) => {
224
+ return camelCase.split("").map(
225
+ (char, charIdx) => charIdx === 0 ? char.toUpperCase() : char === char.toUpperCase() && char !== char.toLowerCase() ? ` ${char}` : char
226
+ ).join("");
227
+ }
228
+ };
229
+ static extract = {
230
+ capitalLetters: (value, count2) => {
231
+ return value.split("", count2).filter(
232
+ (char) => char === char.toUpperCase() && char !== char.toLowerCase()
233
+ );
234
+ }
235
+ };
236
+ static trimString(value, trim) {
237
+ let newValue = value;
238
+ while (newValue.endsWith(trim)) {
239
+ newValue = value.split("").reverse().join("").replace(trim, "").split("").reverse().join("");
240
+ }
241
+ return newValue;
242
+ }
243
+ static pluralize(value) {
244
+ return value[value.length - 1] === "s" ? value + "es" : value + "s";
245
+ }
246
+ static addArticle(value, article) {
247
+ let fmtArticle = "";
248
+ switch (article) {
249
+ case "a/an":
250
+ fmtArticle = VOWELS.includes(value?.[0].toLowerCase()) ? "An" : "A";
251
+ break;
252
+ default:
253
+ return article;
254
+ }
255
+ return `${fmtArticle.toLowerCase()} ${value}`;
256
+ }
257
+ static toSearch(from) {
258
+ return from.split("").filter((char) => char !== " ").join("").toLowerCase().trim();
259
+ }
260
+ static toMoney(from, options) {
261
+ return NumberFormatter_default.toMoney(_StringFormatter.toNumber(from), options);
262
+ }
263
+ static toTRN(from) {
264
+ return InputManager_default.separateNumbersFormatter().format(from);
265
+ }
266
+ static toNumber(value) {
267
+ const potentialNumber = take(value.split("."), 2).join(".").split("").map(
268
+ (char, idx) => idx === 0 && char === "-" ? char : "0123456789.".includes(char) ? char : ""
269
+ ).join("");
270
+ return isEmpty(potentialNumber.trim()) ? 0 : parseFloat(potentialNumber);
271
+ }
272
+ static upperFirst(value) {
273
+ return value.split("").map((char, idx) => idx === 0 ? char.toUpperCase() : char).join("");
274
+ }
275
+ };
276
+ var StringFormatter_default = StringFormatter;
277
+
98
278
  // src/helper-functions/components/time/TimeManager.ts
99
279
  var TimeManager = class _TimeManager {
100
280
  constructor(locale = "en-jm") {
@@ -267,188 +447,61 @@ var TimeManager = class _TimeManager {
267
447
  };
268
448
  var TimeManager_default = TimeManager;
269
449
 
270
- // src/helper-functions/components/formatter/number/NumberFormatter.ts
271
- var NumberFormatter = class _NumberFormatter {
272
- static format(value, format2, options) {
273
- switch (format2) {
274
- case "money":
275
- return _NumberFormatter.toMoney(value, options);
276
- default:
277
- return value.toLocaleString("en-us");
278
- }
279
- }
280
- static toMoney(amount, options) {
281
- const dollarSign = options?.excludeDollarSign ? "" : "$";
282
- if (!amount) return dollarSign + (options?.dropDecimals ? "0" : "0.00");
283
- if (options?.truncate) {
284
- const strAmt = takeWhile(
285
- `${amount}`.split(""),
286
- (char) => char !== "."
287
- ).join("");
288
- const fmtMoney = (value, decimal) => {
289
- const getTruncatedSuffix = () => {
290
- if (strAmt.length <= 3) return "";
291
- if (range(4, 7).includes(strAmt.length)) return "k";
292
- if (range(7, 10).includes(strAmt.length)) return "m";
293
- if (range(10, 13).includes(strAmt.length)) return "b";
294
- if (range(13, 16).includes(strAmt.length)) return "t";
295
- };
296
- const fmtValue = parseInt(decimal) > 0 ? `${value}.${decimal}` : value;
297
- return dollarSign + fmtValue + getTruncatedSuffix();
298
- };
299
- if (strAmt.length <= 3) return fmtMoney(strAmt, "0");
300
- else {
301
- const relevantDigits = takeLast(
302
- windowed([...strAmt.split("")].reverse(), 3).map(
303
- (arr) => arr.reverse()
304
- ),
305
- 2
306
- ).reverse();
307
- return fmtMoney(relevantDigits[0].join(""), relevantDigits[1][0]);
308
- }
309
- }
310
- return (amount < 0 ? "-" : options?.showSigns ? "+" : "") + dollarSign + amount.toLocaleString("en-US", {
311
- minimumFractionDigits: options?.dropDecimals ? 0 : 2,
312
- currency: "USD",
313
- currencyDisplay: "symbol",
314
- currencySign: "accounting",
315
- signDisplay: "never"
316
- });
317
- }
318
- };
319
- var NumberFormatter_default = NumberFormatter;
320
-
321
- // src/helper-functions/components/input/InputManager.ts
322
- var InputManager = class {
323
- static manualValidators = {
324
- percent: (value) => StringFormatter_default.toNumber(value) <= 100 && run(value.split(".")?.[1], (dec) => dec ? dec.length <= 2 : true)
325
- };
326
- static formatters = {
327
- money: {
328
- format: (value) => take(
329
- value.split(".").map(
330
- (sect, idx) => idx === 0 ? `${NumberFormatter_default.format(StringFormatter_default.toNumber(sect))}` : take(sect.split(""), 2).join("")
331
- ),
332
- 2
333
- ).join("."),
334
- unformat: (value) => `${StringFormatter_default.toNumber(value)}`
335
- }
336
- };
337
- static separateNumbersFormatter(options = {
338
- numbersPerGroup: 3,
339
- separator: "-"
340
- }) {
341
- return {
342
- format: (value) => {
343
- let groupedValues = windowed(
344
- value.split(""),
345
- options.numbersPerGroup
346
- ).map((v) => v.join(""));
347
- if (options.groupCount) {
348
- groupedValues = [
349
- ...take(groupedValues, options.groupCount),
350
- drop(groupedValues, options.groupCount).join("").replace(options.separator, "")
351
- ].filter((v) => !isEmpty(v));
450
+ // src/helper-functions/components/ObjectConverter.ts
451
+ var import_uuid = require("uuid");
452
+ var import_types = require("@wavy/types");
453
+ var import_console = require("console");
454
+ function fileToLocalFile(file, options) {
455
+ const fileName = (() => {
456
+ const fileExt = getFileExt(file.name);
457
+ if (options?.filename && options.filename.includes(fileExt))
458
+ return options.filename;
459
+ else if (options?.filename) return options.filename.trim() + fileExt;
460
+ return file.name;
461
+ })()?.trim?.();
462
+ const { name: _, size: __, ..._metadata } = file;
463
+ return {
464
+ uid: (0, import_uuid.v4)(),
465
+ description: options?.description,
466
+ path: options?.filepath || file?.webkitRelativePath,
467
+ typeAlias: options?.typeAlias || run(
468
+ Object.keys(import_types.LOCAL_FILE_MIME_TYPES).find(
469
+ (key) => import_types.LOCAL_FILE_MIME_TYPES[key].includes(file.type)
470
+ ),
471
+ (type) => {
472
+ if (!type) {
473
+ (0, import_console.log)("An unknown file type was found ", file.type);
474
+ return "unknown";
352
475
  }
353
- return groupedValues.join(options.separator);
354
- },
355
- unformat: (value) => {
356
- const unformatted = value.replaceAll(options.separator, "");
357
- return unformatted;
476
+ return type;
358
477
  }
359
- };
360
- }
361
- };
362
- var InputManager_default = InputManager;
363
-
364
- // src/helper-functions/components/formatter/string/StringFormatter.ts
365
- var VOWELS = "aeiouy";
366
- var StringFormatter = class _StringFormatter {
367
- static vowels = VOWELS;
368
- static caseConverter = {
369
- camelToLetter: (camelCase) => {
370
- return camelCase.split("").map(
371
- (char, charIdx) => charIdx === 0 ? char.toUpperCase() : char === char.toUpperCase() && char !== char.toLowerCase() ? ` ${char}` : char
372
- ).join("");
373
- }
478
+ ),
479
+ sizeInBytes: file.size,
480
+ uploadDate: options?.uploadDate === "now" ? Date.now() : options?.uploadDate ?? file?.lastModified,
481
+ name: fileName,
482
+ _metadata
374
483
  };
375
- static extract = {
376
- capitalLetters: (value, count2) => {
377
- return value.split("", count2).filter(
378
- (char) => char === char.toUpperCase() && char !== char.toLowerCase()
379
- );
380
- }
484
+ }
485
+ function localFileToFile(localFile) {
486
+ return {
487
+ name: localFile.name,
488
+ size: localFile.sizeInBytes,
489
+ ...localFile._metadata
381
490
  };
382
- static trimString(value, trim) {
383
- let newValue = value;
384
- while (newValue.endsWith(trim)) {
385
- newValue = value.split("").reverse().join("").replace(trim, "").split("").reverse().join("");
386
- }
387
- return newValue;
388
- }
389
- static pluralize(value) {
390
- return value[value.length - 1] === "s" ? value + "es" : value + "s";
391
- }
392
- static addArticle(value, article) {
393
- let fmtArticle = "";
394
- switch (article) {
395
- case "a/an":
396
- fmtArticle = VOWELS.includes(value?.[0].toLowerCase()) ? "An" : "A";
397
- break;
398
- default:
399
- return article;
491
+ }
492
+ var Overloader = class {
493
+ invoke(...args) {
494
+ if (isFile(args[0])) {
495
+ return fileToLocalFile(...args);
400
496
  }
401
- return `${fmtArticle.toLowerCase()} ${value}`;
402
- }
403
- static toSearch(from) {
404
- return from.split("").filter((char) => char !== " ").join("").toLowerCase().trim();
405
- }
406
- static toMoney(from, options) {
407
- return NumberFormatter_default.toMoney(_StringFormatter.toNumber(from), options);
408
- }
409
- static toTRN(from) {
410
- return InputManager_default.separateNumbersFormatter().format(from);
411
- }
412
- static toNumber(value) {
413
- const potentialNumber = take(value.split("."), 2).join(".").split("").map(
414
- (char, idx) => idx === 0 && char === "-" ? char : "0123456789.".includes(char) ? char : ""
415
- ).join("");
416
- return isEmpty(potentialNumber.trim()) ? 0 : parseFloat(potentialNumber);
417
- }
418
- static upperFirst(value) {
419
- return value.split("").map((char, idx) => idx === 0 ? char.toUpperCase() : char).join("");
497
+ if (isLocalFile(args[0])) {
498
+ return localFileToFile(...args);
499
+ } else throw new Error(`The arguments supplied are insufficient.`);
420
500
  }
421
501
  };
422
- var StringFormatter_default = StringFormatter;
423
-
424
- // src/helper-functions/components/formatter/object/ObjectFormatter.ts
425
- var ObjectFormatter = class {
426
- static toString = {
427
- name: (name) => name ? `${name.first} ${name.last}`.trim() : "no_name",
428
- phoneNumber: (phoneNumber) => {
429
- if (!phoneNumber) return "no_phone_number";
430
- return `${phoneNumber.countryCode} (${phoneNumber.areaCode}) ${insertAt(
431
- phoneNumber.localNumber.split(""),
432
- 3,
433
- "-"
434
- ).join("")}`;
435
- },
436
- address: (address, inline) => {
437
- if (address === void 0) return "no_address";
438
- const addressKeys = Object.keys(address).map((k) => k);
439
- const delimiter = (isLast) => !isLast ? "," + (!inline ? "\n" : "") : "";
440
- return addressKeys.map(
441
- (key, idx) => address[key] + delimiter(idx === lastIndex(addressKeys))
442
- ).join("") || "no_address";
443
- }
444
- };
445
- };
446
- var ObjectFormatter_default = ObjectFormatter;
502
+ var toObject = new Overloader().invoke;
447
503
 
448
504
  // src/helper-functions/HelperFunctions.ts
449
- var import_uuid = require("uuid");
450
- var import_types = require("@wavy/types");
451
- var import_console = require("console");
452
505
  var dateFormat = new TimeManager_default().format;
453
506
  var timeDuration = new TimeManager_default().getDuration;
454
507
  var upperFirst = StringFormatter_default.upperFirst;
@@ -506,7 +559,7 @@ function isLocalFile(value) {
506
559
  uploadDate: 0,
507
560
  _metadata: void 0
508
561
  };
509
- const optionalKeys = ["description", "_metadata"];
562
+ const optionalKeys = ["description"];
510
563
  const requiredKeys = Object.keys(dummyLocalFile).filter((key) => !optionalKeys.includes(key));
511
564
  const allKeys = [requiredKeys, optionalKeys].flat();
512
565
  if (value && typeof value === "object" && requiredKeys.every((key) => key in value) && Object.keys(value).every((key) => allKeys.includes(key))) {
@@ -514,68 +567,8 @@ function isLocalFile(value) {
514
567
  }
515
568
  return false;
516
569
  }
517
- var toObject = new class T {
518
- fileToLocalFile(file, options) {
519
- const fileName = (() => {
520
- const fileExt = getFileExt(file.name);
521
- if (options?.filename && options.filename.includes(fileExt))
522
- return options.filename;
523
- else if (options?.filename) return options.filename.trim() + fileExt;
524
- return file.name;
525
- })()?.trim?.();
526
- const { name: _, size: __, ..._metadata } = file;
527
- return {
528
- uid: (0, import_uuid.v4)(),
529
- description: options?.description,
530
- path: options?.filepath || file.webkitRelativePath,
531
- typeAlias: options?.typeAlias || run(
532
- Object.keys(import_types.LOCAL_FILE_MIME_TYPES).find(
533
- (key) => import_types.LOCAL_FILE_MIME_TYPES[key].includes(file.type)
534
- ),
535
- (type) => {
536
- if (!type) {
537
- (0, import_console.log)("An unknown file type was found ", file.type);
538
- return "unknown";
539
- }
540
- return type;
541
- }
542
- ),
543
- sizeInBytes: file.size,
544
- uploadDate: options?.uploadDate === "now" ? Date.now() : options?.uploadDate ?? file.lastModified,
545
- name: fileName,
546
- _metadata
547
- };
548
- }
549
- localFileToFile(localFile) {
550
- if ("_metadata" in localFile) {
551
- return {
552
- name: localFile.name,
553
- size: localFile.sizeInBytes,
554
- ...localFile._metadata
555
- };
556
- }
557
- return {
558
- name: localFile.name,
559
- size: localFile.sizeInBytes,
560
- webkitRelativePath: localFile.path,
561
- lastModified: localFile.uploadDate
562
- };
563
- }
564
- invoke(...args) {
565
- if (isFile(args[0])) {
566
- return this.fileToLocalFile(
567
- ...args
568
- );
569
- }
570
- if (isLocalFile(args[0])) {
571
- return this.localFileToFile(
572
- ...args
573
- );
574
- } else throw new Error(`The arguments supplied are insufficient.`);
575
- }
576
- }().invoke;
577
570
  function getMimeTypes(typeAliases) {
578
- return distinct(strictArray(typeAliases)).map((alias) => import_types.LOCAL_FILE_MIME_TYPES[alias]).flat();
571
+ return distinct(strictArray(typeAliases)).map((alias) => import_types2.LOCAL_FILE_MIME_TYPES[alias]).flat();
579
572
  }
580
573
  function classNameResolver(baseClassName) {
581
574
  return (className) => {
@@ -845,7 +838,7 @@ function getFileExt(filePath) {
845
838
  async function copyToClipboard(text) {
846
839
  try {
847
840
  await navigator.clipboard.writeText(text);
848
- return { data: "success" };
841
+ return { response: "success" };
849
842
  } catch (err) {
850
843
  console.error("Failed to copy text: ", err);
851
844
  if (err instanceof Error) {
@@ -869,7 +862,7 @@ async function copyToClipboard(text) {
869
862
  async function readClipboardText() {
870
863
  try {
871
864
  const text = await navigator.clipboard.readText();
872
- return { data: { text: text.trim() } };
865
+ return { response: { text: text.trim() } };
873
866
  } catch (err) {
874
867
  console.error("Failed to read clipboard contents: ", err);
875
868
  return {
@@ -888,7 +881,7 @@ function arrayWithConst(array) {
888
881
  }
889
882
 
890
883
  // src/server-adapters/ServerAdapters.ts
891
- var import_types2 = require("@wavy/types");
884
+ var import_types3 = require("@wavy/types");
892
885
  var iiKeys = Object.keys({
893
886
  name: null,
894
887
  address: null,
@@ -1143,7 +1136,6 @@ var serverDataAdapter = new ServerDataAdapter().invoke;
1143
1136
  takeWhile,
1144
1137
  timeDuration,
1145
1138
  toNumber,
1146
- toObject,
1147
1139
  trimString,
1148
1140
  undefinedIfEmpty,
1149
1141
  upperFirst,
package/dist/main.d.cts CHANGED
@@ -51,16 +51,6 @@ declare const toMoney: (value: string | number, options?: NumberFormatterTypes["
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(value: unknown): value is File;
53
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): LocalFile;
62
- (localFile: LocalFile | SanitizeLocalType<LocalFile>): File;
63
- };
64
54
  declare function getMimeTypes(typeAliases: KnownFileTypeAlias[]): string[];
65
55
  declare function classNameResolver(baseClassName: string): (className: string) => string;
66
56
  declare function classNameExt(rootClassName: string): (className: string) => string;
@@ -177,4 +167,4 @@ declare const serverDataAdapter: {
177
167
  }>(event: "unzip", data: DataType): NormalizeFromServer<DataType>;
178
168
  };
179
169
 
180
- export { addArticle, arrayWithConst, asyncRun, averageOf, blankSpaces, buildArray, camelCaseToLetter, classNameExt, classNameResolver, coerceIn, copyToClipboard, count, dataSearcher, distinct, drop, dropLast, dropLastWhile, dropWhile, format, formatGCTRegNo, formatInvoiceNo, getCaps, getFileExt, 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 };
170
+ export { addArticle, arrayWithConst, asyncRun, averageOf, blankSpaces, buildArray, camelCaseToLetter, classNameExt, classNameResolver, coerceIn, copyToClipboard, count, dataSearcher, distinct, drop, dropLast, dropLastWhile, dropWhile, format, formatGCTRegNo, formatInvoiceNo, getCaps, getFileExt, 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, trimString, undefinedIfEmpty, upperFirst, windowed };
package/dist/main.d.ts CHANGED
@@ -51,16 +51,6 @@ declare const toMoney: (value: string | number, options?: NumberFormatterTypes["
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(value: unknown): value is File;
53
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): LocalFile;
62
- (localFile: LocalFile | SanitizeLocalType<LocalFile>): File;
63
- };
64
54
  declare function getMimeTypes(typeAliases: KnownFileTypeAlias[]): string[];
65
55
  declare function classNameResolver(baseClassName: string): (className: string) => string;
66
56
  declare function classNameExt(rootClassName: string): (className: string) => string;
@@ -177,4 +167,4 @@ declare const serverDataAdapter: {
177
167
  }>(event: "unzip", data: DataType): NormalizeFromServer<DataType>;
178
168
  };
179
169
 
180
- export { addArticle, arrayWithConst, asyncRun, averageOf, blankSpaces, buildArray, camelCaseToLetter, classNameExt, classNameResolver, coerceIn, copyToClipboard, count, dataSearcher, distinct, drop, dropLast, dropLastWhile, dropWhile, format, formatGCTRegNo, formatInvoiceNo, getCaps, getFileExt, 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 };
170
+ export { addArticle, arrayWithConst, asyncRun, averageOf, blankSpaces, buildArray, camelCaseToLetter, classNameExt, classNameResolver, coerceIn, copyToClipboard, count, dataSearcher, distinct, drop, dropLast, dropLastWhile, dropWhile, format, formatGCTRegNo, formatInvoiceNo, getCaps, getFileExt, 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, trimString, undefinedIfEmpty, upperFirst, windowed };
package/dist/main.js CHANGED
@@ -1,3 +1,184 @@
1
+ // src/helper-functions/HelperFunctions.ts
2
+ import { LOCAL_FILE_MIME_TYPES as LOCAL_FILE_MIME_TYPES2 } from "@wavy/types";
3
+
4
+ // src/helper-functions/components/formatter/number/NumberFormatter.ts
5
+ var NumberFormatter = class _NumberFormatter {
6
+ static format(value, format2, options) {
7
+ switch (format2) {
8
+ case "money":
9
+ return _NumberFormatter.toMoney(value, options);
10
+ default:
11
+ return value.toLocaleString("en-us");
12
+ }
13
+ }
14
+ static toMoney(amount, options) {
15
+ const dollarSign = options?.excludeDollarSign ? "" : "$";
16
+ if (!amount) return dollarSign + (options?.dropDecimals ? "0" : "0.00");
17
+ if (options?.truncate) {
18
+ const strAmt = takeWhile(
19
+ `${amount}`.split(""),
20
+ (char) => char !== "."
21
+ ).join("");
22
+ const fmtMoney = (value, decimal) => {
23
+ const getTruncatedSuffix = () => {
24
+ if (strAmt.length <= 3) return "";
25
+ if (range(4, 7).includes(strAmt.length)) return "k";
26
+ if (range(7, 10).includes(strAmt.length)) return "m";
27
+ if (range(10, 13).includes(strAmt.length)) return "b";
28
+ if (range(13, 16).includes(strAmt.length)) return "t";
29
+ };
30
+ const fmtValue = parseInt(decimal) > 0 ? `${value}.${decimal}` : value;
31
+ return dollarSign + fmtValue + getTruncatedSuffix();
32
+ };
33
+ if (strAmt.length <= 3) return fmtMoney(strAmt, "0");
34
+ else {
35
+ const relevantDigits = takeLast(
36
+ windowed([...strAmt.split("")].reverse(), 3).map(
37
+ (arr) => arr.reverse()
38
+ ),
39
+ 2
40
+ ).reverse();
41
+ return fmtMoney(relevantDigits[0].join(""), relevantDigits[1][0]);
42
+ }
43
+ }
44
+ return (amount < 0 ? "-" : options?.showSigns ? "+" : "") + dollarSign + amount.toLocaleString("en-US", {
45
+ minimumFractionDigits: options?.dropDecimals ? 0 : 2,
46
+ currency: "USD",
47
+ currencyDisplay: "symbol",
48
+ currencySign: "accounting",
49
+ signDisplay: "never"
50
+ });
51
+ }
52
+ };
53
+ var NumberFormatter_default = NumberFormatter;
54
+
55
+ // src/helper-functions/components/formatter/object/ObjectFormatter.ts
56
+ var ObjectFormatter = class {
57
+ static toString = {
58
+ name: (name) => name ? `${name.first} ${name.last}`.trim() : "no_name",
59
+ phoneNumber: (phoneNumber) => {
60
+ if (!phoneNumber) return "no_phone_number";
61
+ return `${phoneNumber.countryCode} (${phoneNumber.areaCode}) ${insertAt(
62
+ phoneNumber.localNumber.split(""),
63
+ 3,
64
+ "-"
65
+ ).join("")}`;
66
+ },
67
+ address: (address, inline) => {
68
+ if (address === void 0) return "no_address";
69
+ const addressKeys = Object.keys(address).map((k) => k);
70
+ const delimiter = (isLast) => !isLast ? "," + (!inline ? "\n" : "") : "";
71
+ return addressKeys.map(
72
+ (key, idx) => address[key] + delimiter(idx === lastIndex(addressKeys))
73
+ ).join("") || "no_address";
74
+ }
75
+ };
76
+ };
77
+ var ObjectFormatter_default = ObjectFormatter;
78
+
79
+ // src/helper-functions/components/input/InputManager.ts
80
+ var InputManager = class {
81
+ static manualValidators = {
82
+ percent: (value) => StringFormatter_default.toNumber(value) <= 100 && run(value.split(".")?.[1], (dec) => dec ? dec.length <= 2 : true)
83
+ };
84
+ static formatters = {
85
+ money: {
86
+ format: (value) => take(
87
+ value.split(".").map(
88
+ (sect, idx) => idx === 0 ? `${NumberFormatter_default.format(StringFormatter_default.toNumber(sect))}` : take(sect.split(""), 2).join("")
89
+ ),
90
+ 2
91
+ ).join("."),
92
+ unformat: (value) => `${StringFormatter_default.toNumber(value)}`
93
+ }
94
+ };
95
+ static separateNumbersFormatter(options = {
96
+ numbersPerGroup: 3,
97
+ separator: "-"
98
+ }) {
99
+ return {
100
+ format: (value) => {
101
+ let groupedValues = windowed(
102
+ value.split(""),
103
+ options.numbersPerGroup
104
+ ).map((v) => v.join(""));
105
+ if (options.groupCount) {
106
+ groupedValues = [
107
+ ...take(groupedValues, options.groupCount),
108
+ drop(groupedValues, options.groupCount).join("").replace(options.separator, "")
109
+ ].filter((v) => !isEmpty(v));
110
+ }
111
+ return groupedValues.join(options.separator);
112
+ },
113
+ unformat: (value) => {
114
+ const unformatted = value.replaceAll(options.separator, "");
115
+ return unformatted;
116
+ }
117
+ };
118
+ }
119
+ };
120
+ var InputManager_default = InputManager;
121
+
122
+ // src/helper-functions/components/formatter/string/StringFormatter.ts
123
+ var VOWELS = "aeiouy";
124
+ var StringFormatter = class _StringFormatter {
125
+ static vowels = VOWELS;
126
+ static caseConverter = {
127
+ camelToLetter: (camelCase) => {
128
+ return camelCase.split("").map(
129
+ (char, charIdx) => charIdx === 0 ? char.toUpperCase() : char === char.toUpperCase() && char !== char.toLowerCase() ? ` ${char}` : char
130
+ ).join("");
131
+ }
132
+ };
133
+ static extract = {
134
+ capitalLetters: (value, count2) => {
135
+ return value.split("", count2).filter(
136
+ (char) => char === char.toUpperCase() && char !== char.toLowerCase()
137
+ );
138
+ }
139
+ };
140
+ static trimString(value, trim) {
141
+ let newValue = value;
142
+ while (newValue.endsWith(trim)) {
143
+ newValue = value.split("").reverse().join("").replace(trim, "").split("").reverse().join("");
144
+ }
145
+ return newValue;
146
+ }
147
+ static pluralize(value) {
148
+ return value[value.length - 1] === "s" ? value + "es" : value + "s";
149
+ }
150
+ static addArticle(value, article) {
151
+ let fmtArticle = "";
152
+ switch (article) {
153
+ case "a/an":
154
+ fmtArticle = VOWELS.includes(value?.[0].toLowerCase()) ? "An" : "A";
155
+ break;
156
+ default:
157
+ return article;
158
+ }
159
+ return `${fmtArticle.toLowerCase()} ${value}`;
160
+ }
161
+ static toSearch(from) {
162
+ return from.split("").filter((char) => char !== " ").join("").toLowerCase().trim();
163
+ }
164
+ static toMoney(from, options) {
165
+ return NumberFormatter_default.toMoney(_StringFormatter.toNumber(from), options);
166
+ }
167
+ static toTRN(from) {
168
+ return InputManager_default.separateNumbersFormatter().format(from);
169
+ }
170
+ static toNumber(value) {
171
+ const potentialNumber = take(value.split("."), 2).join(".").split("").map(
172
+ (char, idx) => idx === 0 && char === "-" ? char : "0123456789.".includes(char) ? char : ""
173
+ ).join("");
174
+ return isEmpty(potentialNumber.trim()) ? 0 : parseFloat(potentialNumber);
175
+ }
176
+ static upperFirst(value) {
177
+ return value.split("").map((char, idx) => idx === 0 ? char.toUpperCase() : char).join("");
178
+ }
179
+ };
180
+ var StringFormatter_default = StringFormatter;
181
+
1
182
  // src/helper-functions/components/time/TimeManager.ts
2
183
  var TimeManager = class _TimeManager {
3
184
  constructor(locale = "en-jm") {
@@ -170,188 +351,61 @@ var TimeManager = class _TimeManager {
170
351
  };
171
352
  var TimeManager_default = TimeManager;
172
353
 
173
- // src/helper-functions/components/formatter/number/NumberFormatter.ts
174
- var NumberFormatter = class _NumberFormatter {
175
- static format(value, format2, options) {
176
- switch (format2) {
177
- case "money":
178
- return _NumberFormatter.toMoney(value, options);
179
- default:
180
- return value.toLocaleString("en-us");
181
- }
182
- }
183
- static toMoney(amount, options) {
184
- const dollarSign = options?.excludeDollarSign ? "" : "$";
185
- if (!amount) return dollarSign + (options?.dropDecimals ? "0" : "0.00");
186
- if (options?.truncate) {
187
- const strAmt = takeWhile(
188
- `${amount}`.split(""),
189
- (char) => char !== "."
190
- ).join("");
191
- const fmtMoney = (value, decimal) => {
192
- const getTruncatedSuffix = () => {
193
- if (strAmt.length <= 3) return "";
194
- if (range(4, 7).includes(strAmt.length)) return "k";
195
- if (range(7, 10).includes(strAmt.length)) return "m";
196
- if (range(10, 13).includes(strAmt.length)) return "b";
197
- if (range(13, 16).includes(strAmt.length)) return "t";
198
- };
199
- const fmtValue = parseInt(decimal) > 0 ? `${value}.${decimal}` : value;
200
- return dollarSign + fmtValue + getTruncatedSuffix();
201
- };
202
- if (strAmt.length <= 3) return fmtMoney(strAmt, "0");
203
- else {
204
- const relevantDigits = takeLast(
205
- windowed([...strAmt.split("")].reverse(), 3).map(
206
- (arr) => arr.reverse()
207
- ),
208
- 2
209
- ).reverse();
210
- return fmtMoney(relevantDigits[0].join(""), relevantDigits[1][0]);
211
- }
212
- }
213
- return (amount < 0 ? "-" : options?.showSigns ? "+" : "") + dollarSign + amount.toLocaleString("en-US", {
214
- minimumFractionDigits: options?.dropDecimals ? 0 : 2,
215
- currency: "USD",
216
- currencyDisplay: "symbol",
217
- currencySign: "accounting",
218
- signDisplay: "never"
219
- });
220
- }
221
- };
222
- var NumberFormatter_default = NumberFormatter;
223
-
224
- // src/helper-functions/components/input/InputManager.ts
225
- var InputManager = class {
226
- static manualValidators = {
227
- percent: (value) => StringFormatter_default.toNumber(value) <= 100 && run(value.split(".")?.[1], (dec) => dec ? dec.length <= 2 : true)
228
- };
229
- static formatters = {
230
- money: {
231
- format: (value) => take(
232
- value.split(".").map(
233
- (sect, idx) => idx === 0 ? `${NumberFormatter_default.format(StringFormatter_default.toNumber(sect))}` : take(sect.split(""), 2).join("")
234
- ),
235
- 2
236
- ).join("."),
237
- unformat: (value) => `${StringFormatter_default.toNumber(value)}`
238
- }
239
- };
240
- static separateNumbersFormatter(options = {
241
- numbersPerGroup: 3,
242
- separator: "-"
243
- }) {
244
- return {
245
- format: (value) => {
246
- let groupedValues = windowed(
247
- value.split(""),
248
- options.numbersPerGroup
249
- ).map((v) => v.join(""));
250
- if (options.groupCount) {
251
- groupedValues = [
252
- ...take(groupedValues, options.groupCount),
253
- drop(groupedValues, options.groupCount).join("").replace(options.separator, "")
254
- ].filter((v) => !isEmpty(v));
354
+ // src/helper-functions/components/ObjectConverter.ts
355
+ import { v4 } from "uuid";
356
+ import { LOCAL_FILE_MIME_TYPES } from "@wavy/types";
357
+ import { log } from "console";
358
+ function fileToLocalFile(file, options) {
359
+ const fileName = (() => {
360
+ const fileExt = getFileExt(file.name);
361
+ if (options?.filename && options.filename.includes(fileExt))
362
+ return options.filename;
363
+ else if (options?.filename) return options.filename.trim() + fileExt;
364
+ return file.name;
365
+ })()?.trim?.();
366
+ const { name: _, size: __, ..._metadata } = file;
367
+ return {
368
+ uid: v4(),
369
+ description: options?.description,
370
+ path: options?.filepath || file?.webkitRelativePath,
371
+ typeAlias: options?.typeAlias || run(
372
+ Object.keys(LOCAL_FILE_MIME_TYPES).find(
373
+ (key) => LOCAL_FILE_MIME_TYPES[key].includes(file.type)
374
+ ),
375
+ (type) => {
376
+ if (!type) {
377
+ log("An unknown file type was found ", file.type);
378
+ return "unknown";
255
379
  }
256
- return groupedValues.join(options.separator);
257
- },
258
- unformat: (value) => {
259
- const unformatted = value.replaceAll(options.separator, "");
260
- return unformatted;
380
+ return type;
261
381
  }
262
- };
263
- }
264
- };
265
- var InputManager_default = InputManager;
266
-
267
- // src/helper-functions/components/formatter/string/StringFormatter.ts
268
- var VOWELS = "aeiouy";
269
- var StringFormatter = class _StringFormatter {
270
- static vowels = VOWELS;
271
- static caseConverter = {
272
- camelToLetter: (camelCase) => {
273
- return camelCase.split("").map(
274
- (char, charIdx) => charIdx === 0 ? char.toUpperCase() : char === char.toUpperCase() && char !== char.toLowerCase() ? ` ${char}` : char
275
- ).join("");
276
- }
382
+ ),
383
+ sizeInBytes: file.size,
384
+ uploadDate: options?.uploadDate === "now" ? Date.now() : options?.uploadDate ?? file?.lastModified,
385
+ name: fileName,
386
+ _metadata
277
387
  };
278
- static extract = {
279
- capitalLetters: (value, count2) => {
280
- return value.split("", count2).filter(
281
- (char) => char === char.toUpperCase() && char !== char.toLowerCase()
282
- );
283
- }
388
+ }
389
+ function localFileToFile(localFile) {
390
+ return {
391
+ name: localFile.name,
392
+ size: localFile.sizeInBytes,
393
+ ...localFile._metadata
284
394
  };
285
- static trimString(value, trim) {
286
- let newValue = value;
287
- while (newValue.endsWith(trim)) {
288
- newValue = value.split("").reverse().join("").replace(trim, "").split("").reverse().join("");
289
- }
290
- return newValue;
291
- }
292
- static pluralize(value) {
293
- return value[value.length - 1] === "s" ? value + "es" : value + "s";
294
- }
295
- static addArticle(value, article) {
296
- let fmtArticle = "";
297
- switch (article) {
298
- case "a/an":
299
- fmtArticle = VOWELS.includes(value?.[0].toLowerCase()) ? "An" : "A";
300
- break;
301
- default:
302
- return article;
395
+ }
396
+ var Overloader = class {
397
+ invoke(...args) {
398
+ if (isFile(args[0])) {
399
+ return fileToLocalFile(...args);
303
400
  }
304
- return `${fmtArticle.toLowerCase()} ${value}`;
305
- }
306
- static toSearch(from) {
307
- return from.split("").filter((char) => char !== " ").join("").toLowerCase().trim();
308
- }
309
- static toMoney(from, options) {
310
- return NumberFormatter_default.toMoney(_StringFormatter.toNumber(from), options);
311
- }
312
- static toTRN(from) {
313
- return InputManager_default.separateNumbersFormatter().format(from);
314
- }
315
- static toNumber(value) {
316
- const potentialNumber = take(value.split("."), 2).join(".").split("").map(
317
- (char, idx) => idx === 0 && char === "-" ? char : "0123456789.".includes(char) ? char : ""
318
- ).join("");
319
- return isEmpty(potentialNumber.trim()) ? 0 : parseFloat(potentialNumber);
320
- }
321
- static upperFirst(value) {
322
- return value.split("").map((char, idx) => idx === 0 ? char.toUpperCase() : char).join("");
401
+ if (isLocalFile(args[0])) {
402
+ return localFileToFile(...args);
403
+ } else throw new Error(`The arguments supplied are insufficient.`);
323
404
  }
324
405
  };
325
- var StringFormatter_default = StringFormatter;
326
-
327
- // src/helper-functions/components/formatter/object/ObjectFormatter.ts
328
- var ObjectFormatter = class {
329
- static toString = {
330
- name: (name) => name ? `${name.first} ${name.last}`.trim() : "no_name",
331
- phoneNumber: (phoneNumber) => {
332
- if (!phoneNumber) return "no_phone_number";
333
- return `${phoneNumber.countryCode} (${phoneNumber.areaCode}) ${insertAt(
334
- phoneNumber.localNumber.split(""),
335
- 3,
336
- "-"
337
- ).join("")}`;
338
- },
339
- address: (address, inline) => {
340
- if (address === void 0) return "no_address";
341
- const addressKeys = Object.keys(address).map((k) => k);
342
- const delimiter = (isLast) => !isLast ? "," + (!inline ? "\n" : "") : "";
343
- return addressKeys.map(
344
- (key, idx) => address[key] + delimiter(idx === lastIndex(addressKeys))
345
- ).join("") || "no_address";
346
- }
347
- };
348
- };
349
- var ObjectFormatter_default = ObjectFormatter;
406
+ var toObject = new Overloader().invoke;
350
407
 
351
408
  // src/helper-functions/HelperFunctions.ts
352
- import { v4 } from "uuid";
353
- import { LOCAL_FILE_MIME_TYPES } from "@wavy/types";
354
- import { log } from "console";
355
409
  var dateFormat = new TimeManager_default().format;
356
410
  var timeDuration = new TimeManager_default().getDuration;
357
411
  var upperFirst = StringFormatter_default.upperFirst;
@@ -409,7 +463,7 @@ function isLocalFile(value) {
409
463
  uploadDate: 0,
410
464
  _metadata: void 0
411
465
  };
412
- const optionalKeys = ["description", "_metadata"];
466
+ const optionalKeys = ["description"];
413
467
  const requiredKeys = Object.keys(dummyLocalFile).filter((key) => !optionalKeys.includes(key));
414
468
  const allKeys = [requiredKeys, optionalKeys].flat();
415
469
  if (value && typeof value === "object" && requiredKeys.every((key) => key in value) && Object.keys(value).every((key) => allKeys.includes(key))) {
@@ -417,68 +471,8 @@ function isLocalFile(value) {
417
471
  }
418
472
  return false;
419
473
  }
420
- var toObject = new class T {
421
- fileToLocalFile(file, options) {
422
- const fileName = (() => {
423
- const fileExt = getFileExt(file.name);
424
- if (options?.filename && options.filename.includes(fileExt))
425
- return options.filename;
426
- else if (options?.filename) return options.filename.trim() + fileExt;
427
- return file.name;
428
- })()?.trim?.();
429
- const { name: _, size: __, ..._metadata } = file;
430
- return {
431
- uid: v4(),
432
- description: options?.description,
433
- path: options?.filepath || file.webkitRelativePath,
434
- typeAlias: options?.typeAlias || run(
435
- Object.keys(LOCAL_FILE_MIME_TYPES).find(
436
- (key) => LOCAL_FILE_MIME_TYPES[key].includes(file.type)
437
- ),
438
- (type) => {
439
- if (!type) {
440
- log("An unknown file type was found ", file.type);
441
- return "unknown";
442
- }
443
- return type;
444
- }
445
- ),
446
- sizeInBytes: file.size,
447
- uploadDate: options?.uploadDate === "now" ? Date.now() : options?.uploadDate ?? file.lastModified,
448
- name: fileName,
449
- _metadata
450
- };
451
- }
452
- localFileToFile(localFile) {
453
- if ("_metadata" in localFile) {
454
- return {
455
- name: localFile.name,
456
- size: localFile.sizeInBytes,
457
- ...localFile._metadata
458
- };
459
- }
460
- return {
461
- name: localFile.name,
462
- size: localFile.sizeInBytes,
463
- webkitRelativePath: localFile.path,
464
- lastModified: localFile.uploadDate
465
- };
466
- }
467
- invoke(...args) {
468
- if (isFile(args[0])) {
469
- return this.fileToLocalFile(
470
- ...args
471
- );
472
- }
473
- if (isLocalFile(args[0])) {
474
- return this.localFileToFile(
475
- ...args
476
- );
477
- } else throw new Error(`The arguments supplied are insufficient.`);
478
- }
479
- }().invoke;
480
474
  function getMimeTypes(typeAliases) {
481
- return distinct(strictArray(typeAliases)).map((alias) => LOCAL_FILE_MIME_TYPES[alias]).flat();
475
+ return distinct(strictArray(typeAliases)).map((alias) => LOCAL_FILE_MIME_TYPES2[alias]).flat();
482
476
  }
483
477
  function classNameResolver(baseClassName) {
484
478
  return (className) => {
@@ -748,7 +742,7 @@ function getFileExt(filePath) {
748
742
  async function copyToClipboard(text) {
749
743
  try {
750
744
  await navigator.clipboard.writeText(text);
751
- return { data: "success" };
745
+ return { response: "success" };
752
746
  } catch (err) {
753
747
  console.error("Failed to copy text: ", err);
754
748
  if (err instanceof Error) {
@@ -772,7 +766,7 @@ async function copyToClipboard(text) {
772
766
  async function readClipboardText() {
773
767
  try {
774
768
  const text = await navigator.clipboard.readText();
775
- return { data: { text: text.trim() } };
769
+ return { response: { text: text.trim() } };
776
770
  } catch (err) {
777
771
  console.error("Failed to read clipboard contents: ", err);
778
772
  return {
@@ -1045,7 +1039,6 @@ export {
1045
1039
  takeWhile,
1046
1040
  timeDuration,
1047
1041
  toNumber,
1048
- toObject,
1049
1042
  trimString,
1050
1043
  undefinedIfEmpty,
1051
1044
  upperFirst,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wavy/fn",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
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.26",
25
+ "@wavy/types": "^0.0.32",
26
26
  "tsup": "^8.5.0",
27
27
  "typescript": "^5.9.2"
28
28
  }