@palett/convert
Advanced tools
Comparing version 0.8.8 to 0.8.9
@@ -159,2 +159,17 @@ 'use strict'; | ||
/** | ||
* @param {string} hex | ||
* @returns {number} | ||
*/ | ||
function hexToShort(hex) { | ||
let lo = 0, | ||
hi = hex.length; | ||
if (hi === 7) lo++, hi--; | ||
if (hi === 6) return hexAt(hex, lo++) << 8 | hexAt(hex, lo += 2) << 4 | hexAt(hex, lo += 2); | ||
if (hi === 4) lo++, hi--; | ||
if (hi === 3) return hexAt(hex, lo++) << 8 | hexAt(hex, lo++) << 4 | hexAt(hex, lo++); | ||
return 0; | ||
} | ||
/** | ||
* | ||
@@ -229,2 +244,3 @@ * @param {number} n | ||
exports.hexToRgb = hexToRgb; | ||
exports.hexToShort = hexToShort; | ||
exports.hslToHex = hslToHex; | ||
@@ -231,0 +247,0 @@ exports.hslToInt = hslToInt; |
@@ -155,2 +155,17 @@ import { round } from '@aryth/math'; | ||
/** | ||
* @param {string} hex | ||
* @returns {number} | ||
*/ | ||
function hexToShort(hex) { | ||
let lo = 0, | ||
hi = hex.length; | ||
if (hi === 7) lo++, hi--; | ||
if (hi === 6) return hexAt(hex, lo++) << 8 | hexAt(hex, lo += 2) << 4 | hexAt(hex, lo += 2); | ||
if (hi === 4) lo++, hi--; | ||
if (hi === 3) return hexAt(hex, lo++) << 8 | hexAt(hex, lo++) << 4 | hexAt(hex, lo++); | ||
return 0; | ||
} | ||
/** | ||
* | ||
@@ -221,2 +236,2 @@ * @param {number} n | ||
export { Conv, hexToHsl, hexToInt, hexToRgb, hslToHex, hslToInt, hslToRgb, intToHex, intToHsl, intToRgb, rgbToHex, rgbToHsl, rgbToInt }; | ||
export { Conv, hexToHsl, hexToInt, hexToRgb, hexToShort, hslToHex, hslToInt, hslToRgb, intToHex, intToHsl, intToRgb, rgbToHex, rgbToHsl, rgbToInt }; |
{ | ||
"name": "@palett/convert", | ||
"version": "0.8.8", | ||
"version": "0.8.9", | ||
"description": "A color converter among RGB, HEX and HSL.", | ||
@@ -44,3 +44,3 @@ "main": "dist/index.cjs.js", | ||
"homepage": "https://github.com/hoyeungw/palett/rgb#readme", | ||
"gitHead": "34b716e675ffe0d0866df519cbfa62a46679f089" | ||
"gitHead": "7175f50132def2e559edbed00883d1e565be5d90" | ||
} |
14338
411