Dieses Repository beinhaltet HTML- und Javascript Code zur einer NotizenWebApp auf Basis von Web Storage. Zudem sind Mocha/Chai Tests im Browser enthalten. https://meinenotizen.netlify.app/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 5.8KB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <h1 align=center>
  2. <a href="http://chaijs.com" title="Chai Documentation">
  3. <img alt="ChaiJS" src="http://chaijs.com/img/chai-logo.png"/> check-error
  4. </a>
  5. </h1>
  6. <p align=center>
  7. Error comparison and information related utility for <a href="http://nodejs.org">node</a> and the browser.
  8. </p>
  9. <p align=center>
  10. <a href="./LICENSE">
  11. <img
  12. alt="license:mit"
  13. src="https://img.shields.io/badge/license-mit-green.svg?style=flat-square"
  14. />
  15. </a>
  16. <a href="https://github.com/chaijs/check-error/releases">
  17. <img
  18. alt="tag:?"
  19. src="https://img.shields.io/github/tag/chaijs/check-error.svg?style=flat-square"
  20. />
  21. </a>
  22. <a href="https://travis-ci.org/chaijs/check-error">
  23. <img
  24. alt="build:?"
  25. src="https://img.shields.io/travis/chaijs/check-error/master.svg?style=flat-square"
  26. />
  27. </a>
  28. <a href="https://coveralls.io/r/chaijs/check-error">
  29. <img
  30. alt="coverage:?"
  31. src="https://img.shields.io/coveralls/chaijs/check-error/master.svg?style=flat-square"
  32. />
  33. </a>
  34. <a href="https://www.npmjs.com/packages/check-error">
  35. <img
  36. alt="npm:?"
  37. src="https://img.shields.io/npm/v/check-error.svg?style=flat-square"
  38. />
  39. </a>
  40. <a href="https://www.npmjs.com/packages/check-error">
  41. <img
  42. alt="dependencies:?"
  43. src="https://img.shields.io/npm/dm/check-error.svg?style=flat-square"
  44. />
  45. </a>
  46. <a href="">
  47. <img
  48. alt="devDependencies:?"
  49. src="https://img.shields.io/david/chaijs/check-error.svg?style=flat-square"
  50. />
  51. </a>
  52. <br/>
  53. <a href="https://saucelabs.com/u/chaijs-check-error">
  54. <img
  55. alt="Selenium Test Status"
  56. src="https://saucelabs.com/browser-matrix/chaijs-check-error.svg"
  57. />
  58. </a>
  59. <br>
  60. <a href="https://chai-slack.herokuapp.com/">
  61. <img
  62. alt="Join the Slack chat"
  63. src="https://img.shields.io/badge/slack-join%20chat-E2206F.svg?style=flat-square"
  64. />
  65. </a>
  66. <a href="https://gitter.im/chaijs/chai">
  67. <img
  68. alt="Join the Gitter chat"
  69. src="https://img.shields.io/badge/gitter-join%20chat-D0104D.svg?style=flat-square"
  70. />
  71. </a>
  72. </p>
  73. ## What is Check-Error?
  74. Check-Error is a module which you can use to retrieve an Error's information such as its `message` or `constructor` name and also to check whether two Errors are compatible based on their messages, constructors or even instances.
  75. ## Installation
  76. ### Node.js
  77. `check-error` is available on [npm](http://npmjs.org). To install it, type:
  78. $ npm install check-error
  79. ### Browsers
  80. You can also use it within the browser; install via npm and use the `check-error.js` file found within the download. For example:
  81. ```html
  82. <script src="./node_modules/check-error/check-error.js"></script>
  83. ```
  84. ## Usage
  85. The primary export of `check-error` is an object which has the following methods:
  86. * `compatibleInstance(err, errorLike)` - Checks if an error is compatible with another `errorLike` object. If `errorLike` is an error instance we do a strict comparison, otherwise we return `false` by default, because instances of objects can only be compatible if they're both error instances.
  87. * `compatibleConstructor(err, errorLike)` - Checks if an error's constructor is compatible with another `errorLike` object. If `err` has the same constructor as `errorLike` or if `err` is an instance of `errorLike`.
  88. * `compatibleMessage(err, errMatcher)` - Checks if an error message is compatible with an `errMatcher` RegExp or String (we check if the message contains the String).
  89. * `getConstructorName(errorLike)` - Retrieves the name of a constructor, an error's constructor or `errorLike` itself if it's not an error instance or constructor.
  90. * `getMessage(err)` - Retrieves the message of an error or `err` itself if it's a String. If `err` or `err.message` is undefined we return an empty String.
  91. ```js
  92. var checkError = require('check-error');
  93. ```
  94. #### .compatibleInstance(err, errorLike)
  95. ```js
  96. var checkError = require('check-error');
  97. var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
  98. var caughtErr;
  99. try {
  100. funcThatThrows();
  101. } catch(e) {
  102. caughtErr = e;
  103. }
  104. var sameInstance = caughtErr;
  105. checkError.compatibleInstance(caughtErr, sameInstance); // true
  106. checkError.compatibleInstance(caughtErr, new TypeError('Another error')); // false
  107. ```
  108. #### .compatibleConstructor(err, errorLike)
  109. ```js
  110. var checkError = require('check-error');
  111. var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
  112. var caughtErr;
  113. try {
  114. funcThatThrows();
  115. } catch(e) {
  116. caughtErr = e;
  117. }
  118. checkError.compatibleConstructor(caughtErr, Error); // true
  119. checkError.compatibleConstructor(caughtErr, TypeError); // true
  120. checkError.compatibleConstructor(caughtErr, RangeError); // false
  121. ```
  122. #### .compatibleMessage(err, errMatcher)
  123. ```js
  124. var checkError = require('check-error');
  125. var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
  126. var caughtErr;
  127. try {
  128. funcThatThrows();
  129. } catch(e) {
  130. caughtErr = e;
  131. }
  132. var sameInstance = caughtErr;
  133. checkError.compatibleMessage(caughtErr, /TypeError$/); // true
  134. checkError.compatibleMessage(caughtErr, 'I am a'); // true
  135. checkError.compatibleMessage(caughtErr, /unicorn/); // false
  136. checkError.compatibleMessage(caughtErr, 'I do not exist'); // false
  137. ```
  138. #### .getConstructorName(errorLike)
  139. ```js
  140. var checkError = require('check-error');
  141. var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
  142. var caughtErr;
  143. try {
  144. funcThatThrows();
  145. } catch(e) {
  146. caughtErr = e;
  147. }
  148. var sameInstance = caughtErr;
  149. checkError.getConstructorName(caughtErr) // 'TypeError'
  150. ```
  151. #### .getMessage(err)
  152. ```js
  153. var checkError = require('check-error');
  154. var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
  155. var caughtErr;
  156. try {
  157. funcThatThrows();
  158. } catch(e) {
  159. caughtErr = e;
  160. }
  161. var sameInstance = caughtErr;
  162. checkError.getMessage(caughtErr) // 'I am a TypeError'
  163. ```