forked from csstools/css-typed-om
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
62 lines (57 loc) · 1.21 KB
/
test.js
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
import polyfill from "./demo/css-typed-om-polyfill.js";
const CSS = {};
const window = {
CSS,
CSSStyleRule: { prototype: {} },
Element: { prototype: {} },
};
polyfill(window);
const units = {
ch: "ch",
rem: "rem",
vw: "vw",
vh: "vh",
vmin: "vmin",
vmax: "vmax",
cm: "cm",
mm: "mm",
in: "in",
pt: "pt",
pc: "pc",
px: "px",
Q: "Q",
deg: "deg",
grad: "grad",
rad: "rad",
turn: "turn",
s: "s",
ms: "ms",
Hz: "Hz",
kHz: "kHz",
dpi: "dpi",
dpcm: "dpcm",
dppx: "dppx",
fr: "fr",
};
const code =
Object.keys(units).every((unit) =>
[
compare(CSS[unit](10), `10${unit}`),
compare(CSS[unit](10).add(CSS[unit](5), CSS[unit](5)), `20${unit}`),
compare(CSS[unit](10).sub(CSS[unit](2), CSS[unit](3)), `5${unit}`),
compare(CSS[unit](10).sub(CSS[unit](2), CSS[unit](3)), `5${unit}`),
compare(CSS[unit](10).mul(2, 3), `60${unit}`),
compare(CSS[unit](10).div(2, 5), `1${unit}`),
].every((result) => Boolean(result)),
) &&
compare(CSS.px(15).add(CSS.rem(10), CSS.em(5)), "calc(15px + 10rem + 5em)")
? 0
: 1;
process.exit(code);
function compare(a, b) {
if (String(a) === String(b)) {
return true;
} else {
return false;
}
}