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.

60 lines
2.1 KiB

4 years ago
  1. # better-assert
  2. Better c-style assertions using [callsite](https://github.com/visionmedia/callsite) for
  3. self-documenting failure messages.
  4. ## Installation
  5. $ npm install better-assert
  6. ## Example
  7. By default assertions are enabled, however the __NO_ASSERT__ environment variable
  8. will deactivate them when truthy.
  9. ```js
  10. var assert = require('better-assert');
  11. test();
  12. function test() {
  13. var user = { name: 'tobi' };
  14. assert('tobi' == user.name);
  15. assert('number' == typeof user.age);
  16. }
  17. AssertionError: 'number' == typeof user.age
  18. at test (/Users/tj/projects/better-assert/example.js:9:3)
  19. at Object.<anonymous> (/Users/tj/projects/better-assert/example.js:4:1)
  20. at Module._compile (module.js:449:26)
  21. at Object.Module._extensions..js (module.js:467:10)
  22. at Module.load (module.js:356:32)
  23. at Function.Module._load (module.js:312:12)
  24. at Module.runMain (module.js:492:10)
  25. at process.startup.processNextTick.process._tickCallback (node.js:244:9)
  26. ```
  27. ## License
  28. (The MIT License)
  29. Copyright (c) 2012 TJ Holowaychuk &lt;tj@vision-media.ca&gt;
  30. Permission is hereby granted, free of charge, to any person obtaining
  31. a copy of this software and associated documentation files (the
  32. 'Software'), to deal in the Software without restriction, including
  33. without limitation the rights to use, copy, modify, merge, publish,
  34. distribute, sublicense, and/or sell copies of the Software, and to
  35. permit persons to whom the Software is furnished to do so, subject to
  36. the following conditions:
  37. The above copyright notice and this permission notice shall be
  38. included in all copies or substantial portions of the Software.
  39. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
  40. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  41. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  42. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  43. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  44. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  45. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.