@stdlib/assert-is-json
Advanced tools
| { | ||
| "version": 3, | ||
| "sources": ["../lib/main.js", "../lib/index.js"], | ||
| "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\n/**\n* Detects a JSON string.\n*\n* Regular expression: `/^\\{[\\s\\S]*\\}$|^\\[[\\s\\S]*\\]$/`\n*\n* - `^\\{`\n*\n* - match a `{` literal which is the first character\n*\n* - `[\\s\\S]*`\n*\n* - match any whitespace and non-whitespace characters which occur `0` or more times\n*\n* - `\\}$`\n*\n* - match a `}` literal which is the last character\n*\n* - `|`\n*\n* - alternatively\n*\n* - `^\\[`\n*\n* - match a `[` literal which is the first character\n*\n* - `[\\s\\S]*`\n*\n* - match any whitespace and non-whitespace characters which occur `0` or more times\n*\n* - `\\]$`\n*\n* - match a `]` literal which is the last character\n*\n*\n* Example matching strings:\n*\n* - `'{}'`\n* - `'[]'`\n* - `'{adjlkfaj3743.,><\\n\\t\\rdf}'`\n* - `'[adjlkfaj3743.,><\\n\\t\\rdf]'`\n* - `'{\"a\":5}'`\n*\n* @constant\n* @type {RegExp}\n* @default /^\\{[\\s\\S]*\\}$|^\\[[\\s\\S]*\\]$/\n*/\nvar re = /^\\{[\\s\\S]*\\}$|^\\[[\\s\\S]*\\]$/;\n\n\n// MAIN //\n\n/**\n* Tests if a value is a parseable JSON string.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a parseable JSON string\n*\n* @example\n* var v = isJSON( '{\"a\":5}' );\n* // returns true\n*\n* @example\n* var v = isJSON( '{a\":5}' );\n* // returns false\n*/\nfunction isJSON( value ) {\n\tif ( typeof value !== 'string' ) {\n\t\treturn false;\n\t}\n\tif ( !re.test( value ) ) {\n\t\treturn false;\n\t}\n\ttry {\n\t\tJSON.parse( value );\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n\treturn true;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isJSON;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Test if a value is a parseable JSON string.\n*\n* @module @stdlib/assert-is-json\n*\n* @example\n* var isJSON = require( '@stdlib/assert-is-json' );\n*\n* var v = isJSON( '{\"a\":5}' );\n* // returns true\n*\n* v = isJSON( '{a\":5}' );\n* // returns false\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], | ||
| "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAoEA,IAAIC,EAAK,8BAmBT,SAASC,EAAQC,EAAQ,CAIxB,GAHK,OAAOA,GAAU,UAGjB,CAACF,EAAG,KAAME,CAAM,EACpB,MAAO,GAER,GAAI,CACH,KAAK,MAAOA,CAAM,CACnB,OAAUC,EAAM,CACf,MAAO,EACR,CACA,MAAO,EACR,CAKAJ,EAAO,QAAUE,ICpEjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", | ||
| "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\n/**\n* Detects a JSON string.\n*\n* Regular expression: `/^\\{[\\s\\S]*\\}$|^\\[[\\s\\S]*\\]$/`\n*\n* - `^\\{`\n*\n* - match a `{` literal which is the first character\n*\n* - `[\\s\\S]*`\n*\n* - match any whitespace and non-whitespace characters which occur `0` or more times\n*\n* - `\\}$`\n*\n* - match a `}` literal which is the last character\n*\n* - `|`\n*\n* - alternatively\n*\n* - `^\\[`\n*\n* - match a `[` literal which is the first character\n*\n* - `[\\s\\S]*`\n*\n* - match any whitespace and non-whitespace characters which occur `0` or more times\n*\n* - `\\]$`\n*\n* - match a `]` literal which is the last character\n*\n* Example matching strings:\n*\n* - `'{}'`\n* - `'[]'`\n* - `'{adjlkfaj3743.,><\\n\\t\\rdf}'`\n* - `'[adjlkfaj3743.,><\\n\\t\\rdf]'`\n* - `'{\"a\":5}'`\n*\n* @constant\n* @type {RegExp}\n* @default /^\\{[\\s\\S]*\\}$|^\\[[\\s\\S]*\\]$/\n*/\nvar re = /^\\{[\\s\\S]*\\}$|^\\[[\\s\\S]*\\]$/;\n\n\n// MAIN //\n\n/**\n* Tests if a value is a parseable JSON string.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a parseable JSON string\n*\n* @example\n* var v = isJSON( '{\"a\":5}' );\n* // returns true\n*\n* @example\n* var v = isJSON( '{a\":5}' );\n* // returns false\n*/\nfunction isJSON( value ) {\n\tif ( typeof value !== 'string' ) {\n\t\treturn false;\n\t}\n\tif ( !re.test( value ) ) {\n\t\treturn false;\n\t}\n\ttry {\n\t\tJSON.parse( value );\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n\treturn true;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isJSON;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Test if a value is a parseable JSON string.\n*\n* @module @stdlib/assert-is-json\n*\n* @example\n* var isJSON = require( '@stdlib/assert-is-json' );\n*\n* var v = isJSON( '{\"a\":5}' );\n* // returns true\n*\n* v = isJSON( '{a\":5}' );\n* // returns false\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], | ||
| "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAmEA,IAAIC,EAAK,8BAmBT,SAASC,EAAQC,EAAQ,CAIxB,GAHK,OAAOA,GAAU,UAGjB,CAACF,EAAG,KAAME,CAAM,EACpB,MAAO,GAER,GAAI,CACH,KAAK,MAAOA,CAAM,CACnB,OAAUC,EAAM,CACf,MAAO,EACR,CACA,MAAO,EACR,CAKAJ,EAAO,QAAUE,ICnEjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", | ||
| "names": ["require_main", "__commonJSMin", "exports", "module", "re", "isJSON", "value", "err", "main"] | ||
| } |
@@ -35,3 +35,3 @@ /* | ||
| */ | ||
| declare function isJSON( value: any ): value is string; | ||
| declare function isJSON( value: any ): boolean; | ||
@@ -38,0 +38,0 @@ |
+0
-1
@@ -56,3 +56,2 @@ /** | ||
| * | ||
| * | ||
| * Example matching strings: | ||
@@ -59,0 +58,0 @@ * |
+1
-1
| { | ||
| "name": "@stdlib/assert-is-json", | ||
| "version": "0.2.1", | ||
| "version": "0.2.2", | ||
| "description": "Test if a value is a parseable JSON string.", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
+2
-2
@@ -156,4 +156,4 @@ <!-- | ||
| [test-image]: https://github.com/stdlib-js/assert-is-json/actions/workflows/test.yml/badge.svg?branch=v0.2.1 | ||
| [test-url]: https://github.com/stdlib-js/assert-is-json/actions/workflows/test.yml?query=branch:v0.2.1 | ||
| [test-image]: https://github.com/stdlib-js/assert-is-json/actions/workflows/test.yml/badge.svg?branch=v0.2.2 | ||
| [test-url]: https://github.com/stdlib-js/assert-is-json/actions/workflows/test.yml?query=branch:v0.2.2 | ||
@@ -160,0 +160,0 @@ [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/assert-is-json/main.svg |
26523
-0.05%174
-0.57%