twitst4tz

twitter statistics web application
Log | Files | Refs | README | LICENSE

index.js (694B)


      1 /**
      2  * Module dependencies.
      3  */
      4 
      5 var AssertionError = require('assert').AssertionError
      6   , callsite = require('callsite')
      7   , fs = require('fs')
      8 
      9 /**
     10  * Expose `assert`.
     11  */
     12 
     13 module.exports = process.env.NO_ASSERT
     14   ? function(){}
     15   : assert;
     16 
     17 /**
     18  * Assert the given `expr`.
     19  */
     20 
     21 function assert(expr) {
     22   if (expr) return;
     23 
     24   var stack = callsite();
     25   var call = stack[1];
     26   var file = call.getFileName();
     27   var lineno = call.getLineNumber();
     28   var src = fs.readFileSync(file, 'utf8');
     29   var line = src.split('\n')[lineno-1];
     30   var src = line.match(/assert\((.*)\)/)[1];
     31 
     32   var err = new AssertionError({
     33     message: src,
     34     stackStartFunction: stack[0].getFunction()
     35   });
     36 
     37   throw err;
     38 }