This repository has been archived by the owner on Nov 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_functions.scss
50 lines (43 loc) · 1.89 KB
/
_functions.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
// -----------------------------------------------------------------------------
// Define your global functions in here!
// -----------------------------------------------------------------------------
/// Converts a list/map into a string by using a pattern for each entry and a
/// separator for glueing.
/// @author Gridonic
/// @param {String} $input - Input map/list to stringify
/// @param {Map} $options [(pattern: "%key: %value", separator: ", ")]- Options for adjusting how to stringify
/// @return {String}
@function stringify($input, $options) {
$pattern: if(map-has-key($options, "pattern"), map-get($options, "pattern"), "%key: %value");
$separator: if(map-has-key($options, "separator"), map-get($options, "separator"), ", ");
$result: "";
@for $i from 1 through length($input) {
$item: nth($input, $i);
$key: nth($item, 1);
$value: if(length($item) > 1, nth($item, 2), "");
$temp: str-replace($pattern, "%key", $key);
$temp: str-replace($temp, "%value", $value);
$result: $result + $temp + if($i < length($input), $separator, "");
}
@return $result;
}
/// Replace `$search` with `$replace` in `$string`
/// @author Hugo Giraudel
/// @param {String} $string - Initial string
/// @param {String} $search - Substring to replace
/// @param {String} $replace [""] - New value
/// @return {String} - Updated string
@function str-replace($string, $search, $replace: "") {
$index: str-index($string, $search);
@if $index {
@return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
}
@return $string;
}
/// Returns the vertical rhythm base value or a factor of it.
/// @author Gridonic
/// @param {Number} $string [1] - Factor of the vertical base
/// @return {Length}
@function vertical-base($factor: 1) {
@return $base-line-height * $factor;
}