unit.js 472 B

1234567891011121314151617181920212223
  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. module.exports = 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. };