protective

🥽 Runtime protective gear

Usage no npm install needed!

<script type="module">
  import protective from 'https://cdn.skypack.dev/protective';
</script>

README

protective

🥽 Runtime protective gear

stringify

Resort to simple string conversion when JSON.stringify fails

import { stringify } from 'protective';

const something = { key: 'Balue' };
something.circular = something;

JSON.stringify(something, null, 2); // TypeError: Converting circular structure to JSON
stringify(something, null, 2); // '[object Object]'

verbose

Add arguments to function error messages

import { verbose } from 'protective';

function myFunction() {
  throw new Error('This is an error');
}

myFunction('one', 'two'); // Error: This is an error

verbose(myFunction)('one', 'two'); // Error: This is an error. Arguments: "one", "two"