Created
December 16, 2022 11:04
-
-
Save brettsmason/da20ece00644d8099013d6caedb3b892 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
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
/// Check if a string contains a number. | |
@function string-is-number($string) { | |
// Matrices | |
$numbers: '0' '1' '2' '3' '4' '5' '6' '7' '8' '9'; | |
@for $i from 1 through str-length($string) { | |
$character: str-slice($string, $i, $i); | |
$index: index($numbers, $character); | |
@if $index { | |
@return true; | |
} | |
} | |
@return false; | |
} | |
/// Checks a string for the presence of a number. | |
/// If it contains a number, append a separator to it. | |
@function split-string($string, $separator) { | |
@for $i from 1 through str-length($string) { | |
$character: str-slice($string, $i, $i); | |
$next-character: str-slice($string, $i + 1, $i + 1); | |
$previous-character: if($i == 1, false, str-slice($string, $i - 1, $i - 1)); | |
@if string-is-number($character) and not string-is-number($next-character) { | |
$string: str-insert($string, $separator, $i + 1); | |
} | |
} | |
@return $string; | |
} | |
/// Testing | |
body { | |
margin-top: split-string('20xl', '-'); | |
} |
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
body { | |
margin-top: "20-xl"; | |
} |
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
{ | |
"sass": { | |
"compiler": "dart-sass/1.32.12", | |
"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