-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* simplify `negateValue` Co-authored-by: Brad Cornes <bradlc41@gmail.com> * ensure we have the exact same behaviour * Simplify/loosen regex to be more future-proof Co-authored-by: Brad Cornes <bradlc41@gmail.com> Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
- Loading branch information
1 parent
f86c16b
commit 920f212
Showing
4 changed files
with
47 additions
and
80 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
import reduceCalc from 'reduce-css-calc' | ||
|
||
export default function (value) { | ||
try { | ||
return reduceCalc(`calc(${value} * -1)`) | ||
} catch (e) { | ||
return value | ||
value = `${value}` | ||
|
||
// Flip sign of numbers | ||
if (/^[+-]?(\d+|\d*\.\d+)(e[+-]?\d+)?(%|\w+)?$/.test(value)) { | ||
return value.replace(/^[+-]?/, (sign) => (sign === '-' ? '' : '-')) | ||
} | ||
|
||
if (value.includes('var(') || value.includes('calc(')) { | ||
return `calc(${value} * -1)` | ||
} | ||
|
||
return value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters