- Notifications
You must be signed in to change notification settings - Fork22
c-style assert() for nodejs, reporting the expression string as the error message
License
tj/better-assert
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Better c-style assertions usingcallsite forself-documenting failure messages.
$ npm install better-assert
By default assertions are enabled, however theNO_ASSERT environment variablewill deactivate them when truthy.
varassert=require('better-assert');test();functiontest(){varuser={name:'tobi'};assert('tobi'==user.name);assert('number'==typeofuser.age);}AssertionError:'number'==typeofuser.ageattest(/Users/tj/projects/better-assert/example.js:9:3)atObject.<anonymous>(/Users/tj/projects/better-assert/example.js:4:1)atModule._compile(module.js:449:26)atObject.Module._extensions..js(module.js:467:10)atModule.load(module.js:356:32)atFunction.Module._load(module.js:312:12)atModule.runMain(module.js:492:10)atprocess.startup.processNextTick.process._tickCallback(node.js:244:9)
See this fork for use in the browser:https://github.com/devinrhode2/better-assert-browser
(The MIT License)
Copyright (c) 2012 TJ Holowaychuk <tj@vision-media.ca>
Permission is hereby granted, free of charge, to any person obtaininga copy of this software and associated documentation files (the'Software'), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sublicense, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:
The above copyright notice and this permission notice shall beincluded 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 OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANYCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THESOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
About
c-style assert() for nodejs, reporting the expression string as the error message