@wavy/fn 0.0.36 → 0.0.39

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
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/main.ts
21
21
  var main_exports = {};
22
22
  __export(main_exports, {
23
+ TODO: () => TODO,
23
24
  addArticle: () => addArticle,
24
25
  arrayEquals: () => arrayEquals,
25
26
  arrayWithConst: () => arrayWithConst,
@@ -48,7 +49,6 @@ __export(main_exports, {
48
49
  getFileExt: () => getFileExt,
49
50
  getFilename: () => getFilename,
50
51
  getMimeTypes: () => getMimeTypes,
51
- getObjectValue: () => getObjectValue,
52
52
  group: () => group,
53
53
  hasIndex: () => hasIndex,
54
54
  ifDefined: () => ifDefined,
@@ -104,6 +104,7 @@ __export(main_exports, {
104
104
  timeDuration: () => timeDuration,
105
105
  toNumber: () => toNumber,
106
106
  toObject: () => ObjectConverter_default,
107
+ traverse: () => traverse,
107
108
  trimString: () => trimString,
108
109
  undefinedIfEmpty: () => undefinedIfEmpty,
109
110
  upperFirst: () => upperFirst,
@@ -595,6 +596,9 @@ function format(event, ...args) {
595
596
  return event;
596
597
  }
597
598
  }
599
+ function TODO(message) {
600
+ throw new Error(`Todo: ${message}`);
601
+ }
598
602
  function isFile(value) {
599
603
  const requiredKeys = [
600
604
  "name",
@@ -616,7 +620,7 @@ function isFileDetails(value) {
616
620
  return false;
617
621
  }
618
622
  }
619
- function getObjectValue(obj, path) {
623
+ function traverse(obj, path) {
620
624
  const pathArr = path.split(".");
621
625
  return pathArr.reduce((currentObj, key) => {
622
626
  return currentObj?.[key];
@@ -625,12 +629,19 @@ function getObjectValue(obj, path) {
625
629
  function findObjectChanges(source, compareTo, options) {
626
630
  let entries = Object.entries(source);
627
631
  const changes = Object.keys(compareTo).filter(
628
- (key) => !entries.some(([sourceKey]) => sourceKey === key)
632
+ (key) => !options?.ignoredKeys?.includes(key) && !entries.some(([sourceKey]) => sourceKey === key)
629
633
  );
634
+ const ignoreDepth = options?.ignoreDepth === "max" ? Infinity : Math.abs(options?.ignoreDepth || 0);
635
+ const isKeyIgnored = (key) => {
636
+ return key.split(".").some(
637
+ (key2, idx) => idx <= ignoreDepth && options?.ignoredKeys?.includes(key2)
638
+ );
639
+ };
630
640
  for (let idx = 0; idx < entries.length; idx++) {
631
641
  const [key, value] = entries[idx];
632
- const comparedValue = getObjectValue(compareTo, key);
642
+ const comparedValue = traverse(compareTo, key);
633
643
  const checkArrayEquality = options?.strict ? strictArrayEquals : arrayEquals;
644
+ if (isKeyIgnored(key)) continue;
634
645
  if (Array.isArray(value) && Array.isArray(comparedValue) && !checkArrayEquality(value, comparedValue)) {
635
646
  changes.push(key);
636
647
  } else if (!!value && !!comparedValue && typeof value === "object" && typeof comparedValue === "object") {
@@ -640,6 +651,9 @@ function findObjectChanges(source, compareTo, options) {
640
651
  return [path, nestedValue];
641
652
  }
642
653
  );
654
+ const newCompareTo = traverse(compareTo, key);
655
+ const nonExistentKeys = Object.keys(newCompareTo).filter((key2) => !isKeyIgnored(key2) && !(key2 in value)).map((nestedKey) => [key, nestedKey].join("."));
656
+ changes.push(...nonExistentKeys);
643
657
  entries.push(...newEntries);
644
658
  } else if (JSON.stringify(value) !== JSON.stringify(comparedValue)) {
645
659
  changes.push(key);
@@ -647,18 +661,18 @@ function findObjectChanges(source, compareTo, options) {
647
661
  }
648
662
  return changes;
649
663
  }
650
- function findChanges(source, compareTo) {
664
+ function findChanges(source, compareTo, options) {
651
665
  if (Array.isArray(source) && Array.isArray(compareTo)) {
652
666
  const changes = [];
653
667
  for (let idx = 0; idx < source.length; idx++) {
654
- const _changes = findObjectChanges(source[idx], compareTo[idx]);
668
+ const _changes = findObjectChanges(source[idx], compareTo[idx], options);
655
669
  if (_changes.length > 0) {
656
670
  changes.push({ keys: _changes, index: idx });
657
671
  }
658
672
  }
659
673
  return changes;
660
674
  } else if (typeof source === "object" && typeof compareTo === "object") {
661
- return findObjectChanges(source, compareTo);
675
+ return findObjectChanges(source, compareTo, options);
662
676
  }
663
677
  return [];
664
678
  }
@@ -1101,6 +1115,7 @@ function arrayWithConst(array) {
1101
1115
  }
1102
1116
  // Annotate the CommonJS export names for ESM import in node:
1103
1117
  0 && (module.exports = {
1118
+ TODO,
1104
1119
  addArticle,
1105
1120
  arrayEquals,
1106
1121
  arrayWithConst,
@@ -1129,7 +1144,6 @@ function arrayWithConst(array) {
1129
1144
  getFileExt,
1130
1145
  getFilename,
1131
1146
  getMimeTypes,
1132
- getObjectValue,
1133
1147
  group,
1134
1148
  hasIndex,
1135
1149
  ifDefined,
@@ -1185,6 +1199,7 @@ function arrayWithConst(array) {
1185
1199
  timeDuration,
1186
1200
  toNumber,
1187
1201
  toObject,
1202
+ traverse,
1188
1203
  trimString,
1189
1204
  undefinedIfEmpty,
1190
1205
  upperFirst,
package/dist/main.d.cts CHANGED
@@ -82,13 +82,22 @@ declare const toMoney: (value: string | number, options?: NumberFormatterTypes["
82
82
  * @example parseDate, parseMoney, parseName, parseAddress, parseFileSize
83
83
  */
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
+ declare function TODO(message: string): void;
85
86
  declare function isFile(value: unknown): value is File;
86
87
  declare function isFileDetails(value: unknown): value is FileDetails;
87
- declare function getObjectValue(obj: object, path: string): object;
88
+ declare function traverse(obj: object, path: string): object;
88
89
  declare function findObjectChanges<T extends object>(source: T, compareTo: T, options?: Partial<{
89
90
  strict: boolean;
91
+ ignoredKeys: (keyof T | (string & {}))[];
92
+ /**
93
+ * How deep the ignoredKeys should be applied.
94
+ *
95
+ * @default 0 */
96
+ ignoreDepth: "max" | number;
90
97
  }>): string[];
91
- declare function findChanges<T extends object | object[]>(source: T, compareTo: T): T extends object[] ? {
98
+ declare function findChanges<T extends object | object[]>(source: T, compareTo: T, options?: Parameters<typeof findObjectChanges>["2"] & {
99
+ ignoredKeys?: T extends any[] ? (keyof T[number] | (string & {}))[] : T extends object ? (keyof T | (string & {}))[] : never;
100
+ }): T extends object[] ? {
92
101
  keys: string[];
93
102
  index: number;
94
103
  }[] : T extends object ? string[] : never;
@@ -227,4 +236,4 @@ declare function arrayWithConst<T>(array: T[]): {
227
236
  asConst: readonly T[];
228
237
  };
229
238
 
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 };
239
+ export { TODO, 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, 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, traverse, trimString, undefinedIfEmpty, upperFirst, windowed };
package/dist/main.d.ts CHANGED
@@ -82,13 +82,22 @@ declare const toMoney: (value: string | number, options?: NumberFormatterTypes["
82
82
  * @example parseDate, parseMoney, parseName, parseAddress, parseFileSize
83
83
  */
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
+ declare function TODO(message: string): void;
85
86
  declare function isFile(value: unknown): value is File;
86
87
  declare function isFileDetails(value: unknown): value is FileDetails;
87
- declare function getObjectValue(obj: object, path: string): object;
88
+ declare function traverse(obj: object, path: string): object;
88
89
  declare function findObjectChanges<T extends object>(source: T, compareTo: T, options?: Partial<{
89
90
  strict: boolean;
91
+ ignoredKeys: (keyof T | (string & {}))[];
92
+ /**
93
+ * How deep the ignoredKeys should be applied.
94
+ *
95
+ * @default 0 */
96
+ ignoreDepth: "max" | number;
90
97
  }>): string[];
91
- declare function findChanges<T extends object | object[]>(source: T, compareTo: T): T extends object[] ? {
98
+ declare function findChanges<T extends object | object[]>(source: T, compareTo: T, options?: Parameters<typeof findObjectChanges>["2"] & {
99
+ ignoredKeys?: T extends any[] ? (keyof T[number] | (string & {}))[] : T extends object ? (keyof T | (string & {}))[] : never;
100
+ }): T extends object[] ? {
92
101
  keys: string[];
93
102
  index: number;
94
103
  }[] : T extends object ? string[] : never;
@@ -227,4 +236,4 @@ declare function arrayWithConst<T>(array: T[]): {
227
236
  asConst: readonly T[];
228
237
  };
229
238
 
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 };
239
+ export { TODO, 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, 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, traverse, trimString, undefinedIfEmpty, upperFirst, windowed };
package/dist/main.js CHANGED
@@ -485,6 +485,9 @@ function format(event, ...args) {
485
485
  return event;
486
486
  }
487
487
  }
488
+ function TODO(message) {
489
+ throw new Error(`Todo: ${message}`);
490
+ }
488
491
  function isFile(value) {
489
492
  const requiredKeys = [
490
493
  "name",
@@ -506,7 +509,7 @@ function isFileDetails(value) {
506
509
  return false;
507
510
  }
508
511
  }
509
- function getObjectValue(obj, path) {
512
+ function traverse(obj, path) {
510
513
  const pathArr = path.split(".");
511
514
  return pathArr.reduce((currentObj, key) => {
512
515
  return currentObj?.[key];
@@ -515,12 +518,19 @@ function getObjectValue(obj, path) {
515
518
  function findObjectChanges(source, compareTo, options) {
516
519
  let entries = Object.entries(source);
517
520
  const changes = Object.keys(compareTo).filter(
518
- (key) => !entries.some(([sourceKey]) => sourceKey === key)
521
+ (key) => !options?.ignoredKeys?.includes(key) && !entries.some(([sourceKey]) => sourceKey === key)
519
522
  );
523
+ const ignoreDepth = options?.ignoreDepth === "max" ? Infinity : Math.abs(options?.ignoreDepth || 0);
524
+ const isKeyIgnored = (key) => {
525
+ return key.split(".").some(
526
+ (key2, idx) => idx <= ignoreDepth && options?.ignoredKeys?.includes(key2)
527
+ );
528
+ };
520
529
  for (let idx = 0; idx < entries.length; idx++) {
521
530
  const [key, value] = entries[idx];
522
- const comparedValue = getObjectValue(compareTo, key);
531
+ const comparedValue = traverse(compareTo, key);
523
532
  const checkArrayEquality = options?.strict ? strictArrayEquals : arrayEquals;
533
+ if (isKeyIgnored(key)) continue;
524
534
  if (Array.isArray(value) && Array.isArray(comparedValue) && !checkArrayEquality(value, comparedValue)) {
525
535
  changes.push(key);
526
536
  } else if (!!value && !!comparedValue && typeof value === "object" && typeof comparedValue === "object") {
@@ -530,6 +540,9 @@ function findObjectChanges(source, compareTo, options) {
530
540
  return [path, nestedValue];
531
541
  }
532
542
  );
543
+ const newCompareTo = traverse(compareTo, key);
544
+ const nonExistentKeys = Object.keys(newCompareTo).filter((key2) => !isKeyIgnored(key2) && !(key2 in value)).map((nestedKey) => [key, nestedKey].join("."));
545
+ changes.push(...nonExistentKeys);
533
546
  entries.push(...newEntries);
534
547
  } else if (JSON.stringify(value) !== JSON.stringify(comparedValue)) {
535
548
  changes.push(key);
@@ -537,18 +550,18 @@ function findObjectChanges(source, compareTo, options) {
537
550
  }
538
551
  return changes;
539
552
  }
540
- function findChanges(source, compareTo) {
553
+ function findChanges(source, compareTo, options) {
541
554
  if (Array.isArray(source) && Array.isArray(compareTo)) {
542
555
  const changes = [];
543
556
  for (let idx = 0; idx < source.length; idx++) {
544
- const _changes = findObjectChanges(source[idx], compareTo[idx]);
557
+ const _changes = findObjectChanges(source[idx], compareTo[idx], options);
545
558
  if (_changes.length > 0) {
546
559
  changes.push({ keys: _changes, index: idx });
547
560
  }
548
561
  }
549
562
  return changes;
550
563
  } else if (typeof source === "object" && typeof compareTo === "object") {
551
- return findObjectChanges(source, compareTo);
564
+ return findObjectChanges(source, compareTo, options);
552
565
  }
553
566
  return [];
554
567
  }
@@ -990,6 +1003,7 @@ function arrayWithConst(array) {
990
1003
  return { value: array, asConst: [...array] };
991
1004
  }
992
1005
  export {
1006
+ TODO,
993
1007
  addArticle,
994
1008
  arrayEquals,
995
1009
  arrayWithConst,
@@ -1018,7 +1032,6 @@ export {
1018
1032
  getFileExt,
1019
1033
  getFilename,
1020
1034
  getMimeTypes,
1021
- getObjectValue,
1022
1035
  group,
1023
1036
  hasIndex,
1024
1037
  ifDefined,
@@ -1074,6 +1087,7 @@ export {
1074
1087
  timeDuration,
1075
1088
  toNumber,
1076
1089
  ObjectConverter_default as toObject,
1090
+ traverse,
1077
1091
  trimString,
1078
1092
  undefinedIfEmpty,
1079
1093
  upperFirst,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wavy/fn",
3
- "version": "0.0.36",
3
+ "version": "0.0.39",
4
4
  "main": "./dist/main.js",
5
5
  "module": "./dist/main.cjs",
6
6
  "types": "./dist/main.d.ts",
@@ -33,7 +33,7 @@
33
33
  "zod": "^4.2.1"
34
34
  },
35
35
  "dependencies": {
36
- "@wavy/util": "^0.0.7",
36
+ "@wavy/util": "^0.0.9",
37
37
  "uuid": "^13.0.0"
38
38
  }
39
39
  }