Name: js-handler/node_modules/restify/node_modules/assert-plus/README.md
| 1: | # node-assert-plus |
| 2: | |
| 3: | This library is a super small wrapper over node's assert module that has two |
| 4: | things: (1) the ability to disable assertions with the environment variable |
| 5: | NODE_NDEBUG, and (2) some API wrappers for argument testing. Like |
| 6: | `assert.string(myArg, 'myArg')`. As a simple example, most of my code looks |
| 7: | like this: |
| 8: | |
| 9: | var assert = require('assert-plus'); |
| 10: | |
| 11: | function fooAccount(options, callback) { |
| 12: | assert.object(options, 'options'); |
| 13: | assert.number(options.id, 'options.id); |
| 14: | assert.bool(options.isManager, 'options.isManager'); |
| 15: | assert.string(options.name, 'options.name'); |
| 16: | assert.arrayOfString(options.email, 'options.email'); |
| 17: | assert.func(callback, 'callback'); |
| 18: | |
| 19: | // Do stuff |
| 20: | callback(null, {}); |
| 21: | } |
| 22: | |
| 23: | # API |
| 24: | |
| 25: | All methods that *aren't* part of node's core assert API are simply assumed to |
| 26: | take an argument, and then a string 'name' that's not a message; `AssertionError` |
| 27: | will be thrown if the assertion fails with a message like: |
| 28: | |
| 29: | AssertionError: foo (string) is required |
| 30: | at test (/home/mark/work/foo/foo.js:3:9) |
| 31: | at Object.<anonymous> (/home/mark/work/foo/foo.js:15:1) |
| 32: | at Module._compile (module.js:446:26) |
| 33: | at Object..js (module.js:464:10) |
| 34: | at Module.load (module.js:353:31) |
| 35: | at Function._load (module.js:311:12) |
| 36: | at Array.0 (module.js:484:10) |
| 37: | at EventEmitter._tickCallback (node.js:190:38) |
| 38: | |
| 39: | from: |
| 40: | |
| 41: | function test(foo) { |
| 42: | assert.string(foo, 'foo'); |
| 43: | } |
| 44: | |
| 45: | There you go. You can check that arrays are of a homogenous type with `Arrayof$Type`: |
| 46: | |
| 47: | function test(foo) { |
| 48: | assert.arrayOfString(foo, 'foo'); |
| 49: | } |
| 50: | |
| 51: | You can assert IFF an argument is not `undefined` (i.e., an optional arg): |
| 52: | |
| 53: | assert.optionalString(foo, 'foo'); |
| 54: | |
| 55: | Lastly, you can opt-out of assertion checking altogether by setting the |
| 56: | environment variable `NODE_NDEBUG=1`. This is pseudo-useful if you have |
| 57: | lots of assertions, and don't want to pay `typeof ()` taxes to v8 in |
| 58: | production. |
| 59: | |
| 60: | The complete list of APIs is: |
| 61: | |
| 62: | * assert.bool |
| 63: | * assert.buffer |
| 64: | * assert.func |
| 65: | * assert.number |
| 66: | * assert.object |
| 67: | * assert.string |
| 68: | * assert.arrayOfBool |
| 69: | * assert.arrayOfFunc |
| 70: | * assert.arrayOfNumber |
| 71: | * assert.arrayOfObject |
| 72: | * assert.arrayOfString |
| 73: | * assert.optionalBool |
| 74: | * assert.optionalBuffer |
| 75: | * assert.optionalFunc |
| 76: | * assert.optionalNumber |
| 77: | * assert.optionalObject |
| 78: | * assert.optionalString |
| 79: | * assert.optionalArrayOfBool |
| 80: | * assert.optionalArrayOfFunc |
| 81: | * assert.optionalArrayOfNumber |
| 82: | * assert.optionalArrayOfObject |
| 83: | * assert.optionalArrayOfString |
| 84: | * assert.AssertionError |
| 85: | * assert.fail |
| 86: | * assert.ok |
| 87: | * assert.equal |
| 88: | * assert.notEqual |
| 89: | * assert.deepEqual |
| 90: | * assert.notDeepEqual |
| 91: | * assert.strictEqual |
| 92: | * assert.notStrictEqual |
| 93: | * assert.throws |
| 94: | * assert.doesNotThrow |
| 95: | * assert.ifError |
| 96: | |
| 97: | # Installation |
| 98: | |
| 99: | npm install assert-plus |
| 100: | |
| 101: | ## License |
| 102: | |
| 103: | The MIT License (MIT) |
| 104: | Copyright (c) 2012 Mark Cavage |
| 105: | |
| 106: | Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 107: | this software and associated documentation files (the "Software"), to deal in |
| 108: | the Software without restriction, including without limitation the rights to |
| 109: | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
| 110: | the Software, and to permit persons to whom the Software is furnished to do so, |
| 111: | subject to the following conditions: |
| 112: | |
| 113: | The above copyright notice and this permission notice shall be included in all |
| 114: | copies or substantial portions of the Software. |
| 115: | |
| 116: | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 117: | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 118: | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 119: | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 120: | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 121: | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 122: | SOFTWARE. |
| 123: | |
| 124: | ## Bugs |
| 125: | |
| 126: | See <https://github.com/mcavage/node-assert-plus/issues>. |
