API 1.0.1

bar
math
add
abs
utils/string
foo

bar

Returns "bar"

function bar
function bar() {
  return 'bar';
}

add

Returns the sum of two numbers

sample add usage
// typical use
// var add = require('xplain').add;
// have to use relative paths inside the module
var add = require('../src/add').add;
add(2, 3); // 5
edge cases
// add is a function
// add is a function that expects 2 arguments
add(2, 3); // returns a number
add(0, 1); // returns truthy value
add('a', 'b'); // 'ab'
functionality
gt.test('functionality', function() {
  gt.func(add, 'add is a function');
  gt.arity(add, 2, 'expects two arguments');
  gt.equal(add(1, 4), 5, '1 + 4 = 5');
  gt.equal(add(-1, 1), 0, '-1 + 1 = 0');
  gt.equal(add(1, 10), add(10, 1), 'order does not matter');
});
add as concatenate
gt.test('add as concatenate', function() {
  gt.equal(add('a', 0), 'a0', 'result is string if first arg is string');
  gt.equal(add(6, '3'), '63', 'result is number of second arg is a number');
});
function add
function add(a, b) {
  console.assert(a !== undefined, 'missing first argument');
  console.assert(b !== undefined, 'missing second argument');
  return a + b;
}

abs

Returns the absolute value

using abs
abs(10); // 10
abs(-15); // 15
abs(0); // 0
function abs
function abs(a) {
  return a >= 0 ? a : -a;
}

foo

Returns "foo"

function foo
function foo() {
  return 'foo';
}
xplained on Wednesday, April 24th 2013, 11:19:52 pm