4.8.85 • Published 1 year ago

@taktikorg/dicta-eaque v4.8.85

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@taktikorg/dicta-eaque Version Badge

github actions coverage License Downloads

npm badge

deterministic version of JSON.stringify() so you can get a consistent hash from stringified results

You can also pass in a custom comparison function.

example

const stringify = require('@taktikorg/dicta-eaque');

const obj = { c: 8, b: [{ z: 6, y: 5, x: 4 }, 7], a: 3 };

console.log(stringify(obj));

output:

{"a":3,"b":[{"x":4,"y":5,"z":6},7],"c":8}

methods

const stringify = require('@taktikorg/dicta-eaque')

const str = stringify(obj, opts)

Return a deterministic stringified string str from the object obj.

options

cmp

If opts is given, you can supply an opts.cmp to have a custom comparison function for object keys. Your function opts.cmp is called with these parameters:

opts.cmp({ key: akey, value: avalue }, { key: bkey, value: bvalue }, { get(key): value })

For example, to sort on the object key names in reverse order you could write:

const stringify = require('@taktikorg/dicta-eaque');

const obj = { c: 8, b: [{ z: 6, y: 5, x: 4 },7], a: 3 };

const s = stringify(obj, function (a, b) {
	return b.key.localeCompare(a.key);
});

console.log(s);

which results in the output string:

{"c":8,"b":[{"z":6,"y":5,"x":4},7],"a":3}

Or if you wanted to sort on the object values in reverse order, you could write:

const stringify = require('@taktikorg/dicta-eaque');

const obj = { d: 6, c: 5, b: [{ z: 3, y: 2, x: 1 }, 9], a: 10 };

const s = stringify(obj, function (a, b) {
	return a.value < b.value ? 1 : -1;
});

console.log(s);

which outputs:

{"d":6,"c":5,"b":[{"z":3,"y":2,"x":1},9],"a":10}

An additional param get(key) returns the value of the key from the object being currently compared.

space

If you specify opts.space, it will indent the output for pretty-printing. Valid values are strings (e.g. {space: \t}) or a number of spaces ({space: 3}).

For example:

const obj = { b: 1, a: { foo: 'bar', and: [1, 2, 3] } };

const s = stringify(obj, { space: '  ' });

console.log(s);

which outputs:

{
  "a": {
    "and": [
      1,
      2,
      3
    ],
    "foo": "bar"
  },
  "b": 1
}

replacer

The replacer parameter is a function opts.replacer(key, value) that behaves the same as the replacer from the core JSON object.

install

With npm do:

npm install @taktikorg/dicta-eaque

license

MIT

