Turn js operators into delicious first-class functions.
var lift =;1 2 3 4 //= 10
install via npm:
npm install op-lift
cd node_modules/op-lift && npm test
Requires an es5, or es5-shim for older engines.
lift takes a string representing an operator, and returns a function that performs the same job.
var lift =;1 2 3 4 //= 24;true false true //= [ false, true, false ];Object Array Function //= [ 'object', 'object', 'function' ]
It's safe to use with arbitrary strings, too, since lift will simply return
null for unrecognised operators:
The supported operators are:
void typeof ++ -- + - ~ ! new
* / % + - << >> >>> < > <= >= instanceof in == != === !== & ^ | || && . ,
Since the resulting functions simply accept values as arguments, no short-circuiting can be done:
false // an alert still shows up with 'BOO'
Any operator that affects a variables' value won't in its lifted form:
var a = 0a // 1a // 0
Since the primary difference between operators and functions is that functions are first class, op-lift works very well with libraries heavy on the higher-order functions, including: