aboutsummaryrefslogtreecommitdiffhomepage
path: root/node_modules/better-assert/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/better-assert/index.js')
-rw-r--r--node_modules/better-assert/index.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/node_modules/better-assert/index.js b/node_modules/better-assert/index.js
new file mode 100644
index 0000000..fd1c9b7
--- /dev/null
+++ b/node_modules/better-assert/index.js
@@ -0,0 +1,38 @@
+/**
+ * Module dependencies.
+ */
+
+var AssertionError = require('assert').AssertionError
+ , callsite = require('callsite')
+ , fs = require('fs')
+
+/**
+ * Expose `assert`.
+ */
+
+module.exports = process.env.NO_ASSERT
+ ? function(){}
+ : assert;
+
+/**
+ * Assert the given `expr`.
+ */
+
+function assert(expr) {
+ if (expr) return;
+
+ var stack = callsite();
+ var call = stack[1];
+ var file = call.getFileName();
+ var lineno = call.getLineNumber();
+ var src = fs.readFileSync(file, 'utf8');
+ var line = src.split('\n')[lineno-1];
+ var src = line.match(/assert\((.*)\)/)[1];
+
+ var err = new AssertionError({
+ message: src,
+ stackStartFunction: stack[0].getFunction()
+ });
+
+ throw err;
+}