/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/is-shallow-equal/src/objects.ts
48 строк
1 KB
Marco Ciampini
ESLint: Replace strict config with bulk suppressions (#81248)
07 авг 2026, 14:34
Не верифицирован
07 авг 2026, 14:34
7f43eaf
Код
Авторство
О чём код?
import type { ComparableObject } from '.'; /** * Returns true if the two objects are shallow equal, or false otherwise. * * @param a First object to compare. * @param b Second object to compare. * * @return Whether the two objects are shallow equal. */ export default function isShallowEqualObjects( a: ComparableObject, b: ComparableObject ): boolean { if ( a === b ) { return true; } const aKeys = Object.keys( a ); const bKeys = Object.keys( b ); if ( aKeys.length !== bKeys.length ) { return false; } let i = 0; while ( i < aKeys.length ) { const key = aKeys[ i ]; const aValue = a[ key ]; if ( // In iterating only the keys of the first object after verifying // equal lengths, account for the case that an explicit `undefined` // value in the first is implicitly undefined in the second. // // Example: isShallowEqualObjects( { a: undefined }, { b: 5 } ) ( aValue === undefined && ! b.hasOwnProperty( key ) ) || aValue !== b[ key ] ) { return false; } i++; } return true; }