Skip to content

Instantly share code, notes, and snippets.

@graingert
Last active March 30, 2017 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save graingert/fe69a837a4f7a3aafcebbb87d7062c7a to your computer and use it in GitHub Desktop.
Save graingert/fe69a837a4f7a3aafcebbb87d7062c7a to your computer and use it in GitHub Desktop.
iserror.js

This file is dual licensed under the MIT and CC0, you may use it under either the MIT license or the CC0.

function isError(value) {
var tag = ({}).toString.call(value);
switch (tag) {
case '[object Error]': return true;
case '[object Exception]': return true;
case '[object DOMException]': return true;
default: return value instanceof Error;
}
}
The MIT License (MIT)
Copyright (c) 2016 Thomas Grainger.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
<p xmlns:dct="http://purl.org/dc/terms/" xmlns:vcard="http://www.w3.org/2001/vcard-rdf/3.0#">
<a rel="license"
href="http://creativecommons.org/publicdomain/zero/1.0/">
<img src="http://i.creativecommons.org/p/zero/1.0/88x31.png" style="border-style: none;" alt="CC0" />
</a>
<br />
To the extent possible under law,
<a rel="dct:publisher"
href="https://gist.github.com/graingert/fe69a837a4f7a3aafcebbb87d7062c7a">
<span property="dct:title">Thomas A. Grainger</span></a>
has waived all copyright and related or neighboring rights to
<span property="dct:title">iserrror.js</span>.
This work is published from:
<span property="vcard:Country" datatype="dct:ISO3166"
content="GB" about="https://gist.github.com/graingert/fe69a837a4f7a3aafcebbb87d7062c7a">
United Kingdom</span>.
</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment