Skip to content

Commit df0fceb

Browse files
author
Alexander Ryzhikov
committed
Fix px stripping
closes #1
1 parent 6d0aca2 commit df0fceb

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed

lib/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ var objectify = function objectify(root, filepath) {
7272

7373
var key = rule.prop.replace(/^-+/, ''); // replace "--"
7474

75-
result[key] = value.endsWith('px') ? parseInt(value, 10) : value;
75+
result[key] = value.match(/^[+-]?\d*.?(\d*)?(px)$/i) ? parseFloat(value) : value;
7676
}
7777
});
7878
return result;

src/lib/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const objectify = (root, filepath) => {
4949
const { value } = rule
5050
const key = rule.prop.replace(/^-+/, '') // replace "--"
5151

52-
result[key] = value.endsWith('px') ? parseInt(value, 10) : value
52+
result[key] = value.match(/^[+-]?\d*.?(\d*)?(px)$/i) ? parseFloat(value) : value
5353
}
5454
})
5555
return result

test/fixtures/caseSwitch.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:root {
2+
--size-variable: 10em;
3+
}

test/fixtures/pxstrip.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
:root {
2-
--size: 10px;
2+
--size: 10PX;
3+
--padding: 10px 10px;
34
}

test/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@ test('works with es5 option', async (t) => {
1616

1717
test('px strip', async (t) => {
1818
const result = await runner('./pxstrip.css')
19-
const expected = 10
2019

21-
t.is(result.size, expected)
20+
t.is(result.size, 10)
21+
})
22+
23+
test('px strip ignores multiple px values', async (t) => {
24+
const result = await runner('./pxstrip.css')
25+
26+
t.is(result.padding, '10px 10px')
2227
})
2328

2429
test('imports drop', async (t) => {

0 commit comments

Comments
 (0)