Created
September 4, 2014 15:35
-
-
Save chriseppstein/50aad5193b566c050910 to your computer and use it in GitHub Desktop.
String Replacement function in pure-sass
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
@function str-replace($source, $substring, $replacement, $fail-silently: false) { | |
$start: str-index($source, $substring); | |
@if $start { | |
@return str-slice($source, 1, $start - 1) + $replacement + str-slice($source, $start + str-length($substring)) | |
} | |
@if $fail-silently { | |
@return $source; | |
} @else { | |
@error "'#{$substring}' was not found in '#{$source}'"; | |
} | |
} | |
@debug str-replace("beforeDURINGafter", "DURING", "REPLACED"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment