Skip to content

Commit

Permalink
Add str-replace Sass function
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhlauke committed Oct 20, 2016
1 parent b5890e0 commit b2fe974
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions scss/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@
}
}

/// Replace `$search` with `$replace` in `$string`
/// @author Hugo Giraudel
/// @param {String} $string - Initial string
/// @param {String} $search - Substring to replace
/// @param {String} $replace ('') - New value
/// @return {String} - Updated string
@function str-replace($string, $search, $replace: "") {
$index: str-index($string, $search);

@if $index {
@return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
}

@return $string;
}

// General variable structure
//
// Variable format should follow the `$component-modifier-state-property` order.
Expand Down

0 comments on commit b2fe974

Please sign in to comment.