Skip to content

Commit

Permalink
Feat: add 'isJSON' util function
Browse files Browse the repository at this point in the history
  • Loading branch information
fabienwnklr committed Oct 6, 2022
1 parent 111e6f3 commit 3aab507
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,16 +346,30 @@ var domToString = function(d) {
return tmp.innerHTML;
};

var logError = function(message, options){
if(!options) options = {};
var component = "Selectize";
var logError = function (message, options) {
if (!options) options = {};
var component = "Selectize";

console.error(component + ": " + message)
console.error(component + ": " + message)

if(options.explanation){
// console.group is undefined in <IE11
if(console.group) console.group();
console.error(options.explanation);
if(console.group) console.groupEnd();
}
}
if (options.explanation) {
// console.group is undefined in <IE11
if (console.group) console.group();
console.error(options.explanation);
if (console.group) console.groupEnd();
}
};

/**
*
* @param {any} data Data to testing
* @returns {Boolean} true if is an JSON object
*/
var isJSON = function (data) {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
};

0 comments on commit 3aab507

Please sign in to comment.