Giter VIP home page Giter VIP logo

http-assert's Introduction

http-assert

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

Assert with status codes. Like ctx.throw() in Koa, but with a guard.

Install

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install http-assert

Example

var assert = require('http-assert')
var ok = require('assert')

var username = 'foobar' // username from request

try {
  assert(username === 'fjodor', 401, 'authentication failed')
} catch (err) {
  ok(err.status === 401)
  ok(err.message === 'authentication failed')
  ok(err.expose)
}

API

The API of this module is intended to be similar to the Node.js assert module.

Each function will throw an instance of HttpError from the http-errors module when the assertion fails.

assert(value, [status], [message], [properties])

Tests if value is truthy. If value is not truthy, an HttpError is thrown that is constructed with the given status, message, and properties.

assert.deepEqual(a, b, [status], [message], [properties])

Tests for deep equality between a and b. Primitive values are compared with the Abstract Equality Comparison (==). If a and b are not equal, an HttpError is thrown that is constructed with the given status, message, and properties.

assert.equal(a, b, [status], [message], [properties])

Tests shallow, coercive equality between a and b using the Abstract Equality Comparison (==). If a and b are not equal, an HttpError is thrown that is constructed with the given status, message, and properties.

assert.fail([status], [message], [properties])

Always throws an HttpError that is constructed with the given status, message, and properties.

assert.notDeepEqual(a, b, [status], [message], [properties])

Tests for deep equality between a and b. Primitive values are compared with the Abstract Equality Comparison (==). If a and b are equal, an HttpError is thrown that is constructed with the given status, message, and properties.

assert.notEqual(a, b, [status], [message], [properties])

Tests shallow, coercive equality between a and b using the Abstract Equality Comparison (==). If a and b are equal, an HttpError is thrown that is constructed with the given status, message, and properties.

assert.notStrictEqual(a, b, [status], [message], [properties])

Tests strict equality between a and b as determined by the SameValue Comparison (===). If a and b are equal, an HttpError is thrown that is constructed with the given status, message, and properties.

assert.ok(value, [status], [message], [properties])

Tests if value is truthy. If value is not truthy, an HttpError is thrown that is constructed with the given status, message, and properties.

assert.strictEqual(a, b, [status], [message], [properties])

Tests strict equality between a and b as determined by the SameValue Comparison (===). If a and b are not equal, an HttpError is thrown that is constructed with the given status, message, and properties.

Licence

MIT

http-assert's People

Contributors

dead-horse avatar dougwilson avatar eivindfjeldstad avatar jdrydn avatar jonathanong avatar remcohaszing avatar vendethiel avatar zhuangya avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.