code-theme-converter
Version:
Convert any vscode theme with ease!
37 lines (36 loc) • 1.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const toNumber = (r) => (v) => parseInt(v, r);
const match = (m) => (str) => str.match(m);
const splitChannels = match(/.{2}/g);
const fromHex = toNumber(16);
const toPercentage = (v) => ((fromHex(v) / 255) * 1000) / 1000;
function hex2Rgb(hex) {
var _a, _b;
return ((_b = (_a = hex
.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, (_m, r, g, b) => '#' + r + r + g + g + b + b)
.substring(1)
.match(/.{2}/g)) === null || _a === void 0 ? void 0 : _a.map(x => parseInt(x, 16))) !== null && _b !== void 0 ? _b : [0, 0, 0]);
}
exports.hex2Rgb = hex2Rgb;
function hex2Rgba(hex) {
const num = parseInt(hex.slice(1), 16);
return [(num >> 16) & 255, (num >> 8) & 255, num & 255, (num >> 24) & 255];
}
exports.hex2Rgba = hex2Rgba;
function getAlphaFromHex(hex) {
return hex2Rgba(hex).pop();
}
exports.getAlphaFromHex = getAlphaFromHex;
function removeHashFromHex(hex = '') {
return hex.includes('#') ? hex.substr(1) : hex;
}
exports.removeHashFromHex = removeHashFromHex;
function eightDigitHex2Rgba(hex) {
var _a;
const hashless = removeHashFromHex(hex);
const c = (_a = splitChannels(hashless)) !== null && _a !== void 0 ? _a : [];
const alpha = c[3] != null ? toPercentage(c[3]) : 1.0;
return [...c.slice(0, 3).map(fromHex), alpha];
}
exports.eightDigitHex2Rgba = eightDigitHex2Rgba;