@wordpress/is-shallow-equal
Version:
Test for shallow equality between two objects or arrays.
8 lines (7 loc) • 1.6 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../src/index.ts"],
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport isShallowEqualObjects from './objects';\nimport isShallowEqualArrays from './arrays';\n\nexport type ComparableObject = Record< string, any >;\n\n/**\n * Returns true if the two arrays or objects are shallow equal, or false\n * otherwise. Also handles primitive values, just in case.\n *\n * @param a First object or array to compare.\n * @param b Second object or array to compare.\n *\n * @return Whether the two values are shallow equal.\n */\nexport default function isShallowEqual( a: unknown, b: unknown ): boolean {\n\tif ( a && b ) {\n\t\tif ( a.constructor === Object && b.constructor === Object ) {\n\t\t\treturn isShallowEqualObjects( a, b );\n\t\t} else if ( Array.isArray( a ) && Array.isArray( b ) ) {\n\t\t\treturn isShallowEqualArrays( a, b );\n\t\t}\n\t}\n\n\treturn a === b;\n}\n\n// `isShallowEqual` is exported also as a named export because esbuild cannot\n// expose the default export from the `window.wp.isShallowEqual` global.\nexport { isShallowEqual, isShallowEqualObjects, isShallowEqualArrays };\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA,4CAAAA;AAAA,EAAA,4CAAAC;AAAA;AAAA;AAGA,qBAAkC;AAClC,oBAAiC;AAalB,SAAR,eAAiC,GAAY,GAAsB;AACzE,MAAK,KAAK,GAAI;AACb,QAAK,EAAE,gBAAgB,UAAU,EAAE,gBAAgB,QAAS;AAC3D,iBAAO,eAAAA,SAAuB,GAAG,CAAE;AAAA,IACpC,WAAY,MAAM,QAAS,CAAE,KAAK,MAAM,QAAS,CAAE,GAAI;AACtD,iBAAO,cAAAD,SAAsB,GAAG,CAAE;AAAA,IACnC;AAAA,EACD;AAEA,SAAO,MAAM;AACd;",
"names": ["isShallowEqualArrays", "isShallowEqualObjects"]
}