simone-sanfratello / json-stringify-extended Goto Github PK
View Code? Open in Web Editor NEWJSON.stringify any data types
JSON.stringify any data types
Getting this error when trying to import it rather than require it.
Could not find a declaration file for module 'json-stringify-extended'. '/projects/blah/node_modules/json-stringify-extended/src/main.js' implicitly has an 'any' type.
Trynpm i --save-dev @types/json-stringify-extended
if it exists or add a new declaration (.d.ts) file containingdeclare module 'json-stringify-extended';
ts(7016)
const options ={
keyQuote: '"'
}
passing the above option to stringify but still key are coming in as without quotes .
Removing the if following if condition
if (_item.key.match(IRREGULAR_KEY) || !_item.key.match(SQUARED_IN_KEY))
allows me to get quoted key values .
var list = ['a', 'b', 'c'];
const data = [
{a: list},
{b: list}
];
fails and says it's a circular reference
dig some digging. looks like uglifyjs released uglify-es
Here's an example of code that breaks with uglify-js but works with uglify-es
var uglify = require('uglify-es');
fn = function () {
var world = 'world';
return `hello ${world}`;
}
input = "var ___ = " + fn.toString();
output = uglify.minify(input)
if(output.error) {
console.log(output.error);
}
else {
output = output.code
output = output.replace('var ___=', '');
output = output.replace(/;$/, '');
}
console.log(input);
console.log(output);
So I was using this library and was trying to parse the extended stringify back to its original format. I haven't really found a parser that would handle it correctly. JSON.parse returns errors because it doesn't understand functions inside the object
Is there a solution to this? Or a different library that works well with your extension for deserializing/decoding/parsing the extended stringify?
example
var stringify = require('json-stringify-extended');
var obj = {foo: function(){return true}};
console.log(stringify(obj, {compress: true}));
result
{
foo:undefined
}
the following will fix it, but I'm hoping there's a nicer option. I couldn't find any relevant uglify options to support direct minification of "function(){}"
var uglify = require('uglify-js');
var input, output, obj;
obj = {foo: function(){return true}};
input = "var ___ = " + obj.foo.toString();
output = uglify.minify(input).code
output = output.replace('var ___=', '');
output = output.replace(/;$/, '');
console.log(input);
console.log(output);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.