Coder Social home page Coder Social logo

json-stringify-extended's People

Contributors

xiaonai239 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

xiaonai239

json-stringify-extended's Issues

How to use it with import?

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.
Try npm i --save-dev @types/json-stringify-extended if it exists or add a new declaration (.d.ts) file containing declare module 'json-stringify-extended';ts(7016)

Adding Key Quote as options

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 .

es6 support for function compress

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);

Parsing the Extended Stringify?

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?

compress doesn't work with functions

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);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.