Comparing version 1.1.3 to 1.1.4
22
index.js
@@ -1,2 +0,1 @@ | ||
function isString (x) { | ||
@@ -19,8 +18,17 @@ var type = Object.prototype.toString.apply(x); | ||
// https://github.com/douglascrockford/JSON-js/blob/master/json2.js#L451 | ||
return /^[\],:{}\s]*$/ | ||
.test(str | ||
.replace(/\\["\\\/bfnrtu]/g, '@') | ||
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']') | ||
.replace(/(?:^|:|,)(?:\s*\[)+/g, '')); | ||
if (/^\{(.*?)\}$/.test(str)) | ||
return /"(.*?)":(.*?)/g.test(str); | ||
if (/\[(.*?)\]/.test(str)) { | ||
str = str.replace(/\s/g, '') | ||
.replace(/^\[/, '') | ||
.replace(/\]$/, '') | ||
.replace(/},{/g, '}\n{') | ||
.split(/\n/); | ||
console.log(str); | ||
return str.map(function (s) { return isJSON(s); }) | ||
.reduce(function (prev, curr) { return !!curr; }); | ||
} | ||
return false; | ||
} |
{ | ||
"name": "is-json", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "check if a string is a valid JSON string without using Try/Catch", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,3 +6,3 @@ var test = require('tape'); | ||
test('performe isJSON verifications', function (t) { | ||
t.plan(10); | ||
t.plan(14); | ||
@@ -21,2 +21,7 @@ t.deepEqual(isJSON(null), false, '`null`, should return false'); | ||
'`{"a":"obja","b":[0,1,2],"c":{"d":"some object"}}`, should return true'); | ||
t.deepEqual(isJSON('1,2,3'), false, '`1,2,3`, should return false'); | ||
t.deepEqual(isJSON('{1,2,3}'), false, '`{1,2,3}`, should return false'); | ||
t.deepEqual(isJSON('[{"a": 123}, {1,2,3}}]'), false, '`[{"a": 123, {1,2,3}}]`, should return false'); | ||
t.deepEqual(isJSON('[{"a": {"aa": [1,2,3,4], "aaa": {"d": 1212}}}, {"b": "test", "c": [1,2,3]}]'), | ||
true, 'complex object should return true'); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4974
47