is-json-promise
v1.0.7
Published
Check if string is JSON basing on PROMISE instead of TRY-CATCH
Downloads
17
Maintainers
Readme
Use
import 'is-json-promise';
// or: require('is-json-promise')
String.IsJSON(`iam here`)
.then((object) => console.info(object))
.catch((error) => alert('Waww, i cannot be JSON')) ; // promise will run catch
or
import 'is-json-promise';
String.IsJSON(`{"welcome":"Hello"}`)
.then((object) => console.info(object)) // promise will run "then"
.catch((error) => alert('Waww, i cannot be JSON')) ;
Safe import :
It will not extend the String
class with a static method , but it will give you this method as a function :
import {IsJSON} from 'is-json-promise/safe';
//or: const {IsJSON}= require("is-json-promise/safe");
IsJSON(`{"welcome":"Hello"}`)
.then((object) => console.info(object)) // promise will run "then"
.catch((error) => alert('Waww, i cannot be JSON')) ;