4.11.80 • Published 10 months ago

@erboladaiorg/aspernatur-id-itaque v4.11.80

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

@erboladaiorg/aspernatur-id-itaque 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/aspernatur-id-itaque');

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/aspernatur-id-itaque')

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/aspernatur-id-itaque');

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/aspernatur-id-itaque');

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/aspernatur-id-itaque

license

MIT

pathES2021es2016callboundwgetlinuxdayjseventscolourkeysfastifycloudformationprettygetPrototypeOfObject.valuesphoneArray.prototype.findLastoptimistcssbrowserlisttestergetOwnPropertyDescriptordeep3dprotobufArray.prototype.flatauthes8setECMAScript 2020Object.entriescollectionexecfileInt32ArrayES2019springopensslbyteiterationWeakSetgraphqlsesstringifydefinePropertyidentifierssameValueZerotoArraylru@@toStringTagESnextreactcore-jscomparecss variablecall-bindreplayreact-componentObservableisgetintrinsicdescriptionchannelcurriedformssqsJSONCSSStyleDeclarationFloat32ArraynamesSystem.global256installtypanionpackagestypesnumberclientfixed-widthstatelessfpconfigroutingmkdirswindowrfc4122agentarrayimportexporthasdatahigher-orderruntimees-abstractasterisks$.extendtacitswfweaksettrimsyntaxerrorexitescapeArray.prototype.filterextrareduxsetPrototypeOfprivate datafileflagconcatObject.fromEntriespreprocessorcommand-linejsdompredictabledeep-copywindowsglobalsfast-cloneObject.getPrototypeOfcolumnswaitcallbindstreamexpressserializeassertECMAScript 3vestguidpyyamlObject.keyssidetrimEndES7functionssuperagentreducerjQueryrequestArray.prototype.includesenumerablecreatenpmignorestringifiersyntaxnpmjsxutilajvtimeselfeslint-plugingradients css3fullremoveparsingES2015classnamesstableutilsArray.prototype.containspipecachedotenves2015modulebyteLengthdrages-shimspackage.jsondependency manager6to5offsetregular-expressionString.prototype.matchAllformattingwarninginterruptszxpluginjoiES2018corettyfpsebsviewreact animationmatchtestingES2022writablemodulesJSON-Schemapropertieshardlinkspostcss-pluginspinnersvalidationloggerInt16ArrayidleparseharmonyramdaforEachArrayBuffer.prototype.sliceunicodequeryglobmapreducepasswordrandomec2propertydomES2023sigintgestureswidthbundlersymboltoStringTaglivetypescriptelbFloat64Arrayeffect-tsnegativeartECMAScript 2022Array.prototype.flattennopereadablelistenerscryptquoteimmutableworkspace:*-0user-streamsvariables in cssdataviewless mixinsutilitiesArray.prototype.flatMapECMAScript 2021figletlastbindtypedarraysapollotranspilerajaxdynamodbsignalreact posecolorvariablesvartouchWeakMapformhotes2018amazones2017deterministicmetadataStreamquerystringstatusfile systemES2016asciifetchprotocol-bufferssignedeslintexpressionindeepcopy[[Prototype]]mapRegExp.prototype.flagssharedES3takeoutputless compilersomemoveastcloudfrontsimpledbpatchweakmapgenericsglobal this valueprototypegitignorestyleguideiepromisereal-timepopmotionapiReactiveXECMAScriptcodesUint8ArraydeepclonebinariesshimauthenticationstylesbyteOffsetstylebinaryspeedinspectobjsigtermhandlersbootstrap csslocalimmerstylingsettingscommandECMAScript 2016termarktypemakegetpolyfillES2017css nestingstoragegatewayserializationpropfsregexpthreesequencedependenciesjsdiffpreserve-symlinksvalidatereadObjectECMAScript 2019parserworkflowcomputed-typesInt8Arrayfullwidthprunerecursiveform-validationschememake dirrobustArrayBuffer#sliceaccessornodeES2020performancefindLastRegExp#flagshookformUint8ClampedArrayi18ns3BigInt64ArrayelectronRFC-6455full-widthprogressflattentypeofstylesheetObject.isglobalxhrECMAScript 7String.prototype.trimYAMLfantasy-landtextoperating-systemflatMapflagschai.envconcatMapmomenttrimRightReflect.getPrototypeOfvarsoptimizer
4.11.80

10 months ago

4.10.80

11 months ago

4.10.79

11 months ago

4.10.78

11 months ago

4.10.77

11 months ago

4.10.76

11 months ago

4.10.75

11 months ago

4.10.74

11 months ago

4.10.73

11 months ago

4.10.72

11 months ago

4.10.71

11 months ago

4.10.70

11 months ago

4.9.70

11 months ago

4.9.69

11 months ago

4.9.68

11 months ago

4.9.67

11 months ago

4.9.66

11 months ago

4.9.65

11 months ago

4.9.64

11 months ago

4.8.64

11 months ago

4.8.63

11 months ago

4.8.62

11 months ago

4.8.61

11 months ago

4.8.60

11 months ago

4.8.59

11 months ago

4.8.58

11 months ago

4.8.57

11 months ago

4.8.56

11 months ago

4.8.55

11 months ago

4.8.54

11 months ago

4.8.53

11 months ago

4.8.52

12 months ago

4.8.51

12 months ago

4.8.50

12 months ago

4.7.50

12 months ago

4.7.49

12 months ago

4.7.48

12 months ago

4.6.48

12 months ago

4.6.47

12 months ago

4.6.46

12 months ago

4.6.45

12 months ago

4.6.44

12 months ago

4.6.43

12 months ago

4.6.42

12 months ago

4.5.42

12 months ago

4.5.41

12 months ago

4.5.40

12 months ago

4.5.39

12 months ago

4.5.38

12 months ago

4.5.37

12 months ago

4.5.36

12 months ago

4.5.35

1 year ago

4.5.34

1 year ago

4.5.33

1 year ago

4.5.32

1 year ago

4.5.31

1 year ago

4.5.30

1 year ago

4.4.30

1 year ago

4.4.29

1 year ago

4.4.28

1 year ago

4.4.27

1 year ago

4.4.26

1 year ago

4.4.25

1 year ago

4.4.24

1 year ago

4.4.23

1 year ago

4.3.23

1 year ago

4.3.22

1 year ago

4.3.21

1 year ago

4.3.20

1 year ago

4.3.19

1 year ago

4.3.18

1 year ago

4.3.17

1 year ago

3.3.17

1 year ago

2.3.17

1 year ago

2.3.16

1 year ago

2.3.15

1 year ago

2.2.15

1 year ago

1.2.15

1 year ago

1.2.14

1 year ago

1.2.13

1 year ago

1.2.12

1 year ago

1.2.11

1 year ago

1.2.10

1 year ago

1.2.9

1 year ago

1.2.8

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

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