sass:string

string.quote()

string.quote($string)
quote($string) //=> string

$string 作为带引号的字符串返回。

@debug string.quote(Helvetica); // "Helvetica"
@debug string.quote("Helvetica"); // "Helvetica"


string.index()

string.index($string, $substring)
str-index($string, $substring) //=> number

返回 $substring $string 位置中的第一个索引。如果不包含,则返回 null

@debug string.index("Helvetica Neue", "Helvetica"); // 1
@debug string.index("Helvetica Neue", "Neue"); // 11


string.insert()

string.insert($string, $insert, $index)
str-insert($string, $insert, $index) //=> string

根据索引 $index 位置,在 $string 中,插入 $insert ,返回字符串副本结果。

@debug string.insert("Roboto Bold", " Mono", 7); // "Roboto Mono Bold"
@debug string.insert("Roboto Bold", " Mono", -6); // "Roboto Mono Bold"

如果 $index 大于 $string 的长度,则 $insert 添加到末尾。如果 $index 小于字符串的负长度,则 $insert 添加到 $string 开头。

@debug string.insert("Roboto", " Bold", 100); // "Roboto Bold"
@debug string.insert("Bold", "Roboto ", -100); // "Roboto Bold"


string.length()

string.length($string)
str-length($string) //=> number

返回 $string 中的字符数。

@debug string.length("Helvetica Neue"); // 14
@debug string.length(bold); // 4
@debug string.length(""); // 0


string.slice()

string.slice($string, $start-at, $end-at: -1)
str-slice($string, $start-at, $end-at: -1) //=> string 

$string 中,截取开始位置 $start-at ,到结束位置 $end-at (包括两者)。

@debug string.slice("Helvetica Neue", 11); // "Neue"
@debug string.slice("Helvetica Neue", 1, 3); // "Hel"
@debug string.slice("Helvetica Neue", 1, -6); // "Helvetica"


string.to-upper-case()

string.to-upper-case($string)
to-upper-case($string) //=> string

返回 ASCII 字母转换为大写 $string 的副本。

@debug string.to-upper-case("Bold"); // "BOLD"
@debug string.to-upper-case(sans-serif); // SANS-SERIF


string.to-lower-case()

string.to-lower-case($string)
to-lower-case($string) //=> string

返回 ASCII 字母转换为小写 $string 的副本。

@debug string.to-lower-case("Bold"); // "bold"
@debug string.to-lower-case(SANS-SERIF); // sans-serif


string.unique-id()

string.unique-id()
unique-id() //=> string

返回一个随机生成的不带引号的字符串,它保证是一个有效的 CSS 标识符并且在当前 Sass 编译中是唯一的。

@debug string.unique-id(); // uabtrnzug
@debug string.unique-id(); // u6w1b1def


string.unquote()

string.unquote($string)
unquote($string) //=> string

$string 作为不带引号的字符串返回。这会产生无效的CSS字符串,因此请谨慎使用。

@debug string.unquote("Helvetica"); // Helvetica
@debug string.unquote(".widget:hover"); // .widget:hover

上篇: sass:selector