@wavy/fn 0.0.31 → 0.0.32
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 +53 -1
- package/dist/main.d.cts +9 -1
- package/dist/main.d.ts +9 -1
- package/dist/main.js +50 -1
- package/package.json +1 -1
package/dist/main.cjs
CHANGED
|
@@ -41,11 +41,14 @@ __export(main_exports, {
|
|
|
41
41
|
dropLast: () => dropLast,
|
|
42
42
|
dropLastWhile: () => dropLastWhile,
|
|
43
43
|
dropWhile: () => dropWhile,
|
|
44
|
+
findChanges: () => findChanges,
|
|
45
|
+
findObjectChanges: () => findObjectChanges,
|
|
44
46
|
format: () => format,
|
|
45
47
|
getCaps: () => getCaps,
|
|
46
48
|
getFileExt: () => getFileExt,
|
|
47
49
|
getFilename: () => getFilename,
|
|
48
50
|
getMimeTypes: () => getMimeTypes,
|
|
51
|
+
getObjectValue: () => getObjectValue,
|
|
49
52
|
group: () => group,
|
|
50
53
|
hasIndex: () => hasIndex,
|
|
51
54
|
ifDefined: () => ifDefined,
|
|
@@ -613,6 +616,47 @@ function isFileDetails(value) {
|
|
|
613
616
|
return false;
|
|
614
617
|
}
|
|
615
618
|
}
|
|
619
|
+
function getObjectValue(obj, path) {
|
|
620
|
+
const pathArr = path.split(".");
|
|
621
|
+
return pathArr.reduce((currentObj, key) => {
|
|
622
|
+
return currentObj?.[key];
|
|
623
|
+
}, obj);
|
|
624
|
+
}
|
|
625
|
+
function findObjectChanges(source, compareTo, options) {
|
|
626
|
+
const changes = [];
|
|
627
|
+
let entries = Object.entries(source);
|
|
628
|
+
for (let idx = 0; idx < entries.length; idx++) {
|
|
629
|
+
const [key, value] = entries[idx];
|
|
630
|
+
const comparedValue = getObjectValue(compareTo, key);
|
|
631
|
+
const checkArrayEquality = options?.strict ? strictArrayEquals : arrayEquals;
|
|
632
|
+
if (Array.isArray(value) && Array.isArray(comparedValue) && !checkArrayEquality(value, comparedValue)) {
|
|
633
|
+
changes.push(key);
|
|
634
|
+
} else if (typeof value === "object" && typeof comparedValue === "object") {
|
|
635
|
+
const newEntries = Object.entries(value).map(([newKey, newValue]) => {
|
|
636
|
+
return [key + "." + newKey, newValue];
|
|
637
|
+
});
|
|
638
|
+
entries.push(...newEntries);
|
|
639
|
+
} else if (JSON.stringify(value) !== JSON.stringify(comparedValue)) {
|
|
640
|
+
changes.push(key);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
return changes;
|
|
644
|
+
}
|
|
645
|
+
function findChanges(source, compareTo) {
|
|
646
|
+
if (Array.isArray(source) && Array.isArray(compareTo)) {
|
|
647
|
+
const changes = [];
|
|
648
|
+
for (let idx = 0; idx < source.length; idx++) {
|
|
649
|
+
const _changes = findObjectChanges(source[idx], compareTo[idx]);
|
|
650
|
+
if (_changes.length > 0) {
|
|
651
|
+
changes.push({ keys: _changes, index: idx });
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
return changes;
|
|
655
|
+
} else if (typeof source === "object" && typeof compareTo === "object") {
|
|
656
|
+
return findObjectChanges(source, compareTo);
|
|
657
|
+
}
|
|
658
|
+
return [];
|
|
659
|
+
}
|
|
616
660
|
function isIterable(value) {
|
|
617
661
|
return !!value && typeof value === "object" && Symbol.iterator in value && typeof value[Symbol.iterator] === "function";
|
|
618
662
|
}
|
|
@@ -626,7 +670,12 @@ function arrayEquals(...args) {
|
|
|
626
670
|
if (args.length === 1) return true;
|
|
627
671
|
return args.every((array, i) => {
|
|
628
672
|
const compareTo = args[i - 1] ?? args[i + 1];
|
|
629
|
-
|
|
673
|
+
const fmtCompareTo = compareTo.map(
|
|
674
|
+
(item) => JSON.stringify(item).toLowerCase()
|
|
675
|
+
);
|
|
676
|
+
return array.length === compareTo.length && array.every((item) => {
|
|
677
|
+
return fmtCompareTo.includes(JSON.stringify(item).toLowerCase());
|
|
678
|
+
});
|
|
630
679
|
});
|
|
631
680
|
}
|
|
632
681
|
function strictArrayEquals(...args) {
|
|
@@ -1067,11 +1116,14 @@ function arrayWithConst(array) {
|
|
|
1067
1116
|
dropLast,
|
|
1068
1117
|
dropLastWhile,
|
|
1069
1118
|
dropWhile,
|
|
1119
|
+
findChanges,
|
|
1120
|
+
findObjectChanges,
|
|
1070
1121
|
format,
|
|
1071
1122
|
getCaps,
|
|
1072
1123
|
getFileExt,
|
|
1073
1124
|
getFilename,
|
|
1074
1125
|
getMimeTypes,
|
|
1126
|
+
getObjectValue,
|
|
1075
1127
|
group,
|
|
1076
1128
|
hasIndex,
|
|
1077
1129
|
ifDefined,
|
package/dist/main.d.cts
CHANGED
|
@@ -84,6 +84,14 @@ declare const toMoney: (value: string | number, options?: NumberFormatterTypes["
|
|
|
84
84
|
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;
|
|
85
85
|
declare function isFile(value: unknown): value is File;
|
|
86
86
|
declare function isFileDetails(value: unknown): value is FileDetails;
|
|
87
|
+
declare function getObjectValue(obj: object, path: string): object;
|
|
88
|
+
declare function findObjectChanges<T extends object>(source: T, compareTo: T, options?: Partial<{
|
|
89
|
+
strict: boolean;
|
|
90
|
+
}>): string[];
|
|
91
|
+
declare function findChanges<T extends object | object[]>(source: T, compareTo: T): T extends object[] ? {
|
|
92
|
+
keys: string[];
|
|
93
|
+
index: number;
|
|
94
|
+
}[] : T extends object ? string[] : never;
|
|
87
95
|
declare function isIterable<T>(value: unknown): value is Iterable<T>;
|
|
88
96
|
declare function isPromise<T>(value: unknown): value is Promise<T>;
|
|
89
97
|
declare function arrayEquals(...args: any[][]): boolean;
|
|
@@ -219,4 +227,4 @@ declare function arrayWithConst<T>(array: T[]): {
|
|
|
219
227
|
asConst: readonly T[];
|
|
220
228
|
};
|
|
221
229
|
|
|
222
|
-
export { addArticle, arrayEquals, 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, isFileDetails, isIterable, isLetter, 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, someValuesEmpty, sort, strictArray, strictArrayEquals, stringToSearch, subObjectList, sumOf, take, takeLast, takeLastWhile, takeWhile, timeDuration, toNumber, toObject, trimString, undefinedIfEmpty, upperFirst, windowed };
|
|
230
|
+
export { addArticle, arrayEquals, arrayWithConst, asyncRun, averageOf, blankSpaces, buildArray, camelCaseToLetter, castArray, castReturn, classNameExt, classNameResolver, coerceIn, copyToClipboard, count, dataSearcher, distinct, drop, dropLast, dropLastWhile, dropWhile, findChanges, findObjectChanges, format, getCaps, getFileExt, getFilename, getMimeTypes, getObjectValue, group, hasIndex, ifDefined, ifEmpty, inRange, indexOf, indices, inferFilename, insertAt, isEmpty, isFile, isFileDetails, isIterable, isLetter, 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, someValuesEmpty, sort, strictArray, strictArrayEquals, stringToSearch, subObjectList, sumOf, take, takeLast, takeLastWhile, takeWhile, timeDuration, toNumber, toObject, trimString, undefinedIfEmpty, upperFirst, windowed };
|
package/dist/main.d.ts
CHANGED
|
@@ -84,6 +84,14 @@ declare const toMoney: (value: string | number, options?: NumberFormatterTypes["
|
|
|
84
84
|
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;
|
|
85
85
|
declare function isFile(value: unknown): value is File;
|
|
86
86
|
declare function isFileDetails(value: unknown): value is FileDetails;
|
|
87
|
+
declare function getObjectValue(obj: object, path: string): object;
|
|
88
|
+
declare function findObjectChanges<T extends object>(source: T, compareTo: T, options?: Partial<{
|
|
89
|
+
strict: boolean;
|
|
90
|
+
}>): string[];
|
|
91
|
+
declare function findChanges<T extends object | object[]>(source: T, compareTo: T): T extends object[] ? {
|
|
92
|
+
keys: string[];
|
|
93
|
+
index: number;
|
|
94
|
+
}[] : T extends object ? string[] : never;
|
|
87
95
|
declare function isIterable<T>(value: unknown): value is Iterable<T>;
|
|
88
96
|
declare function isPromise<T>(value: unknown): value is Promise<T>;
|
|
89
97
|
declare function arrayEquals(...args: any[][]): boolean;
|
|
@@ -219,4 +227,4 @@ declare function arrayWithConst<T>(array: T[]): {
|
|
|
219
227
|
asConst: readonly T[];
|
|
220
228
|
};
|
|
221
229
|
|
|
222
|
-
export { addArticle, arrayEquals, 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, isFileDetails, isIterable, isLetter, 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, someValuesEmpty, sort, strictArray, strictArrayEquals, stringToSearch, subObjectList, sumOf, take, takeLast, takeLastWhile, takeWhile, timeDuration, toNumber, toObject, trimString, undefinedIfEmpty, upperFirst, windowed };
|
|
230
|
+
export { addArticle, arrayEquals, arrayWithConst, asyncRun, averageOf, blankSpaces, buildArray, camelCaseToLetter, castArray, castReturn, classNameExt, classNameResolver, coerceIn, copyToClipboard, count, dataSearcher, distinct, drop, dropLast, dropLastWhile, dropWhile, findChanges, findObjectChanges, format, getCaps, getFileExt, getFilename, getMimeTypes, getObjectValue, group, hasIndex, ifDefined, ifEmpty, inRange, indexOf, indices, inferFilename, insertAt, isEmpty, isFile, isFileDetails, isIterable, isLetter, 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, someValuesEmpty, sort, strictArray, strictArrayEquals, stringToSearch, subObjectList, sumOf, take, takeLast, takeLastWhile, takeWhile, timeDuration, toNumber, toObject, trimString, undefinedIfEmpty, upperFirst, windowed };
|
package/dist/main.js
CHANGED
|
@@ -506,6 +506,47 @@ function isFileDetails(value) {
|
|
|
506
506
|
return false;
|
|
507
507
|
}
|
|
508
508
|
}
|
|
509
|
+
function getObjectValue(obj, path) {
|
|
510
|
+
const pathArr = path.split(".");
|
|
511
|
+
return pathArr.reduce((currentObj, key) => {
|
|
512
|
+
return currentObj?.[key];
|
|
513
|
+
}, obj);
|
|
514
|
+
}
|
|
515
|
+
function findObjectChanges(source, compareTo, options) {
|
|
516
|
+
const changes = [];
|
|
517
|
+
let entries = Object.entries(source);
|
|
518
|
+
for (let idx = 0; idx < entries.length; idx++) {
|
|
519
|
+
const [key, value] = entries[idx];
|
|
520
|
+
const comparedValue = getObjectValue(compareTo, key);
|
|
521
|
+
const checkArrayEquality = options?.strict ? strictArrayEquals : arrayEquals;
|
|
522
|
+
if (Array.isArray(value) && Array.isArray(comparedValue) && !checkArrayEquality(value, comparedValue)) {
|
|
523
|
+
changes.push(key);
|
|
524
|
+
} else if (typeof value === "object" && typeof comparedValue === "object") {
|
|
525
|
+
const newEntries = Object.entries(value).map(([newKey, newValue]) => {
|
|
526
|
+
return [key + "." + newKey, newValue];
|
|
527
|
+
});
|
|
528
|
+
entries.push(...newEntries);
|
|
529
|
+
} else if (JSON.stringify(value) !== JSON.stringify(comparedValue)) {
|
|
530
|
+
changes.push(key);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
return changes;
|
|
534
|
+
}
|
|
535
|
+
function findChanges(source, compareTo) {
|
|
536
|
+
if (Array.isArray(source) && Array.isArray(compareTo)) {
|
|
537
|
+
const changes = [];
|
|
538
|
+
for (let idx = 0; idx < source.length; idx++) {
|
|
539
|
+
const _changes = findObjectChanges(source[idx], compareTo[idx]);
|
|
540
|
+
if (_changes.length > 0) {
|
|
541
|
+
changes.push({ keys: _changes, index: idx });
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
return changes;
|
|
545
|
+
} else if (typeof source === "object" && typeof compareTo === "object") {
|
|
546
|
+
return findObjectChanges(source, compareTo);
|
|
547
|
+
}
|
|
548
|
+
return [];
|
|
549
|
+
}
|
|
509
550
|
function isIterable(value) {
|
|
510
551
|
return !!value && typeof value === "object" && Symbol.iterator in value && typeof value[Symbol.iterator] === "function";
|
|
511
552
|
}
|
|
@@ -519,7 +560,12 @@ function arrayEquals(...args) {
|
|
|
519
560
|
if (args.length === 1) return true;
|
|
520
561
|
return args.every((array, i) => {
|
|
521
562
|
const compareTo = args[i - 1] ?? args[i + 1];
|
|
522
|
-
|
|
563
|
+
const fmtCompareTo = compareTo.map(
|
|
564
|
+
(item) => JSON.stringify(item).toLowerCase()
|
|
565
|
+
);
|
|
566
|
+
return array.length === compareTo.length && array.every((item) => {
|
|
567
|
+
return fmtCompareTo.includes(JSON.stringify(item).toLowerCase());
|
|
568
|
+
});
|
|
523
569
|
});
|
|
524
570
|
}
|
|
525
571
|
function strictArrayEquals(...args) {
|
|
@@ -959,11 +1005,14 @@ export {
|
|
|
959
1005
|
dropLast,
|
|
960
1006
|
dropLastWhile,
|
|
961
1007
|
dropWhile,
|
|
1008
|
+
findChanges,
|
|
1009
|
+
findObjectChanges,
|
|
962
1010
|
format,
|
|
963
1011
|
getCaps,
|
|
964
1012
|
getFileExt,
|
|
965
1013
|
getFilename,
|
|
966
1014
|
getMimeTypes,
|
|
1015
|
+
getObjectValue,
|
|
967
1016
|
group,
|
|
968
1017
|
hasIndex,
|
|
969
1018
|
ifDefined,
|