UNPKG

node-libpng

Version:

Unofficial bindings for node to libpng.

59 lines 1.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.convertRGBToRGBA = exports.isColorRGB = exports.colorRGB = void 0; const rgba_1 = require("./rgba"); /** * Create a new color of type `number`. * * @param r The value for the `red` part of the color. * @param g The value for the `green` part of the color. * @param b The value for the `blue` part of the color. * * @return The color in rgb representation. */ function colorRGB(r, g, b) { const color = [r, g, b]; Object.defineProperty(color, "r", { get() { return this[0]; } }); Object.defineProperty(color, "g", { get() { return this[1]; } }); Object.defineProperty(color, "b", { get() { return this[2]; } }); return color; } exports.colorRGB = colorRGB; /** * Checks if the given parameter is a color of type `ColorRGB`. * * @param color The input to check. * * @return `true` if `color` was of type `ColorRGB` and `false` otherwise. */ function isColorRGB(color) { if (typeof color !== "object" || !Array.isArray(color)) { return false; } if (color.length !== 3) { return false; } if (typeof color.r !== "number") { return false; } if (typeof color.g !== "number") { return false; } if (typeof color.b !== "number") { return false; } return true; } exports.isColorRGB = isColorRGB; /** * Converts a color of type `ColorRGB` to `ColorRGBA`. * * @param color The color to convert. * * @return The converted color in rgba format. */ function convertRGBToRGBA(rgb) { return rgba_1.colorRGBA(rgb.r, rgb.g, rgb.b, 255); } exports.convertRGBToRGBA = convertRGBToRGBA; //# sourceMappingURL=rgb.js.map