{"id":21189220,"url":"https://github.com/uptick/shallow-utils","last_synced_at":"2025-07-05T00:36:09.152Z","repository":{"id":57357823,"uuid":"133442231","full_name":"uptick/shallow-utils","owner":"uptick","description":"Utilities for shallow comparisons, particularly for React optimisation","archived":false,"fork":false,"pushed_at":"2018-05-15T05:49:48.000Z","size":48,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-30T15:54:38.455Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uptick.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-15T01:32:51.000Z","updated_at":"2018-05-15T05:49:49.000Z","dependencies_parsed_at":"2022-09-26T16:33:23.669Z","dependency_job_id":null,"html_url":"https://github.com/uptick/shallow-utils","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/uptick/shallow-utils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uptick%2Fshallow-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uptick%2Fshallow-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uptick%2Fshallow-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uptick%2Fshallow-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uptick","download_url":"https://codeload.github.com/uptick/shallow-utils/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uptick%2Fshallow-utils/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263640772,"owners_count":23493387,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-20T18:50:44.896Z","updated_at":"2025-07-05T00:36:09.107Z","avatar_url":"https://github.com/uptick.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# shallow-utils\n\n[![npm version](https://badge.fury.io/js/shallow-utils.svg)](http://badge.fury.io/js/shallow-utils)\n![Downloads](http://img.shields.io/npm/dm/shallow-utils.svg?style=flat)\n\nUtilities for shallow comparisons, particularly for React optimisation\n\n## Installation\n\nInstall the package with npm:\n\n```\nnpm install shallow-utils\n```\n\n## Usage\n\nUse the shallow comparison as an auto-typing wrapper for `shallow-equal`'s `shallowEqualArray`\nand `shallowEqualObject`.\n\n```javascript\nimport { shallowEqual } from 'shallow-utils'\n\nlet a = {title: 'The Wizard of Oz',}\nlet b = {title: 'The Wizard of Oz',}\n\nconsole.log(shallowEqual(a, b))\n// true\n\nlet c = [5]\nlet d = [5]\nconsole.log(shallowEqual(c, d))\n// true\n```\n\nWhen you want to compare an object minus a set of attributes, use `shallowEqualExcept`.\n\nThen, for debugging purposes, use `shallowItemsDifferExcept` as a helper to let you know what\nchanged.\n\n```javascript\nimport { shallowEqual, shallowEqualExcept, shallowItemsDifferExcept } from 'shallow-utils'\n\nlet a = {title: 'The Wizard of Oz', showing: false}\nlet b = {title: 'The Wizard of Oz', showing: true}\n\nconsole.log(shallowEqual(a, b))\n// false\n\nconsole.log(shallowEqualExcept(a, b, ['showing',]))\n// true\n\nb.title = 'The Matrix'\nconsole.log(shallowItemsDifferExcept(a, b, ['showing',]))\n// ['title',]\n```\n\nAll together in one `shouldComponentUpdate`:\n\n```javascript\nimport React from 'react'\nimport { shallowEqual, shallowEqualExcept, shallowItemsDifferExcept } from 'shallow-utils'\n\nclass Example extends React.Component {\n  shouldComponentUpdate(nextProps, nextState) {\n    if (!shallowEqual(this.props.arrayOfStuff, nextProps.arrayOfStuff)) {\n      // console.log('arrayOfStuff changed')\n      return true\n    }\n\n    let checkedProps = [\n      'arrayOfStuff',\n    ]\n    if (!shallowEqualExcept(this.props, nextProps, checkedProps)) {\n      // console.log('misc props changed', shallowItemsDifferExcept(this.props, nextProps, checkedProps))\n      return true\n    }\n    return false\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuptick%2Fshallow-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuptick%2Fshallow-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuptick%2Fshallow-utils/lists"}