From: Nicolas Coden Date: Wed, 18 Jul 2018 22:38:50 +0000 (+0200) Subject: feat: add function "zf-is-fraction()" X-Git-Tag: v6.6.0~3^2~68^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fde38861fef454705b78e8b37f1f7440b6eb6824;p=thirdparty%2Ffoundation%2Ffoundation-sites.git feat: add function "zf-is-fraction()" zf-is-fraction(): Returns whether the given `$value` represents a fraction. Supports formats like `50%`, `1 of 2`, `1 per 2` or `1/2`. --- diff --git a/scss/util/_math.scss b/scss/util/_math.scss index 62a5090b7..947a576e5 100644 --- a/scss/util/_math.scss +++ b/scss/util/_math.scss @@ -107,6 +107,18 @@ @return (null, null); } +/// Returns whether the given `$value` represents a fraction. Supports formats like `50%`, `1 of 2`, `1 per 2` or `1/2`. +/// +/// @param {*} $value - Value to test. +/// @param {Boolean} $allow-no-denominator [false] - If `true`, simple numbers without denominators like `50` are supported. +/// +/// @return {Boolean} `true` if `$value` represents a fraction, `false` otherwise. +@function zf-is-fraction($value, $allow-no-denominator: false) { + $parsed: zf-parse-fraction($value); + @return not(nth($parsed, 1) == null + or (nth($parsed, 2) == null and $allow-no-denominator == false)); +} + /// Calculate a percentage from a given fraction. /// /// @param {Number|List} $fraction - Value representing a fraction to use to calculate the percentage, formatted as `50` (relative to `$denominator`), `50%`, `1 of 2` or `1/2`.