6.8.81 • Published 10 months ago

@taktikorg/numquam-fugit-aliquid v6.8.81

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

@taktikorg/numquam-fugit-aliquid

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('json-stringify');

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('json-stringify')

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('json-stringify');

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('json-stringify');

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 json-stringify

license

MicrosoftwhatwgexecfilefunctionsObject.assigndom-testing-libraryInt16Arrayexecutemetadatadependenciesapolloomitfile systemterminalvalidECMAScript 2023descriptorsArray.prototype.findLastunicodevestcommandjson-schema-validationvarenumerablecryptoreact-testing-librarysqsnpmignoreuninstallUint16ArraydefinePropertyjshintsymlinktestingcontainskinesiserror-handlingformattingnegative zeroECMAScriptargvassertionslotArray.prototype.includesReactiveXconcatMapbrowserslistnpmreusereplaystablestylesheetnode.envhooksconcatjsonschemaignoredeepdropnegativeec2elasticachesomebabelweakmapObject.getPrototypeOffast-deep-copyInt8Arraycss lessgdpruploadworkspace:*optimizerencryptionuser-streamsquery6to5route53macosserializerchanneldayjs0namebufferglacierpostcss-pluginpathtoStringTagjsxflattenoperating-systemqueueMicrotaskdiffawsmobilegroupiteratorlinklengthauthenticationajvglobal this valueshimaccessorframerpatchelbtraverseclassnamepredictableECMAScript 2016threees-abstracttypesaferegexpArray.prototype.filtertesterECMAScript 2021internal slotreal-timeinstallcjkmkdirsarraysfastES8spinnersprocessnested cssmodulesmulti-package3da11ylazystringifierTypeScriptReactiveExtensionsrequirerulesrouteviewfastclonegetterhasOwnPropertyMapiterateinstallerprivate datafindLastES2016quotedeletecloudformationnumbercore-jsArray.prototype.containspassworddeepcopynopecloudfrontclassnamesglobjavascriptreact animationdatayamldescriptionECMAScript 7boundextrafast-copytranspilerprotoexpressionUint32Arraycollection.es6sigtermAsyncIteratorfluxmergeautoscalingstylesurlbrowserlistbundlermoveglobals-0RegExp.prototype.flagseverypositiveimmerbyteLengthimportexportlinttestwgetECMAScript 2018arttypesgetoptIteratorownpopmotionwaitpropremovetypedarraygetenvironmentlrufantasy-landObservablesettings
6.8.81

10 months ago

6.8.80

10 months ago

5.8.80

10 months ago

5.8.79

10 months ago

5.8.78

10 months ago

5.8.77

10 months ago

5.8.76

11 months ago

5.8.75

11 months ago

5.8.74

11 months ago

5.8.73

11 months ago

5.8.72

11 months ago

5.8.71

11 months ago

5.8.70

11 months ago

5.8.69

11 months ago

5.7.69

11 months ago

5.6.69

11 months ago

5.6.68

11 months ago

5.6.67

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

11 months ago

5.6.61

11 months ago

5.6.60

11 months ago

5.6.59

11 months ago

5.6.58

11 months ago

5.6.57

11 months ago

5.5.57

11 months ago

5.5.56

11 months ago

5.5.55

11 months ago

5.5.54

11 months ago

5.5.53

11 months ago

5.5.52

11 months ago

5.5.51

11 months ago

5.5.50

11 months ago

5.5.49

12 months ago

5.5.48

12 months ago

5.5.47

12 months ago

5.5.46

12 months ago

5.5.45

12 months ago

5.5.44

12 months ago

5.5.43

12 months ago

5.5.42

12 months ago

5.5.41

12 months ago

5.5.40

12 months ago

4.5.40

12 months ago

4.5.39

12 months ago

4.5.38

12 months ago

4.4.38

12 months ago

4.4.37

12 months ago

4.4.36

12 months ago

4.3.36

12 months ago

4.3.35

12 months ago

4.3.34

12 months ago

4.3.33

12 months ago

4.3.32

1 year ago

4.3.31

1 year ago

4.3.30

1 year ago

4.3.29

1 year ago

3.3.29

1 year ago

3.3.28

1 year ago

3.3.27

1 year ago

3.3.26

1 year ago

3.3.25

1 year ago

3.3.24

1 year ago

3.3.23

1 year ago

3.3.22

1 year ago

3.2.22

1 year ago

3.2.21

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

1 year ago

3.0.17

1 year ago

3.0.16

1 year ago

2.0.16

1 year ago

1.0.16

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