// Sass.@use'sass:list';@use'sass:meta';@use'sass:string';// Status: DONE// The `string.index()` function returns index or list of indexes of `$substrings`.// @param `$string` The value to check whether it contains `$substrings`.// @param `$substring` A substring to find in `$string`.// @arbitrary `$substrings...` The list of substrings to find in `$string`.// @return The return value is the index or list of indexes of the given found substrings.@functionindex($string, $substring, $substrings...) {@iftype-of($string) == string { $result:();@each $substring in list.join($substring, $substrings, comma) { $result: list.append($result, if(meta.type-of($substring) == string, string.index($string, $substring), null), comma);
}@if list.length($result) >0 {@returnif(list.length($result) == 1, list.nth($result,1), $result); } }@return null;}// Examples.// Single// @debug index("Helvetica Neue", "Helvetica"); // 1// @debug index("Helvetica Neue", "Neue"); // 11// Multiple// @debug index("Helvetica Neue", "Helvetica", "Neue"); // 1, 11// @debug index("Helvetica Neue", "Helvetica", "Neue", "Wrong"); // 1, 11, null// @debug index("Helvetica Neue", "Helvetica", "Neue", "Wrong", true); // 1, 11, null, null// Different type of the `$string`// @debug index(true, "Helvetica"); // null