DRY
This commit is contained in:
parent
a55f942895
commit
fde01a6cf1
2 changed files with 11 additions and 37 deletions
|
@ -113,23 +113,11 @@ module.exports = (function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function matchSideOrCorner() {
|
function matchSideOrCorner() {
|
||||||
var captures = scan(tokens.sideOrCorner);
|
return match('directional', tokens.sideOrCorner, 1);
|
||||||
if (captures) {
|
|
||||||
return {
|
|
||||||
type: 'directional',
|
|
||||||
value: captures[1].toLowerCase()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function matchAngle() {
|
function matchAngle() {
|
||||||
var captures = scan(tokens.angleValue);
|
return match('angular', tokens.angleValue, 1);
|
||||||
if (captures) {
|
|
||||||
return {
|
|
||||||
type: 'angle',
|
|
||||||
value: captures[1]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function matchListing(matcher) {
|
function matchListing(matcher) {
|
||||||
|
@ -170,25 +158,11 @@ module.exports = (function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function matchLiteralColor() {
|
function matchLiteralColor() {
|
||||||
var captures = scan(tokens.literalColor);
|
return match('literal', tokens.literalColor, 0);
|
||||||
|
|
||||||
if (captures) {
|
|
||||||
return {
|
|
||||||
type: 'literal',
|
|
||||||
value: captures[0].toLowerCase()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function matchHexColor() {
|
function matchHexColor() {
|
||||||
var captures = scan(tokens.hexColor);
|
return match('hex', tokens.hexColor, 1);
|
||||||
|
|
||||||
if (captures) {
|
|
||||||
return {
|
|
||||||
type: 'hex',
|
|
||||||
value: captures[1]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function matchRGBColor() {
|
function matchRGBColor() {
|
||||||
|
@ -214,17 +188,17 @@ module.exports = (function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function matchLength() {
|
function matchLength() {
|
||||||
return matchMetric(tokens.pixelValue, 'px') ||
|
return match('px', tokens.pixelValue, 1) ||
|
||||||
matchMetric(tokens.percentageValue, '%') ||
|
match('%', tokens.percentageValue, 1) ||
|
||||||
matchMetric(tokens.emValue, 'em');
|
match('em', tokens.emValue, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function matchMetric(pattern, metric) {
|
function match(type, pattern, captureIndex) {
|
||||||
var captures = scan(pattern);
|
var captures = scan(pattern);
|
||||||
if (captures) {
|
if (captures) {
|
||||||
return {
|
return {
|
||||||
type: metric,
|
type: type,
|
||||||
value: captures[1]
|
value: captures[captureIndex]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,7 +153,7 @@ describe('gradient-parser.js', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
[
|
[
|
||||||
{type: 'angle', unparsedValue: '145deg', value: '145'},
|
{type: 'angular', unparsedValue: '145deg', value: '145'},
|
||||||
{type: 'directional', unparsedValue: 'to left top', value: 'left top'}
|
{type: 'directional', unparsedValue: 'to left top', value: 'left top'}
|
||||||
].forEach(function(orientation) {
|
].forEach(function(orientation) {
|
||||||
describe('parse orientation ' + orientation.type, function() {
|
describe('parse orientation ' + orientation.type, function() {
|
||||||
|
|
Loading…
Reference in a new issue