5.8.107 • Published 10 months ago

@diotoborg/nihil-praesentium v5.8.107

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

@diotoborg/nihil-praesentium

Deterministic JSON.stringify() - a faster version of @substack's json-stable-strigify without jsonify.

You can also pass in a custom comparison function.

Build Status Coverage Status

example

var stringify = require('@diotoborg/nihil-praesentium');
var 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

var stringify = require('@diotoborg/nihil-praesentium')

var 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 })

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

var stringify = require('@diotoborg/nihil-praesentium');

var obj = { c: 8, b: [{z:6,y:5,x:4},7], a: 3 };
var s = stringify(obj, function (a, b) {
    return a.key < b.key ? 1 : -1;
});
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:

var stringify = require('@diotoborg/nihil-praesentium');

var obj = { d: 6, c: 5, b: [{z:3,y:2,x:1},9], a: 10 };
var 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}

cycles

Pass true in opts.cycles to stringify circular property as __cycle__ - the result will not be a valid JSON string in this case.

TypeError will be thrown in case of circular object without this option.

install

With npm do:

npm install @diotoborg/nihil-praesentium

benchmark

To run benchmark (requires Node.js 6+):

node benchmark

Results:

@diotoborg/nihil-praesentium x 17,189 ops/sec ±1.43% (83 runs sampled)
json-stable-stringify x 13,634 ops/sec ±1.39% (85 runs sampled)
fast-stable-stringify x 20,212 ops/sec ±1.20% (84 runs sampled)
faster-stable-stringify x 15,549 ops/sec ±1.12% (84 runs sampled)
The fastest is fast-stable-stringify

Enterprise support

@diotoborg/nihil-praesentium package is a part of Tidelift enterprise subscription - it provides a centralised commercial support to open-source software users, in addition to the support provided by software maintainers.

Security contact

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure. Please do NOT report security vulnerability via GitHub issues.

license

MIT

deep-cloneprotocol-bufferserrortermemitrangeerrorcssquotesetPrototypeOfjsstabletelephoneSymbolprogresscodestapepostcssInt32ArraytextasyncpipeString.prototype.trimpackagefast-copyacorntrimchannelvpcparentspolyfilllengthloadbalancingES5real-timeemrprototypexhrecmascriptkoreananimationmapreducevesttoReversedregular expressionkeynodeinternal slottrimRightstoragegatewaymkdirstypesreact posedropautoscalingserializationomitES2018workflowvariablesPushInt16ArraynativeeslintfindLastIndexlockfileflatMaprsshttpglobal objectreact animationes6-0fetchES3toobjectequalityguidArray.prototype.includesconsumearraysfast-deep-copypathArray.prototype.findLastes-shim APIrestfigletqueueSetyupsnsCSSStyleDeclarationlistenershardlinksString.prototype.matchAllsuperstructhasOwnreverselocaleveryhigher-orderpoint-freevarMicrosoftmapstyled-componentsYAMLhas-ownfunctionCSSAsyncIteratorreworkpnpm9debugzeroviewfileeslint-pluginastWebSocketesiteratorArray.prototype.findLastIndexESinsideECMAScript 5popmotionArray.prototype.containsregular-expressionminimalforkperformancetestingargumentECMAScript 2021dragmodulesdirectoryRegExp#flagsclassnameuser-streams6to5symbolcloudformationeslintplugintddpruneserializelocationcloudsearchfixed-widthperformantloadingform-validationoptionzoddebuggersharedarraybufferxmldescriptorreadablejsonschemajsdiffgetJSON-SchemardsES6compilercryptosearchidistanbulwafswfreduceglobalruntimegetterschemees-shimsroute53full-widthtostringtagES2017characteriteratedirwarningBigInt64ArraycallboundsetImmediate0utilityconstBigUint64Arrayassertscode pointsqsbyteLengthmergeshellprefixglobalscalles2018clientjson-schema-validationgenericstypecallbackserializerargvreversedcolorsfeedtoolkitlintsuperagentchromefpsnamesgdprreactsomefolderyamlnegativeignoreamazonArrayBuffer#sliceparentcontainsconcatMapsesuuidelasticacheebsjasmineajaxStreamfunctionalstringifierterminalprivaterandomponyfillprivate dataimmutablecollection.es6ECMAScript 3chinesesorttakerequestsubprocessoptimistuninstallqueueMicrotaskdescriptionupdeepfindLastrm -rfArraygetintrinsicwidth256command-lineECMAScript 7sinatraglacierwriteECMAScript 2016touchexecfileECMAScript 2020trimLeftjapanesebinaryresolverapidawsimmercolourESnextArrayBuffer.prototype.slicecreateunicodesortedes2016varsdefinescheme-validationcharactersasciifile systemglobansieventsbundlingletECMAScript 2019readablestreamformsconsolefast-clonedynamodbgroupBymomentlogredux-toolkithookformdataviewforminstallbundlerbinstreamenvironmentpreprocessorregexpkinesisspinnersairbnbfunctionswhatwgArrayBufferSymbol.toStringTaggitignorefast-deep-cloneautoprefixerregexpropertiesenumerableRxJScoverageextradiffcall-bindcjkspringexecTypeBoximportjsdomtsrgbtrimEndcensorObjecttacit@@toStringTagclass-validatorchromiumsymbolscomparejoiObject.keyswaitnegative zeroenvdom-testing-libraryshrinkwrapes2015regularhttpses-abstractselfhascommanddeterministicelectronobjclonepostcss-plugintoSortedredirectlook-upInt8ArrayWeakMap__proto__oncecurldatametadataphonegrouphashRFC-6455nodejsramdamatchAlllastequalmulti-packagebddtimebinariescloudwatchtapTypedArraypluginfastclonejestsimpledbfnmatchwalkingeast-asian-widthECMAScript 2022rm -frec2fastthreeurlmochafilterformattingutilsameValueZeroimportexporteventDispatcherdeep-copypyyamlrminternalpropsetcomputed-typesmonorepobannerajvArray.prototype.flattensliceES2021weaksetfsStreamsreaddomidlextermmatchrfc4122curriedtrimStartl10narraybufferpackagesasterisksincludespureglobalThiselbReactiveExtensionsfindbabeltypescriptrobustatomredact.envcoreespreeutilitiesgetOwnPropertyDescriptorparseposeboundbindhelpersource maplibphonenumberslotoffsetvalidatorarraywritablecss-in-jsArray.prototype.filterjQuerycolumninspectharmonypackage.jsonfullwidthindicatortypedmanagerObservablesUint8ClampedArrayObject.definePropertydotenvvaliddependenciesefficientdescriptorsassertlookreuseshamdate
5.8.107

