node_modules/flatted/esm/index.js in immosquare-cleaner-0.1.32 vs node_modules/flatted/esm/index.js in immosquare-cleaner-0.1.38
- old
+ new
@@ -1,7 +1,9 @@
-/*! (c) 2020 Andrea Giammarchi */
+/// <reference types="../types/index.d.ts" />
+// (c) 2020-present Andrea Giammarchi
+
const {parse: $parse, stringify: $stringify} = JSON;
const {keys} = Object;
const Primitive = String; // it could be Number
const primitive = 'string'; // it could be 'number'
@@ -48,20 +50,33 @@
const index = Primitive(input.push(value) - 1);
known.set(value, index);
return index;
};
+/**
+ * Converts a specialized flatted string into a JS value.
+ * @param {string} text
+ * @param {(this: any, key: string, value: any) => any} [reviver]
+ * @returns {any}
+ */
export const parse = (text, reviver) => {
const input = $parse(text, Primitives).map(primitives);
const value = input[0];
const $ = reviver || noop;
const tmp = typeof value === object && value ?
revive(input, new Set, value, $) :
value;
return $.call({'': tmp}, '', tmp);
};
+/**
+ * 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} [space]
+ * @returns {string}
+ */
export const stringify = (value, replacer, space) => {
const $ = replacer && typeof replacer === object ?
(k, v) => (k === '' || -1 < replacer.indexOf(k) ? v : void 0) :
(replacer || noop);
const known = new Map;
@@ -88,7 +103,18 @@
}
return after;
}
};
-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));