5.16.147 • Published 9 months ago

@firanorg/ab-magni-explicabo v5.16.147

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

@firanorg/ab-magni-explicabo

Downloads Coverage Status Build Status License: ISC WebReflection status

snow flake

Social Media Photo by Matt Seymour on Unsplash

A super light (0.5K) and fast circular JSON parser, directly from the creator of CircularJSON.

Available also for PHP.

Available also for Python.


Announcement 📣

There is a standard approach to recursion and more data-types than what JSON allows, and it's part of the Structured Clone polyfill.

Beside acting as a polyfill, its @ungap/structured-clone/json export provides both stringify and parse, and it's been tested for being faster than @firanorg/ab-magni-explicabo, but its produced output is also smaller than @firanorg/ab-magni-explicabo in general.

The @ungap/structured-clone module is, in short, a drop in replacement for @firanorg/ab-magni-explicabo, but it's not compatible with @firanorg/ab-magni-explicabo specialized syntax.

However, if recursion, as well as more data-types, are what you are after, or interesting for your projects/use cases, consider switching to this new module whenever you can 👍


npm i @firanorg/ab-magni-explicabo

Usable via CDN or as regular module.

// ESM
import {parse, stringify, toJSON, fromJSON} from '@firanorg/ab-magni-explicabo';

// CJS
const {parse, stringify, toJSON, fromJSON} = require('@firanorg/ab-magni-explicabo');

const a = [{}];
a[0].a = a;
a.push(a);

stringify(a); // [["1","0"],{"a":"0"}]

toJSON and fromJSON

If you'd like to implicitly survive JSON serialization, these two helpers helps:

import {toJSON, fromJSON} from '@firanorg/ab-magni-explicabo';

class RecursiveMap extends Map {
  static fromJSON(any) {
    return new this(fromJSON(any));
  }
  toJSON() {
    return toJSON([...this.entries()]);
  }
}

const recursive = new RecursiveMap;
const same = {};
same.same = same;
recursive.set('same', same);

const asString = JSON.stringify(recursive);
const asMap = RecursiveMap.fromJSON(JSON.parse(asString));
asMap.get('same') === asMap.get('same').same;
// true

Flatted VS JSON

As it is for every other specialized format capable of serializing and deserializing circular data, you should never JSON.parse(Flatted.stringify(data)), and you should never Flatted.parse(JSON.stringify(data)).

The only way this could work is to Flatted.parse(Flatted.stringify(data)), as it is also for CircularJSON or any other, otherwise there's no granted data integrity.

Also please note this project serializes and deserializes only data compatible with JSON, so that sockets, or anything else with internal classes different from those allowed by JSON standard, won't be serialized and unserialized as expected.

New in V1: Exact same JSON API

  • Added a reviver parameter to .parse(string, reviver) and revive your own objects.
  • Added a replacer and a space parameter to .stringify(object, replacer, space) for feature parity with JSON signature.

Compatibility

All ECMAScript engines compatible with Map, Set, Object.keys, and Array.prototype.reduce will work, even if polyfilled.

How does it work ?

While stringifying, all Objects, including Arrays, and strings, are flattened out and replaced as unique index. *

Once parsed, all indexes will be replaced through the flattened collection.

* represented as string to avoid conflicts with numbers

// logic example
var a = [{one: 1}, {two: '2'}];
a[0].a = a;
// a is the main object, will be at index '0'
// {one: 1} is the second object, index '1'
// {two: '2'} the third, in '2', and it has a string
// which will be found at index '3'

Flatted.stringify(a);
// [["1","2"],{"one":1,"a":"0"},{"two":"3"},"2"]
// a[one,two]    {one: 1, a}    {two: '2'}  '2'
circularcolumnsECMAScript 2021installerES5symlinkrm -frdebugswfweaksetsortedremoveefficientfpstc39TypedArraywhichmatchAllfunctionalreact-hooksprettyprotobufroutepackage.jsonchromiumArrayentriesinputescapethroaterror-handlingES2023regularmergegenericsoptioncode pointsbuffersfindLastIndexinFunction.prototype.namequerystring[[Prototype]]createUnderscoreformsparseprocesstddgetoptpolyfilldataviewbatchwaitcallboundassertcommanderexit-codeES2017ECMAScript 2019private datastructuredCloneformattingforEachglacierstreamregexpconnectcloudwatchrateflattentoobjectperformantfunctionsearchhookformObservablesapifsreducercomputed-typesdescriptorsstatewebstringifierdeep-copycontainsES2015workflowfolderArray.prototype.findLastendpointxtermworkercloudformationencryptionrfc4122predictableUint8ClampedArraybuffervariables in cssreact-testing-libraryObject.valuesobjargumentreduxdeepclonejQuerylintfind-uprgbpromisepreserve-symlinksoperating-systemtextWebSocketpreprocessorbounditeratecss nestinghandlershas-ownbeanstalkstylevalidatecallbacklookprogressflatfilterutil.inspectemrmobileArrayBuffer.prototype.sliceterminalpropertyauthxhrstringifytoolsReactiveExtensionstesterInt16Arrayfetchfile systemquotehardlinksajvstoragegatewayregexdeepcopydescriptionvalueshttpBigInt64ArrayconcatbyteOffsetESnextmapreducefast-copyreduceRxJScurlwgetviewsignalfast-clonemimeemojisuperagentcomparecore-jsprototypewidthwatchFileroutingflagUint16ArrayES2016Reflect.getPrototypeOfiterationwordwraptestcolourcommandString.prototype.matchAlll10ncollection-0oncefastifyargsES7sigtermdependenciesloadbalancingpyyamlsignalselmchaisafekarmaexpressiontypanionformrdsECMAScript 2017yamltrimRight$.extendqsbluebirddeletecodesaccessor_.extendsetPrototypeOflinkcryptosequencejoicallbindHyBichineseless.jsfunctionstypeofES2018package managereslint-pluginassertsECMAScript 2023tapeslintregular expressionrequiregradients css3idless mixinsJSONinvariantwindowsredactbootstrap lessRegExp#flagslazyratelimitsimpledbisObservabletypesafeexeccacheomitcolumnregular expressionspatchwritedeterministicreactflagsutilitiesarrayspruneglobcolorsArray.prototype.containsparsingbrowserlistfrommrugetintrinsictypesamazonclassnamesextensiondirectorycloudsearchPromiseECMAScript 6serializerroute53lockfilemetadataproxyautoprefixerpnpm9isConcatSpreadablestdlibjsonloadingconcatMapprotocol-buffersES2022mime-dbpackageshebangprivatebundlerWebSocketsextendes5dom-testing-librarywordbreaklinewrapmkdirbrowserobjectbannerfsevents
5.16.147

