1.3.0 • Published 10 days ago

@libtommy2024/distinctio-voluptates-aliquam-necessitatibus v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 days ago

js-testDiff

NPM

About

Deep object diffing function for JavaScript; returns true if input 1 differs in any way from input 2. Original code was taken from Differentia.js and ported to TypeScript.

The testDiff function was originally created as a unit testing utility and it was primarily designed/used to test Differentia's search algorithm strategy system, setting a "gold standard" for that library's quality and algorithmic correctness.

The key difference with this version of testDiff is that I removed its "search index" functionality, as it introduced more complexity than it was worth.

Feel free to scavenge the original code as I have: https://github.com/Floofies/Differentia.js/blob/master/spec/testUtils.js

Building

Run npm run build to compile and test module dist/index.js.

I have pre-compiled the most up-to-date files in dist. Enjoy.

unitTest.js can be safely ignored, as it's a development-only dependency for test.mjs.

Syntax

import { testDiff } from "testDiff";
testDiff( input1:any, input2:any, [ deep:boolean = false ] );

Parameters:

input1, input2

Two values/objects to compare against each other.

deep (Optional) (Default = true)

TestDiff performs "deep" object/array traversal by default, comparing all reachable values; set this operand to false to disable traversal and nested comparisons.

Return Value:

Returns true if input1's structure, properties, or values differ in any way from input2, or false if otherwsie.

Usage Examples

Example 1: Arbitrary values.

Can handle any arbitrary values, as well as objects/arrays.

const myArray1 = "Hello World!";
const myArray2 = "This is a test";
const result = testDiff(myArray1, myArray2);
// result = true

Example 2: Flat arrays/objects.

const myArray1 = [1,2,3];
const myArray2 = [4,5,6];
const result = testDiff(myArray1, myArray2);
// result = true

Example 3: Nested arrays/objects.

const myArray1 = ["Hello",["World!"]];
const myArray2 = ["Hello",["Developer!"]];
const result = testDiff(myArray1, myArray2);
// result = true

Example 4: Nested arrays. Traversal disabled.

In this example, the function returns false even though the arrays' contents differ; they are regarded as the same because there are no differences at the top, and disabling traversal prevents the algorithm from seeing deeper differences.

