@augment-vir/common 9.3.2 → 11.0.0

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.
@@ -1,8 +1,9 @@
1
- export type PartialWithNullable<T extends object> = {
1
+ import { Jsonifiable } from 'type-fest';
2
+ export type PartialAndNullable<T extends object> = {
2
3
  [Prop in keyof T]?: T[Prop] | null | undefined;
3
4
  };
4
5
  export declare function isObject(input: any): input is NonNullable<object>;
5
- export declare function areJsonEqual(a: object, b: object): boolean;
6
+ export declare function areJsonEqual(a: Jsonifiable, b: Jsonifiable): boolean;
6
7
  /** The input here must be serializable otherwise JSON parsing errors will be thrown */
7
8
  export declare function copyThroughJson<T>(input: T): T;
8
9
  export type PropertyValueType<T> = T[keyof T];
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.copyThroughJson = exports.areJsonEqual = exports.isObject = void 0;
4
+ const error_1 = require("../error");
4
5
  const object_entries_1 = require("./object-entries");
5
6
  function isObject(input) {
6
7
  return !!input && typeof input === 'object';
@@ -8,12 +9,20 @@ function isObject(input) {
8
9
  exports.isObject = isObject;
9
10
  function areJsonEqual(a, b) {
10
11
  try {
11
- const sortedAEntries = (0, object_entries_1.getEntriesSortedByKey)(a);
12
- const sortedBEntries = (0, object_entries_1.getEntriesSortedByKey)(b);
13
- return JSON.stringify(sortedAEntries) === JSON.stringify(sortedBEntries);
12
+ if (a === b) {
13
+ return true;
14
+ }
15
+ if (isObject(a) && isObject(b)) {
16
+ const sortedAEntries = (0, object_entries_1.getEntriesSortedByKey)(a);
17
+ const sortedBEntries = (0, object_entries_1.getEntriesSortedByKey)(b);
18
+ return JSON.stringify(sortedAEntries) === JSON.stringify(sortedBEntries);
19
+ }
20
+ else {
21
+ return JSON.stringify(a) === JSON.stringify(b);
22
+ }
14
23
  }
15
24
  catch (error) {
16
- console.error(`Failed to compare objects using JSON.stringify`);
25
+ console.error(`Failed to compare objects using JSON.stringify: ${(0, error_1.extractErrorMessage)(error)}`);
17
26
  throw error;
18
27
  }
19
28
  }
@@ -1,8 +1,9 @@
1
- export type PartialWithNullable<T extends object> = {
1
+ import { Jsonifiable } from 'type-fest';
2
+ export type PartialAndNullable<T extends object> = {
2
3
  [Prop in keyof T]?: T[Prop] | null | undefined;
3
4
  };
4
5
  export declare function isObject(input: any): input is NonNullable<object>;
5
- export declare function areJsonEqual(a: object, b: object): boolean;
6
+ export declare function areJsonEqual(a: Jsonifiable, b: Jsonifiable): boolean;
6
7
  /** The input here must be serializable otherwise JSON parsing errors will be thrown */
7
8
  export declare function copyThroughJson<T>(input: T): T;
8
9
  export type PropertyValueType<T> = T[keyof T];
@@ -1,15 +1,24 @@
1
+ import { extractErrorMessage } from '../error';
1
2
  import { getEntriesSortedByKey } from './object-entries';
2
3
  export function isObject(input) {
3
4
  return !!input && typeof input === 'object';
4
5
  }
5
6
  export function areJsonEqual(a, b) {
6
7
  try {
7
- const sortedAEntries = getEntriesSortedByKey(a);
8
- const sortedBEntries = getEntriesSortedByKey(b);
9
- return JSON.stringify(sortedAEntries) === JSON.stringify(sortedBEntries);
8
+ if (a === b) {
9
+ return true;
10
+ }
11
+ if (isObject(a) && isObject(b)) {
12
+ const sortedAEntries = getEntriesSortedByKey(a);
13
+ const sortedBEntries = getEntriesSortedByKey(b);
14
+ return JSON.stringify(sortedAEntries) === JSON.stringify(sortedBEntries);
15
+ }
16
+ else {
17
+ return JSON.stringify(a) === JSON.stringify(b);
18
+ }
10
19
  }
11
20
  catch (error) {
12
- console.error(`Failed to compare objects using JSON.stringify`);
21
+ console.error(`Failed to compare objects using JSON.stringify: ${extractErrorMessage(error)}`);
13
22
  throw error;
14
23
  }
15
24
  }
@@ -1,8 +1,9 @@
1
- export type PartialWithNullable<T extends object> = {
1
+ import { Jsonifiable } from 'type-fest';
2
+ export type PartialAndNullable<T extends object> = {
2
3
  [Prop in keyof T]?: T[Prop] | null | undefined;
3
4
  };
4
5
  export declare function isObject(input: any): input is NonNullable<object>;
5
- export declare function areJsonEqual(a: object, b: object): boolean;
6
+ export declare function areJsonEqual(a: Jsonifiable, b: Jsonifiable): boolean;
6
7
  /** The input here must be serializable otherwise JSON parsing errors will be thrown */
7
8
  export declare function copyThroughJson<T>(input: T): T;
8
9
  export type PropertyValueType<T> = T[keyof T];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/common",
3
- "version": "9.3.2",
3
+ "version": "11.0.0",
4
4
  "homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common",
5
5
  "bugs": {
6
6
  "url": "https://github.com/electrovir/augment-vir/issues"