5.11.112 • Published 10 months ago

@taktikorg/alias-asperiores-non v5.11.112

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

@taktikorg/alias-asperiores-non

Last version Coverage Status NPM Status

Deterministic version of JSON.stringify(), so you can get a consistent hash from stringified results.

Similar to json-stable-stringify but:

  • No Dependencies. Minimal as possible.
  • Better cycles detection.
  • Support serialization for object without .toJSON (such as RegExp).
  • Provides built-in TypeScript declarations.

Install

npm install @taktikorg/alias-asperiores-non --save

Usage

const stringify = require('@taktikorg/alias-asperiores-non')
const obj = { c: 8, b: [{ z: 6, y: 5, x: 4 }, 7], a: 3 }

console.log(stringify(obj))
// => {"a":3,"b":[{"x":4,"y":5,"z":6},7],"c":8}

API

stringify(<obj>, opts)

obj

Required Type: object

The input object to be serialized.

opts

opts.stringify

Type: function Default: JSON.stringify

Determinate how to stringify primitives values.

opts.cycles

Type: boolean Default: false

Determinate how to resolve cycles.

Under true, when a cycle is detected, [Circular] will be inserted in the node.

opts.compare

Type: function

Custom comparison function for object keys.

Your function opts.compare 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:

const stringify = require('@taktikorg/alias-asperiores-non')

const obj = { c: 8, b: [{z: 6,y: 5,x: 4}, 7], a: 3 }
const objSerializer = stringify(obj, function (a, b) {
  return a.key < b.key ? 1 : -1
})

console.log(objSerializer)
// => {"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('@taktikorg/alias-asperiores-non')

const obj = { d: 6, c: 5, b: [{ z: 3, y: 2, x: 1 }, 9], a: 10 }
const objtSerializer = stringify(obj, function (a, b) {
  return a.value < b.value ? 1 : -1
})

console.log(objtSerializer)
// => {"d":6,"c":5,"b":[{"z":3,"y":2,"x":1},9],"a":10}
opts.space

Type: string Default: ''

If you specify opts.space, it will indent the output for pretty-printing.

Valid values are strings (e.g. {space: \t}). For example:

const stringify = require('@taktikorg/alias-asperiores-non')

const obj = { b: 1, a: { foo: 'bar', and: [1, 2, 3] } }
const objSerializer = stringify(obj, { space: '  ' })
console.log(objSerializer)
// => {
//   "a": {
//     "and": [
//       1,
//       2,
//       3
//     ],
//     "foo": "bar"
//   },
//   "b": 1
// }
opts.replacer

Type: function

The replacer parameter is a function opts.replacer(key, value) that behaves the same as the replacer from the core JSON object.

Related

License

MIT © Kiko Beats.

