Skip to content

Commit 3aab507

Browse files
committed
Feat: add 'isJSON' util function
1 parent 111e6f3 commit 3aab507

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

src/utils.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -346,16 +346,30 @@ var domToString = function(d) {
346346
return tmp.innerHTML;
347347
};
348348

349-
var logError = function(message, options){
350-
if(!options) options = {};
351-
var component = "Selectize";
349+
var logError = function (message, options) {
350+
if (!options) options = {};
351+
var component = "Selectize";
352352

353-
console.error(component + ": " + message)
353+
console.error(component + ": " + message)
354354

355-
if(options.explanation){
356-
// console.group is undefined in <IE11
357-
if(console.group) console.group();
358-
console.error(options.explanation);
359-
if(console.group) console.groupEnd();
360-
}
361-
}
355+
if (options.explanation) {
356+
// console.group is undefined in <IE11
357+
if (console.group) console.group();
358+
console.error(options.explanation);
359+
if (console.group) console.groupEnd();
360+
}
361+
};
362+
363+
/**
364+
*
365+
* @param {any} data Data to testing
366+
* @returns {Boolean} true if is an JSON object
367+
*/
368+
var isJSON = function (data) {
369+
try {
370+
JSON.parse(str);
371+
} catch (e) {
372+
return false;
373+
}
374+
return true;
375+
};

0 commit comments

Comments
 (0)