-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
_type-checking.scss
137 lines (124 loc) · 4.3 KB
/
_type-checking.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
@use 'sass:list';
@use 'sass:math';
@use 'sass:meta';
/// Check if its a number value
/// @param {Void} $value - Value to check
/// @group Type-Checking
/// @author Hugo Giraudel
/// @link https://css-tricks.com/snippets/sass/advanced-type-checking/
/// @since v1.0.0
@function is-number($value) {
@return meta.type-of($value) == 'number';
}
/// Check if its a time value
/// @param {Void} $value - Value to check
/// @group Type-Checking
/// @author Hugo Giraudel
/// @link https://css-tricks.com/snippets/sass/advanced-type-checking/
/// @since v1.0.0
@function is-time($value) {
@return is-number($value) and list.index('ms' 's', math.unit($value)) != null;
}
/// Check if its a duration value
/// @param {Void} $value - Value to check
/// @group Type-Checking
/// @author Hugo Giraudel
/// @link https://css-tricks.com/snippets/sass/advanced-type-checking/
/// @since v1.0.0
@function is-duration($value) {
@return is-time($value);
}
/// Check if its a angle value
/// @param {Void} $value - Value to check
/// @group Type-Checking
/// @author Hugo Giraudel
/// @link https://css-tricks.com/snippets/sass/advanced-type-checking/
/// @since v1.0.0
@function is-angle($value) {
@return is-number($value) and
list.index('deg' 'rad' 'grad' 'turn', math.unit($value)) != null;
}
/// Check if its a frequency value
/// @param {Void} $value - Value to check
/// @group Type-Checking
/// @author Hugo Giraudel
/// @link https://css-tricks.com/snippets/sass/advanced-type-checking/
/// @since v1.0.0
@function is-frequency($value) {
@return is-number($value) and list.index('Hz' 'kHz', math.unit($value)) != null;
}
/// Check if its a integer value
/// @param {Void} $value - Value to check
/// @group Type-Checking
/// @author Hugo Giraudel
/// @link https://css-tricks.com/snippets/sass/advanced-type-checking/
/// @since v1.0.0
@function is-integer($value) {
@return is-number($value) and math.round($value) == $value;
}
/// Check if its a relative-length value
/// @param {Void} $value - Value to check
/// @group Type-Checking
/// @author Hugo Giraudel
/// @link https://css-tricks.com/snippets/sass/advanced-type-checking/
/// @since v1.0.0
@function is-relative-length($value) {
@return is-number($value) and
list.index('em' 'ex' 'ch' 'rem' 'vw' 'vh' 'vmin' 'vmax', math.unit($value)) != null;
}
/// Check if its a absolute-length value
/// @param {Void} $value - Value to check
/// @group Type-Checking
/// @author Hugo Giraudel
/// @link https://css-tricks.com/snippets/sass/advanced-type-checking/
/// @since v1.0.0
@function is-absolute-length($value) {
@return is-number($value) and
list.index('cm' 'mm' 'in' 'px' 'pt' 'pc', math.unit($value)) != null;
}
/// Check if its a percentage value
/// @param {Void} $value - Value to check
/// @group Type-Checking
/// @author Hugo Giraudel
/// @link https://css-tricks.com/snippets/sass/advanced-type-checking/
/// @since v1.0.0
@function is-percentage($value) {
@return is-number($value) and math.unit($value) == '%';
}
/// Check if its a length value
/// @param {Void} $value - Value to check
/// @group Type-Checking
/// @author Hugo Giraudel
/// @link https://css-tricks.com/snippets/sass/advanced-type-checking/
/// @since v1.0.0
@function is-length($value) {
@return is-relative-length($value) or is-absolute-length($value);
}
/// Check if its a resolution value
/// @param {Void} $value - Value to check
/// @group Type-Checking
/// @author Hugo Giraudel
/// @link https://css-tricks.com/snippets/sass/advanced-type-checking/
/// @since v1.0.0
@function is-resolution($value) {
@return is-number($value) and
list.index('dpi' 'dpcm' 'dppx', math.unit($value)) != null;
}
/// Check if its a position value
/// @param {Void} $value - Value to check
/// @group Type-Checking
/// @author Hugo Giraudel
/// @link https://css-tricks.com/snippets/sass/advanced-type-checking/
/// @since v1.0.0
@function is-position($value) {
@return is-length($value) or is-percentage($value) or
list.index('top' 'right' 'bottom' 'left' 'center', $value) != null;
}
/// Check if its a color value
/// @param {Void} $value - Value to check
/// @group Type-Checking
/// @author https://github.com/red-freak
/// @since v2.5.0
@function is-color($value) {
@return meta.type-of($value) == 'color';
}