@exadel/esl
Version:
Exadel Smart Library (ESL) is the lightweight custom elements library that provide a set of super-flexible components
29 lines (28 loc) • 823 B
JavaScript
/**
* Common function that returns coefficient aspect ratio
* Supported formats: w:h, w/h, coefficient
* @example
* `16:9`, `16/9`, `1.77`
* @param str - string to parse
* @returns aspect ratio coefficient
*/
export function parseAspectRatio(str) {
const [w, h] = str.split(/[:/]/);
if (typeof h !== 'undefined')
return +w / +h;
return +w || 0;
}
/**
* Common parser for lazy attribute. Case insensitive. Note:
* - empty string or unknown values are treated as `auto`.
* - `null` (or non string objects) is treated as `none`.
* - `manual` or `none` are treated as it is
*/
export function parseLazyAttr(value) {
if (typeof value !== 'string')
return 'none';
const v = value.trim().toLowerCase();
if (v === 'none' || v === 'manual')
return v;
return 'auto';
}