UNPKG

color-to-vec4

Version:

:white_square_button: a color (rgb, rgba, hex) to vec4 convertor

30 lines (20 loc) 1 kB
'use strict'; exports.__esModule = true; var _rgbToVec = require('./lib/rgbToVec4'); var _rgbToVec2 = _interopRequireDefault(_rgbToVec); var _hexToVec = require('./lib/hexToVec4'); var _hexToVec2 = _interopRequireDefault(_hexToVec); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } exports.default = function (color) { if (typeof color === 'string') { if (color.startsWith('rgba')) return (0, _rgbToVec2.default)(color);else if (color.startsWith('rgb')) return (0, _rgbToVec2.default)(color);else if (color.startsWith('#')) return (0, _hexToVec2.default)(color);else throw new Error(color + ' is not a valid color, must be rgba, rgb, hex or vec4'); } else if (Array.isArray(color)) { if (color.length !== 4) { throw new Error('[' + color + '] is not a valid vec4'); } return color; } else { throw new Error(color + ' is not a valid color, must be rgba, rgb, hex or vec4'); } }; module.exports = exports['default'];