Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

Add support for calc() in arbitrary values #14

Merged
merged 2 commits into from
Mar 15, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add support for calc() in arbitrary values
  • Loading branch information
bradlc committed Mar 15, 2021
commit 6fe9cb477105894cffc28c25958e0256a71ace03
11 changes: 9 additions & 2 deletions src/pluginUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,15 @@ function asValue(modifier, lookup = {}, { validate = () => true, transform = (v)
function asUnit(modifier, units, lookup = {}) {
return asValue(modifier, lookup, {
validate: (value) => {
let pattern = new RegExp(`.+(${units.join('|')})$`, 'g')
return value.match(pattern) !== null
let unitsPattern = `(?:${units.join('|')})`
return (
new RegExp(`${unitsPattern}$`).test(value) ||
new RegExp(`^calc\\(.+?${unitsPattern}`).test(value)
)
},
transform: (value) => {
// add spaces around operators inside calc() that do not follow an operator or (
return value.replace(/(?<=^calc\(.+?)(?<![-+*/(])([-+*/])/g, ' $1 ')
},
})
}
Expand Down