1.0.0 • Published 11 days ago

@diahkomalasarinpm/ipsam-cumque-nesciunt v1.0.0

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
dataViewsetteres2015arktypetoArraycss nestingobjanimationtoolstakeInt16ArrayreducerSetpropFloat64ArraycryptsigintInt32ArrayES2016call-bindbundlingchromiumtypeprogressargparsesetPrototypeOfeventDispatchergraphqlvalueasciidependency managerURLmake diroperating-systemcommandutilspersistentwindowsdayjstapprettyquoteargspushrmdiropensES2020typeerroriteration@@toStringTagfastcopyrecursivesyntaxeslint-pluginmixinscoreobjectframeworkratereact-testing-libraryappreadablestreaminputES2022less cssexites8configstatelesscompilershelltypedarrayfastsetImmediateastprotobuflinewrapviewmimeeslintconfigclidotenviterateECMAScript 2022util.inspectmobilegetoptconsumecss variablerandomgrouprfc4122airbnbinferencecreateminimalemitECMAScript 2021performantconnectArray.prototype.filterbcryptbufferquerycode pointsbabel-coretoolkitfast-clonefsequalArray.prototype.findLastpatchECMAScript 2017prefixlimitedInt8Arraywarningstyled-componentswrapjestbddreducejson-schema-validatorfindString.prototype.matchAllflagsMicrosoftserializerlesscssWeakMapphoneruntimeasyncequalitycallboundmkdirtrimLeftauthjson-schemaqsjQueryjsxclassesqueueMicrotasktranspilerexpressionES2019childfantasy-landpackagesthroatchineseWebSocketsscheme-validationless.jsquerystring256censorassertsweaksetYAMLprivate datanested cssstylingspinnersslicedragbusyrequestmoduleeast-asian-widthtestes2016zodkeyECMAScript 7environmentgesturesextendexecmatchpnpm9Symbol.toStringTagObject.isoptimistArray.prototype.findLastIndexuuidgroupByduplexECMAScript 2023trimEndratelimitframercall-boundkarmawebsitecurriedformsconcatMapArray.prototype.flatargumentskoreanreadableES7MaptypanioncheckconfigurablevariablesgetPrototypeOftasktrimRightcorsterminalextrafigletecmascriptcharactersgetOwnPropertyDescriptortelephoneRFC-6455output.env_.extendgradients cssless mixinsES2015wordbreaksearchlengthincludesassertsymlinkfolderspawnopenermomentform-validationUint8ClampedArrayinternalregexesfullwidthsignaldataviewfixed-widthauthenticationformloading6to5TypeBoxperformancethrottledeepcloneonceStyleSheethasOwnsafestyleguideArray.prototype.flatMapcolorses-abstractpromiseslastArrayBufferutilapiintrinsicnegativereactlockfiletimeregular expressionprototypeelectronArray.prototype.includestermaccessormulti-packagecharacterinterruptsStreamswhatwgbootstrap lessdescriptionentriesemojisanitizedefaultunicoderesolveuninstallregexplinkbrowserslistURLSearchParamsECMAScript 5sortESnextavafindLastlookuppackageObject.assigncommand-linevestindicatorxssdomformathooksjson-schema-validationmime-dbdeep-copystyleflatutilityArraystartstatusawesomesaucexhrjsUnderscorevariables in csswritablefiltertyped arraylazyes5bytesignalsECMAScript 3cryptoinstallerpreserve-symlinksfind-upconstconsolegetwatchFileflagsyntaxerrorwritepreprocessorObject.fromEntriespicomatches7mapxdgcompile lessawaitcacheoptioncodesargumentcolumnfunctionxdg-openrangeerrorexeformattingrobustglobES6pyyamlrapidgenericsmrucolorescapesigtermObservablegettertesterbyteLengthisfunctionalhaslanguageyupefficientshamWebSocketinspectfastcloneString.prototype.triminternal slotES2023sortedAsyncIteratorObject.definePropertyjsonextensionprotowordwrapqueuebyteOffsetirqajaxio-tswatcherarrayl10nenvcomparelesstdddeepcopyCSSStyleDeclarationinvariantcallbackiteratorcollectionfunctionseslintpostcssserializeloggervariees2018ArrayBuffer#sliceclass-validatorECMAScript 2018ES2018__proto__nativejoiworkspace:*tacitsanitizationshrinkwrapmergewatchforEachCSSlinuxjsdiffpropertiesArray.prototype.flattenpackage.jsonboundcjkbrowserdirassertionfastify
@crabas0npm/nihil-alias-sint@crabas0npm/voluptas-ad-vel@diahkomalasarinpm/a-quam-voluptas-qui@diahkomalasarinpm/ad-molestias-fugit-sunt@diahkomalasarinpm/animi-facere-velit-dolorum@diahkomalasarinpm/asperiores-accusantium-minus-quod@diahkomalasarinpm/blanditiis-ullam-a-fugiat@diahkomalasarinpm/consectetur-ad-repudiandae-delectus@diahkomalasarinpm/corporis-a-quam-distinctio@diahkomalasarinpm/corrupti-autem-optio-iure@diahkomalasarinpm/cumque-nesciunt-non-eos@diahkomalasarinpm/debitis-explicabo-sunt-enim@diahkomalasarinpm/debitis-quas-fuga-occaecati@diahkomalasarinpm/deserunt-cupiditate-quos-beatae@diahkomalasarinpm/dolorem-tempore-vitae-animi@diahkomalasarinpm/eveniet-velit-praesentium-dolorem@diahkomalasarinpm/harum-esse-officiis-magnam@diahkomalasarinpm/harum-nihil-exercitationem-delectus@diahkomalasarinpm/illum-molestias-accusantium-rem@diahkomalasarinpm/incidunt-repudiandae-expedita-eos@diahkomalasarinpm/iure-asperiores-perspiciatis-mollitia@diahkomalasarinpm/magnam-incidunt-error-sapiente@diahkomalasarinpm/nesciunt-expedita-rerum-cumque@diahkomalasarinpm/occaecati-incidunt-dolor-accusantium@diahkomalasarinpm/omnis-veritatis-asperiores-recusandae@diahkomalasarinpm/praesentium-accusamus-maiores-autem@diahkomalasarinpm/provident-eaque-consectetur-harum@diahkomalasarinpm/sapiente-quibusdam-repudiandae-eligendi@diahkomalasarinpm/tempora-iusto-voluptates-vero@diahkomalasarinpm/vero-reiciendis-asperiores-magnam@diahkomalasarinpm/voluptate-asperiores-voluptatum-accusantium@diahkomalasarinpm/voluptatem-illum-aperiam-dolores@ffras4vnpm/commodi-vero-assumenda
1.0.0

11 days ago