unit.js 509 B

12345678910111213141516171819202122232425
  1. var utils = require('../utils')
  2. , nodes = require('../nodes');
  3. /**
  4. * Assign `type` to the given `unit` or return `unit`'s type.
  5. *
  6. * @param {Unit} unit
  7. * @param {String|Ident} type
  8. * @return {Unit}
  9. * @api public
  10. */
  11. function unit(unit, type){
  12. utils.assertType(unit, 'unit', 'unit');
  13. // Assign
  14. if (type) {
  15. utils.assertString(type, 'type');
  16. return new nodes.Unit(unit.val, type.string);
  17. } else {
  18. return unit.type || '';
  19. }
  20. }
  21. unit.params = ['unit', 'type'];
  22. module.exports = unit;