@wavy/fn 0.0.26 → 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 +72 -10
- package/dist/main.d.cts +27 -8
- package/dist/main.d.ts +27 -8
- package/dist/main.js +67 -10
- 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,10 @@ __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,
|
|
74
79
|
parseName: () => parseName,
|
|
75
80
|
pick: () => pick,
|
|
76
81
|
pluralize: () => pluralize,
|
|
@@ -618,9 +623,59 @@ function isPromise(value) {
|
|
|
618
623
|
if (value instanceof Promise) return true;
|
|
619
624
|
return !!value && (typeof value === "object" || typeof value === "function") && "then" in value && typeof value.then === "function";
|
|
620
625
|
}
|
|
626
|
+
var parseDate = dateFormat;
|
|
621
627
|
function parseName(value) {
|
|
622
|
-
|
|
623
|
-
|
|
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;
|
|
624
679
|
}
|
|
625
680
|
function castArray(value) {
|
|
626
681
|
return Array.isArray(value) ? value : [value];
|
|
@@ -657,6 +712,16 @@ function omitNils(value) {
|
|
|
657
712
|
}
|
|
658
713
|
return result;
|
|
659
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
|
+
}
|
|
660
725
|
function getMimeTypes(typeAliases) {
|
|
661
726
|
return distinct(strictArray(typeAliases)).map((alias) => import_types2.LOCAL_FILE_MIME_TYPES[alias]).flat();
|
|
662
727
|
}
|
|
@@ -886,14 +951,6 @@ function distinct(arr) {
|
|
|
886
951
|
});
|
|
887
952
|
return newArr;
|
|
888
953
|
}
|
|
889
|
-
function map(from, mappedFields) {
|
|
890
|
-
return Object.fromEntries(
|
|
891
|
-
Object.keys(mappedFields).map((key) => {
|
|
892
|
-
const validKey = key;
|
|
893
|
-
return [mappedFields[validKey], from[validKey]];
|
|
894
|
-
})
|
|
895
|
-
);
|
|
896
|
-
}
|
|
897
954
|
function isEmpty(value) {
|
|
898
955
|
const valueLength = typeof value === "string" ? value.trim().length : value.length;
|
|
899
956
|
return valueLength === 0;
|
|
@@ -1189,6 +1246,7 @@ var serverDataAdapter = new ServerDataAdapter().invoke;
|
|
|
1189
1246
|
isNumber,
|
|
1190
1247
|
isPromise,
|
|
1191
1248
|
lastIndex,
|
|
1249
|
+
limit,
|
|
1192
1250
|
map,
|
|
1193
1251
|
mapToArray,
|
|
1194
1252
|
maxOf,
|
|
@@ -1198,6 +1256,10 @@ var serverDataAdapter = new ServerDataAdapter().invoke;
|
|
|
1198
1256
|
omitNils,
|
|
1199
1257
|
ordinalIndicator,
|
|
1200
1258
|
overwrite,
|
|
1259
|
+
parseAddress,
|
|
1260
|
+
parseDate,
|
|
1261
|
+
parseFileSize,
|
|
1262
|
+
parseMoney,
|
|
1201
1263
|
parseName,
|
|
1202
1264
|
pick,
|
|
1203
1265
|
pluralize,
|
package/dist/main.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import "@wavy/types"
|
|
2
|
-
import
|
|
3
|
-
import { LocalFile, Name, 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
|
|
|
@@ -61,20 +60,41 @@ declare const toNumber: typeof StringFormatter.toNumber;
|
|
|
61
60
|
declare const addArticle: typeof StringFormatter.addArticle;
|
|
62
61
|
declare const pluralize: typeof StringFormatter.pluralize;
|
|
63
62
|
declare const nameToString: (name: Name | undefined) => string;
|
|
64
|
-
declare const addressToString: (address:
|
|
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>;
|
|
72
|
-
declare
|
|
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;
|
|
73
92
|
declare function castArray<T>(value: T | T[]): T[];
|
|
74
93
|
declare function castReturn<T extends NonFunction<any>>(value: T | (() => T)): T;
|
|
75
|
-
declare function pick<O extends object, K extends keyof O>(value: O, keys: K[]): { [Key in K]: O[Key] | null; };
|
|
76
|
-
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; };
|
|
77
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[];
|
|
78
98
|
declare function getMimeTypes(typeAliases: KnownFileTypeAlias[]): string[];
|
|
79
99
|
declare function classNameResolver(baseClassName: string): (className: string) => string;
|
|
80
100
|
declare function classNameExt(rootClassName: string): (className: string) => string;
|
|
@@ -162,7 +182,6 @@ declare function mapToArray<K extends string | number | symbol, V>(map: Map<K, V
|
|
|
162
182
|
[Key in K]: V;
|
|
163
183
|
}[];
|
|
164
184
|
declare function distinct<T>(arr: T[]): T[];
|
|
165
|
-
declare function map<To extends object, From extends object>(from: From, mappedFields: Record<keyof From, keyof To>): To;
|
|
166
185
|
declare function isEmpty(value: string | unknown[]): boolean;
|
|
167
186
|
declare function ifDefined<T, R>(value: T | undefined, cb: (value: T) => R): R | undefined;
|
|
168
187
|
declare function someValuesEmpty<O extends {
|
|
@@ -193,4 +212,4 @@ declare const serverDataAdapter: {
|
|
|
193
212
|
}>(event: "unzip", data: DataType): NormalizeFromServer<DataType>;
|
|
194
213
|
};
|
|
195
214
|
|
|
196
|
-
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, 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 };
|
|
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, Name, 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
|
|
|
@@ -61,20 +60,41 @@ declare const toNumber: typeof StringFormatter.toNumber;
|
|
|
61
60
|
declare const addArticle: typeof StringFormatter.addArticle;
|
|
62
61
|
declare const pluralize: typeof StringFormatter.pluralize;
|
|
63
62
|
declare const nameToString: (name: Name | undefined) => string;
|
|
64
|
-
declare const addressToString: (address:
|
|
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>;
|
|
72
|
-
declare
|
|
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;
|
|
73
92
|
declare function castArray<T>(value: T | T[]): T[];
|
|
74
93
|
declare function castReturn<T extends NonFunction<any>>(value: T | (() => T)): T;
|
|
75
|
-
declare function pick<O extends object, K extends keyof O>(value: O, keys: K[]): { [Key in K]: O[Key] | null; };
|
|
76
|
-
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; };
|
|
77
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[];
|
|
78
98
|
declare function getMimeTypes(typeAliases: KnownFileTypeAlias[]): string[];
|
|
79
99
|
declare function classNameResolver(baseClassName: string): (className: string) => string;
|
|
80
100
|
declare function classNameExt(rootClassName: string): (className: string) => string;
|
|
@@ -162,7 +182,6 @@ declare function mapToArray<K extends string | number | symbol, V>(map: Map<K, V
|
|
|
162
182
|
[Key in K]: V;
|
|
163
183
|
}[];
|
|
164
184
|
declare function distinct<T>(arr: T[]): T[];
|
|
165
|
-
declare function map<To extends object, From extends object>(from: From, mappedFields: Record<keyof From, keyof To>): To;
|
|
166
185
|
declare function isEmpty(value: string | unknown[]): boolean;
|
|
167
186
|
declare function ifDefined<T, R>(value: T | undefined, cb: (value: T) => R): R | undefined;
|
|
168
187
|
declare function someValuesEmpty<O extends {
|
|
@@ -193,4 +212,4 @@ declare const serverDataAdapter: {
|
|
|
193
212
|
}>(event: "unzip", data: DataType): NormalizeFromServer<DataType>;
|
|
194
213
|
};
|
|
195
214
|
|
|
196
|
-
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, 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 };
|
|
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,9 +515,59 @@ 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;
|
|
518
519
|
function parseName(value) {
|
|
519
|
-
|
|
520
|
-
|
|
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;
|
|
521
571
|
}
|
|
522
572
|
function castArray(value) {
|
|
523
573
|
return Array.isArray(value) ? value : [value];
|
|
@@ -554,6 +604,16 @@ function omitNils(value) {
|
|
|
554
604
|
}
|
|
555
605
|
return result;
|
|
556
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
|
+
}
|
|
557
617
|
function getMimeTypes(typeAliases) {
|
|
558
618
|
return distinct(strictArray(typeAliases)).map((alias) => LOCAL_FILE_MIME_TYPES2[alias]).flat();
|
|
559
619
|
}
|
|
@@ -783,14 +843,6 @@ function distinct(arr) {
|
|
|
783
843
|
});
|
|
784
844
|
return newArr;
|
|
785
845
|
}
|
|
786
|
-
function map(from, mappedFields) {
|
|
787
|
-
return Object.fromEntries(
|
|
788
|
-
Object.keys(mappedFields).map((key) => {
|
|
789
|
-
const validKey = key;
|
|
790
|
-
return [mappedFields[validKey], from[validKey]];
|
|
791
|
-
})
|
|
792
|
-
);
|
|
793
|
-
}
|
|
794
846
|
function isEmpty(value) {
|
|
795
847
|
const valueLength = typeof value === "string" ? value.trim().length : value.length;
|
|
796
848
|
return valueLength === 0;
|
|
@@ -1085,6 +1137,7 @@ export {
|
|
|
1085
1137
|
isNumber,
|
|
1086
1138
|
isPromise,
|
|
1087
1139
|
lastIndex,
|
|
1140
|
+
limit,
|
|
1088
1141
|
map,
|
|
1089
1142
|
mapToArray,
|
|
1090
1143
|
maxOf,
|
|
@@ -1094,6 +1147,10 @@ export {
|
|
|
1094
1147
|
omitNils,
|
|
1095
1148
|
ordinalIndicator,
|
|
1096
1149
|
overwrite,
|
|
1150
|
+
parseAddress,
|
|
1151
|
+
parseDate,
|
|
1152
|
+
parseFileSize,
|
|
1153
|
+
parseMoney,
|
|
1097
1154
|
parseName,
|
|
1098
1155
|
pick,
|
|
1099
1156
|
pluralize,
|