const myArray1 = ["Hello",["World!"]];
const myArray2 = ["Hello",["Developer!"]];
const result = testDiff(myArray1, myArray2, false);
// result = false
asciiframeworkObject.keysjson-schemaObservablesreactonceprotocol-buffersexecutablenametrimLeftmime-dbreadablefetchdeepclonecjkxdg-openObject.getPrototypeOffsmkdirpdebugwebsitenopetestgroupcodesstablesetImmediatevariables in csspropertieslasttesterstylingmimegradients css3modulevalidatorzeroURLObject.entriesform-validationlesscssutilObject.fromEntriesregular expressionoptimizerJSONserializerequireassertiontapeformattingargparseweaksetqueueMicrotaskloadingstringstyled-componentsdefaultObject.valuesopenformsFloat64Arraycolorswordbreakio-tsperformantpostcssexit-codeposetostringtagiterationsearchECMAScript 2020Uint16ArrayBigInt64Arrayes6windowslengthschemetypedrapidfinddataViewfindLastIndextrimEndconcurrencyshrinkwrapoperating-systemdropBigUint64ArrayspecpromiseconsolecompilerdescriptionbcryptansiwritablemoveReactiveExtensionswhichuser-streamskarmaWeakSetnativerobustECMAScript 2019whatwgbusythrottlegetopthandlersdirectorygettranspilerenumerableUint8ArrayisomitUint32Arraypolyfillcommand-lineextrahardlinksmimetypesdataStreamoutputdrageslint-pluginpreserve-symlinks[[Prototype]]typessidecopyless.jsmobileYAMLregularfastclonestylesvariablesexecanimationsetterxssES2020wgetpackage.jsonerrorartAsyncIteratorpropertydirInt16Arrayweakmapratecontainsutilsxtermlinttdddependency managercallastappRxJSArray.prototype.flatMap-0commandernegative zeroslicedeep-copyargsmodulesArraysharedcompareindicatorfast-deep-copypnpm9monorepocollectioninspectforEachrgbpicomatchTypeScriptreact animationexpresspositivetraversejssettingsextensionreadablestreamvestprivate datachildinternal slotnameses2016ajvenvecmascriptrm -frwrapcurriedcheckbundlingtypeof3d$.extendcollection.es6Underscoreresolvelinuxformtoolkitxhrloggingemitstringifiertyped arrayexpressionArrayBuffer#sliceurlslaunchcode pointsprototypegetOwnPropertyDescriptorreact-testing-librarygroupByArrayBufferbabel-corecensorjwtwatchlessdomreusecss lessargvmkdirspipeRxmapinstallerES2023endercacheopenerInt8Arraya11yeditoreventEmitterES3less cssesphoneassertflatbdddotenvbabelcryptlibphonenumberpopmotionclassnamesclitoolsdatermdirECMAScript 2021URLSearchParamshashfantasy-landguidjapanesebufferaccessorreact-hook-formsomesequencemakeautoprefixerES2022WeakMapawesomesauceeslintconfiges-shimsspawnfastifyES20176to5chromewidthsortfunctionalparsesignaldeterministicbrowserslistWebSocketspringWebSocketsECMAScript 6emoji__proto__estreeprettyRegExp.prototype.flagsUint8ClampedArraylazystreams2fseventsproptacitwaapigestureslockfilechromiumRFC-6455figletjestdescriptorses7rm0arrayskeycryptoless compilerxdgyamlbreakReflect.getPrototypeOfbindregexwatchingvalidateserializerjsonschematypanionStyleSheetparserclassesdayjstslibquoteString.prototype.trimjson-schema-validatoroffsetvisualminimalSetcurlwebpackagesclientquerystringconstimportperformancevalidationhasfullwidthstreamfoldersymlinksyupECMAScript 2022keysSymbol.toStringTagreduxArray.prototype.findLastIndex@@toStringTagArray.prototype.includesframerfile systemes5formatconnectsymbolssigtermeast-asian-widthutil.inspecturlvarsetTypeBoxduplexconcatmkdirECMAScript 3computed-typestypedarrayclassnamemetadataarrayjavascriptworkermrufastcopyObject.definePropertyhookstoobjecttoArraytoSorteddeep-clonelinewrapECMAScript 2016viewspeedcallboundwatchFilesymlinkruntimeprefixkoreanbluebirdbuffersiteratebytefulleveryArray.prototype.containsmacosargumentcharactersstartschemasuperstructasyncESnextES7environmentimmerfull-widthsymboltrimStartcreateES2015multi-packagees8Promisesanitizebundlercsstestingencryptionlinkupsigintdom-testing-libraryArray.prototype.flattenmomentjQuerydefinePropertylrupreprocessorReactiveXentrieshttpses2017unicodeclonestreamscss-in-jscall-boundpluginstyleapiTypedArraybootstrap cssjoimatchconfigobjectjsoncss variablecore-jsjsdomRegExp#flagsintrinsicgetterPushrequestECMAScript 2015typesafeES2016byteLengthsanitizationfast-deep-clonegdprmochaprocesstsrangeerrorflattenArrayBuffer.prototype.sliceString.prototype.matchAllpersistenttypescriptshellFunction.prototype.namelimitslotprogressparentstructuredClonetaskinvariantisConcatSpreadableprotosignalseventsharmonywatcherprunestyleguiderecursiveES5typedarrayspostcss-pluginterminalobjthroatefficientCSSStyleDeclarationMicrosofttoStringTagconcatMapArray.prototype.flatcommandprivatepurejson-schema-validationmergescheme-validationarktypeextendreduceequalexecompile lessfastcircularreal-timereact-hooksstylesheetES2018authenticationimmutabletrimRightObservablefixed-widthnodejseslintlanguagel10njsdifftaptakejasminestarterreducerassignflatMapECMAScript 2018exitvaluesapollopackageredacttermfast-clone_.extendi18nsyntaxerrorfindLastpatchbrowsercolumnsoptimistjsxremovevalidletglobmatchesStreamshookformdatastructurechinesepromisespasswordnpmavanested csswalkES2021callbindratelimitdependenciestranspilecoercibleargumentsvaluettyuninstallES2019deepreadfromtelephonereact posefpsyntax256uuidbrowserlistgraphqlshimstatuses-abstractdescriptorcharacterbannergetintrinsicescapespinnersuperagentEScolornodehttppackage managerJSON-Schematrimwalkingtypeerrorchaiaccessibilityboundidlefast-copybyteOffsetstatelessHyBiponyfill.envwriteES6regexpieregular expressionsfind-upparentsbatchopensflagsshamfunctionconsumelistenersObjectpoint-freeincludesqueryECMAScript 7ECMAScript 2017timetypefunctionssameValueZerorm -rfsafepathzodtc39columnclass-validatorajaxutilitiestouchcmdfilterinterruptsdataviewarraybufferFloat32ArraywarningfilepyyamlairbnbelectronArray.prototype.findLastdeletegenericshigher-orderECMAScript 5matchAllspinnersoptionrfc4122flagcorsdeepcopyredux-toolkites2015lookES8mixinsauthawaitsetPrototypeOfECMAScript 2023coreutilitygradients cssbootstrap lessmake dires-shim APIdebuggerIteratorwaitdiffirqless mixinsprotobufqsinputqueuenumbergetPrototypeOflook-upnegativeconfigurablerandomcall-bindequalitydefinelogcallbackes2018error-handlingeventDispatcherlimitedeslintpluginloggerjsonpathInt32ArraysortediteratorinternalinferencehasOwnassertsramdahelpers
1.2.0

11 days ago

1.3.0

10 days ago

1.0.0

1 month ago