all files / src/extractor/ web-color-extractor.js

100% Statements 34/34
100% Branches 12/12
100% Functions 7/7
100% Lines 10/10
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 22 23 24 25                     145× 145×   143× 143×          
import { Color } from "../color";
import { WebColorDetector } from "../detector/web-color-detector";
import { WebColor } from "../web-color";
 
/**
 * WEBカラー表現の抽出処理を提供します。
 */
class WebColorExtractor {
    /**
     * 色情報を抽出します。
     * @param {String} expression WEBカラーの色表現。
     * @return {Color} 抽出結果を返します。
     */
    extract(expression) {
        const detector = new WebColorDetector();
        if (!detector.match(expression)) return null;
 
        const color = WebColor[expression];
        return new Color(color.r, color.g, color.b, null);
    }
}
 
export { WebColorExtractor };