-
-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathcomponent-value-is.ts
More file actions
64 lines (55 loc) · 1.5 KB
/
component-value-is.ts
File metadata and controls
64 lines (55 loc) · 1.5 KB
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
import { ComponentValue, ComponentValueType, FunctionNode } from '@csstools/css-parser-algorithms';
import { CSSToken, TokenFunction, TokenType } from '@csstools/css-tokenizer';
import { toLowerCaseAZ } from './to-lower-case-a-z';
export function isNumber(componentValue: ComponentValue) {
if (
(componentValue.type === ComponentValueType.Token && (componentValue.value as CSSToken)[0] === TokenType.Number) ||
(componentValue.type === ComponentValueType.Function && mathFunctions.has(toLowerCaseAZ(((componentValue as FunctionNode).name as TokenFunction)[4].value)))
) {
return true;
}
return false;
}
const mathFunctions = new Set([
'abs',
'acos',
'asin',
'atan',
'atan2',
'calc',
'clamp',
'cos',
'exp',
'hypot',
'log',
'max',
'min',
'mod',
'pow',
'rem',
'round',
'sign',
'sin',
'sqrt',
'tan',
]);
export function isDimension(componentValue: ComponentValue) {
if (componentValue.type === ComponentValueType.Token && (componentValue.value as CSSToken)[0] === TokenType.Dimension) {
return true;
}
return false;
}
export function isIdent(componentValue: ComponentValue) {
if (componentValue.type === ComponentValueType.Token && (componentValue.value as CSSToken)[0] === TokenType.Ident) {
return true;
}
return false;
}
export function isEnvironmentVariable(componentValue: ComponentValue) {
if (componentValue.type === ComponentValueType.Function &&
toLowerCaseAZ(((componentValue as FunctionNode).name as TokenFunction)[4].value) === 'env'
) {
return true;
}
return false;
}