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