UNPKG

@wordpress/is-shallow-equal

Version:
8 lines (7 loc) 1.46 kB
{ "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": ";AAGA,OAAO,2BAA2B;AAClC,OAAO,0BAA0B;AAalB,SAAR,eAAiC,GAAY,GAAsB;AACzE,MAAK,KAAK,GAAI;AACb,QAAK,EAAE,gBAAgB,UAAU,EAAE,gBAAgB,QAAS;AAC3D,aAAO,sBAAuB,GAAG,CAAE;AAAA,IACpC,WAAY,MAAM,QAAS,CAAE,KAAK,MAAM,QAAS,CAAE,GAAI;AACtD,aAAO,qBAAsB,GAAG,CAAE;AAAA,IACnC;AAAA,EACD;AAEA,SAAO,MAAM;AACd;", "names": [] }