forked from edonet/svgx-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.scss
61 lines (45 loc) · 1.32 KB
/
utils.scss
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
@charset "utf-8";
/**
*************************************
* 扩展函数
*************************************
*/
/* 连接字符串 */
@function str-join($map, $sep: '&', $eq: '=') {
$result: null;
@each $key, $val in $map {
$param: if($val, $key + $eq + $val, $key);
$result: if($result, $result + $sep + $param, $param);
}
@return $result;
}
/* 替换字符串 */
@function str-replace($string, $search, $replace: '') {
$index: str-index($string, $search);
// 替换找到的字符串
@if $index {
$prevString: str-slice($string, 1, $index - 1);
$nextString: str-slice($string, $index + str-length($search));
@return $prevString + $replace + str-replace($nextString, $search, $replace);
}
// 返回原字符串
@return $string;
}
/* 生成查询字符串 */
@function str-query($args) {
// 连接参数
$params: str-join($args);
// 替换特殊字符
$params: str-replace($params, '%', '%25');
$params: str-replace($params, '#', '%23');
// 返回参数
@return $params;
}
/**
*************************************
* 定义模块加载器
*************************************
*/
@function svgx($path, $args: null) {
@return url('~svgx-loader!' + $path + '?output=sass&' + if($args, str-query($args), ''));
}