X-Git-Url: https://git.josue.xyz/?p=dotfiles%2F.git;a=blobdiff_plain;f=.config%2Fcoc%2Fextensions%2Fnode_modules%2Fcoc-prettier%2Fnode_modules%2Fflatted%2FREADME.md;h=78763277c28160943c5c0405cda508de5f665a5a;hp=0c1627f7d2dda838cd26fc2226533366d3740135;hb=3be0a9efc698a9570a44456009afc6014812625a;hpb=d2f432cc757f42f0318fdddcab8c00b240d47088 diff --git a/.config/coc/extensions/node_modules/coc-prettier/node_modules/flatted/README.md b/.config/coc/extensions/node_modules/coc-prettier/node_modules/flatted/README.md index 0c1627f7..78763277 100644 --- a/.config/coc/extensions/node_modules/coc-prettier/node_modules/flatted/README.md +++ b/.config/coc/extensions/node_modules/coc-prettier/node_modules/flatted/README.md @@ -1,11 +1,23 @@ # flatted -[![Downloads](https://img.shields.io/npm/dm/flatted.svg)](https://www.npmjs.com/package/flatted) [![Coverage Status](https://coveralls.io/repos/github/WebReflection/flatted/badge.svg?branch=master)](https://coveralls.io/github/WebReflection/flatted?branch=master) [![Build Status](https://travis-ci.org/WebReflection/flatted.svg?branch=master)](https://travis-ci.org/WebReflection/flatted) [![License: ISC](https://img.shields.io/badge/License-ISC-yellow.svg)](https://opensource.org/licenses/ISC) ![WebReflection status](https://offline.report/status/webreflection.svg) +[![Downloads](https://img.shields.io/npm/dm/flatted.svg)](https://www.npmjs.com/package/flatted) [![Coverage Status](https://coveralls.io/repos/github/WebReflection/flatted/badge.svg?branch=main)](https://coveralls.io/github/WebReflection/flatted?branch=main) [![Build Status](https://travis-ci.com/WebReflection/flatted.svg?branch=main)](https://travis-ci.com/WebReflection/flatted) [![License: ISC](https://img.shields.io/badge/License-ISC-yellow.svg)](https://opensource.org/licenses/ISC) ![WebReflection status](https://offline.report/status/webreflection.svg) ![snow flake](./flatted.jpg) **Social Media Photo by [Matt Seymour](https://unsplash.com/@mattseymour) on [Unsplash](https://unsplash.com/)** +## Announcement 📣 + +There is a standard approach to recursion and more data-types than what JSON allow, and it's part of this [Structured Clone Module](https://github.com/ungap/structured-clone/#readme). + +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 *flatted*, but its produced output is also smaller than *flatted*. + +The *@ungap/structured-clone* module is, in short, a drop in replacement for *flatted*, but it's not compatible with *flatted* specialized syntax. + +However, if recursion, as well as more data-types, are what you are after, or interesting for your projects, consider switching to this new module whenever you can 👍 + +- - - + 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)**. @@ -18,10 +30,10 @@ Usable via [CDN](https://unpkg.com/flatted) or as regular module. ```js // ESM -import {parse, stringify} from 'flatted'; +import {parse, stringify, toJSON, fromJSON} from 'flatted'; // CJS -const {parse, stringify} = require('flatted'); +const {parse, stringify, toJSON, fromJSON} = require('flatted'); const a = [{}]; a[0].a = a; @@ -30,6 +42,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))`.