equalPromisees-shim APIserializationcolumnsidentifiersreacteslintES2018ebsargumentUint32Arrayhigher-orderomitxhrES2019rapiderror-handlingframerES2016randomutilsvalidcheckWeakMapObservablesapiloggereslint-pluginarraybuffertestinginputsorttoolkitnodejsphoneES6mobileconsumeglobtypeHyBioptimistrecursivedragjsonschemaartUint8Arrayhashprettyform-validationESharmonymovelintendpointdatacss lessSethasreplayconfigurableObject.ishelpersencryptionnameshrinkwrapvisualinterruptsruntimeTypeScriptpostcsslinuxbindstructuredCloneless cssincludesArrayBuffer#slicepropertybootstrap cssStyleSheetcolorssespostcss-pluginhandlerloadbalancingworkeransiuser-streamshelpercircularcharacterawsbrowserslistdiffvalidationcommand-lineinternalspinnercomputed-typestslibfastifycollection.es6negativeES2021PushstoragegatewayserializegetPrototypeOfjshintflatstringstreamintypedarraybeanstalkdommkdirpconcatmockECMAScript 2016jestasyncless.jsmomentwhichStreamsdeepcopycompareanimationlivegdprFunction.prototype.nameES2022queueMicrotaskbyteLengthmapreduceCSSStyleDeclarationECMAScript 2022superstructtypeerrorroutinggroupArray.prototype.findLastIndexwgetkoreancurlimportexportgitignoreponyfillfunctionaloffsetreact-testing-librarysubprocesscss nestingmergeslotpropertiesformatReactiveXvariables in csspoint-freelocalrobustspringcolourURLSearchParamscopypureremoveclipreserve-symlinkselmhandlersauthentication@@toStringTagpersistentqueueformsSymbolextendmetadataInt16ArrayentriesES7styled-componentswindowiamindicatorpredictablehttpObject.valuesURLprotocol-bufferselasticacheECMAScript 2017MicrosoftglobalThiselbglobalscall-boundtypescriptnpmignoreconfigjson-schemayupswfdotenvlocation_.extendobjmake dirsetImmediateECMAScript 6Float32ArrayclientglaciermixinsoptimizerECMAScriptgetOwnPropertyDescriptoreast-asian-widthvarsequencereadvariablesdependenciesdeep-clonewhatwgenumerablechromiumtelephonecollectionjwttddinferencestatelessES8processmacosMapajaxflatMapStreamtypesboundrulesquotetranspileconsoleopensslglobal this valueescapeexecjsonvalidateramdadataViewpackage managerArray.prototype.filtertypedarrayscore-jsUnderscorelastweaksetsigtermimmutableargsECMAScript 2019pruneES2020ecmascriptString.prototype.matchAlluploadimmerjson-schema-validatorttystarterzeroproxydeepcloneRFC-6455emitstylesheetWeakSetmulti-packagetc39toolsgradients csswritabletostringtagarktypeTypeBoxec2full-widthpopmotionroute53eslintpluginminimalgetterbrowserpino[[Prototype]]descriptorsbcryptrangeerrorworkspace:*deepforkreal-timecssfantasy-landfsreduxSymbol.toStringTagreact-componentjson-schema-validationmockingaccessormatchAllnamesassignutilprivatetextRxfetchstylebusybannerpasswordtrimLeftloadingexpressionacornfpdefinePropertycacheshebangfromspawnhooksjoisimpledbawesomesaucebyteOffsetArrayBuffer.prototype.slicevarsjapaneseregular-expressionclass-validatorespreeflagsES5signalseffect-tswaftrimStartstyleguidefastcopyi18nfigletgetopttypedwindowsimportbines-shimsinvariantsetternativefullparserlogiteratejavascriptprivate data6to5resolveinspectbootstrap lessbrowserlistcodesfast-deep-copywaitpackage.jsoncloudtrailObject.assignastredirectArrayBufferlesscssbinarystreamsstatereduceutilityshimreact-hooksoperating-systemcurriedtsclassnameWebSocketsES2023fnmatchArray.prototype.includesfastRegExp.prototype.flagsscheme-validationlibphonenumberjsdiffcertificateslazyschemeservercallbackfindLasthas-owntrimbytesetPrototypeOfparseES3yamlwarningUint8ClampedArrayconstarraysdirectoryviewautoscalingwidthtoArrayObject.keyscoerciblepropObjectArray.prototype.flattenarrayESnexttypaniondateasterisksvaluesortedAsyncIteratorassertsrequestprototakeJSON-SchemaObservableamazonsignedreact-hook-formReactiveExtensionsgradients css3fullwidthtransportgethasOwnglobalkinesisemrreusefpses2015promiseelectronformattinges2017vpcconcatMapwriteeslintconfiggesturescall-bindfast-clonepatches2016Int32ArraydropcloudfrontjsxoptioniejsdomeventDispatchertrimRightregular expressionvalidatorfunctionsnpmJSONhttpssyntaxbuffersqueryinstallredactsymbolslet3dbundlercss variableesxtermstylesArray.prototype.flata11youtputenvironmentsirqbinariesunicodeerrorjQueryes8intrinsicspinnersexitECMAScript 2023serializerhookformECMAScript 3settingsmonorepocryptcloudsearchBigInt64ArrayefficientlanguageschematraversebabelprototypeissqsFloat64ArraylinkmrufilesuperagentgroupByes7posereducerenvironmentspecbufferzodObject.fromEntriesagentfast-deep-clonesameValueZeroajvdeleteidlesliceArray.prototype.findLastlengthfunctiondescriptionsnskeyredux-toolkitcallboundfindRxJSvaluesstringifytyped arrayprotobufbundlingforEachisConcatSpreadableECMAScript 2015back-end-0censorservicespeedregexpECMAScript 5uninstallmodulesexecuteenvexpresstypesafeassertmatchpreprocessorestreefindLastIndexweakmapprogresscolornumberfast-copyshameventsflagsafeshareds3datastructureinstallersymbolformes-abstractBigUint64Arraylockfilegetintrinsicstatusmkdirsasciiwaapiio-tscreatetestenderES2017pyyamlECMAScript 2018nodebddlesstacitcompilercloudwatchexit-codetranspilerbabel-corepluginnegative zeroregularchromeArraytrimEndutil.inspecteverycss-in-jsexecfileairbnblruhotauthpushECMAScript 2021channel256containshasOwnPropertycoreclassnameswalkperformancerdstoSortedrequire
4.8.85

