All files / src/components html-attributes.ts

20% Statements 1/5
0% Branches 0/4
0% Functions 0/1
20% Lines 1/5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22                  1x                        
/**
 * @description This function will ensure that we propertly treat a potential string value for a boolean attribute
 * as the boolean representation
 *
 * @param {string} attributeName Name of the boolean attribute we are normalizing for
 * @param {boolean|string} value Existing value of the boolean html attribute represented as a boolean or string
 *
 * @returns {boolean}
 */
export function normalizeBooleanAttribute(attributeName: string, value: boolean | string): boolean {
  let ret: boolean;
 
  // tslint:disable-next-line
  if (typeof value === 'string') {
    ret = value === '' || value.toLocaleLowerCase() === attributeName.toLocaleLowerCase();
  } else {
    ret = value as boolean;
  }
 
  return ret;
}