-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ebe490e
commit be49f0d
Showing
4 changed files
with
53 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
export { getClasses } from "./classnames" | ||
export { compareObjects } from "./objects" | ||
export { copyValue } from "./clipboard" | ||
export { hexToRgb, rgbToHex } from "./colors" | ||
export { debounce } from "./debounce" | ||
export { getClasses } from "./classnames" | ||
export { getSlug } from "./slug" | ||
export { hexToRgb, rgbToHex } from "./colors" | ||
export { isUUID, getUUID } from "./uuid" | ||
export { sanitizeText, removeMarkdown, middleEllipsis, removeNewlines } from "./strings" | ||
export { throttle } from "./throttle" | ||
export { isUUID, getUUID } from "./uuid" | ||
export { validateUrl, validateEmail } from "./validations" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { describe, it, expect } from "vitest" | ||
import { compareObjects } from './objects' | ||
|
||
describe('compareObjects', () => { | ||
it('should return true for identical objects', () => { | ||
const obj1 = { a: 1, b: 2 } | ||
const obj2 = { a: 1, b: 2 } | ||
expect(compareObjects(obj1, obj2)).toBeTruthy() | ||
}) | ||
|
||
it('should return false for different objects', () => { | ||
const obj1 = { a: 1, b: 2 } | ||
const obj2 = { a: 2, b: 3 } | ||
expect(compareObjects(obj1, obj2)).toBeFalsy() | ||
}) | ||
|
||
it('should handle null and undefined', () => { | ||
const obj1 = { a: 1, b: 2 } | ||
expect(compareObjects(obj1, null as unknown as any)).toBeFalsy() | ||
expect(compareObjects(null as unknown as any, obj1)).toBeFalsy() | ||
expect(compareObjects(undefined as unknown as any, undefined as unknown as any)).toBeTruthy() | ||
}) | ||
|
||
it('should not depend on property order', () => { | ||
const obj1 = { a: 1, b: 2 } | ||
const obj2 = { b: 2, a: 1 } | ||
expect(compareObjects(obj1, obj2)).toBeTruthy() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const _orderObjectProperties = (obj: object): object => { | ||
if (!obj || typeof obj !== 'object' || Array.isArray(obj)) return obj | ||
|
||
return Object.keys(obj).sort().reduce((acc, key) => { | ||
acc[key] = _orderObjectProperties(obj[key]) | ||
|
||
return acc | ||
}, {}) | ||
} | ||
|
||
export const compareObjects = (first: unknown, second: unknown): boolean => { | ||
if (!first || !second) return first === second | ||
|
||
const orderedFirst = _orderObjectProperties(first) | ||
const orderedSecond = _orderObjectProperties(second) | ||
|
||
return JSON.stringify(orderedFirst) === JSON.stringify(orderedSecond) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
{ | ||
"name": "@heliosgraphics/utils", | ||
"version": "5.3.5", | ||
"version": "5.3.6", | ||
"type": "module", | ||
"author": "03b8 <[email protected]>", | ||
"license": "MIT", | ||
"private": false, | ||
"description": "Universal javascript helpers", | ||
"description": "Universal Javascript helpers", | ||
"main": "index.ts", | ||
"engines": { | ||
"npm": ">=10.2.4", | ||
|