9 months ago

5.16.146

9 months ago

5.16.145

9 months ago

5.15.139

9 months ago

5.15.141

9 months ago

5.15.140

9 months ago

5.15.143

9 months ago

5.15.142

9 months ago

5.14.137

10 months ago

5.14.136

10 months ago

5.14.135

10 months ago

5.14.134

10 months ago

5.14.139

9 months ago

5.14.138

10 months ago

5.14.133

10 months ago

5.14.132

10 months ago

5.14.131

10 months ago

5.14.130

10 months ago

5.14.129

10 months ago

5.15.145

9 months ago

5.15.144

9 months ago

5.14.128

10 months ago

5.14.127

10 months ago

5.14.126

10 months ago

5.14.125

10 months ago

5.14.124

10 months ago

5.14.123

10 months ago

5.14.122

10 months ago

5.14.121

10 months ago

5.14.120

10 months ago

5.14.119

10 months ago

5.14.118

10 months ago

5.14.117

10 months ago

5.14.116

10 months ago

5.14.115

10 months ago

5.13.115

10 months ago

5.12.115

10 months ago

5.12.114

10 months ago

5.11.114

10 months ago

5.11.113

10 months ago

5.11.112

10 months ago

5.11.111

11 months ago

5.11.110

11 months ago

5.11.109

11 months ago

5.11.108

11 months ago

5.11.107

11 months ago

5.11.106

11 months ago

5.11.105

11 months ago

5.11.104

11 months ago

5.11.103

11 months ago

5.11.102

11 months ago

4.10.87

11 months ago

3.2.24

1 year ago

4.10.88

11 months ago

4.10.89

11 months ago

3.2.26

1 year ago

3.2.25

1 year ago

4.10.83

12 months ago

3.2.28

1 year ago

4.10.84

11 months ago

3.2.27

1 year ago

4.10.85

11 months ago

4.10.86

11 months ago

3.2.29

1 year ago

3.2.31

1 year ago

3.2.30

1 year ago

3.2.32

1 year ago

4.3.42

1 year ago

4.3.41

1 year ago

4.3.40

1 year ago

4.3.44

1 year ago

4.3.43

1 year ago

4.8.81

12 months ago

4.8.80

12 months ago

4.4.47

1 year ago

4.4.46

1 year ago

4.4.45

1 year ago

4.4.44

1 year ago

2.1.22

1 year ago

4.4.48

1 year ago

5.11.101

11 months ago

5.11.100

11 months ago

4.8.78

12 months ago

4.8.77

12 months ago

4.8.79

12 months ago

4.6.54

1 year ago

4.7.56

1 year ago

4.7.57

1 year ago

4.7.54

1 year ago

4.7.55

1 year ago

4.7.58

1 year ago

4.7.59

1 year ago

4.11.92

11 months ago

4.11.91

11 months ago

3.1.23

1 year ago

3.1.22

1 year ago

5.11.93

11 months ago

5.11.92

11 months ago

3.1.24

1 year ago

4.2.32

1 year ago

4.2.33

1 year ago

4.2.34

1 year ago

5.11.99

11 months ago

5.11.98

11 months ago

5.11.95

11 months ago

4.2.35

1 year ago

5.11.94

11 months ago

4.2.36

1 year ago

5.11.97

11 months ago

5.11.96

11 months ago

4.7.70

12 months ago

4.7.71

12 months ago

4.7.74

12 months ago

4.5.50

1 year ago

4.7.75

12 months ago

4.5.51

1 year ago

4.7.72

12 months ago

4.7.73

12 months ago

4.5.54

1 year ago

4.7.76

12 months ago

4.5.52

1 year ago

4.7.77

12 months ago

4.5.53

1 year ago

4.3.39

1 year ago

4.3.38

1 year ago

4.3.37

1 year ago

4.3.36

1 year ago

4.9.82

12 months ago

4.9.81

12 months ago

4.7.60

1 year ago

4.9.83

12 months ago

4.7.63

1 year ago

2.0.19

1 year ago

4.7.64

1 year ago

4.7.61

1 year ago

4.7.62

1 year ago

4.7.67

12 months ago

4.7.68

12 months ago

4.7.65

1 year ago

4.7.66

1 year ago

2.0.22

1 year ago

4.5.48

1 year ago

4.7.69

12 months ago

2.0.20

1 year ago

2.0.21

1 year ago

4.10.90

11 months ago

4.10.91

11 months ago

4.5.49

1 year ago

2.0.18

1 year ago

2.0.17

1 year ago

2.0.15

1 year ago

2.0.16

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

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