math.js 379 B

12345678910111213141516171819
  1. var utils = require('../utils')
  2. , nodes = require('../nodes');
  3. /**
  4. * Apply Math `fn` to `n`.
  5. *
  6. * @param {Unit} n
  7. * @param {String} fn
  8. * @return {Unit}
  9. * @api private
  10. */
  11. function math(n, fn){
  12. utils.assertType(n, 'unit', 'n');
  13. utils.assertString(fn, 'fn');
  14. return new nodes.Unit(Math[fn.string](n.val), n.type);
  15. }
  16. math.params = ['n', 'fn'];
  17. module.exports = math;