flatted
3.2.73.4.2
−
Removed (1 files)
+
Added (4 files)
~
Modified (9 files)
Index: package/es.js
===================================================================
--- package/es.js
+++ package/es.js
@@ -1,2 +1,1 @@
-self.Flatted=function(t){"use strict";
-/*! (c) 2020 Andrea Giammarchi */const{parse:e,stringify:n}=JSON,{keys:r}=Object,s=String,o="string",c={},l="object",a=(t,e)=>e,f=t=>t instanceof s?s(t):t,i=(t,e)=>typeof e===o?new s(e):e,u=(t,e,n,o)=>{const a=[];for(let f=r(n),{length:i}=f,u=0;u<i;u++){const r=f[u],i=n[r];if(i instanceof s){const s=t[i];typeof s!==l||e.has(s)?n[r]=o.call(n,r,s):(e.add(s),n[r]=c,a.push({k:r,a:[t,e,s,o]}))}else n[r]!==c&&(n[r]=o.call(n,r,i))}for(let{length:t}=a,e=0;e<t;e++){const{k:t,a:r}=a[e];n[t]=o.call(n,t,u.apply(null,r))}return n},p=(t,e,n)=>{const r=s(e.push(n)-1);return t.set(n,r),r},y=(t,n)=>{const r=e(t,i).map(f),s=r[0],o=n||a,c=typeof s===l&&s?u(r,new Set,s,o):s;return o.call({"":c},"",c)},g=(t,e,r)=>{const s=e&&typeof e===l?(t,n)=>""===t||-1<e.indexOf(t)?n:void 0:e||a,c=new Map,f=[],i=[];let u=+p(c,f,s.call({"":t},"",t)),y=!u;for(;u<f.length;)y=!0,i[u]=n(f[u++],g,r);return"["+i.join(",")+"]";function g(t,e){if(y)return y=!y,e;const n=s.call(this,t,e);switch(typeof n){case l:if(null===n)return n;case o:return c.get(n)||p(c,f,n)}return n}};return t.fromJSON=t=>y(n(t)),t.parse=y,t.stringify=g,t.toJSON=t=>e(g(t)),t}({});
+self.Flatted=function(t){"use strict";const{parse:e,stringify:n}=JSON,{keys:r}=Object,o=String,s="string",c={},l="object",f=(t,e)=>e,i=t=>t instanceof o?o(t):t,a=(t,e)=>typeof e===s?new o(e):e,u=(t,e,n)=>{const r=o(e.push(n)-1);return t.set(n,r),r},p=(t,n)=>{const s=e(t,a).map(i),u=n||f;let p=s[0];if(typeof p===l&&p){const t=[],e=((t,e,n,s)=>f=>{for(let i=r(f),{length:a}=i,u=0;u<a;u++){const r=i[u],a=f[r];if(a instanceof o){const o=t[+a];typeof o!==l||n.has(o)?f[r]=s.call(f,r,o):(n.add(o),f[r]=c,e.push({o:f,k:r,r:o}))}else f[r]!==c&&(f[r]=s.call(f,r,a))}return f})(s,t,new Set,u);p=e(p);let n=0;for(;n<t.length;){const{o:r,k:o,r:s}=t[n++];r[o]=u.call(r,o,e(s))}}return u.call({"":p},"",p)},g=(t,e,r)=>{const o=e&&typeof e===l?(t,n)=>""===t||-1<e.indexOf(t)?n:void 0:e||f,c=new Map,i=[],a=[];let p=+u(c,i,o.call({"":t},"",t)),g=!p;for(;p<i.length;)g=!0,a[p]=n(i[p++],h,r);return"["+a.join(",")+"]";function h(t,e){if(g)return g=!g,e;const n=o.call(this,t,e);switch(typeof n){case l:if(null===n)return n;case s:return c.get(n)||u(c,i,n)}return n}};return t.fromJSON=t=>p(n(t)),t.parse=p,t.stringify=g,t.toJSON=t=>e(g(t)),t}({}); Index: package/esm.js
===================================================================
--- package/esm.js
+++ package/esm.js
@@ -1,2 +1,1 @@
-/*! (c) 2020 Andrea Giammarchi */
-const{parse:t,stringify:e}=JSON,{keys:n}=Object,o=String,c={},r=(t,e)=>e,s=t=>t instanceof o?o(t):t,l=(t,e)=>"string"==typeof e?new o(e):e,a=(t,e,r,s)=>{const l=[];for(let a=n(r),{length:f}=a,i=0;i<f;i++){const n=a[i],f=r[n];if(f instanceof o){const o=t[f];"object"!=typeof o||e.has(o)?r[n]=s.call(r,n,o):(e.add(o),r[n]=c,l.push({k:n,a:[t,e,o,s]}))}else r[n]!==c&&(r[n]=s.call(r,n,f))}for(let{length:t}=l,e=0;e<t;e++){const{k:t,a:n}=l[e];r[t]=s.call(r,t,a.apply(null,n))}return r},f=(t,e,n)=>{const c=o(e.push(n)-1);return t.set(n,c),c},i=(e,n)=>{const o=t(e,l).map(s),c=o[0],f=n||r,i="object"==typeof c&&c?a(o,new Set,c,f):c;return f.call({"":i},"",i)},p=(t,n,o)=>{const c=n&&"object"==typeof n?(t,e)=>""===t||-1<n.indexOf(t)?e:void 0:n||r,s=new Map,l=[],a=[];let i=+f(s,l,c.call({"":t},"",t)),p=!i;for(;i<l.length;)p=!0,a[i]=e(l[i++],u,o);return"["+a.join(",")+"]";function u(t,e){if(p)return p=!p,e;const n=c.call(this,t,e);switch(typeof n){case"object":if(null===n)return n;case"string":return s.get(n)||f(s,l,n)}return n}},u=e=>t(p(e)),g=t=>i(e(t));export{g as fromJSON,i as parse,p as stringify,u as toJSON};
+const{parse:t,stringify:e}=JSON,{keys:n}=Object,o=String,r="string",s={},c="object",l=(t,e)=>e,f=t=>t instanceof o?o(t):t,i=(t,e)=>typeof e===r?new o(e):e,a=(t,e,n)=>{const r=o(e.push(n)-1);return t.set(n,r),r},u=(e,r)=>{const a=t(e,i).map(f),u=r||l;let p=a[0];if(typeof p===c&&p){const t=[],e=((t,e,r,l)=>f=>{for(let i=n(f),{length:a}=i,u=0;u<a;u++){const n=i[u],a=f[n];if(a instanceof o){const o=t[+a];typeof o!==c||r.has(o)?f[n]=l.call(f,n,o):(r.add(o),f[n]=s,e.push({o:f,k:n,r:o}))}else f[n]!==s&&(f[n]=l.call(f,n,a))}return f})(a,t,new Set,u);p=e(p);let r=0;for(;r<t.length;){const{o:n,k:o,r:s}=t[r++];n[o]=u.call(n,o,e(s))}}return u.call({"":p},"",p)},p=(t,n,o)=>{const s=n&&typeof n===c?(t,e)=>""===t||-1<n.indexOf(t)?e:void 0:n||l,f=new Map,i=[],u=[];let p=+a(f,i,s.call({"":t},"",t)),h=!p;for(;p<i.length;)h=!0,u[p]=e(i[p++],g,o);return"["+u.join(",")+"]";function g(t,e){if(h)return h=!h,e;const n=s.call(this,t,e);switch(typeof n){case c:if(null===n)return n;case r:return f.get(n)||a(f,i,n)}return n}},h=e=>t(p(e)),g=t=>u(e(t));export{g as fromJSON,u as parse,p as stringify,h as toJSON}; Index: package/cjs/index.js
===================================================================
--- package/cjs/index.js
+++ package/cjs/index.js
@@ -1,7 +1,9 @@
'use strict';
-/*! (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
@@ -19,30 +21,25 @@
const Primitives = (_, value) => (
typeof value === primitive ? new Primitive(value) : value
);
-const revive = (input, parsed, output, $) => {
- const lazy = [];
+const resolver = (input, lazy, parsed, $) => output => {
for (let ke = keys(output), {length} = ke, y = 0; y < length; y++) {
const k = ke[y];
const value = output[k];
if (value instanceof Primitive) {
- const tmp = input[value];
+ const tmp = input[+value];
if (typeof tmp === object && !parsed.has(tmp)) {
parsed.add(tmp);
output[k] = ignore;
- lazy.push({k, a: [input, parsed, tmp, $]});
+ lazy.push({ o: output, k, r: tmp });
}
else
output[k] = $.call(output, k, tmp);
}
else if (output[k] !== ignore)
output[k] = $.call(output, k, value);
}
- for (let {length} = lazy, i = 0; i < length; i++) {
- const {k, a} = lazy[i];
- output[k] = $.call(output, k, revive.apply(null, a));
- }
return output;
};
const set = (known, input, value) => {
@@ -50,19 +47,44 @@
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}
+ */
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);
+
+ let value = input[0];
+
+ if (typeof value === object && value) {
+ const lazy = [];
+ const revive = resolver(input, lazy, new Set, $);
+ value = revive(value);
+
+ let i = 0;
+ while (i < lazy.length) {
+ // it could be a lazy.shift() but that's costly
+ const {o, k, r} = lazy[i++];
+ o[k] = $.call(o, k, revive(r));
+ }
+ }
+
+ return $.call({'': value}, '', value);
};
exports.parse = parse;
+/**
+ * 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}
+ */
const stringify = (value, replacer, space) => {
const $ = replacer && typeof replacer === object ?
(k, v) => (k === '' || -1 < replacer.indexOf(k) ? v : void 0) :
(replacer || noop);
@@ -92,8 +114,19 @@
}
};
exports.stringify = stringify;
-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; Index: package/esm/index.js
===================================================================
--- package/esm/index.js
+++ package/esm/index.js
@@ -1,6 +1,8 @@
-/*! (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
@@ -18,30 +20,25 @@
const Primitives = (_, value) => (
typeof value === primitive ? new Primitive(value) : value
);
-const revive = (input, parsed, output, $) => {
- const lazy = [];
+const resolver = (input, lazy, parsed, $) => output => {
for (let ke = keys(output), {length} = ke, y = 0; y < length; y++) {
const k = ke[y];
const value = output[k];
if (value instanceof Primitive) {
- const tmp = input[value];
+ const tmp = input[+value];
if (typeof tmp === object && !parsed.has(tmp)) {
parsed.add(tmp);
output[k] = ignore;
- lazy.push({k, a: [input, parsed, tmp, $]});
+ lazy.push({ o: output, k, r: tmp });
}
else
output[k] = $.call(output, k, tmp);
}
else if (output[k] !== ignore)
output[k] = $.call(output, k, value);
}
- for (let {length} = lazy, i = 0; i < length; i++) {
- const {k, a} = lazy[i];
- output[k] = $.call(output, k, revive.apply(null, a));
- }
return output;
};
const set = (known, input, value) => {
@@ -49,18 +46,43 @@
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);
+
+ let value = input[0];
+
+ if (typeof value === object && value) {
+ const lazy = [];
+ const revive = resolver(input, lazy, new Set, $);
+ value = revive(value);
+
+ let i = 0;
+ while (i < lazy.length) {
+ // it could be a lazy.shift() but that's costly
+ const {o, k, r} = lazy[i++];
+ o[k] = $.call(o, k, revive(r));
+ }
+ }
+
+ return $.call({'': value}, '', value);
};
+/**
+ * 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);
@@ -89,6 +111,17 @@
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)); Index: package/index.js
===================================================================
--- package/index.js
+++ package/index.js
@@ -1,86 +1,101 @@
self.Flatted = (function (exports) {
'use strict';
- function _typeof(obj) {
+ function _typeof(o) {
"@babel/helpers - typeof";
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
- return typeof obj;
- } : function (obj) {
- return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
- }, _typeof(obj);
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
+ return typeof o;
+ } : function (o) {
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
+ }, _typeof(o);
}
- /*! (c) 2020 Andrea Giammarchi */
+ /// <reference types="../types/index.d.ts" />
+
+ // (c) 2020-present Andrea Giammarchi
+
var $parse = JSON.parse,
- $stringify = JSON.stringify;
+ $stringify = JSON.stringify;
var keys = Object.keys;
var Primitive = String; // it could be Number
-
var primitive = 'string'; // it could be 'number'
var ignore = {};
var object = 'object';
-
var noop = function noop(_, value) {
return value;
};
-
var primitives = function primitives(value) {
return value instanceof Primitive ? Primitive(value) : value;
};
-
var Primitives = function Primitives(_, value) {
return _typeof(value) === primitive ? new Primitive(value) : value;
};
-
- var revive = function revive(input, parsed, output, $) {
- var lazy = [];
-
- for (var ke = keys(output), length = ke.length, y = 0; y < length; y++) {
- var k = ke[y];
- var value = output[k];
-
- if (value instanceof Primitive) {
- var tmp = input[value];
-
- if (_typeof(tmp) === object && !parsed.has(tmp)) {
- parsed.add(tmp);
- output[k] = ignore;
- lazy.push({
- k: k,
- a: [input, parsed, tmp, $]
- });
- } else output[k] = $.call(output, k, tmp);
- } else if (output[k] !== ignore) output[k] = $.call(output, k, value);
- }
-
- for (var _length = lazy.length, i = 0; i < _length; i++) {
- var _lazy$i = lazy[i],
- _k = _lazy$i.k,
- a = _lazy$i.a;
- output[_k] = $.call(output, _k, revive.apply(null, a));
- }
-
- return output;
+ var resolver = function resolver(input, lazy, parsed, $) {
+ return function (output) {
+ for (var ke = keys(output), length = ke.length, y = 0; y < length; y++) {
+ var k = ke[y];
+ var value = output[k];
+ if (value instanceof Primitive) {
+ var tmp = input[+value];
+ if (_typeof(tmp) === object && !parsed.has(tmp)) {
+ parsed.add(tmp);
+ output[k] = ignore;
+ lazy.push({
+ o: output,
+ k: k,
+ r: tmp
+ });
+ } else output[k] = $.call(output, k, tmp);
+ } else if (output[k] !== ignore) output[k] = $.call(output, k, value);
+ }
+ return output;
+ };
};
-
var set = function set(known, input, value) {
var 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}
+ */
var parse = function parse(text, reviver) {
var input = $parse(text, Primitives).map(primitives);
- var value = input[0];
var $ = reviver || noop;
- var tmp = _typeof(value) === object && value ? revive(input, new Set(), value, $) : value;
+ var value = input[0];
+ if (_typeof(value) === object && value) {
+ var lazy = [];
+ var revive = resolver(input, lazy, new Set(), $);
+ value = revive(value);
+ var i = 0;
+ while (i < lazy.length) {
+ // it could be a lazy.shift() but that's costly
+ var _lazy$i = lazy[i++],
+ o = _lazy$i.o,
+ k = _lazy$i.k,
+ r = _lazy$i.r;
+ o[k] = $.call(o, k, revive(r));
+ }
+ }
return $.call({
- '': tmp
- }, '', tmp);
+ '': value
+ }, '', value);
};
+
+ /**
+ * 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}
+ */
var stringify = function stringify(value, replacer, space) {
var $ = replacer && _typeof(replacer) === object ? function (k, v) {
return k === '' || -1 < replacer.indexOf(k) ? v : void 0;
} : replacer || noop;
@@ -90,40 +105,45 @@
var i = +set(known, input, $.call({
'': value
}, '', value));
var firstRun = !i;
-
while (i < input.length) {
firstRun = true;
output[i] = $stringify(input[i++], replace, space);
}
-
return '[' + output.join(',') + ']';
-
function replace(key, value) {
if (firstRun) {
firstRun = !firstRun;
return value;
}
-
var after = $.call(this, key, value);
-
switch (_typeof(after)) {
case object:
if (after === null) return after;
-
case primitive:
return known.get(after) || set(known, input, after);
}
-
return after;
}
};
- 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));
};
exports.fromJSON = fromJSON;
exports.parse = parse; Index: package/min.js
===================================================================
--- package/min.js
+++ package/min.js
@@ -1,2 +1,1 @@
-self.Flatted=function(n){"use strict";function t(n){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},t(n)
-/*! (c) 2020 Andrea Giammarchi */}var r=JSON.parse,e=JSON.stringify,o=Object.keys,u=String,f="string",i={},c="object",a=function(n,t){return t},l=function(n){return n instanceof u?u(n):n},s=function(n,r){return t(r)===f?new u(r):r},y=function n(r,e,f,a){for(var l=[],s=o(f),y=s.length,p=0;p<y;p++){var v=s[p],S=f[v];if(S instanceof u){var b=r[S];t(b)!==c||e.has(b)?f[v]=a.call(f,v,b):(e.add(b),f[v]=i,l.push({k:v,a:[r,e,b,a]}))}else f[v]!==i&&(f[v]=a.call(f,v,S))}for(var m=l.length,g=0;g<m;g++){var h=l[g],O=h.k,d=h.a;f[O]=a.call(f,O,n.apply(null,d))}return f},p=function(n,t,r){var e=u(t.push(r)-1);return n.set(r,e),e},v=function(n,e){var o=r(n,s).map(l),u=o[0],f=e||a,i=t(u)===c&&u?y(o,new Set,u,f):u;return f.call({"":i},"",i)},S=function(n,r,o){for(var u=r&&t(r)===c?function(n,t){return""===n||-1<r.indexOf(n)?t:void 0}:r||a,i=new Map,l=[],s=[],y=+p(i,l,u.call({"":n},"",n)),v=!y;y<l.length;)v=!0,s[y]=e(l[y++],S,o);return"["+s.join(",")+"]";function S(n,r){if(v)return v=!v,r;var e=u.call(this,n,r);switch(t(e)){case c:if(null===e)return e;case f:return i.get(e)||p(i,l,e)}return e}};return n.fromJSON=function(n){return v(e(n))},n.parse=v,n.stringify=S,n.toJSON=function(n){return r(S(n))},n}({});
\ No newline at end of file
+self.Flatted=function(n){"use strict";function t(n){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},t(n)}var r=JSON.parse,e=JSON.stringify,o=Object.keys,u=String,f="string",i={},c="object",a=function(n,t){return t},l=function(n){return n instanceof u?u(n):n},s=function(n,r){return t(r)===f?new u(r):r},y=function(n,t,r){var e=u(t.push(r)-1);return n.set(r,e),e},p=function(n,e){var f=r(n,s).map(l),y=e||a,p=f[0];if(t(p)===c&&p){var v=[],S=function(n,r,e,f){return function(a){for(var l=o(a),s=l.length,y=0;y<s;y++){var p=l[y],v=a[p];if(v instanceof u){var S=n[+v];t(S)!==c||e.has(S)?a[p]=f.call(a,p,S):(e.add(S),a[p]=i,r.push({o:a,k:p,r:S}))}else a[p]!==i&&(a[p]=f.call(a,p,v))}return a}}(f,v,new Set,y);p=S(p);for(var b=0;b<v.length;){var m=v[b++],g=m.o,h=m.k,O=m.r;g[h]=y.call(g,h,S(O))}}return y.call({"":p},"",p)},v=function(n,r,o){for(var u=r&&t(r)===c?function(n,t){return""===n||-1<r.indexOf(n)?t:void 0}:r||a,i=new Map,l=[],s=[],p=+y(i,l,u.call({"":n},"",n)),v=!p;p<l.length;)v=!0,s[p]=e(l[p++],S,o);return"["+s.join(",")+"]";function S(n,r){if(v)return v=!v,r;var e=u.call(this,n,r);switch(t(e)){case c:if(null===e)return e;case f:return i.get(e)||y(i,l,e)}return e}};return n.fromJSON=function(n){return p(e(n))},n.parse=p,n.stringify=v,n.toJSON=function(n){return r(v(n))},n}({});
\ No newline at end of file Index: package/package.json
===================================================================
--- package/package.json
+++ package/package.json
@@ -1,10 +1,9 @@
{
"name": "flatted",
- "version": "3.2.7",
+ "version": "3.4.2",
"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",
"cjs": "ascjs esm cjs",
@@ -14,14 +13,30 @@
"min": "terser index.js -c -m -o min.js",
"size": "cat index.js | wc -c;cat min.js | wc -c;gzip -c9 min.js | wc -c;cat min.js | brotli | wc -c; cat es.js | brotli | wc -c; cat esm.js | brotli | wc -c",
"test": "c8 node test/index.js",
"test:php": "php php/test.php",
+ "test:py": "python python/test.py",
+ "ts": "tsc -p .",
"coverage": "mkdir -p ./coverage; c8 report --reporter=text-lcov > ./coverage/lcov.info"
},
"repository": {
"type": "git",
"url": "git+https://github.com/WebReflection/flatted.git"
},
+ "files": [
+ "LICENSE",
+ "README.md",
+ "cjs/",
+ "es.js",
+ "esm.js",
+ "esm/",
+ "index.js",
+ "min.js",
+ "php/flatted.php",
+ "python/flatted.py",
+ "golang/pkg/flatted/flatted.go",
+ "types/"
+ ],
"keywords": [
"circular",
"JSON",
"fast",
@@ -34,30 +49,32 @@
"url": "https://github.com/WebReflection/flatted/issues"
},
"homepage": "https://github.com/WebReflection/flatted#readme",
"devDependencies": {
- "@babel/core": "^7.18.10",
- "@babel/preset-env": "^7.18.10",
- "@ungap/structured-clone": "^1.0.1",
- "ascjs": "^5.0.1",
- "c8": "^7.12.0",
+ "@babel/core": "^7.29.0",
+ "@babel/preset-env": "^7.29.0",
+ "@rollup/plugin-babel": "^7.0.0",
+ "@rollup/plugin-terser": "^1.0.0",
+ "@ungap/structured-clone": "^1.3.0",
+ "ascjs": "^6.0.3",
+ "c8": "^11.0.0",
"circular-json": "^0.5.9",
"circular-json-es6": "^2.0.2",
+ "flatted-view": "^0.1.1",
"jsan": "^3.1.14",
- "rollup": "^2.78.1",
- "rollup-plugin-babel": "^4.4.0",
- "rollup-plugin-node-resolve": "^5.2.0",
- "rollup-plugin-terser": "^7.0.2",
- "terser": "^5.14.2"
+ "rollup": "^4.59.0",
+ "terser": "^5.46.0",
+ "typescript": "^5.9.3"
},
"module": "./esm/index.js",
"type": "module",
"exports": {
".": {
- "types": "./types.d.ts",
+ "types": "./types/index.d.ts",
"import": "./esm/index.js",
"default": "./cjs/index.js"
},
"./esm": "./esm.js",
"./package.json": "./package.json"
- }
+ },
+ "types": "./types/index.d.ts"
} Index: package/README.md
===================================================================
--- package/README.md
+++ package/README.md
@@ -1,28 +1,28 @@
# flatted
-[](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) 
+[](https://www.npmjs.com/package/flatted) [](https://coveralls.io/github/WebReflection/flatted?branch=main) [](https://opensource.org/licenses/ISC) 

<sup>**Social Media Photo by [Matt Seymour](https://unsplash.com/@mattseymour) on [Unsplash](https://unsplash.com/)**</sup>
-## Announcement 📣
+A super light (0.5K) and fast circular JSON parser, directly from the creator of [CircularJSON](https://github.com/WebReflection/circular-json/#circularjson).
-There is a standard approach to recursion and more data-types than what JSON allows, and it's part of the [Structured Clone polyfill](https://github.com/ungap/structured-clone/#readme).
+Available also for **[PHP](./php/flatted.php)**.
-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* in general.
+Available also for **[Python](./python/flatted.py)**.
-The *@ungap/structured-clone* module is, in short, a drop in replacement for *flatted*, but it's not compatible with *flatted* specialized syntax.
+Available also for **[Go](./golang/README.md)**.
-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 👍
-
- - -
-A super light (0.5K) and fast circular JSON parser, directly from the creator of [CircularJSON](https://github.com/WebReflection/circular-json/#circularjson).
+## ℹ️ JSON only values
-Now available also for **[PHP](./php/flatted.php)**.
+If you need anything more complex than values JSON understands, there is a standard approach to recursion and more data-types than what JSON allows, and it's part of the [Structured Clone polyfill](https://github.com/ungap/structured-clone/#readme).
+- - -
+
```js
npm i flatted
``` Index: package/php/flatted.php
===================================================================
--- package/php/flatted.php
+++ package/php/flatted.php
@@ -18,8 +18,9 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
class FlattedString {
+ public $value = '';
public function __construct($value) {
$this->value = $value;
}
}
@@ -147,9 +148,8 @@
$keys = Flatted::keys($value);
foreach ($keys as $key) {
$value->$key = self::wrap($value->$key);
}
- return $value;
}
return $value;
}
}