4.11.106 • Published 10 months ago

@patrtorg/aliquid-minus v4.11.106

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

@patrtorg/aliquid-minus

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('@patrtorg/aliquid-minus');
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('@patrtorg/aliquid-minus')

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('@patrtorg/aliquid-minus');

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('@patrtorg/aliquid-minus');

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 @patrtorg/aliquid-minus

benchmark

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

node benchmark

Results:

@patrtorg/aliquid-minus 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

@patrtorg/aliquid-minus 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

class-validatorstyled-componentsFloat32Arrayramdaprotobuffantasy-landquerytypescriptstringifierArray.prototype.flatMapproxytypeunicodeaccessormkdirclasseseventstestingloadbalancingeslintpluginjoijapanesedirectorytouchrequestsafeoptimizercallPushiamJSONboundcolorrfc4122debugespreees6getoptserializeautoscalingsyntaxerrorshimvalidatorresolveRxJSArray.prototype.findLastIndexsource mapjestsetPrototypeOfpostcsscss-in-jsistanbulnumberlogeslintfileString.prototype.matchAlltypescall-bindchannelrssframergetOwnPropertyDescriptorES2016enderuninstallPromiseObservablesparentlockfileajaxregular-expressionhashinternalWebSocketrmdirdatesymbolssameValueZerodeterministic.envpathformsreducestoragegatewayoptionmodulesmobilecoloureslint-pluginsharedminimalwgetiteratortestercode pointsequalastfunction.lengthpackage managerESnexteventDispatcheres-shim APImatchesCSShttpfasthttpsreworkflagsmruurlArraybannertranspilerjson-schema-validationexpressassertsforkcorerecursiveArray.prototype.flatYAMLES2020hookformoutputstreamsfullmergeconsumespringES2019invariantSystem.globalhasOwnPropertygroupsinatrawritablehelpersstylesObject.valuesl10nes2016amazontextlocationconfiges2018WebSocketsassertdefinePropertymomentvarcallboundECMAScript 5readspawnsymlinksObjectbyteLengthfindLastIndexpromiseprefixebs@@toStringTagdeep-cloneparentsvalidec2performantECMAScript 6swfharmonyimportexportObject.getPrototypeOfmkdirpmatchAllbabel-coreMicrosoftsettercomparezerofsclientglobal objectECMAScriptmake dircollectionincludesObservableclimonorepoes-shimscopyWeakSetAsyncIteratorwarningbinaryforEachoncepipehtmlfastcopypicomatchnamequeueMicrotaskArrayBufferprotolengthlook-upup
4.10.100

10 months ago

4.10.101

10 months ago

4.10.102

10 months ago

4.10.103

10 months ago

4.11.105

10 months ago

4.11.106

10 months ago

4.11.103

10 months ago

4.11.104

10 months ago

4.9.95

10 months ago

4.9.94

10 months ago

4.9.96

10 months ago

4.10.98

10 months ago

4.10.99

10 months ago

4.10.96

10 months ago

4.10.97

10 months ago

4.9.91

11 months ago

4.9.90

11 months ago

4.9.93

10 months ago

4.9.92

11 months ago

4.9.88

11 months ago

4.9.89

11 months ago

4.9.87

11 months ago

4.9.84

11 months ago

4.9.83

11 months ago

4.9.86

11 months ago

4.9.85

11 months ago

4.9.82

11 months ago

4.9.81

11 months ago

4.9.80

11 months ago

4.9.79

11 months ago

4.9.78

11 months ago

4.8.78

11 months ago

4.8.77

11 months ago

4.8.76

11 months ago

4.8.75

11 months ago

4.8.74

11 months ago

4.8.73

11 months ago

4.8.72

11 months ago

4.8.71

11 months ago

4.8.70

11 months ago

4.7.70

11 months ago

4.7.69

11 months ago

4.7.68

11 months ago

4.7.67

11 months ago

4.7.66

11 months ago

4.7.65

11 months ago

4.7.64

12 months ago

4.7.63

12 months ago

4.7.62

12 months ago

4.7.61

12 months ago

4.7.60

12 months ago

4.7.59

12 months ago

4.7.58

12 months ago

4.7.57

12 months ago

4.7.56

12 months ago

4.7.55

12 months ago

4.7.54

12 months ago

4.7.53

12 months ago

4.7.52

12 months ago

4.7.51

12 months ago

4.7.50

12 months ago

4.7.49

12 months ago

4.7.48

12 months ago

4.7.47

12 months ago

4.7.46

12 months ago

4.7.45

12 months ago

4.6.45

1 year ago

4.6.44

1 year ago

4.5.44

1 year ago

4.5.43

1 year ago

4.5.42

1 year ago

4.5.41

1 year ago

4.5.40

1 year ago

4.4.40

1 year ago

4.4.39

1 year ago

4.4.38

1 year ago

4.4.37

1 year ago

4.4.36

1 year ago

4.4.35

1 year ago

4.4.34

1 year ago

4.4.33

1 year ago

4.4.32

1 year ago

4.4.31

1 year ago

4.4.30

1 year ago

4.4.29

1 year ago

4.3.29

1 year ago

4.3.28

1 year ago

4.2.28

1 year ago

3.2.28

1 year ago

3.2.27

1 year ago

3.2.26

1 year ago

3.2.25

1 year ago

3.2.24

1 year ago

3.2.23

1 year ago

3.2.22

1 year ago

2.2.22

1 year ago

2.2.21

1 year ago

2.2.20

1 year ago

2.2.19

1 year ago

2.2.18

1 year ago

2.2.17

1 year ago

2.2.16

1 year ago

2.2.15

1 year ago

2.2.14

1 year ago

2.1.14

1 year ago

2.1.13

1 year ago

2.1.12

1 year ago

2.1.11

1 year ago

2.1.10

1 year ago

2.1.9

1 year ago

1.1.9

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

1 year ago

1.1.3

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