Some base utils for javascript:
- ecmascript5 shim
- Assert
- Precond
For details, see base.moddef
- Object.keys
- String.prototype.trim
- Array.prototype.filter
- Array.prototype.map
- etc, etc, ...
Inspired by JUnit4's Assert
function getAge(name) {
Assert.present(name, 'name is null'); // assert that name is not undefined or null
}
Assert.between(i, 0, ar.length - 1); // between is inclusive
Assert.equalsIgnoreCase(tagName, 'h3'); // throw an AssertErrorPrecond.check(cond, msg); // if cond is false, throw an ArgumentErrorBoth Assert and Precond have the meaning of "if some condition failed, throw an Error", but they are used in different scenarios.
Assertis used to indicate a program error. The error message is for the programmer (e.g. logged in the console, etc).Precondis used to indicate a user input error. The error message will usually return to the user (e.g. shown in a dialog, etc).
So, Assert will add detail information to the error message, suitable for debug. While Precond do nothing to the error message, leave it as it is.
Build tool is rainy
Build:
RAINY_PATH=~/rainy makeIf you don't want to type "RAINY_PATH=" every time, create a file config.mk:
# you'd better use absolute path
RAINY_PATH=/where/you/install/rainy