@techmely/utils
Version:
Collection of helpful JavaScript / TypeScript utils
19 lines (15 loc) • 433 B
JavaScript
/*!
* @techmely/utils
* Copyright(c) 2021-2024 Techmely <techmely.creation@gmail.com>
* MIT Licensed
*/
// src/percentToHex.ts
function percentToHex(percent) {
if (percent < 0 || percent > 100) {
throw new Error("Value must in range [0, 100]");
}
const intValue = Math.round(percent / 100 * 255);
const hexValue = intValue.toString(16);
return hexValue.padStart(2, "0").toUpperCase();
}
export { percentToHex };