Comparing version 1.1.5 to 1.2.5
10
index.js
@@ -12,2 +12,3 @@ function isString (x) { | ||
module.exports = isJSON; | ||
isJSON.strict = strict; | ||
@@ -35,1 +36,10 @@ function isJSON (str, pass_object) { | ||
} | ||
function strict (str) { | ||
try { | ||
return JSON.parse(str) && true; | ||
} catch (ex) { | ||
return false; | ||
} | ||
} |
{ | ||
"name": "is-json", | ||
"version": "1.1.5", | ||
"version": "1.2.5", | ||
"description": "check if a string is a valid JSON string without using Try/Catch", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -12,3 +12,3 @@ # is-json | ||
**V1.1** | ||
**V1.2** | ||
@@ -38,2 +38,6 @@ | ||
console.log(isJSON(object, true)); // true | ||
console.log(isJSON(object, true)); // true | ||
// can use isJSON.strict (uses try/catch) if wants something more robust | ||
console.log(isJSON.strict('{\n "config": 123,\n "test": "abcde" \n}')); // true |
@@ -6,3 +6,3 @@ var test = require('tape'); | ||
test('performe isJSON verifications', function (t) { | ||
t.plan(15); | ||
t.plan(16); | ||
@@ -24,5 +24,6 @@ t.deepEqual(isJSON(null), false, '`null`, should return false'); | ||
t.deepEqual(isJSON('[{"a": 123}, {1,2,3}}]'), false, '`[{"a": 123, {1,2,3}}]`, should return false'); | ||
var cobj = '[{"a": {"aa": [1,2,3,4], "aaa": {"d": 1212}}}, {"b": "test", "c": [1,2,3], "date": "' + new Date() + '"}]'; | ||
var cobj = '[{"a": {"aa": [1,2,3,4], "aaa": {"d": 1212}}}, {"b": "test", "c": [1,2,3], "date": "' + new Date() + '}]'; | ||
t.deepEqual(isJSON(cobj), true, cobj + ', should return true'); | ||
t.deepEqual(isJSON(new Date()), false, '`Date`, should return false'); | ||
t.deepEqual(isJSON.strict('{\n "config": 123,\n "test": "abcde" \n}'), true, '`{\n "config": 123,\n "test": "abcde" \n}`, 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
5498
56
42