GithubHelp home page GithubHelp logo

jsdump's Introduction

jsDump

jsDump.parse(object) returns a string containing a human-readable representation of object.

jsDump is like Mozilla’s toSource(), but it works in all modern browsers.

jsDump was originally developed by Ariel Flesler. This fork based on version 1.0.0.

Similar Stuff

  • JSON.stringify(). Doesn’t serialize functions and DOM nodes.
  • inspect() from Node.js sys module
  • repr() from Narwhal’s util module
  • console._source_of() from Console.js
npm install jsDump

Usage:

var jsDump = require("jsDump");
jsDump.parse({foo: 'bar', length: 0});

In the browser:

  1. git submodule update --init
  2. open tests/index.html

Or from command line:

$ narwhal tests/*_test.js

Contribution

Use jQuery coding style. Basically, use tabs instead of spaces.

jsdump's People

Contributors

nv avatar ozalexo avatar russelldavis avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

jsdump's Issues

JSON with a key of "length" causes a problem

JSON requires quotes around keys so reserved words don't cause a problem. But I suspect there's an issue with jsDump's parsing because it returns "[ ]" for the following valid JSON:

{
"width": 0,
"length": 0
}

Change it slightly though:

{
"width": 0,
"length_": 0
}

and it parses and formats it just fine. My guess is that other reserved words might cause similar problems though I haven't tested that to make sure.

The “arguments” object detection causes problems

Inside the typeOf function, the arguments object is detected using the callee property:

if ( 'callee' in obj )
  // Opera: Object.prototype.toString.call(arguments) == 'Object' :(

This creates a problem in at least two situations:

  1. When dealing with regular objects containing the callee property, such as AST nodes resulting from parsing JavaScript by a parser conforming to Mozilla SpiderMonkey Parser API (or its successor, The ESTree Spec).
  2. In JavaScript strict mode, which defines (5.1, 6.0) the callee getter to throw an exception. This can be demonstrated e.g. using this code in recent Chrome: (function() { "use strict"; arguments.callee; })();).

The first case frequently bites users of the online editor at PEG.js website.

Since Object.prorotype.toString called on an arguments object returns [object Arguments] on recent versions of all common browsers (including Opera mentioned in a comment in jsDump code), I think it would be better to rewrite the detection to use it to detect arguments instead of the callee property.

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.