Performance: sass:string module
Using the sass:string module affects the CSS build time and output size, impacting how fast styles are generated and applied.
@use "sass:string"; $color-name: "blue"; $color-var: string.join(("var(--", $color-name, ")"), ""); .selector { color: unquote($color-var); }
@use "sass:string"; $color-name: "blue"; $color-var: unquote("var(--" + $color-name + ")"); .selector { color: $color-var; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual string concatenation with + and unquote | 0 | 0 | 0 | [X] Bad - slows Sass compilation |
| Using sass:string string.join function | 0 | 0 | 0 | [OK] Good - faster compilation |
sass:string module in Sass?sass:string module provides functions to work with text strings, such as changing case or joining strings.string module in Sass?@use to import modules, so @use 'sass:string'; is correct.@import is deprecated for modules, @require and @include are invalid for importing modules.@use 'sass:string';
$word: 'Hello';
$result: string.to-upper-case($word);
.test {
content: $result;
}string.to-upper-case() converts all letters in the string to uppercase.string module:@use 'sass:string';
$greeting: 'Hi';
$new: string.append($greeting, 123);
.test {
content: $new;
}string.append() expects string arguments, but 123 is a number, causing a type error.sass:string module to achieve this?Pass the test and this pattern moves unknown