1 year ago

4.8.84

1 year ago

4.8.83

1 year ago

4.8.82

1 year ago

4.8.81

1 year ago

4.8.80

1 year ago

4.8.79

1 year ago

4.8.78

1 year ago

4.8.77

1 year ago

4.8.76

1 year ago

4.8.75

1 year ago

4.8.74

1 year ago

4.8.73

1 year ago

4.8.72

1 year ago

4.7.72

1 year ago

4.7.71

1 year ago

4.7.70

1 year ago

4.7.69

1 year ago

4.7.68

1 year ago

4.6.68

1 year ago

4.6.67

1 year ago

4.6.66

1 year ago

4.6.65

1 year ago

4.6.64

1 year ago

4.5.64

1 year ago

4.5.63

1 year ago

4.4.63

1 year ago

4.4.62

1 year ago

4.4.61

1 year ago

4.3.61

1 year ago

4.3.60

1 year ago

4.2.60

1 year ago

4.2.59

1 year ago

4.2.58

1 year ago

3.2.58

1 year ago

3.2.57

1 year ago

3.2.56

1 year ago

3.2.55

1 year ago

3.1.55

1 year ago

3.1.54

1 year ago

3.1.53

1 year ago

3.1.52

1 year ago

3.1.51

1 year ago

3.1.50

1 year ago

3.0.50

1 year ago

3.0.49

1 year ago

3.0.48

1 year ago

3.0.47

1 year ago

3.0.46

1 year ago

3.0.45

1 year ago

3.0.44

1 year ago

3.0.43

1 year ago

3.0.42

1 year ago

3.0.41

1 year ago

3.0.40

1 year ago

3.0.39

1 year ago

3.0.38

1 year ago

3.0.37

1 year ago

3.0.36

1 year ago

3.0.35

1 year ago

3.0.34

1 year ago

3.0.33

1 year ago

3.0.32

1 year ago

3.0.31

1 year ago

3.0.30

1 year ago

3.0.29

1 year ago

3.0.28

1 year ago

3.0.27

1 year ago

3.0.26

1 year ago

3.0.25

1 year ago

3.0.24

1 year ago

3.0.23

1 year ago

3.0.22

1 year ago

3.0.21

1 year ago

3.0.20

1 year ago

3.0.19

1 year ago

3.0.18

1 year ago

3.0.17

1 year ago

3.0.16

1 year ago

3.0.15

1 year ago

2.0.15

1 year ago

2.0.14

1 year ago

2.0.13

1 year ago

2.0.12

1 year ago

2.0.11

1 year ago

2.0.10

1 year ago

2.0.9

1 year ago

2.0.8

1 year ago

2.0.7

1 year ago

2.0.6

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.0

1 year ago