isValidUnit = (attr, val, selectedElement) => {
  if (unitAttrs.includes(attr)) {
    // True if it's just a number
    if (!isNaN(val)) {
      return true
    }
    // Not a number, check if it has a valid unit
    val = val.toLowerCase()
    return Object.keys(typeMap_).some((unit) => {
      const re = new RegExp('^-?[\\d\\.]+' + unit + '$')
      return re.test(val)
    })
  }
  if (attr === 'id') {
    // if we're trying to change the id, make sure it's not already present in the doc
    // and the id value is valid.

    let result = false
    // because getElement() can throw an exception in the case of an invalid id
    // (according to https://www.w3.org/TR/xml-id/ IDs must be a NCName)
    // we wrap it in an exception and only return true if the ID was valid and
    // not already present
    try {
      const elem = elementContainer_.getElement(val)
      result = (!elem || elem === selectedElement)
    } catch (e) { console.error(e) }
    return result
  }
  return true
}
Check if an attribute's value is in a valid format.
@function module:units.isValidUnit
@param {string} attr - The name of the attribute associated with the value
@param {string} val - The attribute value to check
@param {Element} selectedElement
@returns {boolean} Whether the unit is valid