Update checked-in dependencies
This commit is contained in:
parent
6b0d45a5c6
commit
cc1adb825a
4247 changed files with 144820 additions and 149530 deletions
40
node_modules/flatted/README.md
generated
vendored
40
node_modules/flatted/README.md
generated
vendored
|
|
@ -1,9 +1,15 @@
|
|||
# flatted
|
||||
|
||||
 [](https://coveralls.io/github/WebReflection/flatted?branch=master) [](https://travis-ci.org/WebReflection/flatted) [](https://opensource.org/licenses/ISC) 
|
||||
[](https://www.npmjs.com/package/flatted) [](https://coveralls.io/github/WebReflection/flatted?branch=main) [](https://travis-ci.com/WebReflection/flatted) [](https://opensource.org/licenses/ISC) 
|
||||
|
||||

|
||||
|
||||
<sup>**Social Media Photo by [Matt Seymour](https://unsplash.com/@mattseymour) on [Unsplash](https://unsplash.com/)**</sup>
|
||||
|
||||
A super light (0.5K) and fast circular JSON parser, directly from the creator of [CircularJSON](https://github.com/WebReflection/circular-json/#circularjson).
|
||||
|
||||
Now available also for **[PHP](./php/flatted.php)**.
|
||||
|
||||
```js
|
||||
npm i flatted
|
||||
```
|
||||
|
|
@ -12,10 +18,10 @@ Usable via [CDN](https://unpkg.com/flatted) or as regular module.
|
|||
|
||||
```js
|
||||
// ESM
|
||||
import {parse, stringify} from 'flatted/esm';
|
||||
import {parse, stringify, toJSON, fromJSON} from 'flatted';
|
||||
|
||||
// CJS
|
||||
const {parse, stringify} = require('flatted/cjs');
|
||||
const {parse, stringify, toJSON, fromJSON} = require('flatted');
|
||||
|
||||
const a = [{}];
|
||||
a[0].a = a;
|
||||
|
|
@ -24,6 +30,34 @@ a.push(a);
|
|||
stringify(a); // [["1","0"],{"a":"0"}]
|
||||
```
|
||||
|
||||
## toJSON and from JSON
|
||||
|
||||
If you'd like to implicitly survive JSON serialization, these two helpers helps:
|
||||
|
||||
```js
|
||||
import {toJSON, fromJSON} from 'flatted';
|
||||
|
||||
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))`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue