unit method

Dimension unit (
  1. Node val,
  2. [Node unit]
)

Remove or change the unit of a dimension

Parameters: dimension: A number, with or without a dimension. unit: (Optional) the unit to change to, or if omitted it will remove the unit. Example: unit(5, px) Output: 5px

Implementation

Dimension unit(Node val, [Node unit]) {
  String unitValue;

  if (val is! Dimension) {
    final p = val is Operation ? '. Have you forgotten parenthesis?' : '';
    throw LessExceptionError(LessError(
        type: 'Argument',
        message: 'the first argument to unit must be a number$p'));
  }

  if (unit != null) {
    unitValue = unit is Keyword ? unit.value : unit.toCSS(null);
  } else {
    unitValue = '';
  }
  return Dimension(val.value, unitValue);

//2.4.0
//  unit: function (val, unit) {
//      if (!(val instanceof Dimension)) {
//          throw { type: "Argument",
//              message: "the first argument to unit must be a number" +
//                  (val instanceof Operation ? ". Have you forgotten parenthesis?" : "") };
//      }
//      if (unit) {
//          if (unit instanceof Keyword) {
//              unit = unit.value;
//          } else {
//              unit = unit.toCSS();
//          }
//      } else {
//          unit = "";
//      }
//      return new Dimension(val.value, unit);
//  },
}