all files / src/creator/ hex8-creator.js

100% Statements 33/33
100% Branches 12/12
100% Functions 9/9
100% Lines 8/8
2 statements, 4 branches Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21                     28× 28×        
import { Color } from "../color";
 
/**
 * 8桁の16進数表現の作成処理を提供します。
 */
class Hex8Creator {
    /**
     * 色表現を作成します。
     * @param {Color} color 生成元の色情報。
     * @return {String} 色表現。
     */
    create(color) {
        const hex = x => ("0"+(Number(x).toString(16))).slice(-2);
        const alpha = Math.round((color.a != null ? color.a : 100) / 100 * 255);
        const rgba = [ color.r, color.g, color.b, alpha ].map(x => hex(x));
        return `#${rgba.join("")}`;
    }
}
 
export { Hex8Creator };