All files / roosterjs-content-model-dom/lib/domToModel/utils areSameFormats.ts

100% Statements 8/8
100% Branches 4/4
100% Functions 2/2
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 191x               1x 190x 1x   189x 189x   189x      
import { getObjectKeys } from '../../domUtils/getObjectKeys';
import type { ContentModelFormatBase } from 'roosterjs-content-model-types';
 
/**
 * Check if the two given formats object are equal. This is a check to value but not to reference
 * @param f1 The first format object to check
 * @param f2 The second format object to check
 */
export function areSameFormats<T extends ContentModelFormatBase>(f1: T, f2: T) {
    if (f1 == f2) {
        return true;
    } else {
        const keys1 = getObjectKeys(f1);
        const keys2 = getObjectKeys(f2);
 
        return keys1.length == keys2.length && keys1.every(key => f1[key] == f2[key]);
    }
}