UNPKG

differify-js

Version:

Differify allows you to get the diff between two entities (objects diff, arrays diff, date diff, functions diff, number diff, etc) very easily, quickly and in a friendly way.

59 lines (58 loc) 2.53 kB
/*! * Copyright(c) 2020 Fabian Roberto Orue <fabianorue@gmail.com> * BSD Licensed */ import DIFF_MODES from './enums/modes'; import PROPERTY_STATUS from './enums/property-status'; import config from './types/config'; import { multiPropDiff, deepPropDiff, propDiff } from './types/diff'; declare class Differify { static DIFF_MODES: typeof DIFF_MODES; static PROPERTY_STATUS: typeof PROPERTY_STATUS; static multiPropDiff: multiPropDiff; static deepPropDiff: deepPropDiff; static propDiff: propDiff; private compSelector; private config; constructor(config?: config); /** * It sets the configuration options that will be applied when compare() method is called. * @param _config */ setConfig: (_config: config) => void; /** * It returns a copy of the current configuration object. * @returns {config} */ getConfig: () => config; /** * It returns the difference between two entities. * @param a * @param b * @returns {multiPropDiff} */ compare: (a: any, b: any) => multiPropDiff; /** * It will apply the changes (merge both entities) and will keep the modified values * @param {multiPropDiff} diffResult | it is the Object returned by the compare() method call. * @param {boolean} diffOnly | It returns just the difference (only the !== EQUAL properties) [default: false]. * @returns {Object|Array} */ applyLeftChanges: (diffResult: multiPropDiff, diffOnly?: boolean) => any; /** * It will apply the changes (merge both entities) and will keep the modified values * @param {multiPropDiff} diffResult | it is the Object returned by the compare() method call. * @param {boolean} diffOnly | It returns just the difference (only the !== EQUAL properties) * @returns {Object} */ applyRightChanges: (diffResult: multiPropDiff, diffOnly?: boolean) => any; /** * It will return the changes that match with the specified status (second parameter). * @param {multiPropDiff} diffResult | It is the Object returned by the compare() method call. * @param {boolean} status | one of the following (ADDED || MODIFIED || DELETED || EQUAL). * @returns {Object|Array} | depending on if the input is an Object or an Array. */ filterDiffByStatus: (diffResult: multiPropDiff, status?: string, extendedInformation?: boolean) => any; } export default Differify; export { DIFF_MODES, PROPERTY_STATUS, multiPropDiff, deepPropDiff, propDiff };