1.5.73 • Published 1 year ago

@dramaorg/voluptas-natus v1.5.73

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@dramaorg/voluptas-natus 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('@dramaorg/voluptas-natus');

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('@dramaorg/voluptas-natus')

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('@dramaorg/voluptas-natus');

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('@dramaorg/voluptas-natus');

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 @dramaorg/voluptas-natus

license

MIT

bundling[[Prototype]]getPrototypeOfassertscssESflatrandomincludeszerodeterministiciamcalldependency managerastzodspinnersbinarystreamwindowlinkbindstylesgdprconsumeassigncommand-linehookformsearchgroupio-tsString.prototype.matchAlllintflatMapcontainsfile systembindotenvmergeWeakSetutilitysnscss-in-jsjsdommonorepouptelephonenumberES2017SymboltrimEndfunction.lengthimportargumentECMAScript 2015installerdefinePropertyvalidationES8make dirkeyreverseRFC-6455pnpm9negative zeroStreamtslibtoobjectdatacompilerspecharmonyelasticacheESnexttrimStarttddansipackagesreversedformsecmascriptcloudsearchcolorswalknamemapreduceoutputtoReversedwarningemojitapeworkeres6cloudwatchhashreal-timefeedpluginqueuewaapidataViewECMAScript 2021commandimmeroffsetinputdeep-copybundlercurriedhasOwnPropertyObject.isenderparentcjkECMAScript 2018private datarouterObservablesbrowserslistanimationarrayserializerjshintlockfileArray.prototype.flattensetmatchAllchromel10narraybufferoptimistselfasyncconcatmkdirsatomhttpsesruntimegraphqlstringifierrulesStyleSheetfindLastrobustlocalsyntaxerrorObject.definePropertygetOwnPropertyDescriptorreact-hooksRxbrowserlistvestSetwritableistanbulrm -rfclass-validatordataviewprocessfixed-widthmkdirshrinkwrapsuperstructdebugperformantArrayBuffermochautil.inspectES5ReactiveExtensionsInt32ArrayUint32ArrayreuseSystem.globalObjecttypescriptapollofast-cloneString.prototype.trimaccessorprunecompareprivatees2015ajvcolourescaperemovereadableenvironmentswebfsworkspace:*ECMAScript 2016fantasy-landstringamazonObject.getPrototypeOfsharedtypesafemanagerdefinequeueMicrotasktapidnativeconfigurable.gitignoregroupByyupES2023Object.keyskoreanrssstylesortedinternalredux-toolkitmapTypeBoxoncetoStringTagglobal objectcollectionslicesortsomehardlinksUnderscorearktypeposevalidatetoSortedexecnodeawsfastcopyyamlURLSearchParamses-shim APIconsolecolumnsforkwafreducerfnmatchsymbolscall-boundlanguagetypedarraypostcss-pluginpropertypipeFloat32ArrayWebSocketsyntaxes-shimscloudtraillognamesacorncode pointsxhrfunctionalloggingenvfastclonezxpropArray.prototype.flatMapStreams
1.5.73

1 year ago

1.5.72

1 year ago

1.5.71

1 year ago

1.5.70

1 year ago

1.5.69

1 year ago

1.5.68

1 year ago

1.5.67

1 year ago

1.5.66

1 year ago

1.5.65

1 year ago

1.5.64

1 year ago

1.5.63

1 year ago

1.5.62

1 year ago

1.5.61

1 year ago

1.5.60

1 year ago

1.5.59

1 year ago

1.5.58

1 year ago

1.5.57

1 year ago

1.5.56

1 year ago

1.5.55

1 year ago

1.5.54

1 year ago

1.5.53

1 year ago

1.5.52

1 year ago

1.5.51

1 year ago

1.5.50

1 year ago

1.5.49

1 year ago

1.4.49

1 year ago

1.4.48

1 year ago

1.3.48

1 year ago

1.2.48

1 year ago

1.2.47

1 year ago

1.2.46

1 year ago

1.2.45

1 year ago

1.2.44

1 year ago

1.2.43

1 year ago

1.2.42

1 year ago

1.2.41

1 year ago

1.2.40

1 year ago

1.2.39

1 year ago

1.2.38

1 year ago

1.2.37

1 year ago

1.1.37

1 year ago

1.1.36

1 year ago

1.1.35

1 year ago

1.1.34

1 year ago

1.1.33

1 year ago

1.1.32

1 year ago

1.1.31

1 year ago

1.1.30

1 year ago

1.1.29

1 year ago

1.1.28

1 year ago

1.1.27

1 year ago

1.1.26

1 year ago

1.1.25

1 year ago

1.1.24

1 year ago

1.1.23

1 year ago

1.1.22

1 year ago

1.1.21

1 year ago

1.1.20

1 year ago

1.1.19

1 year ago

1.1.18

1 year ago

1.1.17

1 year ago

1.1.16

1 year ago

1.1.15

1 year ago

1.1.14

1 year ago

1.1.13

1 year ago

1.1.12

1 year ago

1.1.11

1 year ago

1.1.10

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