Created
December 9, 2021 11:56
-
-
Save WinterSilence/50fd5511b58f1bb86265dcdba2881d65 to your computer and use it in GitHub Desktop.
SCSS/SASS port of PHP function substr()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Returns part of string. | |
/// Similar to PHP `substr()`: `substr("abc", 2, 1)` - "c", `substr("abc", 1)` - "bc", `substr("abcd", -3, -1)` - "bc". | |
/// | |
/// @param {String} $str The input string | |
/// @param {Number} $offset The returned string will start at the offset'th position in string, counting from zero | |
/// @param {Number} $length The string returned will contain at most length characters beginning from offset (optional) | |
/// @return {String} | |
/// @see https://www.php.net/manual/en/function.substr | |
@function substr($str, $offset, $length: 0) { | |
$length: if($length < 0, $length - 1, if($length == 0, str-length($str), $length)); | |
@return str-slice(str-slice($str, $offset), 1, $length); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment