Skip to content

Instantly share code, notes, and snippets.

@jathak
Created January 25, 2021 21:48
Show Gist options
  • Save jathak/51a4e10cf16a669f4c9b067aae01fdf2 to your computer and use it in GitHub Desktop.
Save jathak/51a4e10cf16a669f4c9b067aae01fdf2 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
@use "sass:string";
@use "sass:color";
@function hex-digit($char) {
$char: string.to-lower-case($char);
@return if($char == "0", 0,
if($char == "1", 1,
if($char == "2", 2,
if($char == "3", 3,
if($char == "4", 4,
if($char == "5", 5,
if($char == "6", 6,
if($char == "7", 7,
if($char == "8", 8,
if($char == "9", 9,
if($char == "a", 10,
if($char == "b", 11,
if($char == "c", 12,
if($char == "d", 13,
if($char == "e", 14,
if($char == "f", 15, 0))))))))))))))));
}
@function hex-to-int($hex) {
$total: 0;
$multiplier: 1;
@for $i from string.length($hex) to 0 {
$total: $total + hex-digit(string.slice($hex, $i, $i)) * $multiplier;
$multiplier: $multiplier * 16;
}
@return $total;
}
@function str-to-color($str) {
@return rgb(hex-to-int(string.slice($str, 2, 3)),
hex-to-int(string.slice($str, 4, 5)),
hex-to-int(string.slice($str, 6, 7)));
}
a {
b: str-to-color("#33b5e5");
}
a {
b: #33b5e5;
}
{
"sass": {
"compiler": "dart-sass/1.26.11",
"extensions": {},
"syntax": "SCSS",
"outputStyle": "expanded"
},
"autoprefixer": false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment