summaryrefslogtreecommitdiff
path: root/node_modules/is-json/test
diff options
context:
space:
mode:
authorShipwreckt <me@shipwreckt.co.uk>2025-10-31 20:02:14 +0000
committerShipwreckt <me@shipwreckt.co.uk>2025-10-31 20:02:14 +0000
commit7a52ddeba2a68388b544f529d2d92104420f77b0 (patch)
tree15ddd47457a2cb4a96060747437d36474e4f6b4e /node_modules/is-json/test
parent53d6ae2b5568437afa5e4995580a3fb679b7b91b (diff)
Changed from static to 11ty!
Diffstat (limited to 'node_modules/is-json/test')
-rw-r--r--node_modules/is-json/test/index.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/node_modules/is-json/test/index.js b/node_modules/is-json/test/index.js
new file mode 100644
index 0000000..134d614
--- /dev/null
+++ b/node_modules/is-json/test/index.js
@@ -0,0 +1,33 @@
+var test = require('tape');
+var isJSON = require('../');
+
+
+test('performe isJSON verifications', function (assert) {
+ assert.deepEqual(isJSON('asdada[]asdadada sd asdasda das das'), false, '`asdada[]asdadada sd asdasda das das`, should return false');
+ assert.deepEqual(isJSON(null), false, '`null`, should return false');
+ assert.deepEqual(isJSON(false), false, '`false`, should return false');
+ assert.deepEqual(isJSON(''), false, '`\'\'`, should return false');
+ assert.deepEqual(isJSON('normal string'), false, '\'normal string\', should return false');
+ assert.deepEqual(isJSON(2014), false, '`2014`, should return false');
+ assert.deepEqual(isJSON(2014.5), false, '`2014.5`, should return false');
+ assert.deepEqual(isJSON([1,2,3,4]), false, '`[1,2,3,4]`, should return false');
+ assert.deepEqual(isJSON({a: 12, b: [1,2,3]}), false, 'a JSON object `{a: 12, b: [1,2,3]},`, should return false');
+ assert.deepEqual(isJSON({a: 12, b: [1,2,3]}, true), true,
+ 'a JSON object `{a: 12, b: [1,2,3]}` but pass the 2 arg as true (check objects too), should return true');
+ assert.deepEqual(isJSON('{"a":"obja","b":[0,1,2],"c":{"d":"some object"}}'), true,
+ '`{"a":"obja","b":[0,1,2],"c":{"d":"some object"}}`, should return true');
+ assert.deepEqual(isJSON('1,2,3'), false, '`1,2,3`, should return false');
+ assert.deepEqual(isJSON('{1,2,3}'), false, '`{1,2,3}`, should return false');
+ assert.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() + '"}]';
+
+ assert.deepEqual(isJSON(cobj), true, cobj + ', should return true');
+ assert.deepEqual(isJSON(new Date()), false, '`Date`, should return false');
+ assert.deepEqual(isJSON.strict('{\n "config": 123,\n "test": "abcde" \n}'), true, '`{\n "config": 123,\n "test": "abcde" \n}`, should return true');
+ assert.deepEqual(
+ isJSON.strict({a: 1}),
+ true,
+ 'should return true when passing a js object into `strict`'
+ );
+ assert.end();
+});