expressionassignbddvestStyleSheetfullwidthextrabluebirdtapnamesgraphqlJSONnpmregular expressionspluginhttpfast-clonetakesesunicodereduxstylingextensionjestemrdependenciesperformantsymlinkwafparentwarningArrayelbWebSocketlinewrapwritablematchAllschemecommandregularFunction.prototype.namebrowserlistECMAScript 2021momentstablecolormimees-abstractpropertiesRegExp.prototype.flagsiamnumberfpsstringifyshrinkwrapenumerablepushhigher-orderkeyjQueryfastclonerequesttrimStartreducefunctionalObservableexpressObjectqsArray.prototype.findLastIndexdateschemaUint8ArrayTypeBoxReflect.getPrototypeOfinternal sloteventEmitterrecursiveArray.prototype.flatMapStreamscommand-linees8sidekoreanworkflowshelllastassertionmkdirgetterlocationprotocol-buffersObject.getPrototypeOfassertsastflagsscheme-validationcolourtermECMAScript 2022coveragetypehashminimalmake dir_.extendstylejavascriptvariablesthroatURLSearchParamsreact animationInt16ArraydataESlistenersbannerdefinePropertyinternal__proto__requirerandomsyntaxcachetypedarrayECMAScript 2019emojinegative zerocloudfrontgroupttyprefixio-tsUint8ClampedArraycallboundbusysetyamltypanioncompareworkspace:*multi-packagereadablestreamcjkawaitstreamarrayloggercolumnsslicesnstrimLeftxdgArray.prototype.flattendefinefindaccessibilitytypesafebyteOffsetes2016WebSocketsprivatesettingsCSSomitautoscalingserializerwalkinges6uninstallcryptotsutilitieschromeString.prototype.trimJSON-SchemaidurlsdebugdataViewflatMapstarterES2019findLastIndexowni18nvpcapolloclirdsargsRxoffset-0class-validatorObject.fromEntriesconcurrencyes-shim APIjsxECMAScript 2023reducermovematchstreams2real-timecode pointscharacterURLrfc4122mapreduceamazonlogcircularconfigsyntaxerrorformattingratelimithelperconcatMapMicrosoftvieweslintplugincmdfunction.lengthjapaneselengthfile systemwraptelephonetc39shimvalidatefile cacheecmascriptoptimistpipefast-deep-copystreamsfastifypropertynopecoerciblespinnerebsinspectequalitydompyyamlString.prototype.matchAlldeepinputfastcopyUint32Arrayes2018packagesReactiveXrobustserializehasOwnPropertyreadcreatereactcurlES5workerES2022startArrayBuffer#slicemkdirslinkiteratorpolyfillECMAScript 6ES2020regexpavajoimochatestingiterationjasmineredacthttpshelpersforEachoutputdynamodbdebuggertoolsargumentsphonestoragegatewayconfigurablelibphonenumbercommanderinstalltrimRightdefaultprotobuflazyglobdirectoryStreamsetPrototypeOfstyled-componentsextendglobalCSSStyleDeclarationelasticachefull-widthgetPrototypeOfchaipatchcss-in-jses5estreetestdatastructureArray.prototype.findLastnegativecompilereslint-plugincallbindtraversedeep-copycomputed-typesframerrateloadingicubreakhardlinkssortimmerECMAScript 2015apispringformpreserve-symlinksyuptoobjectvaluelaunchgdprES6copyvaluesproxyES2023getoptWeakMapvarsremovemonoreporeusetoArraytypedenvironmentlimitedSetreadablecheckes-shimsrmsomeWeakSetstringifierpropfast-deep-cloneargvECMAScript 5globalspostcss-plugindataviewmetadataagentArrayBuffer.prototype.slicethreetrimEndtextspeedguidmime-dbcss@@toStringTagweakmapmkdirpeswaapiconsumeduplexcontainsRFC-6455descriptiontapeopenshasOwncall-bindutilityjson cachequerystringArrayBufferECMAScript 2020bundlerexecutableisbyteLengthECMAScript 7assertlook-uptostringtagslotRxJSartwhatwgenvpostcssdeep-clonegetfunctioncloudwatchbeanstalkistanbularraybuffersharedarraybufferstringwhiches2017jsonpatheverydescriptorsruntimeelectrontoSortedshamdirenvironmentsgetintrinsiclockfileargumentsimple caches3redux-toolkitpicomatchajaxES2021dom-testing-libraryeditorespreesharedconcatroute53arrayseventslruformsfind-upxhrpromiseescapefast-copyECMAScript 2017toucheslintstatelessdiffutilconsole0specqueueMicrotaskweaksetFloat32ArraynameawesomesaucetypeoflookredirectappES2017regular expressionformatparserArray.prototype.flatES2015nativeObject.assignqueuetrimcall-boundUint16Arraya11yReactiveExtensionscloudtrailerrorpromisesfromindicatorprivate dataimmutableform-validationboundtoolkitwidthconvertrgbArray.prototype.containsairbnbESnextwgetbytechromiumECMAScript 2016es7sortedYAMLES2016descriptorobjstructuredCloneentriespersistenticonvidlequoterouteES3isConcatSpreadableSymbol.toStringTagzodreact-hooksparseponyfilltsliblimitIteratorcloudformationPushkey valueswfinferencelanguagecorethrottleInt32ArrayAsyncIteratorbufferajveslintconfig3dmobileroutingbuffersgenericsasyncInt8ArraybatchsuperagentSymboliebrowserMapObject.isclonefunctionsjsonoptimizerTypedArrayPromisedeleteflatinstallerdeepcopyawsclientfetchrangeerrorparsingTypeScriptinnodejsdeepclonepackageopeneremitoptionsymbolmakesetImmediatejsdiffprocessreact posepositivewebsiteserializationprogresscollection.es6searchmoduleshas-ownlintBigInt64Arrayxtermdragdroppath[[Prototype]]Object.keysUnderscoreregexflattengesturestypesfindupdeterministicwalkwordwrapnode256visualrapidfastrm -frmruhasprettyuuidglacierwritevalidationflagsameValueZeroeventDispatcherimportexportsafebindbundlingObject.defineProperty
4.7.92

