@wavy/fn 0.0.25 → 0.0.27
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 +76 -8
- package/dist/main.d.cts +28 -8
- package/dist/main.d.ts +28 -8
- package/dist/main.js +70 -8
- package/package.json +1 -1
package/dist/main.cjs
CHANGED
|
@@ -62,6 +62,7 @@ __export(main_exports, {
|
|
|
62
62
|
isNumber: () => isNumber,
|
|
63
63
|
isPromise: () => isPromise,
|
|
64
64
|
lastIndex: () => lastIndex,
|
|
65
|
+
limit: () => limit,
|
|
65
66
|
map: () => map,
|
|
66
67
|
mapToArray: () => mapToArray,
|
|
67
68
|
maxOf: () => maxOf,
|
|
@@ -71,6 +72,11 @@ __export(main_exports, {
|
|
|
71
72
|
omitNils: () => omitNils,
|
|
72
73
|
ordinalIndicator: () => ordinalIndicator,
|
|
73
74
|
overwrite: () => overwrite,
|
|
75
|
+
parseAddress: () => parseAddress,
|
|
76
|
+
parseDate: () => parseDate,
|
|
77
|
+
parseFileSize: () => parseFileSize,
|
|
78
|
+
parseMoney: () => parseMoney,
|
|
79
|
+
parseName: () => parseName,
|
|
74
80
|
pick: () => pick,
|
|
75
81
|
pluralize: () => pluralize,
|
|
76
82
|
poll: () => poll,
|
|
@@ -617,6 +623,60 @@ function isPromise(value) {
|
|
|
617
623
|
if (value instanceof Promise) return true;
|
|
618
624
|
return !!value && (typeof value === "object" || typeof value === "function") && "then" in value && typeof value.then === "function";
|
|
619
625
|
}
|
|
626
|
+
var parseDate = dateFormat;
|
|
627
|
+
function parseName(value) {
|
|
628
|
+
if (typeof value === "string") {
|
|
629
|
+
const [first2 = "", last2 = ""] = (value || "").trim().split(" ");
|
|
630
|
+
return { first: first2, last: last2 };
|
|
631
|
+
}
|
|
632
|
+
const { first = "", last = "" } = value || {};
|
|
633
|
+
return first.trim() + " " + last.trim();
|
|
634
|
+
}
|
|
635
|
+
function parseMoney(value) {
|
|
636
|
+
if (typeof value === "string") return StringFormatter_default.toMoney(value);
|
|
637
|
+
return NumberFormatter_default.toMoney(value);
|
|
638
|
+
}
|
|
639
|
+
function parseAddress(address, ...args) {
|
|
640
|
+
if (typeof address === "string") {
|
|
641
|
+
const [
|
|
642
|
+
options = {
|
|
643
|
+
delimiter: "|",
|
|
644
|
+
syntax: ["streetAddress", "city", "parish", "country"]
|
|
645
|
+
}
|
|
646
|
+
] = args;
|
|
647
|
+
if (typeof options === "boolean") {
|
|
648
|
+
throw new Error(
|
|
649
|
+
"Type mismatch. Expected 'object' but 'boolean' was provided."
|
|
650
|
+
);
|
|
651
|
+
}
|
|
652
|
+
const fields = address.split(options.delimiter);
|
|
653
|
+
return Object.fromEntries(
|
|
654
|
+
limit(distinct(options.syntax), 4).map((key, i) => {
|
|
655
|
+
return [key, fields[i]];
|
|
656
|
+
})
|
|
657
|
+
);
|
|
658
|
+
}
|
|
659
|
+
if (typeof address === "object") {
|
|
660
|
+
const [inline] = args;
|
|
661
|
+
return addressToString(
|
|
662
|
+
address,
|
|
663
|
+
typeof inline === "boolean" ? inline : void 0
|
|
664
|
+
);
|
|
665
|
+
}
|
|
666
|
+
return null;
|
|
667
|
+
}
|
|
668
|
+
function parseFileSize(bytes) {
|
|
669
|
+
return new FileSizeFormatter(bytes).format();
|
|
670
|
+
}
|
|
671
|
+
function limit(array, limit2) {
|
|
672
|
+
const newArray = [];
|
|
673
|
+
if (!array) return;
|
|
674
|
+
for (const item of array) {
|
|
675
|
+
if (newArray.length === limit2) break;
|
|
676
|
+
newArray.push(item);
|
|
677
|
+
}
|
|
678
|
+
return newArray;
|
|
679
|
+
}
|
|
620
680
|
function castArray(value) {
|
|
621
681
|
return Array.isArray(value) ? value : [value];
|
|
622
682
|
}
|
|
@@ -652,6 +712,16 @@ function omitNils(value) {
|
|
|
652
712
|
}
|
|
653
713
|
return result;
|
|
654
714
|
}
|
|
715
|
+
function map(arr, callback) {
|
|
716
|
+
let ended = false;
|
|
717
|
+
for (let i = 0; i < arr.length; i++) {
|
|
718
|
+
if (ended) break;
|
|
719
|
+
arr[i] = callback(arr[i], i, arr, () => {
|
|
720
|
+
ended = true;
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
return arr;
|
|
724
|
+
}
|
|
655
725
|
function getMimeTypes(typeAliases) {
|
|
656
726
|
return distinct(strictArray(typeAliases)).map((alias) => import_types2.LOCAL_FILE_MIME_TYPES[alias]).flat();
|
|
657
727
|
}
|
|
@@ -881,14 +951,6 @@ function distinct(arr) {
|
|
|
881
951
|
});
|
|
882
952
|
return newArr;
|
|
883
953
|
}
|
|
884
|
-
function map(from, mappedFields) {
|
|
885
|
-
return Object.fromEntries(
|
|
886
|
-
Object.keys(mappedFields).map((key) => {
|
|
887
|
-
const validKey = key;
|
|
888
|
-
return [mappedFields[validKey], from[validKey]];
|
|
889
|
-
})
|
|
890
|
-
);
|
|
891
|
-
}
|
|
892
954
|
function isEmpty(value) {
|
|
893
955
|
const valueLength = typeof value === "string" ? value.trim().length : value.length;
|
|
894
956
|
return valueLength === 0;
|
|
@@ -1184,6 +1246,7 @@ var serverDataAdapter = new ServerDataAdapter().invoke;
|
|
|
1184
1246
|
isNumber,
|
|
1185
1247
|
isPromise,
|
|
1186
1248
|
lastIndex,
|
|
1249
|
+
limit,
|
|
1187
1250
|
map,
|
|
1188
1251
|
mapToArray,
|
|
1189
1252
|
maxOf,
|
|
@@ -1193,6 +1256,11 @@ var serverDataAdapter = new ServerDataAdapter().invoke;
|
|
|
1193
1256
|
omitNils,
|
|
1194
1257
|
ordinalIndicator,
|
|
1195
1258
|
overwrite,
|
|
1259
|
+
parseAddress,
|
|
1260
|
+
parseDate,
|
|
1261
|
+
parseFileSize,
|
|
1262
|
+
parseMoney,
|
|
1263
|
+
parseName,
|
|
1196
1264
|
pick,
|
|
1197
1265
|
pluralize,
|
|
1198
1266
|
poll,
|
package/dist/main.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import "@wavy/types"
|
|
2
|
-
import
|
|
3
|
-
import { LocalFile, SanitizeFile, NonFunction, KnownFileTypeAlias, TaskResult, FromServer, NormalizeFromServer } from '@wavy/types';
|
|
2
|
+
import { LocalFile, Name, Address, SanitizeFile, NonFunction, KnownFileTypeAlias, TaskResult, FromServer, NormalizeFromServer } from '@wavy/types';
|
|
4
3
|
|
|
5
4
|
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";
|
|
6
5
|
|
|
@@ -60,20 +59,42 @@ declare const getCaps: (value: string, count?: number) => string[];
|
|
|
60
59
|
declare const toNumber: typeof StringFormatter.toNumber;
|
|
61
60
|
declare const addArticle: typeof StringFormatter.addArticle;
|
|
62
61
|
declare const pluralize: typeof StringFormatter.pluralize;
|
|
63
|
-
declare const nameToString: (name:
|
|
64
|
-
declare const addressToString: (address:
|
|
62
|
+
declare const nameToString: (name: Name | undefined) => string;
|
|
63
|
+
declare const addressToString: (address: Address | undefined, inline?: boolean) => string;
|
|
65
64
|
declare const toMoney: (value: string | number, options?: NumberFormatterTypes["options"]["money"]) => string;
|
|
65
|
+
/**
|
|
66
|
+
* @deprecated Migrate to individual function calls.
|
|
67
|
+
* @example parseDate, parseMoney, parseName, parseAddress, parseFileSize
|
|
68
|
+
*/
|
|
66
69
|
declare function format<Event extends "date" | "money" | "name" | "address" | "file-size">(event: Event, ...args: Event extends "date" ? Parameters<typeof dateFormat> : Event extends "money" ? Parameters<typeof toMoney> : Event extends "name" ? Parameters<typeof nameToString> : Event extends "address" ? Parameters<typeof addressToString> : Event extends "file-size" ? [bytes: number] : never): Event extends "date" | "money" | "name" | "address" | "file-size" ? string : never;
|
|
67
70
|
declare function sanitizeLocalFile({ _metadata: _, ...file }: LocalFile): SanitizeFile<LocalFile>;
|
|
68
71
|
declare function isFile(value: unknown): value is File;
|
|
69
72
|
declare function isLocalFile(value: unknown): value is LocalFile;
|
|
70
73
|
declare function isIterable<T>(value: unknown): value is Iterable<T>;
|
|
71
74
|
declare function isPromise<T>(value: unknown): value is Promise<T>;
|
|
75
|
+
declare const parseDate: (time: number | Date | "now", format?: DateFormat) => string;
|
|
76
|
+
declare function parseName<Value extends string | Name>(value: Value): Value extends string ? Name : Value extends Name ? string : never;
|
|
77
|
+
declare function parseMoney(value: string | number): string;
|
|
78
|
+
declare function parseAddress<T extends Address | string>(address: T, ...args: T extends string ? [
|
|
79
|
+
options?: Partial<{
|
|
80
|
+
/**The value used to separate each field in the string
|
|
81
|
+
* @default "|"
|
|
82
|
+
*/
|
|
83
|
+
delimiter?: string;
|
|
84
|
+
/**The order in which the fields appear
|
|
85
|
+
* @default ["streetAddress", "city", "parish", "country"]
|
|
86
|
+
*/
|
|
87
|
+
syntax?: (keyof Address)[];
|
|
88
|
+
}>
|
|
89
|
+
] : T extends Address ? [inline?: boolean] : []): (T extends Address ? string : T extends string ? Address : never) | null;
|
|
90
|
+
declare function parseFileSize(bytes: number): string;
|
|
91
|
+
declare function limit<T>(array: T[], limit: number): T[] | undefined;
|
|
72
92
|
declare function castArray<T>(value: T | T[]): T[];
|
|
73
93
|
declare function castReturn<T extends NonFunction<any>>(value: T | (() => T)): T;
|
|
74
|
-
declare function pick<O extends object, K extends keyof O>(value: O, keys: K[]): { [Key in K]: O[Key] | null; };
|
|
75
|
-
declare function omit<O extends object, K extends keyof O>(value: O, keys: K[]): { [Key in Exclude<keyof O, K>]: O[Key] | null; };
|
|
94
|
+
declare function pick<O extends object, K extends keyof O = keyof O>(value: O, keys: K[]): { [Key in K]: O[Key] | null; };
|
|
95
|
+
declare function omit<O extends object, K extends keyof O = keyof O>(value: O, keys: K[]): { [Key in Exclude<keyof O, K>]: O[Key] | null; };
|
|
76
96
|
declare function omitNils<O extends object>(value: O): O;
|
|
97
|
+
declare function map<T>(arr: T[], callback: (value: T, index: number, array: T[], end: () => void) => T): T[];
|
|
77
98
|
declare function getMimeTypes(typeAliases: KnownFileTypeAlias[]): string[];
|
|
78
99
|
declare function classNameResolver(baseClassName: string): (className: string) => string;
|
|
79
100
|
declare function classNameExt(rootClassName: string): (className: string) => string;
|
|
@@ -161,7 +182,6 @@ declare function mapToArray<K extends string | number | symbol, V>(map: Map<K, V
|
|
|
161
182
|
[Key in K]: V;
|
|
162
183
|
}[];
|
|
163
184
|
declare function distinct<T>(arr: T[]): T[];
|
|
164
|
-
declare function map<To extends object, From extends object>(from: From, mappedFields: Record<keyof From, keyof To>): To;
|
|
165
185
|
declare function isEmpty(value: string | unknown[]): boolean;
|
|
166
186
|
declare function ifDefined<T, R>(value: T | undefined, cb: (value: T) => R): R | undefined;
|
|
167
187
|
declare function someValuesEmpty<O extends {
|
|
@@ -192,4 +212,4 @@ declare const serverDataAdapter: {
|
|
|
192
212
|
}>(event: "unzip", data: DataType): NormalizeFromServer<DataType>;
|
|
193
213
|
};
|
|
194
214
|
|
|
195
|
-
export { addArticle, arrayWithConst, asyncRun, averageOf, blankSpaces, buildArray, camelCaseToLetter, castArray, castReturn, 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, isIterable, isLetter, isLocalFile, isNumber, isPromise, lastIndex, map, mapToArray, maxOf, minOf, negate, omit, omitNils, ordinalIndicator, overwrite, pick, 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 };
|
|
215
|
+
export { addArticle, arrayWithConst, asyncRun, averageOf, blankSpaces, buildArray, camelCaseToLetter, castArray, castReturn, 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, isIterable, isLetter, isLocalFile, isNumber, isPromise, lastIndex, limit, map, mapToArray, maxOf, minOf, negate, omit, omitNils, ordinalIndicator, overwrite, parseAddress, parseDate, parseFileSize, parseMoney, parseName, pick, 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
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import "@wavy/types"
|
|
2
|
-
import
|
|
3
|
-
import { LocalFile, SanitizeFile, NonFunction, KnownFileTypeAlias, TaskResult, FromServer, NormalizeFromServer } from '@wavy/types';
|
|
2
|
+
import { LocalFile, Name, Address, SanitizeFile, NonFunction, KnownFileTypeAlias, TaskResult, FromServer, NormalizeFromServer } from '@wavy/types';
|
|
4
3
|
|
|
5
4
|
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";
|
|
6
5
|
|
|
@@ -60,20 +59,42 @@ declare const getCaps: (value: string, count?: number) => string[];
|
|
|
60
59
|
declare const toNumber: typeof StringFormatter.toNumber;
|
|
61
60
|
declare const addArticle: typeof StringFormatter.addArticle;
|
|
62
61
|
declare const pluralize: typeof StringFormatter.pluralize;
|
|
63
|
-
declare const nameToString: (name:
|
|
64
|
-
declare const addressToString: (address:
|
|
62
|
+
declare const nameToString: (name: Name | undefined) => string;
|
|
63
|
+
declare const addressToString: (address: Address | undefined, inline?: boolean) => string;
|
|
65
64
|
declare const toMoney: (value: string | number, options?: NumberFormatterTypes["options"]["money"]) => string;
|
|
65
|
+
/**
|
|
66
|
+
* @deprecated Migrate to individual function calls.
|
|
67
|
+
* @example parseDate, parseMoney, parseName, parseAddress, parseFileSize
|
|
68
|
+
*/
|
|
66
69
|
declare function format<Event extends "date" | "money" | "name" | "address" | "file-size">(event: Event, ...args: Event extends "date" ? Parameters<typeof dateFormat> : Event extends "money" ? Parameters<typeof toMoney> : Event extends "name" ? Parameters<typeof nameToString> : Event extends "address" ? Parameters<typeof addressToString> : Event extends "file-size" ? [bytes: number] : never): Event extends "date" | "money" | "name" | "address" | "file-size" ? string : never;
|
|
67
70
|
declare function sanitizeLocalFile({ _metadata: _, ...file }: LocalFile): SanitizeFile<LocalFile>;
|
|
68
71
|
declare function isFile(value: unknown): value is File;
|
|
69
72
|
declare function isLocalFile(value: unknown): value is LocalFile;
|
|
70
73
|
declare function isIterable<T>(value: unknown): value is Iterable<T>;
|
|
71
74
|
declare function isPromise<T>(value: unknown): value is Promise<T>;
|
|
75
|
+
declare const parseDate: (time: number | Date | "now", format?: DateFormat) => string;
|
|
76
|
+
declare function parseName<Value extends string | Name>(value: Value): Value extends string ? Name : Value extends Name ? string : never;
|
|
77
|
+
declare function parseMoney(value: string | number): string;
|
|
78
|
+
declare function parseAddress<T extends Address | string>(address: T, ...args: T extends string ? [
|
|
79
|
+
options?: Partial<{
|
|
80
|
+
/**The value used to separate each field in the string
|
|
81
|
+
* @default "|"
|
|
82
|
+
*/
|
|
83
|
+
delimiter?: string;
|
|
84
|
+
/**The order in which the fields appear
|
|
85
|
+
* @default ["streetAddress", "city", "parish", "country"]
|
|
86
|
+
*/
|
|
87
|
+
syntax?: (keyof Address)[];
|
|
88
|
+
}>
|
|
89
|
+
] : T extends Address ? [inline?: boolean] : []): (T extends Address ? string : T extends string ? Address : never) | null;
|
|
90
|
+
declare function parseFileSize(bytes: number): string;
|
|
91
|
+
declare function limit<T>(array: T[], limit: number): T[] | undefined;
|
|
72
92
|
declare function castArray<T>(value: T | T[]): T[];
|
|
73
93
|
declare function castReturn<T extends NonFunction<any>>(value: T | (() => T)): T;
|
|
74
|
-
declare function pick<O extends object, K extends keyof O>(value: O, keys: K[]): { [Key in K]: O[Key] | null; };
|
|
75
|
-
declare function omit<O extends object, K extends keyof O>(value: O, keys: K[]): { [Key in Exclude<keyof O, K>]: O[Key] | null; };
|
|
94
|
+
declare function pick<O extends object, K extends keyof O = keyof O>(value: O, keys: K[]): { [Key in K]: O[Key] | null; };
|
|
95
|
+
declare function omit<O extends object, K extends keyof O = keyof O>(value: O, keys: K[]): { [Key in Exclude<keyof O, K>]: O[Key] | null; };
|
|
76
96
|
declare function omitNils<O extends object>(value: O): O;
|
|
97
|
+
declare function map<T>(arr: T[], callback: (value: T, index: number, array: T[], end: () => void) => T): T[];
|
|
77
98
|
declare function getMimeTypes(typeAliases: KnownFileTypeAlias[]): string[];
|
|
78
99
|
declare function classNameResolver(baseClassName: string): (className: string) => string;
|
|
79
100
|
declare function classNameExt(rootClassName: string): (className: string) => string;
|
|
@@ -161,7 +182,6 @@ declare function mapToArray<K extends string | number | symbol, V>(map: Map<K, V
|
|
|
161
182
|
[Key in K]: V;
|
|
162
183
|
}[];
|
|
163
184
|
declare function distinct<T>(arr: T[]): T[];
|
|
164
|
-
declare function map<To extends object, From extends object>(from: From, mappedFields: Record<keyof From, keyof To>): To;
|
|
165
185
|
declare function isEmpty(value: string | unknown[]): boolean;
|
|
166
186
|
declare function ifDefined<T, R>(value: T | undefined, cb: (value: T) => R): R | undefined;
|
|
167
187
|
declare function someValuesEmpty<O extends {
|
|
@@ -192,4 +212,4 @@ declare const serverDataAdapter: {
|
|
|
192
212
|
}>(event: "unzip", data: DataType): NormalizeFromServer<DataType>;
|
|
193
213
|
};
|
|
194
214
|
|
|
195
|
-
export { addArticle, arrayWithConst, asyncRun, averageOf, blankSpaces, buildArray, camelCaseToLetter, castArray, castReturn, 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, isIterable, isLetter, isLocalFile, isNumber, isPromise, lastIndex, map, mapToArray, maxOf, minOf, negate, omit, omitNils, ordinalIndicator, overwrite, pick, 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 };
|
|
215
|
+
export { addArticle, arrayWithConst, asyncRun, averageOf, blankSpaces, buildArray, camelCaseToLetter, castArray, castReturn, 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, isIterable, isLetter, isLocalFile, isNumber, isPromise, lastIndex, limit, map, mapToArray, maxOf, minOf, negate, omit, omitNils, ordinalIndicator, overwrite, parseAddress, parseDate, parseFileSize, parseMoney, parseName, pick, 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
|
@@ -515,6 +515,60 @@ function isPromise(value) {
|
|
|
515
515
|
if (value instanceof Promise) return true;
|
|
516
516
|
return !!value && (typeof value === "object" || typeof value === "function") && "then" in value && typeof value.then === "function";
|
|
517
517
|
}
|
|
518
|
+
var parseDate = dateFormat;
|
|
519
|
+
function parseName(value) {
|
|
520
|
+
if (typeof value === "string") {
|
|
521
|
+
const [first2 = "", last2 = ""] = (value || "").trim().split(" ");
|
|
522
|
+
return { first: first2, last: last2 };
|
|
523
|
+
}
|
|
524
|
+
const { first = "", last = "" } = value || {};
|
|
525
|
+
return first.trim() + " " + last.trim();
|
|
526
|
+
}
|
|
527
|
+
function parseMoney(value) {
|
|
528
|
+
if (typeof value === "string") return StringFormatter_default.toMoney(value);
|
|
529
|
+
return NumberFormatter_default.toMoney(value);
|
|
530
|
+
}
|
|
531
|
+
function parseAddress(address, ...args) {
|
|
532
|
+
if (typeof address === "string") {
|
|
533
|
+
const [
|
|
534
|
+
options = {
|
|
535
|
+
delimiter: "|",
|
|
536
|
+
syntax: ["streetAddress", "city", "parish", "country"]
|
|
537
|
+
}
|
|
538
|
+
] = args;
|
|
539
|
+
if (typeof options === "boolean") {
|
|
540
|
+
throw new Error(
|
|
541
|
+
"Type mismatch. Expected 'object' but 'boolean' was provided."
|
|
542
|
+
);
|
|
543
|
+
}
|
|
544
|
+
const fields = address.split(options.delimiter);
|
|
545
|
+
return Object.fromEntries(
|
|
546
|
+
limit(distinct(options.syntax), 4).map((key, i) => {
|
|
547
|
+
return [key, fields[i]];
|
|
548
|
+
})
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
if (typeof address === "object") {
|
|
552
|
+
const [inline] = args;
|
|
553
|
+
return addressToString(
|
|
554
|
+
address,
|
|
555
|
+
typeof inline === "boolean" ? inline : void 0
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
return null;
|
|
559
|
+
}
|
|
560
|
+
function parseFileSize(bytes) {
|
|
561
|
+
return new FileSizeFormatter(bytes).format();
|
|
562
|
+
}
|
|
563
|
+
function limit(array, limit2) {
|
|
564
|
+
const newArray = [];
|
|
565
|
+
if (!array) return;
|
|
566
|
+
for (const item of array) {
|
|
567
|
+
if (newArray.length === limit2) break;
|
|
568
|
+
newArray.push(item);
|
|
569
|
+
}
|
|
570
|
+
return newArray;
|
|
571
|
+
}
|
|
518
572
|
function castArray(value) {
|
|
519
573
|
return Array.isArray(value) ? value : [value];
|
|
520
574
|
}
|
|
@@ -550,6 +604,16 @@ function omitNils(value) {
|
|
|
550
604
|
}
|
|
551
605
|
return result;
|
|
552
606
|
}
|
|
607
|
+
function map(arr, callback) {
|
|
608
|
+
let ended = false;
|
|
609
|
+
for (let i = 0; i < arr.length; i++) {
|
|
610
|
+
if (ended) break;
|
|
611
|
+
arr[i] = callback(arr[i], i, arr, () => {
|
|
612
|
+
ended = true;
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
return arr;
|
|
616
|
+
}
|
|
553
617
|
function getMimeTypes(typeAliases) {
|
|
554
618
|
return distinct(strictArray(typeAliases)).map((alias) => LOCAL_FILE_MIME_TYPES2[alias]).flat();
|
|
555
619
|
}
|
|
@@ -779,14 +843,6 @@ function distinct(arr) {
|
|
|
779
843
|
});
|
|
780
844
|
return newArr;
|
|
781
845
|
}
|
|
782
|
-
function map(from, mappedFields) {
|
|
783
|
-
return Object.fromEntries(
|
|
784
|
-
Object.keys(mappedFields).map((key) => {
|
|
785
|
-
const validKey = key;
|
|
786
|
-
return [mappedFields[validKey], from[validKey]];
|
|
787
|
-
})
|
|
788
|
-
);
|
|
789
|
-
}
|
|
790
846
|
function isEmpty(value) {
|
|
791
847
|
const valueLength = typeof value === "string" ? value.trim().length : value.length;
|
|
792
848
|
return valueLength === 0;
|
|
@@ -1081,6 +1137,7 @@ export {
|
|
|
1081
1137
|
isNumber,
|
|
1082
1138
|
isPromise,
|
|
1083
1139
|
lastIndex,
|
|
1140
|
+
limit,
|
|
1084
1141
|
map,
|
|
1085
1142
|
mapToArray,
|
|
1086
1143
|
maxOf,
|
|
@@ -1090,6 +1147,11 @@ export {
|
|
|
1090
1147
|
omitNils,
|
|
1091
1148
|
ordinalIndicator,
|
|
1092
1149
|
overwrite,
|
|
1150
|
+
parseAddress,
|
|
1151
|
+
parseDate,
|
|
1152
|
+
parseFileSize,
|
|
1153
|
+
parseMoney,
|
|
1154
|
+
parseName,
|
|
1093
1155
|
pick,
|
|
1094
1156
|
pluralize,
|
|
1095
1157
|
poll,
|