Skip to content

njflynn/dbc

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dbc - Design by Contract module

Design By Contract (DBC) utility module which allows for precise and verifiable interface specification. This modules functions can be used at the entry point of a function to verify that the incoming data/message has the required fields. If an assertion fails an exception is thrown and the program is exited (failing early helps identify bugs).

Getting Started

Install the module with: npm install dbc

var dbc = require('dbc');
dbc.assert(null !== msg, errorMessage)

The dbc.assert function checks that a statement equates to true or false and throws an exception with the message if it doesn't.

dbc.hasMember(object, 'action')

The dbc.hasMember function takes two parameters: 1) a JavaScript object and 2) a member name as a string. It throws and exception if the object doesn't contains the member.

Conributors

Donal McCarthy ([email protected]) David Benson ([email protected])

Examples

var dbc = require('dbc');
var obj = {age:99}

dbc.assert   (null !== obj, "Message cannot be null")
dbc.hasMember(obj, 'age')

Release History

0.1.0 (23/10/14 [email protected] [email protected]) Includes assert and hasMember functions

License

Copyright (c) 2013 Licensed under the MIT license.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published