UNPKG

color-fns

Version:

Modern JavaScript color utility library.

23 lines 868 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function parseRgb(value) { if (typeof value !== 'string') { return null; } // will consider rgb/rgba color prefix as a valid input color // while the output will be a valid web colors // valid input colors examples 'rgb(100, 0, 0, 0.5)', 'rgba(0, 0, 0)' // the output for the inputted examples 'rgba(100, 0, 0, 0.5)', 'rgb(0, 0, 0)' var match = value.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,*\s*(\d*(?:\.\d+)*)*\)/i); if (!match || match.length < 4) { return null; } return { alpha: typeof match[4] !== 'undefined' ? Number(match[4]) : undefined, blue: Number(match[3]), green: Number(match[2]), red: Number(match[1]) }; } exports.parseRgb = parseRgb; //# sourceMappingURL=parseRgb.js.map