turns js operators into delicious first-class functions
Turn js operators into delicious first-class functions.
var lift = require'op-lift';1 2 3 4reducelift'+' //= 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 = require'op-lift';1 2 3 4reducelift'*' //= 24;true false truemaplift'!' //= [ false, true, false ];Object Array Functionmaplift'new'maplift'typeof' //= [ 'object', 'object', 'function' ]
It's safe to use with arbitrary strings, too, since lift will simply return
null for unrecognised operators:
lift'; console.log(a), a +' //= null
The supported operators are:
void typeof ++ -- + - ~ ! new
* / % + - << >> >>> < > <= >= instanceof in == != === !== & ^ | || && . ,
Since the resulting functions simply accept values as arguments, no short-circuiting can be done:
lift'||'false alert'BOO' // an alert still shows up with 'BOO'
Any operator that affects a variables' value won't in its lifted form:
var a = 0lift'++'a // 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: