1.0.3 • Published 8 years ago

smooth-operator v1.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

Javascript operators as functions

var o = require('smooth-operator')
// o(operator, y)(x) === x operator y
o('+', 1)(2)
// returns 3
[1, 2, 3].map(o('+', 1))
// returns [2, 3, 4]
//supported operators
[
  '++',
  '--',
  'typeof',
  '+',
  '-',
  '~',
  '!',
  '/',
  '*',
  '%',
  'in',
  'instanceof',
  '<',
  '>',
  '<=',
  '>=',
  '==',
  '!=',
  '===',
  '!==',
  '<<',
  '>>',
  '>>>',
  '&',
  '|',
  '^',
  '&&',
  '||',
  '=',
  '*=',
  '/=',
  '%=',
  '+=',
  '-=',
  '<<=',
  '>>=',
  '>>>=',
  '&=',
  '^=',
  '|=',
  ','
]
OperatorExpressionExample
Increment++xo('++')(1) === 2
Decrement--xo('--')(1) === 2
Typeoftypeof xo('typeof')(1) === 'number'
Unary plus+xo('+')('1') === 1
Unary negation-xo('-')('1') === -1
Additionx + yo('+', 2)(1) === 3
1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

9 years ago