simple-color-functions
Version:
A set of simple color functions.
14 lines (11 loc) • 404 B
text/typescript
import { IRgb } from '../types';
import { convertFromShortNotation } from './convertFromShortNotation';
export const hex2rgb = (hex: string): IRgb => {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(convertFromShortNotation(hex)) || [];
return {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16),
a: 1
};
};