-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostcss.functions.js
More file actions
36 lines (29 loc) · 941 Bytes
/
postcss.functions.js
File metadata and controls
36 lines (29 loc) · 941 Bytes
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
// helpers
function getUnit(a) {
return [...a].filter((num) => !isFinite(num)).join("")
}
exports.mod = function mod(x, y, preserveUnits = false) {
const result = parseInt(x, 10) % parseInt(y, 10)
const unit = getUnit(x) == getUnit(y) ? getUnit(x) : result
return !preserveUnits ? result : `${result}${unit}`
}
exports.q = function q(x, preserveUnits = false) {
const result = parseInt(
[...(x) => [...x].filter((num) => isFinite(num)).join("")].reduce(
(a, b) => a + b
),
10
)
return !preserveUnits ? result : `${result}${getUnit(x)}`
}
exports.steps = function steps(min, max, step, preserveUnits = false) {
let result = []
let result_units = []
for (let i = q(max); i >= q(min); i -= q(step)) {
result.push(i)
result_units.push(getUnit(min) || getUnit(max) || getUnit(step))
}
return !preserveUnits
? result.join()
: result.map((x, i) => `${x}${result_units[i]}`).join()
}