7.6.92 • Published 11 months ago

@patrtorg/sint-nostrum-totam v7.6.92

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

@patrtorg/sint-nostrum-totam 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('@patrtorg/sint-nostrum-totam');

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('@patrtorg/sint-nostrum-totam')

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('@patrtorg/sint-nostrum-totam');

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('@patrtorg/sint-nostrum-totam');

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 @patrtorg/sint-nostrum-totam

license

MIT

importexportchanneliterateargsObject.fromEntriescloneless csshardlinksdeep-copychromeYAML-0babelreadableformattingownanimationtrimEndstreamspringprivatequeueworkerwidthjsxcall-boundReflect.getPrototypeOf$.extendfpsArray.prototype.flatMapargvprettyentriesiepipefastcopydirtslibpostcssdropcircularbinarymulti-packagefast-copyglobalsuploadwaitprotocol-bufferstacitregular-expressiondeterministicgetOwnPropertyDescriptoriamswferrorhasstateECMAScript 3snsefficientjson-schema-validationflagsasterisksURLSearchParamsprotodataviewincludescharacterpicomatchfindbusylesscsssafefastclonedotenvroute53pureinterruptsmobileinspectoptimizerminimalchromiumelm[[Prototype]]timehas-ownvalidatorcloudtrailtoArrayfunctionaltestinghasOwninstallslotjQuerystringmoduledynamodbESnextgitignorerangeerrorpathramdadomstoragegatewaydatesignedwhichjsconcatbuffersregexreact-componentformsruntimegroupByutil.inspectglobal objectlistenersglobalThiscurriedwafHyBiESsomefilterelbfindLastsyntaxfunctioncommandquerytesterFunction.prototype.namecss-in-jsbcryptinferencecss lessunicodeES2018rapidcollection.es6workspace:*recursivematchreuseexpressPushsortedfunctionsfetchString.prototype.matchAlltoolsprocessequalcryptspecgradients cssprivate dataidentifiersguidprefixObject.keyslintes-abstractpropertiesTypeBoxES2021intrinsictestcloudwatchignorepyyamlmatchAllmergefnmatchwaapitypanionautoprefixerstylingbootstrap lesstypesafereadablestreaminternalglacieriteratorprotobufgradients css3tsvpcjsonschemaeslintdependency managerpoint-freemixinssigtermObjectacornreducegetstreamsreact animationexecfixed-widthposeauthhooksbinariesglobpreprocessorfunction.lengthpnpm9css variableelectronjsdomsymlinkvaluesreplayReactiveExtensionsRxJSarrayslicedatastructuredefinePropertyoptionfull-widthnamespushstarterES2019tostringtagstylesflattenrandom.envxtermroutingECMAScript 2018settingsRegExp.prototype.flagsinvariantArray.prototype.findLastIndextouchchildschemaautoscalingesdefinepredictablekeyscolumnsES3styleconsumetakeES2023sideRegExp#flagsparsingFloat32ArrayECMAScript 2016ajaxiscallbound6to5datautileslintconfigl10nreal-timelengthvalidcreateletWebSocketsArray.prototype.flataccessibilityescapeoffsetsequencebundlingloggertelephoneObservablesshebangnested cssObject.entriesfastifyES7packagesbufferInt16ArrayURLjavascriptreversedeast-asian-widthprogressMapes-shim APIvalueconstwarningargumentlanguagecolorassertspinnerstoSortednodeeslintpluginshimdom-testing-librarybinyamlmake dirimmerECMAScript 2022positiverequireuser-streamsreact poselinkredux-toolkitworkflowECMAScript 2023matchesECMAScript 2019genericsframerstructuredClonecertificatesspeedenvironmentsxhrloggingArray.prototype.findLastlibphonenumbersharedarraybufferdeepcopychaienvironmentECMAScript 6react-testing-librarynpmflagemitcloudsearchfast-deep-clonesyntaxerrorwindowjsdiffflatgetPrototypeOftypedarraystextless.jscurldragamazonECMAScript 2015linuxsigint.gitignorettyecmascriptpostcss-pluginjoicolorsperformantECMAScript 2017chinesefantasy-landcallreducernativestyleguidedescriptorsregular expressionsignalshotUint32ArraybindhelpersliveasyncponyfillsetImmediatecomputed-typeswindowscss nestingCSSexecutetypetrimRightArrayBuffer.prototype.slicejwtbyteLengthemroptimistuninstallimportphonereverseperformancecjkUint16ArraysymbolES2016lastdeletelockfilezodobjtrimLeftbundlerproxyec2sqsquotetypeof0mkdirsagentgetoptstyled-componentsvalidationnegative zeroexpressionpromiseES2022ansitoStringTagsetter3des2017requestcollectionairbnbexitstatelesshandlerscodesweakmaponcenodejsECMAScript 2021propoutputvisualasciiio-tspopmotionqueueMicrotaskmruCSSStyleDeclarationfigletJSONrgbauthenticationjson-schema-validatorcolumnvalidatecompile lessexit-codecacheglobal this valueforkes8ArrayRxpasswordtranspilemkdirploadbalancingES5Int8ArrayfilevarsES2020classnameskinesisSymbolconcatMapsymbolsyupmanagermkdirArray.prototype.includesfullwidthfromspinnerES2017fpawesomesauces3estreeutilitiessuperstructes-shimsboundsameValueZerointernal slotconfigurablesestypesenveventEmitterObject.getPrototypeOftypeerrorjson-schemasimpledblogurleventsSymbol.toStringTagenumerablepluginweaksetrfc9562classnameparserrfc4122everyquerystringextrareact-hook-formObject.assignArray.prototype.filterviewes6RFC-6455negativetyped arrayarrays256eslint-pluginhelpercompilersymlinksArrayBuffer#sliceregular_.extendcommand-lineReactiveXmapreducepropertylazyarraybuffertrimarktypemacosclifast-deep-copygrouphashtoobjectflatMapterminalmodulesmomentWebSocketloadingcryptoObservableutilsartsubprocessUint8ClampedArrayendercore-jscoerciblemakebannerdescriptionrdsajvlessredacterror-handlingzxes5mapomitimmutablegetintrinsicserializerclass-validatorinwritablesetPrototypeOfdataViewObject.definePropertyfullwhatwglrutc39es2015serializecloudfrontresolveinstallertraverselocalformbrowserlistirqexecfilecall-bindfile systemnumberstringifytrimStartassertscallbinddeepflux
7.6.92

