Hi all,

Precond is a small library inspired by Guava's precondition checking 
utilities<https://code.google.com/p/guava-libraries/wiki/PreconditionsExplained>.
 
It provides the same basic API plus some additions relevant to a 
dynamically typed language like Javascript. It also leverages some of 
Javascript's introspection capabilities to generate stack traces starting 
from the precondition check itself, i.e. the same stack trace that would be 
generated by a plain throw statement.

Here's a simple example.

function div(a, b) {
>   precond.checkArgument(b != 0, 'Expected denominator != 0 but was %s.', 
> b);
>   return a / b;
> }


The following precondition checks are provided.

   - checkArgument(expression, [messageFormat, [formatArgs, ...]])
   - checkState(expression, [messageFormat, [formatArgs, ...]])
   - checkIsDef(expression, [messageFormat, [formatArgs, ...]])
   - checkIsDefAndNotNull(expression, [messageFormat, [formatArgs, ...]])
   - checkIsString(expression, [messageFormat, [formatArgs, ...]])
   - checkIsArray(expression, [messageFormat, [formatArgs, ...]])
   - checkIsNumber(expression, [messageFormat, [formatArgs, ...]])
   - checkIsBoolean(expression, [messageFormat, [formatArgs, ...]])
   - checkIsFunction(expression, [messageFormat, [formatArgs, ...]])
   - checkIsObject(expression, [messageFormat, [formatArgs, ...]])

The documentation, source code and examples can be found on Github. As 
usual, the module can be installed from npm.

   - https://github.com/MathieuTurcotte/node-precond
   - https://npmjs.org/package/precond
   
Simple, but hopefully useful stuff.

Cheers,
Mathieu

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to