Created
January 30, 2015 22:42
-
-
Save TexRx/d0d9dbb8fd53ef6d91ca to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
This file contains hidden or 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
// ---- | |
// Sass (v3.4.9) | |
// Compass (v1.0.1) | |
// ---- | |
/// Trim `$string` | |
/// @param {String} $string - String to trim | |
/// @return {String} | |
@function trim($string) { | |
@return str-slice( | |
$string, | |
first-index($string, 'left'), | |
first-index($string, 'right') | |
); | |
} | |
/// Find first char which is not a space | |
/// @param {String} $string - String | |
/// @param {String} $direction ['left'] - Either `left` or `right` | |
/// @return {Number} | |
@function first-index($string, $direction: 'left') { | |
@for $i from 1 through str-length($string) { | |
$index: if('left' == $direction, $i, -$i); | |
@if ' ' != str-slice($string, $index, $index) { | |
@return $index; | |
} | |
} | |
@return 0; | |
} | |
.foo { | |
content: trim(' '); | |
content: trim('no spaces'); | |
content: trim(' 3 spaces in front'); | |
content: trim(' 3 spaces in front and back '); | |
content: trim(' lots and lots of spaces'); | |
} |
This file contains hidden or 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
.foo { | |
content: ""; | |
content: "no spaces"; | |
content: "3 spaces in front"; | |
content: "3 spaces in front and back"; | |
content: "lots and lots of spaces"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment