hyper/app/utils/to-electron-background-color.js
Leo Lamprecht 0ee4fb6104 Updated dependencies to the latest version (#2146)
* Bumped dependencies to the latest version

* Bumped root lockfile

* Bumped app dependencies

* Fixed linting

* No command line switch needed anymore for native async/await

* Fixed color error

* Bumped Node.js versions for CI

* Downgraded hterm-umdjs

* Try to fix the AppVeyor build

* Made colors work again
2017-08-31 15:20:39 +02:00

17 lines
508 B
JavaScript

// Packages
const Color = require('color');
// returns a background color that's in hex
// format including the alpha channel (e.g.: `#00000050`)
// input can be any css value (rgb, hsl, string…)
module.exports = bgColor => {
const color = Color(bgColor);
if (color.alpha() === 1) {
return color.hex().toString();
}
// http://stackoverflow.com/a/11019879/1202488
const alphaHex = Math.round(color.alpha() * 255).toString(16);
return '#' + alphaHex + color.hex().toString().substr(1);
};