UNPKG

@sketch-hq/sketch-assistant-utils

Version:

Utility functions and types for Sketch Assistants.

23 lines (22 loc) 901 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.objectsEqual = exports.objectHash = void 0; const object_hash_1 = __importDefault(require("object-hash")); /** * Return the md5 hash of an object. Keys are deeply sorted for a stable hash. * Useful for comparing deep similarity of Sketch document objects. */ const objectHash = (obj, excludeKeys = []) => object_hash_1.default(obj, { unorderedObjects: true, algorithm: 'md5', excludeKeys: (key) => excludeKeys.includes(key), }); exports.objectHash = objectHash; /** * Compares two objects for deep equality. */ const objectsEqual = (o1, o2, excludeKeys = []) => objectHash(o1, excludeKeys) === objectHash(o2, excludeKeys); exports.objectsEqual = objectsEqual;