4.5.86 • Published 10 months ago

@erboladaiorg/dignissimos-ducimus-perferendis v4.5.86

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

@erboladaiorg/dignissimos-ducimus-perferendis 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('@erboladaiorg/dignissimos-ducimus-perferendis');

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('@erboladaiorg/dignissimos-ducimus-perferendis')

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('@erboladaiorg/dignissimos-ducimus-perferendis');

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('@erboladaiorg/dignissimos-ducimus-perferendis');

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 @erboladaiorg/dignissimos-ducimus-perferendis

license

MIT

querystringsetinvariantbrowserslistsortedtypedarray256RxJSserializejshintfunctionstypesobjectredux-toolkitObject.definePropertyregular expressionbinaryprivatepromiseassertes2016error-handlinghassliceregexeventspackage.jsontypedencryptionbyteOffsetregular-expressionwidthutilslanguageworkerdeep-cloneObservablearraysrapidcollectioneffect-tsconcatfsentries6to5macosparsinglivepostcsstranspilerfc4122identifiersbrowserlistpropertytrimLeftcompilergdprHyBifetchtraversecss variabletypesafeaccessibilitydomspawncss-in-jsmonorepotimeURLSearchParamsRxswfECMAScript 5queryeslint-pluginselfES2020global objectttycontainsstreamsresolvesqscertificatessubprocesschecktranspilerroute53es-shim APIischaracterjavascriptprotocol-buffersless.jsjwthookformlocalsuperagentsigneddeletemkdirtouchnested csswalktrimEnddircallbindwritablewaitgetterhandlersnamedeepclonegroupBypersistentjoianimationlessprotostableopensslelectronpasswordES2023AsyncIteratorrdsiteratorlastbabelquotesomedescriptionslotcolourfunctionalSetrandomeshotsignalsmovehttpcss lessinspectES2019performantbabel-coreendpointlockfileeast-asian-widthfull-widthcore-jsajaxrangeerrorramdaObservablestransportRFC-6455preprocessorES5es-abstractxtermfile systemredact.envfantasy-landfigletstatesequenceECMAScript 2018telephoneform-validationcryptbannervarStyleSheetnumberdotenvmatchesawesomesauceCSSStyleDeclarationsortproxyhas-ownUint8ArraycallhasOwnobjeslintpluginroutingdataIteratorInt16Arrayenvironment3denvironmentssescodesassignminimalUint16ArrayinferencecensorelbjestfnmatchsyntaxoptimistdescriptorscssArrayclassestslibfindLastIndexwgetTypedArrayposewarningschememobilefastcloudformationefficientqueueincludesinternalsyntaxerrorpipeglaciercallboundpicomatchsetteriteratedataviewformattingArray.prototype.containsglobalss3expressArray.prototype.flattendynamodbincopyreact animationastbundlerdiffECMAScript 2016requestmulti-packagefunction.lengthassertses2018typebddonceclonewriteStreamnpmignoreESnextconsolesharedarraybufferlinuxoptimizerutilitiesinstallerzeroconfigstoragegatewayagentvalidtoobjectnodejsdifflinkequalitylogginglibphonenumberfullwidthapolloecmascriptTypeScript0escapedom-testing-librarybinariesArrayBufferstylingcall-bindRegExp#flagsuploadECMAScript 2020Streamsstreamgraphqlwhatwglistenersshellcjkless compilerstyleguidebundlingconfigurableArray.prototype.includespluginclassnamecloudsearchES2017ECMAScript 2021dependenciesbrowserspeces2015windowairbnbclichildasyncreversekeytoReversedeslinthasOwnPropertyimportexportstylesbytetypedarraystddexpressionnegativemodules@@toStringTageverysymbolextratypeerrorcurlprotobufkinesisES2015emrreact-testing-libraryArrayBuffer.prototype.slicefast-deep-clonejsonstringifyyamlreducematchchromiumbinjsuuidglobalThismapemitObject.getPrototypeOfECMAScriptstringreversedutilitystartertoolstoolkitvariablesgroupchinese-0RegExp.prototype.flagsdeterministicnodejspatchfindString.prototype.matchAllgradients cssstyled-componentsvalidationcollection.es6uninstallfilesnsarktypeindicatorclassnamesremovedatel10nnamesmetadataECMAScript 2017rfc9562CSSpinoUint32Arraycryptomake dirowninternal slotloadbalancingcachevisualponyfillcloudfrontcolumnssetPrototypeOfcomparejapanesetypanion.gitignorefastcopyfindLastmatchAllspinnerrgbcommandcommand-linemruexitignoretypeoflazyestreeschemaBigInt64Arraypredictablevpcroutenegative zerocircularYAMLtrimStartcorespringECMAScript 2019commanderfixed-widthObject.valuesmomentoffsetflattenfull
4.5.86

10 months ago

4.5.85

10 months ago

4.5.84

10 months ago

4.5.83

10 months ago

4.5.82

10 months ago

4.5.81

11 months ago

4.5.80

11 months ago

4.5.79

11 months ago

4.5.78

11 months ago

4.4.78

11 months ago

4.4.77

11 months ago

4.4.76

11 months ago

4.4.75

11 months ago

4.4.74

11 months ago

4.4.73

11 months ago

4.4.72

11 months ago

4.4.71

11 months ago

4.4.70

11 months ago

4.4.69

11 months ago

4.4.68

11 months ago

4.4.67

11 months ago

4.4.66

11 months ago

4.4.65

11 months ago

4.4.64

11 months ago

4.4.63

11 months ago

4.4.62

11 months ago

4.3.62

11 months ago

3.3.62

11 months ago

3.3.61

11 months ago

3.3.60

11 months ago

3.3.59

11 months ago

3.3.58

11 months ago

3.3.57

11 months ago

3.3.56

11 months ago

3.3.55

11 months ago

3.3.54

12 months ago

3.2.54

12 months ago

3.2.53

12 months ago

3.2.52

12 months ago

3.2.51

12 months ago

3.2.50

12 months ago

3.2.49

12 months ago

3.2.48

12 months ago

3.2.47

12 months ago

3.2.46

12 months ago

3.2.45

12 months ago

3.2.44

12 months ago

3.2.43

12 months ago

3.2.42

12 months ago

3.2.41

12 months ago

3.1.41

12 months ago

3.1.40

12 months ago

3.1.39

12 months ago

3.1.38

12 months ago

3.1.37

12 months ago

3.1.36

1 year ago

3.1.35

1 year ago

3.1.34

1 year ago

3.1.33

1 year ago

3.1.32

1 year ago

3.1.31

1 year ago

3.1.30

1 year ago

3.1.29

1 year ago

3.1.28

1 year ago

3.1.27

1 year ago

3.1.26

1 year ago

3.0.26

1 year ago

2.0.26

1 year ago

2.0.25

1 year ago

2.0.24

1 year ago

2.0.23

1 year ago

2.0.22

1 year ago

2.0.21

1 year ago

2.0.20

1 year ago

2.0.19

1 year ago

2.0.18

1 year ago

2.0.17

1 year ago

2.0.16

1 year ago

2.0.15

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago