{"name":"toSrc","description":"Turns every JavaScript object or primitive into valid source code.","version":"0.1.4","homepage":"http://jhnns.github.com/toSrc","repository":{"type":"git","url":"git://github.com/jhnns/toSrc.git"},"author":{"name":"Johannes Ewald","email":"mail@johannesewald.de","url":"http://johannesewald.de"},"main":"./lib/toSrc.js","keywords":["toSource","toSrc","source","object","serialization","stringify","JSON","eval","vm","obj2src"],"bugs":{"url":"http://github.com/jhnns/toSrc/issues","email":"mail@johannesewald.de"},"dependencies":{},"devDependencies":{},"scripts":{"test":"node test/test.js"},"_id":"toSrc@0.1.4","_shasum":"a57b60b9e002e1c580d3250fea1c95f22207a9a6","_from":".","_npmVersion":"1.4.9","_npmUser":{"name":"jhnns","email":"mail@johannesewald.de"},"maintainers":[{"name":"jhnns","email":"mail@johannesewald.de"}],"dist":{"shasum":"a57b60b9e002e1c580d3250fea1c95f22207a9a6","tarball":"http://registry-npm.ywwl.com/toSrc/download/toSrc-0.1.4.tgz","integrity":"sha512-OR6AlSRif1xVT03Zy3M9njdYrq/K+s1h4hjgfPGhipMF916YTwf46VoXbZ1HlTdU9pl5RAAj9P4KHJicEvXINw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDVSDmuVftPeR8DQstxBqUE8nR0wSI7JM1FgxeYjYxJ5QIgXZaSw0hB748Te6WwvudHG/6CePmzU/ZD+J0ernkSXys="}],"size":7051,"noattachment":false,"key":"/toSrc/-/toSrc-0.1.4.tgz"},"directories":{},"readme":"**toSrc** [![Build Status](https://secure.travis-ci.org/jhnns/toSrc.png?branch=master)](http://travis-ci.org/jhnns/toSrc)\r\n========\r\n\r\n**Turns every JavaScript object or primitive into valid source\r\ncode that can be evaled again.**\r\n\r\nYou can use it to serialize classes, modules or other programming objects\r\nand reuse them in an other environment such as a browser. JSON.stringify doesnt work with programming objects (that contain functions, dates, etc.) because they're no legal JSONs.\r\n\r\n<br />\r\n\r\nInstallation\r\n------------\r\n`npm install toSrc`\r\n\r\n<br />\r\n\r\nExamples\r\n-----\r\n\r\n```javascript\r\n\r\n    var toSrc = require(\"toSrc\");\r\n    \r\n    // Primitives\r\n    ///////////////////////////////////////\r\n    toSrc(1); // = '1'\r\n    toSrc(true); // = 'true'\r\n    toSrc(undefined); // = 'undefined'\r\n    tOSrc(null); // = null\r\n    toSrc(\"1\"); // = '\"1\"'\r\n    toSrc('1'); // = '\"1\"' toSrc always uses double-quotes    \r\n\r\n    // Constants\r\n    ///////////////////////////////////////\r\n    toSrc(Math.PI); // = 'Math.PI'\r\n    toSrc(NaN); // = 'NaN'\r\n\r\n    // RegExp\r\n    ///////////////////////////////////////\r\n    toSrc(/myRegEx/gi); // = '/myRegEx/gi'\r\n    toSrc(new RegExp(\"myRegEx\")); // = '/myRegEx/'\r\n\r\n    // Date\r\n    ///////////////////////////////////////\r\n    toSrc(new Date()); // = 'new Date(<the time of creation in ms>)'\r\n\r\n    // Functions\r\n    ///////////////////////////////////////\r\n    function testFunc() {\r\n        var test = \"hello\";\r\n    }\r\n    toSrc(testFunc); // = 'function testFunc() {\\n    var test = \"hello\";\\n}'\r\n    toSrc(String); // = 'String', native functions don't expose the source code\r\n\r\n    // Arrays\r\n    ///////////////////////////////////////\r\n    toSrc([1, 2, \"3\"]); // = '[1, 2, \"3\"]'\r\n    toSrc([1, 2, [\"a\", \"b\", \"c\"]]); // = '[1, 2, undefined]' because the depth\r\n                                    // is 1 by default\r\n    toSrc([1, 2, [\"a\", \"b\", \"c\"]], 2); // = '[1, 2, [\"a\", \"b\", \"c\"]]'\r\n\r\n    // Objects\r\n    ///////////////////////////////////////\r\n    toSrc({\r\n        regEx: /regex/gi,\r\n        anotherObj: {\r\n            test: \"test\"\r\n        }\r\n    });\r\n    // = '{\"regEx\": /regex/gi, \"anotherObj\": undefined}'\r\n    // anotherObj is undefined because the depth is 1 by default.\r\n    toSrc({\r\n        \"regEx\": /regex/gi,\r\n        \"anotherObj\": {\r\n            \"test\": \"test\"\r\n        }\r\n    }, 2);\r\n    // = '{\"regEx\": /regex/gi, \"anotherObj\": {\"test\": \"test\"}}'\r\n\r\n```\r\n\r\nFor more examples check out `test/test.js`\r\n\r\n<br />\r\n\r\n\r\n\r\nAPI\r\n-----\r\n\r\n###toSrc(obj: *, depth: Number): String\r\n\r\n- *obj*: <br/>\r\nThe object to stringify. Can also be a primitive like `1` or `true`.\r\n\r\n- *{Number=1} depth*:<br />\r\nThe depth to go. All nested structures like objects or arrays deeper than this will be undefined. Defaults to 1, meaning that every object or array within `obj` will be undefined by default.\r\n\r\n<br />\r\n\r\nUsage\r\n-----\r\n\r\n### In node.js\r\n\r\n```javascript\r\nvar toSrc = require(\"toSrc\");\r\n\r\ntoSrc(obj, depth);\r\n```\r\n\r\n### In the browser\r\n\r\nJust call `toSrc(obj, depth);`\r\n\r\n<br />\r\n\r\nNotes\r\n-----\r\n* Circular references will be undefined. No error is thrown, but a warning is logged.\r\n* All math constants are restored to their source representation, e.g.: `toSrc(Math.PI); // = 'Math.PI' instead of 3.14...`\r\n* All dates are restored to their original time of creation, e.g.: `toSrc(new Date()) // = 'new Date(<time of creation in ms>)'`\r\n* Dynamic regular expressions created via `new RegExp()` will **not** be dynamic anymore. `toSrc(new RegExp(someString))` will return `'/<value of someString>/'` instead of `'new RegExp(someString)'`\r\n\r\nFeel free to modify the code to meet your needs.\r\n\r\n\r\n<br />\r\n\r\n## License\r\n\r\nMIT\r\n","publish_time":1404118328192,"_cnpm_publish_time":1404118328192,"dist-tags":{"latest":"0.1.4"}}