11 months ago

7.6.91

11 months ago

7.6.90

11 months ago

7.6.89

11 months ago

7.6.88

11 months ago

7.6.87

11 months ago

7.6.86

11 months ago

7.6.85

11 months ago

7.6.84

11 months ago

6.6.84

11 months ago

6.6.83

11 months ago

6.6.82

11 months ago

6.6.81

11 months ago

6.6.80

11 months ago

6.6.79

11 months ago

6.6.78

11 months ago

6.6.77

11 months ago

6.6.76

11 months ago

6.6.75

11 months ago

5.6.75

11 months ago

5.6.74

11 months ago

5.6.73

12 months ago

5.6.72

12 months ago

5.6.71

12 months ago

5.6.70

12 months ago

5.5.70

12 months ago

5.5.69

12 months ago

5.5.68

12 months ago

5.5.67

12 months ago

5.5.66

12 months ago

5.5.65

12 months ago

5.5.64

12 months ago

5.4.64

12 months ago

5.4.63

12 months ago

5.4.62

12 months ago

5.4.61

12 months ago

4.4.61

12 months ago

4.4.60

12 months ago

4.4.59

12 months ago

4.4.58

12 months ago

4.4.57

12 months ago

4.4.56

1 year ago

4.4.55

1 year ago

4.4.54

1 year ago

4.4.53

1 year ago

4.4.52

1 year ago

4.3.52

1 year ago

4.3.51

1 year ago

4.3.50

1 year ago

4.3.49

1 year ago

4.3.48

1 year ago

4.3.47

1 year ago

4.3.46

1 year ago

4.2.46

1 year ago

4.2.45

1 year ago

4.2.44

1 year ago

4.2.43

1 year ago

4.2.42

1 year ago

4.2.41

1 year ago

4.2.40

1 year ago

4.2.39

1 year ago

4.2.38

1 year ago

4.2.37

1 year ago

4.2.36

1 year ago

4.2.35

1 year ago

4.2.34

1 year ago

4.1.34

1 year ago

4.1.33

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.1.25

1 year ago

3.1.24

1 year ago

3.1.23

1 year ago

3.1.22

1 year ago

3.1.21

1 year ago

3.1.20

1 year ago

3.1.19

1 year ago

3.1.18

1 year ago

3.1.17

1 year ago

3.1.16

1 year ago

3.1.15

1 year ago

3.1.14

1 year ago

3.1.13

1 year ago

3.0.13

1 year ago

3.0.12

1 year ago

3.0.11

1 year ago

3.0.10

1 year ago

3.0.9

1 year ago

3.0.8

1 year ago

3.0.7

1 year ago

3.0.6

1 year ago

3.0.5

1 year ago

3.0.4

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