Comparing version
var tostr = require('./') | ||
var obj = { | ||
str: "A string", | ||
str: "'A' \"string\"\r\n.", | ||
strO: new String("'A' \"string\" \r\nObject."), | ||
num: 0, | ||
numO: new Number(0), | ||
bool: true, | ||
boolO: new Boolean(true), | ||
undef: undefined, | ||
reg: /re/g, | ||
regO: new RegExp("re", "g"), | ||
date: new Date(), | ||
date2: new Date('2014-01-01'), | ||
arr: [1, 2, 3], | ||
arrO: new Array().concat([0,"1",true]), | ||
obj: { | ||
name: "fool2fish", email: "fool2fish@gmail.com" | ||
}, | ||
objO: new Object(), | ||
func: function(a, b) { | ||
// some comment | ||
return a + b | ||
} | ||
}, | ||
funcO: new Function("a", "alert(a)") | ||
} | ||
var str = tostr(obj) | ||
console.log(str) |
11
index.js
@@ -16,4 +16,4 @@ "use strict"; | ||
var isString = isType("String") | ||
var isDate = isType("Date") | ||
function tostr(data /* private params*/, indent) { | ||
@@ -53,4 +53,8 @@ indent = indent || 2 | ||
if (isDate(data)) { | ||
return "new Date('" + data.toString() + "')" | ||
} | ||
if (isString(data)) { | ||
return inspect(data) | ||
return inspect(data).replace(/^\[String: (.*)\]$/, '$1') | ||
} | ||
@@ -63,4 +67,1 @@ | ||
module.exports = tostr | ||
{ | ||
"name": "tostr", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Convert object to string.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/fool2fish/tostr", |
@@ -14,17 +14,28 @@ # tostr | ||
var obj = { | ||
str: "A string", | ||
str: "'A' \"string\"\r\n.", | ||
strO: new String("'A' \"string\" \r\nObject."), | ||
num: 0, | ||
numO: new Number(0), | ||
bool: true, | ||
boolO: new Boolean(true), | ||
undef: undefined, | ||
reg: /re/g, | ||
regO: new RegExp("re", "g"), | ||
date: new Date(), | ||
date2: new Date('2014-01-01'), | ||
arr: [1, 2, 3], | ||
arrO: new Array().concat([0,"1",true]), | ||
obj: { | ||
name: "fool2fish", email: "fool2fish@gmail.com" | ||
}, | ||
objO: new Object(), | ||
func: function(a, b) { | ||
// some comment | ||
return a + b | ||
} | ||
}, | ||
funcO: new Function("a", "alert(a)") | ||
} | ||
var str = tostr(obj) | ||
console.log(str) | ||
``` | ||
@@ -36,6 +47,13 @@ | ||
{ | ||
str: 'A string', | ||
str: '\'A\' "string"\r\n.', | ||
strO: '\'A\' "string" \r\nObject.', | ||
num: 0, | ||
numO: 0, | ||
bool: true, | ||
boolO: true, | ||
undef: undefined, | ||
reg: /re/g, | ||
regO: /re/g, | ||
date: new Date('Mon Dec 22 2014 16:09:46 GMT+0800 (CST)'), | ||
date2: new Date('Wed Jan 01 2014 08:00:00 GMT+0800 (CST)'), | ||
arr: [ | ||
@@ -46,2 +64,7 @@ 1, | ||
], | ||
arrO: [ | ||
0, | ||
'1', | ||
true | ||
], | ||
obj: { | ||
@@ -51,8 +74,15 @@ name: 'fool2fish', | ||
}, | ||
func: function(a, b) { | ||
objO: { | ||
}, | ||
func: function (a, b) { | ||
// some comment | ||
return a + b | ||
} | ||
}, | ||
funcO: function anonymous(a | ||
/**/) { | ||
alert(a) | ||
} | ||
} | ||
``` | ||
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
3676
42.65%77
22.22%85
54.55%1
Infinity%