-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_string.replace-multiple.function.scss
More file actions
34 lines (29 loc) · 1.94 KB
/
_string.replace-multiple.function.scss
File metadata and controls
34 lines (29 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Modules.
@use 'string.replace.function';
// Status: DONE
// The `string.replace-multiple()` function handles multiple string replaces, using `string.replace()` function.
// @param `$string` The string to do multiple `$replaces`.
// @arbitrary `$replaces...` Arbitrary replaces (occurrence, substring, replacement) to do on `$string`.
// @return The return value is a `string` with done `$replaces`.
@function replace-multiple($string, $replaces...) {
@each $occurrence, $substring, $replacement in $replaces {
$string: string.replace($string, $occurrence, $substring, $replacement);
}
@return $string;
}
// Examples.
// single replacement first occurrence
// @debug replace-multiple('bold king is hairy', first 'bold' 'baloon'); // baloon king is hairy
// @debug replace-multiple('bold king is hairy', first 'bold' ''); // king is hairy
// @debug replace-multiple(':==', first ':' '');
// single replacement all occurrences
// @debug replace-multiple('bold king is bold hairy', all 'bold' ''); // king is hairy
// @debug replace-multiple('bold king is bold hairy', all 'bold' 'test'); // test king is test hairy
// multiple replacements
// @debug replace-multiple('bold king is hairy', first (bold is) ''); // king hairy
// @debug replace-multiple('bold king is hairy', first bold baloon, first king baloon); // baloon baloon is hairy
// @debug replace-multiple('bold king is hairy', first (bold king) baloon, first (is hairy) bold); // baloon baloon bold bold
// @debug replace-multiple('atmosphere bold bold bold king is hairy', first (king bold) baloon); // atmosphere baloon bold bold baloon is hairy
// @debug replace-multiple('atmosphere bold bold bold king is hairy', all (king bold) baloon); // atmosphere baloon baloon baloon baloon is hairy
// multiple replacements different occurrences
// @debug replace-multiple('atmosphere bold bold bold king is hairy', first bold clean, all (king bold) baloon); // atmosphere clean baloon baloon baloon is hairy