UNPKG

json-deep-compare

Version:

A powerful library for comparing JSON objects with support for deep comparison, regex validation, and customizable options

1 lines 1.14 kB
class Result{constructor(e={}){this.options=e,this.reset()}reset(){this.data={matched:{keys:[],values:[]},unmatched:{keys:[],values:[],types:[]},regexChecks:{passed:[],failed:[]},summary:{matchPercentage:0,totalKeysCompared:0,totalMatched:0,totalUnmatched:0,totalRegexChecks:0}}}addMatchedKey(e){this.data.matched.keys.push(e)}addMatchedValue(e){this.data.matched.values.push(e)}addUnmatchedKey(e){this.data.unmatched.keys.push(e)}addUnmatchedValue(e){this.data.unmatched.values.push(e)}addUnmatchedType(e){this.data.unmatched.types.push(e)}addPassedRegexCheck(e){this.data.regexChecks.passed.push(e)}addFailedRegexCheck(e){this.data.regexChecks.failed.push(e)}updateSummary(){const e=this.data.matched.keys.length,t=void 0===this.options.strictTypes||this.options.strictTypes?this.data.unmatched.types.length:0,a=this.data.unmatched.keys.length+this.data.unmatched.values.length+t,s=e+a,h=this.data.regexChecks.passed.length+this.data.regexChecks.failed.length;this.data.summary={matchPercentage:s>0?e/s*100:100,totalKeysCompared:s,totalMatched:e,totalUnmatched:a,totalRegexChecks:h}}getResult(){return this.data}}module.exports=Result;