postcss-calc 8.2.4 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +24 -17
- package/src/__tests__/convertUnit.js +0 -421
- package/src/__tests__/index.js +0 -903
- package/src/parser.jison +0 -111
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-calc",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "PostCSS plugin to reduce calc()",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"css",
|
|
@@ -9,6 +9,11 @@
|
|
|
9
9
|
"calculation",
|
|
10
10
|
"calc"
|
|
11
11
|
],
|
|
12
|
+
"homepage": "https://github.com/postcss/postcss-calc",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/postcss/postcss-calc.git"
|
|
16
|
+
},
|
|
12
17
|
"main": "src/index.js",
|
|
13
18
|
"types": "types/index.d.ts",
|
|
14
19
|
"files": [
|
|
@@ -16,6 +21,12 @@
|
|
|
16
21
|
"types",
|
|
17
22
|
"LICENSE"
|
|
18
23
|
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"prepare": "pnpm run build && tsc",
|
|
26
|
+
"build": "jison ./parser.jison -o src/parser.js",
|
|
27
|
+
"lint": "eslint . && tsc",
|
|
28
|
+
"test": "uvu test"
|
|
29
|
+
},
|
|
19
30
|
"author": "Andy Jansson",
|
|
20
31
|
"license": "MIT",
|
|
21
32
|
"repository": "https://github.com/postcss/postcss-calc.git",
|
|
@@ -35,28 +46,24 @@
|
|
|
35
46
|
"curly": "error"
|
|
36
47
|
}
|
|
37
48
|
},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": "^14 || ^16 || >=18.0"
|
|
51
|
+
},
|
|
38
52
|
"devDependencies": {
|
|
39
|
-
"@types/node": "^
|
|
40
|
-
"eslint": "^8.
|
|
41
|
-
"eslint-config-prettier": "^8.
|
|
53
|
+
"@types/node": "^18.16.2",
|
|
54
|
+
"eslint": "^8.39.0",
|
|
55
|
+
"eslint-config-prettier": "^8.8.0",
|
|
42
56
|
"jison-gho": "^0.6.1-216",
|
|
43
57
|
"postcss": "^8.2.2",
|
|
44
|
-
"prettier": "^2.
|
|
45
|
-
"typescript": "
|
|
46
|
-
"uvu": "^0.5.
|
|
58
|
+
"prettier": "^2.8.8",
|
|
59
|
+
"typescript": "~5.0.4",
|
|
60
|
+
"uvu": "^0.5.6"
|
|
47
61
|
},
|
|
48
62
|
"dependencies": {
|
|
49
|
-
"postcss-selector-parser": "^6.0.
|
|
63
|
+
"postcss-selector-parser": "^6.0.11",
|
|
50
64
|
"postcss-value-parser": "^4.2.0"
|
|
51
65
|
},
|
|
52
66
|
"peerDependencies": {
|
|
53
67
|
"postcss": "^8.2.2"
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
"build": "jison src/parser.jison -o src/parser.js",
|
|
57
|
-
"lint": "eslint src && tsc",
|
|
58
|
-
"pretest": "pnpm run build",
|
|
59
|
-
"test": "uvu src/__tests__"
|
|
60
|
-
},
|
|
61
|
-
"readme": "# PostCSS Calc [<img src=\"https://postcss.github.io/postcss/logo.svg\" alt=\"PostCSS\" width=\"90\" height=\"90\" align=\"right\">][PostCSS]\n\n[![NPM Version][npm-img]][npm-url]\n[![Support Chat][git-img]][git-url]\n\n[PostCSS Calc] lets you reduce `calc()` references whenever it's possible.\nWhen multiple units are mixed together in the same expression, the `calc()`\nstatement is left as is, to fallback to the [W3C calc() implementation].\n\n## Installation\n\n```bash\nnpm install postcss-calc\n```\n\n## Usage\n\n```js\n// dependencies\nvar fs = require(\"fs\")\nvar postcss = require(\"postcss\")\nvar calc = require(\"postcss-calc\")\n\n// css to be processed\nvar css = fs.readFileSync(\"input.css\", \"utf8\")\n\n// process css\nvar output = postcss()\n .use(calc())\n .process(css)\n .css\n```\n\nUsing this `input.css`:\n\n```css\nh1 {\n font-size: calc(16px * 2);\n height: calc(100px - 2em);\n width: calc(2*var(--base-width));\n margin-bottom: calc(16px * 1.5);\n}\n```\n\nyou will get:\n\n```css\nh1 {\n font-size: 32px;\n height: calc(100px - 2em);\n width: calc(2*var(--base-width));\n margin-bottom: 24px\n}\n```\nCheckout [tests] for more examples.\n\n### Options\n\n#### `precision` (default: `5`)\n\nAllow you to define the precision for decimal numbers.\n\n```js\nvar out = postcss()\n .use(calc({precision: 10}))\n .process(css)\n .css\n```\n\n#### `preserve` (default: `false`)\n\nAllow you to preserve calc() usage in output so browsers will handle decimal\nprecision themselves.\n\n```js\nvar out = postcss()\n .use(calc({preserve: true}))\n .process(css)\n .css\n```\n\n#### `warnWhenCannotResolve` (default: `false`)\n\nAdds warnings when calc() are not reduced to a single value.\n\n```js\nvar out = postcss()\n .use(calc({warnWhenCannotResolve: true}))\n .process(css)\n .css\n```\n\n#### `mediaQueries` (default: `false`)\n\nAllows calc() usage as part of media query declarations.\n\n```js\nvar out = postcss()\n .use(calc({mediaQueries: true}))\n .process(css)\n .css\n```\n\n#### `selectors` (default: `false`)\n\nAllows calc() usage as part of selectors.\n\n```js\nvar out = postcss()\n .use(calc({selectors: true}))\n .process(css)\n .css\n```\n\nExample:\n\n```css\ndiv[data-size=\"calc(3*3)\"] {\n width: 100px;\n}\n```\n\n---\n\n## Related PostCSS plugins\nTo replace the value of CSS custom properties at build time, try [PostCSS Custom Properties].\n\n## Contributing\n\nWork on a branch, install dev-dependencies, respect coding style & run tests\nbefore submitting a bug fix or a feature.\n\n```bash\ngit clone git@github.com:postcss/postcss-calc.git\ngit checkout -b patch-1\nnpm install\nnpm test\n```\n\n## [Changelog](CHANGELOG.md)\n\n## [License](LICENSE)\n\n[git-img]: https://img.shields.io/badge/support-chat-blue.svg\n[git-url]: https://gitter.im/postcss/postcss\n[npm-img]: https://img.shields.io/npm/v/postcss-calc.svg\n[npm-url]: https://www.npmjs.com/package/postcss-calc\n\n[PostCSS]: https://github.com/postcss\n[PostCSS Calc]: https://github.com/postcss/postcss-calc\n[PostCSS Custom Properties]: https://github.com/postcss/postcss-custom-properties\n[tests]: src/__tests__/index.js\n[W3C calc() implementation]: https://www.w3.org/TR/css3-values/#calc-notation\n"
|
|
62
|
-
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -1,421 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
const { test } = require('uvu');
|
|
3
|
-
const assert = require('uvu/assert');
|
|
4
|
-
|
|
5
|
-
const convertUnit = require('../lib/convertUnit.js');
|
|
6
|
-
|
|
7
|
-
test('valid conversions', () => {
|
|
8
|
-
const conversions = [
|
|
9
|
-
// source value, source unit, expected value, target unit
|
|
10
|
-
[10, 'px', 10, 'px'],
|
|
11
|
-
[10, 'px', 0.26458, 'cm'],
|
|
12
|
-
[10, 'px', 2.64583, 'mm'],
|
|
13
|
-
[10, 'px', 10.58333, 'q'],
|
|
14
|
-
[10, 'px', 0.10417, 'in'],
|
|
15
|
-
[10, 'px', 7.5, 'pt'],
|
|
16
|
-
[10, 'px', 0.625, 'pc'],
|
|
17
|
-
[10, 'cm', 377.95276, 'px'],
|
|
18
|
-
[10, 'cm', 10, 'cm'],
|
|
19
|
-
[10, 'cm', 100, 'mm'],
|
|
20
|
-
[10, 'cm', 400, 'q'],
|
|
21
|
-
[10, 'cm', 3.93701, 'in'],
|
|
22
|
-
[10, 'cm', 283.46457, 'pt'],
|
|
23
|
-
[10, 'cm', 23.62205, 'pc'],
|
|
24
|
-
[10, 'mm', 37.79528, 'px'],
|
|
25
|
-
[10, 'mm', 1, 'cm'],
|
|
26
|
-
[10, 'mm', 10, 'mm'],
|
|
27
|
-
[10, 'mm', 40, 'q'],
|
|
28
|
-
[10, 'mm', 0.3937, 'in'],
|
|
29
|
-
[10, 'mm', 28.34646, 'pt'],
|
|
30
|
-
[10, 'mm', 2.3622, 'pc'],
|
|
31
|
-
[10, 'q', 9.44882, 'px'],
|
|
32
|
-
[10, 'q', 0.25, 'cm'],
|
|
33
|
-
[10, 'q', 2.5, 'mm'],
|
|
34
|
-
[10, 'q', 0.09843, 'in'],
|
|
35
|
-
[10, 'q', 7.08661, 'pt'],
|
|
36
|
-
[10, 'q', 0.59055, 'pc'],
|
|
37
|
-
[10, 'in', 960, 'px'],
|
|
38
|
-
[10, 'in', 25.4, 'cm'],
|
|
39
|
-
[10, 'in', 254, 'mm'],
|
|
40
|
-
[10, 'in', 1016, 'q'],
|
|
41
|
-
[10, 'in', 10, 'in'],
|
|
42
|
-
[10, 'in', 720, 'pt'],
|
|
43
|
-
[10, 'in', 60, 'pc'],
|
|
44
|
-
[10, 'pt', 13.33333, 'px'],
|
|
45
|
-
[10, 'pt', 0.35278, 'cm'],
|
|
46
|
-
[10, 'pt', 3.52778, 'mm'],
|
|
47
|
-
[10, 'pt', 14.11111, 'q'],
|
|
48
|
-
[10, 'pt', 0.13889, 'in'],
|
|
49
|
-
[10, 'pt', 10, 'pt'],
|
|
50
|
-
[10, 'pt', 0.83333, 'pc'],
|
|
51
|
-
[10, 'pc', 160, 'px'],
|
|
52
|
-
[10, 'pc', 4.23333, 'cm'],
|
|
53
|
-
[10, 'pc', 42.33333, 'mm'],
|
|
54
|
-
[10, 'pc', 169.33333, 'q'],
|
|
55
|
-
[10, 'pc', 1.66667, 'in'],
|
|
56
|
-
[10, 'pc', 120, 'pt'],
|
|
57
|
-
[10, 'pc', 10, 'pc'],
|
|
58
|
-
[10, 'deg', 10, 'deg'],
|
|
59
|
-
[10, 'deg', 11.11111, 'grad'],
|
|
60
|
-
[10, 'deg', 0.17453, 'rad'],
|
|
61
|
-
[10, 'deg', 0.02778, 'turn'],
|
|
62
|
-
[10, 'grad', 9, 'deg'],
|
|
63
|
-
[10, 'grad', 10, 'grad'],
|
|
64
|
-
[10, 'grad', 0.15708, 'rad'],
|
|
65
|
-
[10, 'grad', 0.025, 'turn'],
|
|
66
|
-
[10, 'rad', 572.9578, 'deg'],
|
|
67
|
-
[10, 'rad', 636.61977, 'grad'],
|
|
68
|
-
[10, 'rad', 10, 'rad'],
|
|
69
|
-
[10, 'rad', 1.59155, 'turn'],
|
|
70
|
-
[10, 'turn', 3600, 'deg'],
|
|
71
|
-
[10, 'turn', 4000, 'grad'],
|
|
72
|
-
[10, 'turn', 62.83185, 'rad'],
|
|
73
|
-
[10, 'turn', 10, 'turn'],
|
|
74
|
-
[10, 's', 10, 's'],
|
|
75
|
-
[10, 's', 10000, 'ms'],
|
|
76
|
-
[10, 'ms', 0.01, 's'],
|
|
77
|
-
[10, 'ms', 10, 'ms'],
|
|
78
|
-
[10, 'Hz', 10, 'Hz'],
|
|
79
|
-
[10, 'Hz', 0.01, 'kHz'],
|
|
80
|
-
[10, 'kHz', 10000, 'Hz'],
|
|
81
|
-
[10, 'kHz', 10, 'kHz'],
|
|
82
|
-
[10, 'dpi', 10, 'dpi'],
|
|
83
|
-
[10, 'dpi', 25.4, 'dpcm'],
|
|
84
|
-
[10, 'dpi', 960, 'dppx'],
|
|
85
|
-
[10, 'dpcm', 3.93701, 'dpi'],
|
|
86
|
-
[10, 'dpcm', 10, 'dpcm'],
|
|
87
|
-
[10, 'dpcm', 377.95276, 'dppx'],
|
|
88
|
-
[10, 'dppx', 0.10417, 'dpi'],
|
|
89
|
-
[10, 'dppx', 0.26458, 'dpcm'],
|
|
90
|
-
[10, 'dppx', 10, 'dppx'],
|
|
91
|
-
];
|
|
92
|
-
|
|
93
|
-
conversions.forEach(function (e) {
|
|
94
|
-
const value = e[0];
|
|
95
|
-
const unit = e[1];
|
|
96
|
-
const expected = e[2];
|
|
97
|
-
const targetUnit = e[3];
|
|
98
|
-
|
|
99
|
-
assert.is(
|
|
100
|
-
convertUnit(value, unit, targetUnit),
|
|
101
|
-
expected,
|
|
102
|
-
unit + ' -> ' + targetUnit
|
|
103
|
-
);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
test('invalid conversions', () => {
|
|
108
|
-
const invalid_units = {
|
|
109
|
-
px: [
|
|
110
|
-
'deg',
|
|
111
|
-
'grad',
|
|
112
|
-
'rad',
|
|
113
|
-
'turn',
|
|
114
|
-
's',
|
|
115
|
-
'ms',
|
|
116
|
-
'Hz',
|
|
117
|
-
'kHz',
|
|
118
|
-
'dpi',
|
|
119
|
-
'dpcm',
|
|
120
|
-
'dppx',
|
|
121
|
-
],
|
|
122
|
-
cm: [
|
|
123
|
-
'deg',
|
|
124
|
-
'grad',
|
|
125
|
-
'rad',
|
|
126
|
-
'turn',
|
|
127
|
-
's',
|
|
128
|
-
'ms',
|
|
129
|
-
'Hz',
|
|
130
|
-
'kHz',
|
|
131
|
-
'dpi',
|
|
132
|
-
'dpcm',
|
|
133
|
-
'dppx',
|
|
134
|
-
],
|
|
135
|
-
mm: [
|
|
136
|
-
'deg',
|
|
137
|
-
'grad',
|
|
138
|
-
'rad',
|
|
139
|
-
'turn',
|
|
140
|
-
's',
|
|
141
|
-
'ms',
|
|
142
|
-
'Hz',
|
|
143
|
-
'kHz',
|
|
144
|
-
'dpi',
|
|
145
|
-
'dpcm',
|
|
146
|
-
'dppx',
|
|
147
|
-
],
|
|
148
|
-
q: [
|
|
149
|
-
'deg',
|
|
150
|
-
'grad',
|
|
151
|
-
'rad',
|
|
152
|
-
'turn',
|
|
153
|
-
's',
|
|
154
|
-
'ms',
|
|
155
|
-
'Hz',
|
|
156
|
-
'kHz',
|
|
157
|
-
'dpi',
|
|
158
|
-
'dpcm',
|
|
159
|
-
'dppx',
|
|
160
|
-
],
|
|
161
|
-
in: [
|
|
162
|
-
'deg',
|
|
163
|
-
'grad',
|
|
164
|
-
'rad',
|
|
165
|
-
'turn',
|
|
166
|
-
's',
|
|
167
|
-
'ms',
|
|
168
|
-
'Hz',
|
|
169
|
-
'kHz',
|
|
170
|
-
'dpi',
|
|
171
|
-
'dpcm',
|
|
172
|
-
'dppx',
|
|
173
|
-
],
|
|
174
|
-
pt: [
|
|
175
|
-
'deg',
|
|
176
|
-
'grad',
|
|
177
|
-
'rad',
|
|
178
|
-
'turn',
|
|
179
|
-
's',
|
|
180
|
-
'ms',
|
|
181
|
-
'Hz',
|
|
182
|
-
'kHz',
|
|
183
|
-
'dpi',
|
|
184
|
-
'dpcm',
|
|
185
|
-
'dppx',
|
|
186
|
-
],
|
|
187
|
-
pc: [
|
|
188
|
-
'deg',
|
|
189
|
-
'grad',
|
|
190
|
-
'rad',
|
|
191
|
-
'turn',
|
|
192
|
-
's',
|
|
193
|
-
'ms',
|
|
194
|
-
'Hz',
|
|
195
|
-
'kHz',
|
|
196
|
-
'dpi',
|
|
197
|
-
'dpcm',
|
|
198
|
-
'dppx',
|
|
199
|
-
],
|
|
200
|
-
deg: [
|
|
201
|
-
'px',
|
|
202
|
-
'cm',
|
|
203
|
-
'mm',
|
|
204
|
-
'in',
|
|
205
|
-
'pt',
|
|
206
|
-
'pc',
|
|
207
|
-
's',
|
|
208
|
-
'ms',
|
|
209
|
-
'Hz',
|
|
210
|
-
'kHz',
|
|
211
|
-
'dpi',
|
|
212
|
-
'dpcm',
|
|
213
|
-
'dppx',
|
|
214
|
-
],
|
|
215
|
-
grad: [
|
|
216
|
-
'px',
|
|
217
|
-
'cm',
|
|
218
|
-
'mm',
|
|
219
|
-
'in',
|
|
220
|
-
'pt',
|
|
221
|
-
'pc',
|
|
222
|
-
's',
|
|
223
|
-
'ms',
|
|
224
|
-
'Hz',
|
|
225
|
-
'kHz',
|
|
226
|
-
'dpi',
|
|
227
|
-
'dpcm',
|
|
228
|
-
'dppx',
|
|
229
|
-
],
|
|
230
|
-
rad: [
|
|
231
|
-
'px',
|
|
232
|
-
'cm',
|
|
233
|
-
'mm',
|
|
234
|
-
'in',
|
|
235
|
-
'pt',
|
|
236
|
-
'pc',
|
|
237
|
-
's',
|
|
238
|
-
'ms',
|
|
239
|
-
'Hz',
|
|
240
|
-
'kHz',
|
|
241
|
-
'dpi',
|
|
242
|
-
'dpcm',
|
|
243
|
-
'dppx',
|
|
244
|
-
],
|
|
245
|
-
turn: [
|
|
246
|
-
'px',
|
|
247
|
-
'cm',
|
|
248
|
-
'mm',
|
|
249
|
-
'in',
|
|
250
|
-
'pt',
|
|
251
|
-
'pc',
|
|
252
|
-
's',
|
|
253
|
-
'ms',
|
|
254
|
-
'Hz',
|
|
255
|
-
'kHz',
|
|
256
|
-
'dpi',
|
|
257
|
-
'dpcm',
|
|
258
|
-
'dppx',
|
|
259
|
-
],
|
|
260
|
-
s: [
|
|
261
|
-
'px',
|
|
262
|
-
'cm',
|
|
263
|
-
'mm',
|
|
264
|
-
'in',
|
|
265
|
-
'pt',
|
|
266
|
-
'pc',
|
|
267
|
-
'deg',
|
|
268
|
-
'grad',
|
|
269
|
-
'rad',
|
|
270
|
-
'turn',
|
|
271
|
-
'Hz',
|
|
272
|
-
'kHz',
|
|
273
|
-
'dpi',
|
|
274
|
-
'dpcm',
|
|
275
|
-
'dppx',
|
|
276
|
-
],
|
|
277
|
-
ms: [
|
|
278
|
-
'px',
|
|
279
|
-
'cm',
|
|
280
|
-
'mm',
|
|
281
|
-
'in',
|
|
282
|
-
'pt',
|
|
283
|
-
'pc',
|
|
284
|
-
'deg',
|
|
285
|
-
'grad',
|
|
286
|
-
'rad',
|
|
287
|
-
'turn',
|
|
288
|
-
'Hz',
|
|
289
|
-
'kHz',
|
|
290
|
-
'dpi',
|
|
291
|
-
'dpcm',
|
|
292
|
-
'dppx',
|
|
293
|
-
],
|
|
294
|
-
Hz: [
|
|
295
|
-
'px',
|
|
296
|
-
'cm',
|
|
297
|
-
'mm',
|
|
298
|
-
'in',
|
|
299
|
-
'pt',
|
|
300
|
-
'pc',
|
|
301
|
-
'deg',
|
|
302
|
-
'grad',
|
|
303
|
-
'rad',
|
|
304
|
-
'turn',
|
|
305
|
-
's',
|
|
306
|
-
'ms',
|
|
307
|
-
'dpi',
|
|
308
|
-
'dpcm',
|
|
309
|
-
'dppx',
|
|
310
|
-
],
|
|
311
|
-
kHz: [
|
|
312
|
-
'px',
|
|
313
|
-
'cm',
|
|
314
|
-
'mm',
|
|
315
|
-
'in',
|
|
316
|
-
'pt',
|
|
317
|
-
'pc',
|
|
318
|
-
'deg',
|
|
319
|
-
'grad',
|
|
320
|
-
'rad',
|
|
321
|
-
'turn',
|
|
322
|
-
's',
|
|
323
|
-
'ms',
|
|
324
|
-
'dpi',
|
|
325
|
-
'dpcm',
|
|
326
|
-
'dppx',
|
|
327
|
-
],
|
|
328
|
-
dpi: [
|
|
329
|
-
'px',
|
|
330
|
-
'cm',
|
|
331
|
-
'mm',
|
|
332
|
-
'in',
|
|
333
|
-
'pt',
|
|
334
|
-
'pc',
|
|
335
|
-
'deg',
|
|
336
|
-
'grad',
|
|
337
|
-
'rad',
|
|
338
|
-
'turn',
|
|
339
|
-
's',
|
|
340
|
-
'ms',
|
|
341
|
-
'Hz',
|
|
342
|
-
'kHz',
|
|
343
|
-
],
|
|
344
|
-
dpcm: [
|
|
345
|
-
'px',
|
|
346
|
-
'cm',
|
|
347
|
-
'mm',
|
|
348
|
-
'in',
|
|
349
|
-
'pt',
|
|
350
|
-
'pc',
|
|
351
|
-
'deg',
|
|
352
|
-
'grad',
|
|
353
|
-
'rad',
|
|
354
|
-
'turn',
|
|
355
|
-
's',
|
|
356
|
-
'ms',
|
|
357
|
-
'Hz',
|
|
358
|
-
'kHz',
|
|
359
|
-
],
|
|
360
|
-
dppx: [
|
|
361
|
-
'px',
|
|
362
|
-
'cm',
|
|
363
|
-
'mm',
|
|
364
|
-
'in',
|
|
365
|
-
'pt',
|
|
366
|
-
'pc',
|
|
367
|
-
'deg',
|
|
368
|
-
'grad',
|
|
369
|
-
'rad',
|
|
370
|
-
'turn',
|
|
371
|
-
's',
|
|
372
|
-
'ms',
|
|
373
|
-
'Hz',
|
|
374
|
-
'kHz',
|
|
375
|
-
],
|
|
376
|
-
};
|
|
377
|
-
|
|
378
|
-
for (const unit in invalid_units) {
|
|
379
|
-
invalid_units[unit].forEach((targetUnit) => {
|
|
380
|
-
let failed = false;
|
|
381
|
-
|
|
382
|
-
try {
|
|
383
|
-
convertUnit(10, unit, targetUnit);
|
|
384
|
-
} catch (e) {
|
|
385
|
-
failed = true;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
assert.ok(failed, unit + ' -> ' + targetUnit);
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
});
|
|
392
|
-
|
|
393
|
-
test('precision', () => {
|
|
394
|
-
const precision = 10;
|
|
395
|
-
const conversions = [
|
|
396
|
-
// source value, source unit, expected value, target unit
|
|
397
|
-
[10, 'px', 0.2645833333, 'cm'],
|
|
398
|
-
[10, 'px', 2.6458333333, 'mm'],
|
|
399
|
-
[10, 'px', 0.1041666667, 'in'],
|
|
400
|
-
[10, 'cm', 377.9527559055, 'px'],
|
|
401
|
-
];
|
|
402
|
-
|
|
403
|
-
conversions.forEach((e) => {
|
|
404
|
-
const value = e[0];
|
|
405
|
-
const unit = e[1];
|
|
406
|
-
const expected = e[2];
|
|
407
|
-
const targetUnit = e[3];
|
|
408
|
-
|
|
409
|
-
assert.is(
|
|
410
|
-
convertUnit(value, unit, targetUnit, precision),
|
|
411
|
-
expected,
|
|
412
|
-
unit + ' -> ' + targetUnit
|
|
413
|
-
);
|
|
414
|
-
});
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
test('falsey precision', () => {
|
|
418
|
-
assert.is(convertUnit(10, 'px', 'cm', false), 0.26458333333333334);
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
test.run();
|