diff options
| author | Shipwreckt <me@shipwreckt.co.uk> | 2025-10-31 20:02:14 +0000 |
|---|---|---|
| committer | Shipwreckt <me@shipwreckt.co.uk> | 2025-10-31 20:02:14 +0000 |
| commit | 7a52ddeba2a68388b544f529d2d92104420f77b0 (patch) | |
| tree | 15ddd47457a2cb4a96060747437d36474e4f6b4e /node_modules/is-json | |
| parent | 53d6ae2b5568437afa5e4995580a3fb679b7b91b (diff) | |
Changed from static to 11ty!
Diffstat (limited to 'node_modules/is-json')
| -rw-r--r-- | node_modules/is-json/.npmignore | 12 | ||||
| -rw-r--r-- | node_modules/is-json/.travis.yml | 14 | ||||
| -rw-r--r-- | node_modules/is-json/LICENSE | 15 | ||||
| -rw-r--r-- | node_modules/is-json/README.md | 41 | ||||
| -rw-r--r-- | node_modules/is-json/index.js | 48 | ||||
| -rw-r--r-- | node_modules/is-json/package.json | 29 | ||||
| -rw-r--r-- | node_modules/is-json/test/index.js | 33 |
7 files changed, 192 insertions, 0 deletions
diff --git a/node_modules/is-json/.npmignore b/node_modules/is-json/.npmignore new file mode 100644 index 0000000..b0e8ee7 --- /dev/null +++ b/node_modules/is-json/.npmignore @@ -0,0 +1,12 @@ +.*.swp +._* +.DS_Store +.git +.hg +.lock-wscript +.svn +.wafpickle-* +CVS +npm-debug.log +*.sublime-project +*.sublime-workspace
\ No newline at end of file diff --git a/node_modules/is-json/.travis.yml b/node_modules/is-json/.travis.yml new file mode 100644 index 0000000..250e5ab --- /dev/null +++ b/node_modules/is-json/.travis.yml @@ -0,0 +1,14 @@ + language: node_js + node_js: + - "0.12" + - "0.10" + - "0.8" + branches: + only: + - master + notifications: + email: + - joaquim.serafim@gmail.com + script: npm test + before_install: + - npm install -g npm@~1.4.6 diff --git a/node_modules/is-json/LICENSE b/node_modules/is-json/LICENSE new file mode 100644 index 0000000..7773e29 --- /dev/null +++ b/node_modules/is-json/LICENSE @@ -0,0 +1,15 @@ +The ISC License + +Copyright (c) Joaquim José F. Serafim + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR +IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/node_modules/is-json/README.md b/node_modules/is-json/README.md new file mode 100644 index 0000000..2fea1b4 --- /dev/null +++ b/node_modules/is-json/README.md @@ -0,0 +1,41 @@ +# is-json + +<a href="https://nodei.co/npm/is-json/"><img src="https://nodei.co/npm/is-json.png?downloads=true"></a> + +[](https://travis-ci.org/joaquimserafim/is-json) + + +check if a string is a valid JSON string without using Try/Catch and is a JSON object + + + +**V1.2** + + +isJSON(str*, [passObjects=bool]) + +*with `passObjects = true` can pass a JSON object in `str`, default to `false` + + + var isJSON = require('is-json'); + + var good_json = '{"a":"obja","b":[0,1,2],"c":{"d":"some object"}}'; + var bad_json = '{"a":"obja""b":[0,1,2],"c":{"d":"some object"}}'; + var str_number = '121212'; + + + console.log(isJSON(good_json)); // true + console.log(isJSON(bad_json)); // false + console.log(isJSON(str_number)); // false + + + + // check is an object + + var object = {a: 12, b: [1,2,3]}; + + 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 diff --git a/node_modules/is-json/index.js b/node_modules/is-json/index.js new file mode 100644 index 0000000..2a09a3a --- /dev/null +++ b/node_modules/is-json/index.js @@ -0,0 +1,48 @@ +'use strict' + +module.exports = isJSON; +isJSON.strict = strict; + +function isJSON (str, pass_object) { + if (pass_object && isObject(str)) return true; + + if (!isString(str)) return false; + + str = str.replace(/\s/g, '').replace(/\n|\r/, ''); + + if (/^\{(.*?)\}$/.test(str)) + return /"(.*?)":(.*?)/g.test(str); + + if (/^\[(.*?)\]$/.test(str)) { + return str.replace(/^\[/, '') + .replace(/\]$/, '') + .replace(/},{/g, '}\n{') + .split(/\n/) + .map(function (s) { return isJSON(s); }) + .reduce(function (prev, curr) { return !!curr; }); + } + + return false; +} + + +function strict (str) { + if (isObject(str)) { + return true; + } + + try { + return JSON.parse(str) && true; + } catch (ex) { + return false; + } +} + +function isString (x) { + return Object.prototype.toString.call(x) === '[object String]'; +} + +function isObject (obj) { + return Object.prototype.toString.call(obj) === '[object Object]'; +} + diff --git a/node_modules/is-json/package.json b/node_modules/is-json/package.json new file mode 100644 index 0000000..75ac1af --- /dev/null +++ b/node_modules/is-json/package.json @@ -0,0 +1,29 @@ +{ + "name": "is-json", + "version": "2.0.1", + "description": "check if a string is a valid JSON string without using Try/Catch", + "main": "index.js", + "directories": { + "test": "test" + }, + "scripts": { + "test": "node test" + }, + "repository": { + "type": "git", + "url": "git@github.com:joaquimserafim/is-json.git" + }, + "keywords": [ + "JSON", + "validation" + ], + "author": "@joaquimserafim", + "license": "ISC", + "bugs": { + "url": "https://github.com/joaquimserafim/is-json/issues" + }, + "homepage": "https://github.com/joaquimserafim/is-json", + "devDependencies": { + "tape": "^2.13.1" + } +} 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(); +}); |
