@annoai/js-decode-if-json

A helper method that decodes a value if json else defaults to an input value.

Usage no npm install needed!

<script type="module">
  import annoaiJsDecodeIfJson from 'https://cdn.skypack.dev/@annoai/js-decode-if-json';
</script>

README

js-decode-if-json

A helper method that decodes a value if json else defaults to an input value.

const test = decodeIfJson('Hello World', { defaultValue: 'Hello World Default' });
console.log(test); // { defaultValue: 'Hello World Default' }