11 months ago

4.7.90

11 months ago

4.7.91

11 months ago

4.5.72

12 months ago

4.5.73

12 months ago

4.10.100

11 months ago

4.10.101

11 months ago

4.10.102

11 months ago

4.5.74

12 months ago

4.10.103

11 months ago

4.1.38

1 year ago

4.1.39

1 year ago

4.3.59

1 year ago

4.1.37

1 year ago

4.10.104

11 months ago

4.10.105

11 months ago

4.7.89

11 months ago

4.7.87

11 months ago

4.7.88

11 months ago

3.1.34

1 year ago

3.1.33

1 year ago

3.1.36

1 year ago

3.1.35

1 year ago

3.1.37

1 year ago

3.1.30

1 year ago

3.1.32

1 year ago

3.1.31

1 year ago

4.1.52

1 year ago

4.1.53

1 year ago

4.1.54

1 year ago

4.1.55

1 year ago

2.1.26

1 year ago

4.1.50

1 year ago

4.1.51

1 year ago

4.11.107

10 months ago

4.11.108

10 months ago

4.11.105

11 months ago

4.1.56

1 year ago

1.1.16

1 year ago

4.11.106

10 months ago

1.1.15

1 year ago

1.1.14

1 year ago

1.1.19

1 year ago

1.1.18

1 year ago

1.1.17

1 year ago

4.3.60

1 year ago

4.1.41

1 year ago

4.3.63

1 year ago

4.1.42

1 year ago

4.3.62

1 year ago

4.1.43

1 year ago

4.3.61

1 year ago

4.1.44

1 year ago

4.1.40

1 year ago

4.1.49

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

4.1.45

1 year ago

4.1.46

1 year ago

1.1.26

1 year ago

4.1.47

1 year ago

1.1.25

1 year ago

4.1.48

1 year ago

1.1.24

1 year ago

5.11.112

10 months ago

5.11.111

10 months ago

5.11.110

10 months ago

4.6.80

12 months ago

4.6.81

11 months ago

4.6.84

11 months ago

4.6.85

11 months ago

4.6.82

11 months ago

4.6.83

11 months ago

4.4.65

12 months ago

4.4.64

12 months ago

4.6.86

11 months ago

4.4.63

12 months ago

4.6.87

11 months ago

4.4.69

12 months ago

4.4.68

12 months ago

4.4.67

12 months ago

4.4.66

12 months ago

5.11.109

10 months ago

5.11.108

10 months ago

3.1.27

1 year ago

3.1.26

1 year ago

3.1.29

1 year ago

3.1.28

1 year ago

4.8.92

11 months ago

4.8.94

11 months ago

4.8.93

11 months ago

4.8.96

11 months ago

4.8.95

11 months ago

4.6.74

12 months ago

4.6.77

12 months ago

4.6.78

12 months ago

4.6.75

12 months ago

4.6.76

12 months ago

4.6.79

12 months ago

4.9.97

11 months ago

4.9.96

11 months ago

4.9.99

11 months ago

4.9.98

11 months ago

4.10.99

11 months ago

4.4.72

12 months ago

4.4.71

12 months ago

4.4.70

12 months ago

4.2.56

1 year ago

4.2.57

1 year ago

4.2.58

1 year ago

4.2.59

1 year ago

1.1.12

1 year ago

1.1.13

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.7

1 year ago

1.1.6

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