css-time-sort
Version:
Sort an array of CSS <time> values
23 lines (22 loc) • 655 B
TypeScript
/**
* Compare two CSS <time> values
* @param {string} a
* @param {string} b
* @returns {number} 0 if equal, smaller than 0 if A is less than B, >0 if A is greater than B. `ms` will be sorted before `s`
* @example
* compare('1s', '2s') // -1
* compare('1000ms', '1s') // 0
*/
export function compare(a: string, b: string): number;
/**
* Convert a time string to ms
* @param {string} time
* @returns {number}
* @example
* convert('1s') // 1000
* convert('1ms') // 1
* convert('+2ms') // 2
* convert('var(--foo)') // Number.MAX_SAFE_INTEGER - 1
* convert('bars') // Number.MAX_SAFE_INTEGER
*/
export function convert(time: string): number;