@palett/convert
Advanced tools
Comparing version 0.0.15 to 0.0.16
@@ -7,3 +7,3 @@ 'use strict'; | ||
const rgbToLong = ([r, g, b]) => ((r & 0xFF) << 16) + ((g & 0xFF) << 8) + (b & 0xFF); | ||
const rgbToInt = ([r, g, b]) => ((r & 0xFF) << 16) + ((g & 0xFF) << 8) + (b & 0xFF); | ||
@@ -15,3 +15,3 @@ /** | ||
const rgbToHex = rgb => '#' + rgbToLong(rgb).toString(16).toUpperCase().padStart(6, '0'); | ||
const rgbToHex = rgb => '#' + rgbToInt(rgb).toString(16).toUpperCase().padStart(6, '0'); | ||
@@ -76,3 +76,3 @@ const hue = (r, g, b, max, dif) => { | ||
const dilhex = (hex, hi) => { | ||
const diluteHex = (hex, hi) => { | ||
hi = hi || hex.length; | ||
@@ -93,2 +93,14 @@ let x = ''; | ||
* @param {string} hex | ||
* @returns {number} | ||
*/ | ||
function hexToInt(hex) { | ||
if (hex.charAt(0) === '#') hex = hex.substring(1); | ||
if (!hex[3]) hex = diluteHex(hex); | ||
return parseInt(hex, 16); | ||
} | ||
/** | ||
* | ||
* @param {string} hex | ||
* @returns {number[]} | ||
@@ -98,6 +110,4 @@ */ | ||
function hexToRgb(hex) { | ||
if (hex.charAt(0) === '#') hex = hex.substring(1); | ||
if (!hex[3]) hex = dilhex(hex); | ||
const n = parseInt(hex, 16); | ||
return [n >> 16 & 0xFF, n >> 8 & 0xFF, n & 0xFF]; | ||
const int = hexToInt(hex); | ||
return [int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF]; | ||
} | ||
@@ -149,2 +159,3 @@ | ||
exports.hexToHsl = hexToHsl; | ||
exports.hexToInt = hexToInt; | ||
exports.hexToRgb = hexToRgb; | ||
@@ -155,2 +166,2 @@ exports.hslToHex = hslToHex; | ||
exports.rgbToHsl = rgbToHsl; | ||
exports.rgbToLong = rgbToLong; | ||
exports.rgbToInt = rgbToInt; |
import { round } from 'aryth'; | ||
const rgbToLong = ([r, g, b]) => ((r & 0xFF) << 16) + ((g & 0xFF) << 8) + (b & 0xFF); | ||
const rgbToInt = ([r, g, b]) => ((r & 0xFF) << 16) + ((g & 0xFF) << 8) + (b & 0xFF); | ||
@@ -10,3 +10,3 @@ /** | ||
const rgbToHex = rgb => '#' + rgbToLong(rgb).toString(16).toUpperCase().padStart(6, '0'); | ||
const rgbToHex = rgb => '#' + rgbToInt(rgb).toString(16).toUpperCase().padStart(6, '0'); | ||
@@ -71,3 +71,3 @@ const hue = (r, g, b, max, dif) => { | ||
const dilhex = (hex, hi) => { | ||
const diluteHex = (hex, hi) => { | ||
hi = hi || hex.length; | ||
@@ -88,2 +88,14 @@ let x = ''; | ||
* @param {string} hex | ||
* @returns {number} | ||
*/ | ||
function hexToInt(hex) { | ||
if (hex.charAt(0) === '#') hex = hex.substring(1); | ||
if (!hex[3]) hex = diluteHex(hex); | ||
return parseInt(hex, 16); | ||
} | ||
/** | ||
* | ||
* @param {string} hex | ||
* @returns {number[]} | ||
@@ -93,6 +105,4 @@ */ | ||
function hexToRgb(hex) { | ||
if (hex.charAt(0) === '#') hex = hex.substring(1); | ||
if (!hex[3]) hex = dilhex(hex); | ||
const n = parseInt(hex, 16); | ||
return [n >> 16 & 0xFF, n >> 8 & 0xFF, n & 0xFF]; | ||
const int = hexToInt(hex); | ||
return [int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF]; | ||
} | ||
@@ -143,2 +153,2 @@ | ||
export { hexToHsl, hexToRgb, hslToHex, hslToRgb, rgbToHex, rgbToHsl, rgbToLong }; | ||
export { hexToHsl, hexToInt, hexToRgb, hslToHex, hslToRgb, rgbToHex, rgbToHsl, rgbToInt }; |
{ | ||
"name": "@palett/convert", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"description": "A color converter among RGB, HEX and HSL.", | ||
@@ -43,3 +43,3 @@ "main": "dist/index.cjs.js", | ||
"homepage": "https://github.com/hoyeungw/palett/rgb#readme", | ||
"gitHead": "0c47b12f229babf25f5841925245a1d2d63fda01" | ||
"gitHead": "64ccfe78f8e7d28e40901daf6c9dabbdd7891ced" | ||
} |
8622
251