diff --git a/scss/functions/_index.scss b/scss/functions/_index.scss index dfe81af7..9e55f7ff 100644 --- a/scss/functions/_index.scss +++ b/scss/functions/_index.scss @@ -1,3 +1,4 @@ @forward "./encode-color"; @forward "./media-queries"; -@forward "./to-number"; \ No newline at end of file +@forward "./strip-unit"; +@forward "./to-number"; diff --git a/scss/functions/_strip-unit.scss b/scss/functions/_strip-unit.scss new file mode 100644 index 00000000..cc86560d --- /dev/null +++ b/scss/functions/_strip-unit.scss @@ -0,0 +1,19 @@ +//////////////////////////////// +// CORE / FUNCTIONS / STRIP UNIT +//////////////////////////////// + + +@use 'sass:math'; +@use 'sass:meta'; + + +/// https://css-tricks.com/snippets/sass/strip-unit-function/ +/// Remove the unit of a length +/// @param {Number} $number - Number to remove unit from +/// @return {Number} - Unitless number +@function strip-unit($number) { + @if meta.type-of($number) == 'number' and not math.unitless($number) { + @return math.div($number, $number * 0 + 1); + } + @return $number; +}