Skip to content

Commit 4c1fede

Browse files
authored
Merge pull request #1 from ginpei/negativeNumbers
Support negative numbers
2 parents de45a02 + 37fa58c commit 4c1fede

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Parser.prototype.ident = function(){
3939
};
4040

4141
Parser.prototype.int = function(){
42-
var m = /^((\d+)([^\s\/]+)?) */.exec(this.str);
42+
var m = /^((-?\d+)([^\s\/]+)?) */.exec(this.str);
4343
if (!m) return;
4444
this.skip(m[0]);
4545
var n = ~~m[2];
@@ -54,7 +54,7 @@ Parser.prototype.int = function(){
5454
};
5555

5656
Parser.prototype.float = function(){
57-
var m = /^(((?:\d+)?\.\d+)([^\s\/]+)?) */.exec(this.str);
57+
var m = /^((-?(?:\d+)?\.\d+)([^\s\/]+)?) */.exec(this.str);
5858
if (!m) return;
5959
this.skip(m[0]);
6060
var n = parseFloat(m[2]);

test/cases/numbers.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
exports.string = '1px 0 0 5% .5px .10 1.5';
2+
exports.string = '1px 0 0 5% .5px .10 1.5 -1 -0.1';
33

44
exports.object = [
55
{ type: 'number', string: '1px', unit: 'px', value: 1 },
@@ -8,5 +8,7 @@ exports.object = [
88
{ type: 'number', string: '5%', unit: '%', value: 5 },
99
{ type: 'number', string: '.5px', unit: 'px', value: .5 },
1010
{ type: 'number', string: '.10', unit: '', value: .1 },
11-
{ type: 'number', string: '1.5', unit: '', value: 1.5 }
11+
{ type: 'number', string: '1.5', unit: '', value: 1.5 },
12+
{ type: 'number', string: '-1', unit: '', value: -1 },
13+
{ type: 'number', string: '-0.1', unit: '', value: -0.1 }
1214
];

0 commit comments

Comments
 (0)