Comparing version 0.1.0 to 0.1.1
@@ -231,3 +231,7 @@ /** | ||
if(typeof window !== 'undefined') { // IF TRUE: We're within a browser context | ||
window.toSrc = toSrc; | ||
if (window.toSrc === undefined) { | ||
window.toSrc = toSrc; | ||
} else { | ||
console.log("Name collision: window.toSrc already exists..."); | ||
} | ||
} else if(typeof module !== 'undefined'){ // IF TRUE: We're within a commonJS context (like node.js) | ||
@@ -234,0 +238,0 @@ module.exports = toSrc; |
{ | ||
"name": "toSrc", | ||
"description": "Turns every JavaScript object or primitive into valid source code.", | ||
"version": "0.1.0", | ||
"homepage": "http://github.com/jhnns/toSrc", | ||
"repository": "git://github.com/jhnns/toSrc.git", | ||
"version": "0.1.1", | ||
"homepage": "https://github.com/pandaa/toSrc", | ||
"repository": "git://github.com/pandaa/toSrc.git", | ||
"author": "Johannes Ewald <mail@johannesewald.de>", | ||
@@ -8,0 +8,0 @@ "main": "./lib/toSrc.js", |
@@ -10,2 +10,4 @@ toSrc | ||
Works with node.js (tested) or in the browser (not tested) | ||
Installation | ||
@@ -17,8 +19,16 @@ ------------ | ||
----- | ||
`require("toSrc")` returns a single function accepting these parameters: | ||
* **Params** | ||
1. **obj**: *The object to stringify. Can also be a primitive like `1` or `true`.* | ||
2. **depth** (optional): *The 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 will be undefined by default.* | ||
1. **obj**: *The object to stringify. Can also be a primitive like `1` or `true`.* | ||
2. **depth** (optional): *The 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 will be undefined by default.* | ||
* **In node.js** | ||
`require("toSrc")(obj, depth);` | ||
* **In the browser** | ||
Just call `toSrc(obj, depth);` | ||
Examples | ||
@@ -28,2 +38,3 @@ ----- | ||
```javascript | ||
var toSrc = require("toSrc"); | ||
@@ -82,2 +93,3 @@ | ||
// = '{"regEx": /regex/gi, "anotherObj": {"test": "test"}}' | ||
``` | ||
@@ -94,2 +106,2 @@ | ||
Feel free to modify the code to meet your needs. | ||
Feel free to modify the code to meet your needs. |
@@ -109,5 +109,3 @@ ////////////////////////////////////////////////////////////////////////////////// | ||
); | ||
assert.equal(toSrc(function() { | ||
var test = "hello"; | ||
}), 'function () {\n var test = "hello";\n}'); | ||
assert.equal(toSrc(function() { var test = "hello"; }), 'function () { var test = "hello"; }'); | ||
assert.equal(toSrc([1, 2, "3"]), '[1, 2, "3"]'); | ||
@@ -114,0 +112,0 @@ assert.equal(toSrc({ |
Sorry, the diff of this file is not supported yet
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
16143
360
103
2