flatted
Advanced tools
Comparing version 3.2.10 to 3.2.11
'use strict'; | ||
/// <reference types="../types.d.ts" /> | ||
// (c) 2020-present Andrea Giammarchi | ||
@@ -56,2 +54,8 @@ | ||
/** | ||
* Converts a specialized flatted string into a JS value. | ||
* @param {string} text | ||
* @param {((this: any, key: string, value: any) => any) | undefined): any} [reviver] | ||
* @returns {any} | ||
*/ | ||
const parse = (text, reviver) => { | ||
@@ -68,2 +72,9 @@ const input = $parse(text, Primitives).map(primitives); | ||
/** | ||
* Converts a JS value into a specialized flatted string. | ||
* @param {any} value | ||
* @param {((this: any, key: string, value: any) => any) | (string | number)[] | null | undefined} [replacer] | ||
* @param {string | number | undefined} [string] | ||
* @returns {string} | ||
*/ | ||
const stringify = (value, replacer, space) => { | ||
@@ -100,5 +111,16 @@ const $ = replacer && typeof replacer === object ? | ||
const toJSON = any => $parse(stringify(any)); | ||
/** | ||
* Converts a generic value into a JSON serializable object without losing recursion. | ||
* @param {any} value | ||
* @returns {any} | ||
*/ | ||
const toJSON = value => $parse(stringify(value)); | ||
exports.toJSON = toJSON; | ||
const fromJSON = any => parse($stringify(any)); | ||
/** | ||
* Converts a previously serialized object with recursion into a recursive one. | ||
* @param {any} value | ||
* @returns {any} | ||
*/ | ||
const fromJSON = value => parse($stringify(value)); | ||
exports.fromJSON = fromJSON; |
@@ -1,3 +0,1 @@ | ||
/// <reference types="../types.d.ts" /> | ||
// (c) 2020-present Andrea Giammarchi | ||
@@ -55,2 +53,8 @@ | ||
/** | ||
* Converts a specialized flatted string into a JS value. | ||
* @param {string} text | ||
* @param {((this: any, key: string, value: any) => any) | undefined): any} [reviver] | ||
* @returns {any} | ||
*/ | ||
export const parse = (text, reviver) => { | ||
@@ -66,2 +70,9 @@ const input = $parse(text, Primitives).map(primitives); | ||
/** | ||
* Converts a JS value into a specialized flatted string. | ||
* @param {any} value | ||
* @param {((this: any, key: string, value: any) => any) | (string | number)[] | null | undefined} [replacer] | ||
* @param {string | number | undefined} [string] | ||
* @returns {string} | ||
*/ | ||
export const stringify = (value, replacer, space) => { | ||
@@ -97,3 +108,14 @@ const $ = replacer && typeof replacer === object ? | ||
export const toJSON = any => $parse(stringify(any)); | ||
export const fromJSON = any => parse($stringify(any)); | ||
/** | ||
* Converts a generic value into a JSON serializable object without losing recursion. | ||
* @param {any} value | ||
* @returns {any} | ||
*/ | ||
export const toJSON = value => $parse(stringify(value)); | ||
/** | ||
* Converts a previously serialized object with recursion into a recursive one. | ||
* @param {any} value | ||
* @returns {any} | ||
*/ | ||
export const fromJSON = value => parse($stringify(value)); |
37
index.js
@@ -14,4 +14,2 @@ self.Flatted = (function (exports) { | ||
/// <reference types="../types.d.ts" /> | ||
// (c) 2020-present Andrea Giammarchi | ||
@@ -66,2 +64,9 @@ | ||
}; | ||
/** | ||
* Converts a specialized flatted string into a JS value. | ||
* @param {string} text | ||
* @param {((this: any, key: string, value: any) => any) | undefined): any} [reviver] | ||
* @returns {any} | ||
*/ | ||
var parse = function parse(text, reviver) { | ||
@@ -76,2 +81,10 @@ var input = $parse(text, Primitives).map(primitives); | ||
}; | ||
/** | ||
* Converts a JS value into a specialized flatted string. | ||
* @param {any} value | ||
* @param {((this: any, key: string, value: any) => any) | (string | number)[] | null | undefined} [replacer] | ||
* @param {string | number | undefined} [string] | ||
* @returns {string} | ||
*/ | ||
var stringify = function stringify(value, replacer, space) { | ||
@@ -108,7 +121,19 @@ var $ = replacer && _typeof(replacer) === object ? function (k, v) { | ||
}; | ||
var toJSON = function toJSON(any) { | ||
return $parse(stringify(any)); | ||
/** | ||
* Converts a generic value into a JSON serializable object without losing recursion. | ||
* @param {any} value | ||
* @returns {any} | ||
*/ | ||
var toJSON = function toJSON(value) { | ||
return $parse(stringify(value)); | ||
}; | ||
var fromJSON = function fromJSON(any) { | ||
return parse($stringify(any)); | ||
/** | ||
* Converts a previously serialized object with recursion into a recursive one. | ||
* @param {any} value | ||
* @returns {any} | ||
*/ | ||
var fromJSON = function fromJSON(value) { | ||
return parse($stringify(value)); | ||
}; | ||
@@ -115,0 +140,0 @@ |
{ | ||
"name": "@wr/flatted", | ||
"version": "3.2.9", | ||
"version": "3.2.11", | ||
"exports": "./esm/index.js", | ||
@@ -18,4 +18,5 @@ "exclude": [ | ||
"min.js", | ||
"package-lock.json" | ||
"package-lock.json", | ||
"tsconfig.json" | ||
] | ||
} |
{ | ||
"name": "flatted", | ||
"version": "3.2.10", | ||
"version": "3.2.11", | ||
"description": "A super light and fast circular JSON parser.", | ||
"unpkg": "min.js", | ||
"types": "types.d.ts", | ||
"main": "./cjs/index.js", | ||
"scripts": { | ||
"build": "npm run cjs && npm run rollup:esm && npm run rollup:es && npm run rollup:babel && npm run min && npm run test && npm run size", | ||
"build": "npm run cjs && npm run rollup:esm && npm run rollup:es && npm run rollup:babel && npm run min && npm run test && npm run ts && npm run size", | ||
"cjs": "ascjs esm cjs", | ||
@@ -19,2 +18,3 @@ "rollup:es": "rollup --config rollup/es.config.js && sed -i.bck 's/^var /self./' es.js && rm -rf es.js.bck", | ||
"test:py": "python python/test.py", | ||
"ts": "tsc -p .", | ||
"coverage": "mkdir -p ./coverage; c8 report --reporter=text-lcov > ./coverage/lcov.info" | ||
@@ -51,3 +51,4 @@ }, | ||
"rollup": "^4.11.0", | ||
"terser": "^5.27.0" | ||
"terser": "^5.27.0", | ||
"typescript": "^5.3.3" | ||
}, | ||
@@ -58,3 +59,3 @@ "module": "./esm/index.js", | ||
".": { | ||
"types": "./types.d.ts", | ||
"types": "./types/index.d.ts", | ||
"import": "./esm/index.js", | ||
@@ -61,0 +62,0 @@ "default": "./cjs/index.js" |
40411
384
13