<commit_before>import {equals, equalTo, clone} from 'tsfun';

/**
 * @author <NAME>
 * @author <NAME>
 */
export module ObjectUtil {

    /**
     * Clones the object, keeping the type of Date objects as Date.
     *
     * @param {O} object
     * @returns {O}
     */
    export function cloneWithDates<O>(object: O): O {

        return clone(object, convertDates);
    }


    function convertDates<O>(original: any, plain: any) {

        if (original) {
            for (let key of Object.keys(original)) {

                if (original[key] instanceof Date) {
                    plain[key] = new Date(original[key]);
                } else if (typeof original[key] === 'object') {
                    convertDates(original[key], plain[key])
                }

            }
        }
        return plain;

    }


    export function getDuplicateValues(array: any[]): any[] {

        const temp: any[] = [];
        const result: any[] = [];

        for (let value of array) {
            if (temp.indexOf(value) > -1 && result.indexOf(value) == -1) {
                result.push(value);
            } else {
                temp.push(value);
            }
        }

        return result;
    }


    export function findDifferingFieldsInObject(object1: Object, object2: Object, fieldsToIgnore?: string[]): string[] {

        const differingFieldsNames: string[] = [];

        for (let fieldName in object1) {
            if (object1.hasOwnProperty(fieldName)) {

                if (fieldsToIgnore && fieldsToIgnore.indexOf(fieldName) > -1) continue;

                if (!ObjectUtil.compare(
                    (object1 as any)[fieldName],
                    (object2 as any)[fieldName])) differingFieldsNames.push(fieldName);
            }
        }
        return differingFieldsNames;
    }


    export function compare(value1: any, value2: any): boolean {

        if (!value1 && !value2) return true;
        if ((value1 && !value2) || (!value1 && value2)) return false;

        const type1: string = ObjectUtil.getType(value1);
        const type2: string = ObjectUtil.getType(value2);

        if (type1 !== type2) {
            return false;
        } else if (type1 === 'object') {
            return compareObjects(value1, value2);
        } else if (type1 === 'array') {
            return equals(value1, value2, equalTo);
        } else {
            return compareFields(value1, value2);
        }
    }


    export function compareObjects(object1: Object, object2: Object): boolean {

        return JSON.stringify(object1) == JSON.stringify(object2);
    }

<commit_msg>Make use of equalTo<commit_after>import {equals, equalTo, clone} from 'tsfun';

/**
 * @author <NAME>
 * @author <NAME>
 */
export module ObjectUtil {

    /**
     * Clones the object, keeping the type of Date objects as Date.
     *
     * @param {O} object
     * @returns {O}
     */
    export function cloneWithDates<O>(object: O): O {

        return clone(object, convertDates);
    }


    function convertDates<O>(original: any, plain: any) {

        if (original) {
            for (let key of Object.keys(original)) {

                if (original[key] instanceof Date) {
                    plain[key] = new Date(original[key]);
                } else if (typeof original[key] === 'object') {
                    convertDates(original[key], plain[key])
                }

            }
        }
        return plain;

    }


    export function getDuplicateValues(array: any[]): any[] {

        const temp: any[] = [];
        const result: any[] = [];

        for (let value of array) {
            if (temp.indexOf(value) > -1 && result.indexOf(value) == -1) {
                result.push(value);
            } else {
                temp.push(value);
            }
        }

        return result;
    }


    export function findDifferingFieldsInObject(object1: Object, object2: Object, fieldsToIgnore?: string[]): string[] {

        const differingFieldsNames: string[] = [];

        for (let fieldName in object1) {
            if (object1.hasOwnProperty(fieldName)) {

                if (fieldsToIgnore && fieldsToIgnore.indexOf(fieldName) > -1) continue;

                if (!ObjectUtil.compare(
                    (object1 as any)[fieldName],
                    (object2 as any)[fieldName])) differingFieldsNames.push(fieldName);
            }
        }
        return differingFieldsNames;
    }


    export function compare(value1: any, value2: any): boolean {

        if (!value1 && !value2) return true;
        if ((value1 && !value2) || (!value1 && value2)) return false;

        const type1: string = ObjectUtil.getType(value1);
        const type2: string = ObjectUtil.getType(value2);

        if (type1 !== type2) {
            return false;
        } else if (type1 === 'object') {
            return equalTo(value1)(value2);
        } else if (type1 === 'array') {
            return equals(value1, value2, equalTo);
        } else {
            return compareFields(value1, value2);
        }
    }


{'fraction_non_alphanumeric': 0.1253707731856832, 'fraction_numerical': 0.013051216136049041, 'mean_word_length': 1.8689733408961997, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1644620', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1379, 'n_words': 366}