1.1.3 • Published 11 days ago

@teamteanpm2024/cumque-eligendi-vero v1.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
11 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
Reflect.getPrototypeOfObject.definePropertyFunction.prototype.nameflagseslintpluginpostcssstringifierasyncpoint-freemime-dbtrimLeftinvariantReactiveExtensionsargvfinduptaskUint32Arrayperformantmapcommand-lineformatvalidationnodejsreact poselessECMAScript 2017modulesflagES2016joifind-upRFC-6455make dirdefinereadablestreamdefaultES2022linkTypedArraystyleguidecmdbytetrimStartjavascriptgradients css3workspace:*waapibabelopensrangeerrorbuffersfast-deep-clonehasOwnchildInt8Arraycryptoserializationpuredom-testing-libraryurlsconsumejestfiltersanitizationentrieshigher-orderstylingspawnes7configurableUint8ArrayrecursivemoduledirdeleteoptionserializermruerrorvariablesTypeBoxinspectmoveauthenticationes-shimswindowsyamlcensorsetPrototypeOfwritesigintbusyaccessormatchrapidarrays$.extendcss variableESnextiterationnodeWeakSettranspilequeuetranspilerreducerprogressformattingnested cssinferencebannerObject.keyscharactersregular expressioncode pointsArray.prototype.containsObject.entriesECMAScript 2016ECMAScript 2021environmentfigletfindstringifyfastcopyfetchcss lessinstallernameswidthnegativeassertsbrowserqueueMicrotaskutilreduxcallbackcoreconfigSetchromeObject.valuesfunctionqueryconstlinewrapObject.iscallvisualparseformletextendshamsettingswatchingparserPromisecore-jspasswordspeces-abstractpostcss-plugintacitcolumnavasharedindicatordiffArrayBuffer#sliceschemaes5irqreduceURLSearchParamsargsasserttesterString.prototype.trimwatchFilefast-deep-copyresolveruntimelookdayjs3dtyped arraydataUint16Arrayl10narrayES2023jsxbufferObservablesweaksetcallboundJSONdeepcloneemitObjectclientmimeworkerwebsiteexpresssignalsRegExp#flagsreadableansifseventsstreamCSSStyleDeclarationassignprettysliceES2015dataViewguidsymboldescriptoryuptouchramdalimitedReactiveXestreewatchstarterfastlesscssreusefindLastIndexpositivexhrreact-testing-librarydatastructurewrapargumentschromiumpluginless compilershimspinnershrinkwrappicomatchfromhelpersiteratorgroupBykarmaPushstreamsdragURLhookformHyBijson-schema-validatorpackageasciiajaxclassnamefantasy-landemojiUint8ClampedArrayprivate datagroupequalthreewalkingfilehookskeysmulti-packagelimitES3tdddotenvxtermi18nmkdirsoptimizerimportvargradients cssappcolumnsdropiefullwidthmetadataRegExp.prototype.flagssafeMapprotocol-buffersphoneobjlazyArray.prototype.flatMapInt16ArraytypesES8argumentstyled-componentsforEachtoolkitdescriptiontostringtagreact animationpopmotionfull-widthregexpidhttpurlless mixinscss nestingtraversecompile lesstyperegulargenericsbatchECMAScript 2023parentsoptimistsearchthrottle256randommkdirBigUint64Arraytakedeep-cloneutilitiesspeedwgetassertioncircularnpmextrautil.inspectquerystring0validaccessibilitycorsreal-timeshebangES7springexpression6to5exeeventscsscreatedefinePropertyexecflatMaprm -rfsomeeast-asian-widthRxterminalcurldeepreadWeakMapxdg-openwatcherES2020jasmineframerArrayBuffer.prototype.slicees6globlook-upless csspackage managerCSSperformancelockfileArrayBufferconcurrencyconnectdependency managerStreamsWebSocketslotcall-boundajvtoolspushpackageses-shim APIvestserializebddvalidatorhasjwtpreserve-symlinksclassnameslognegative zeroprefixremoveES2017duplexjsonschemapackage.jsoncall-binddeepcopycjksharedarraybufferuuidconsoletestingencryptionexit-codekoreananimationwordwrappathlibphonenumbererror-handlingUnderscorestatusexitless.jsdatemakemergeoffsetfast-clonejsdifflintdeep-copypreprocessorthroatxssArray.prototype.flatsanitizeregular expressionsinternalsetterArray.prototype.flattenescapegetterrateBigInt64Arraycomputed-typesstylesheetimmutablemochacachetoStringTagArray.prototype.findLastIndexgetPrototypeOfsetImmediateautoprefixerquoteES2019Object.assignObject.getPrototypeOfastwalkapibluebirdwhichreactextensionfolderjsonpropertiesArrayupstylepyyamlpipeinterruptsmimetypespatchfunctionalobjectcoerciblermlaunchtypesafeiteraterfc4122promisesdataviewtypedoutputomitsigtermenumerabletoSortedfixed-widthcallbindcodeschineseform-validationfindLastcolorsbootstrap less_.extendsymlinkmixins@@toStringTagjsonpathcompilerloadingvaluehttpsbrowserslisttapcommandgestureseslintconfigmonorepoenvzodistypedarraytoArraySymbolprunegraphqltrimhardlinks[[Prototype]]valuesbyteOffsetstartio-tspnpm9weakmapjsdomESTypeScriptsuperstructscheme-validationdebuggeres8variables in csssuperagentgeteslanguagefsreact-hooksincludesposejapaneseIteratorauthwordbreaklrulisteners.envelectronparenteslintbcryptjson-schema-validationsyntaxerrorcollection.es6everymiddlewareArray.prototype.filterrequesteslint-plugineditorspinnerspersistentpropmkdirpfastclonedependenciesminimalecmascripttypeerrormomenttapetoobjectfast-copycolorstructuredCloneframeworkbrowserlistexecutableYAMLwritableSymbol.toStringTagtelephoneopencryptschemepropertytrimEndgdpreventEmitterprotodeterministicfullFloat64ArrayconcatMapcli__proto__containstsratelimit-0enderfpnumberharmonydomponyfillargparseFloat32Arraygetoptprotobufuser-streamses2018nativeECMAScript 2022trimRightdirectorylastcharacterredux-toolkitES2018sidesortmatchAlldescriptorslinuxcss-in-jsbindECMAScript 2015setclassesECMAScript 2018streams2arktypechaihashes2017typedarraystypanionsymbolscheckRxJSarraybuffernopewarningisConcatSpreadableECMAScript 6bootstrap cssrm -frhandlersformsconcatclass-validatoruninstallmacosopenerutilitywebES6oncees2016bundlertimenameObject.fromEntriesflatkeyfunctionssymlinkssignalstylesJSON-SchematextES2021validateteststringjsECMAScript 5equalityArray.prototype.includesjson-schemainputbreakawesomesauceoperating-systemrmdirloggingES5rgbeventDispatcherInt32ArraymobilesameValueZeroclonebyteLengthpromiseintrinsicawaitboundtc39viewinternal slotidlerequireprocessinstallchannelimmerartcopyunicoderobustcommanderefficientcolourapolloshelltypeofsyntaxfastifyAsyncIteratorprivateStreamreact-hook-formtypescriptgetintrinsicpolyfillqsMicrosoftcollectiontslibsequencettyECMAScript 2019termprototypebundlingdebugmatchesstablebabel-coreflattencurriedWebSocketses2015whatwgxdgStyleSheetwaitArray.prototype.findLastgetOwnPropertyDescriptor
1.1.3

11 days ago

1.0.3

12 days ago

1.0.2

13 days ago

1.0.1

14 days ago

1.0.0

14 days ago