10 months ago

5.8.106

10 months ago

5.8.105

10 months ago

5.8.104

10 months ago

5.8.103

10 months ago

5.8.102

10 months ago

5.8.101

10 months ago

5.8.100

10 months ago

5.8.99

10 months ago

5.8.98

10 months ago

5.8.97

10 months ago

5.8.96

10 months ago

5.8.95

10 months ago

5.8.94

10 months ago

5.8.93

10 months ago

5.8.92

10 months ago

5.8.91

10 months ago

5.8.90

11 months ago

5.8.89

11 months ago

5.8.88

11 months ago

5.8.87

11 months ago

5.8.86

11 months ago

5.8.85

11 months ago

5.8.84

11 months ago

5.8.83

11 months ago

5.8.82

11 months ago

5.8.81

11 months ago

5.8.80

11 months ago

5.8.79

11 months ago

5.8.78

11 months ago

5.8.77

11 months ago

5.8.76

11 months ago

5.8.75

11 months ago

5.7.75

11 months ago

5.7.74

11 months ago

5.7.73

11 months ago

5.7.72

11 months ago

5.7.71

11 months ago

5.7.70

11 months ago

5.7.69

11 months ago

5.7.68

11 months ago

5.7.67

11 months ago

5.7.66

11 months ago

5.6.66

11 months ago

5.6.65

11 months ago

5.6.64

11 months ago

5.6.63

11 months ago

5.6.62

12 months ago

5.6.61

12 months ago

4.6.61

12 months ago

4.5.61

12 months ago

4.5.60

12 months ago

4.5.59

12 months ago

4.5.58

12 months ago

4.5.57

12 months ago

4.5.56

12 months ago

4.5.55

12 months ago

4.5.54

12 months ago

4.5.53

12 months ago

4.5.52

12 months ago

4.5.51

12 months ago

4.5.50

12 months ago

4.4.50

12 months ago

4.4.49

12 months ago

4.4.48

12 months ago

3.4.48

12 months ago

3.4.47

12 months ago

3.4.46

1 year ago

3.4.45

1 year ago

3.4.44

1 year ago

3.4.43

1 year ago

3.4.42

1 year ago

3.4.41

1 year ago

3.3.41

1 year ago

3.3.40

1 year ago

3.2.40

1 year ago

3.2.39

1 year ago

3.2.38

1 year ago

3.2.37

1 year ago

3.2.36

1 year ago

3.2.35

1 year ago

2.2.35

1 year ago

2.2.34

1 year ago

2.2.33

1 year ago

2.2.32

1 year ago

2.1.32

1 year ago

2.1.31

1 year ago

2.1.30

1 year ago

2.1.29

1 year ago

2.1.28

1 year ago

2.1.27

1 year ago

2.1.26

1 year ago

2.1.25

1 year ago

2.1.24

1 year ago

2.1.23

1 year ago

2.1.22

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

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

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