UNPKG

ambilighter

Version:

Ambilight around the video, image or canvas HTML elements

29 lines (16 loc) 450 B
export interface ISize { value: number; unit: string; }; export class Size { static parseSize( sizeString: string = '0px' ): ISize | null { const sizeRegex = /^(-?\d+(\.\d+)?)(px|%|em|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc)$/; const match = sizeString.match(sizeRegex); if (match) { const value = parseFloat( match[1] ); const unit = match[3]; return { value, unit }; } return null; } };