Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lutien committed Jul 25, 2016
2 parents c9a6a88 + 921962b commit 59a0984
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 10 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ module.exports = postcss.plugin('postcss-extract-value', function (opts) {
var reCSSVariable = /^var\(-{2}\w{1}[\w+-]*/;
var reHex = /#(\w{6}|\w{3})/;
var reRgb = /rgba?\([\d,.\s]+\)/;
var reHls = /hsla?\(\s?[0-9]{1,3},\s?(([0-9]{1,3})+%,\s?){2}[0-9.]+\s?\)/;
var reHsl = /hsla?\(\s?[0-9]{1,3},\s?(([0-9]{1,3})+%,\s?){2}[0-9.]+\s?\)/;
var reExtract = new RegExp(reHex.source + '|' + reRgb.source + '|' +
reHls.source + '|' + reColorKeywords.source, 'g');
reHsl.source + '|' + reColorKeywords.source, 'g');

// Options
var filterByProps = opts.filterByProps;
Expand Down
67 changes: 59 additions & 8 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,25 @@ test('repeated values', t => {
return run(t, input, output, optDefault);
});

test('option "onlyColor"', t => {
/** *************Color types*********************** **/
test('HSL', t => {
let input = `.foo {
border: 1px solid hsl(120,100%,50%, 0.5);
}`;
let output = `:root {
--border-1: hsl(120,100%,50%, 0.5);\n}\n.foo {
border: 1px solid var(--border-1);
}`;
return run(t, input, output, { onlyColor: true });
});

test('HSLA', t => {
let input = `.foo {
color: #000;
border: 1px solid hsla(120,100%,50%, 0.5);
width: 10px;
display: block;
}`;
let output = `:root {
--color-1: #000;
--border-1: hsla(120,100%,50%, 0.5);\n}\n.foo {
color: var(--color-1);
border: 1px solid var(--border-1);
width: 10px;
display: block;
}`;
return run(t, input, output, { onlyColor: true });
});
Expand All @@ -79,6 +84,52 @@ test('color keyword', t => {
return run(t, input, output, { onlyColor: true });
});

test('RGB', t => {
let input = `.foo {
border: 1px solid rgb(120, 100, 50);
}`;
let output = `:root {
--border-1: rgb(120, 100, 50);\n}\n.foo {
border: 1px solid var(--border-1);
}`;
return run(t, input, output, { onlyColor: true });
});

test('RGBA', t => {
let input = `.foo {
border: 1px solid rgba(120, 100, 50, 0.4);
}`;
let output = `:root {
--border-1: rgba(120, 100, 50, 0.4);\n}\n.foo {
border: 1px solid var(--border-1);
}`;
return run(t, input, output, { onlyColor: true });
});

test('short hex', t => {
let input = `.foo {
border: 1px solid #000;
}`;
let output = `:root {
--border-1: #000;\n}\n.foo {
border: 1px solid var(--border-1);
}`;
return run(t, input, output, { onlyColor: true });
});

test('long hex', t => {
let input = `.foo {
border: 1px solid #101113;
}`;
let output = `:root {
--border-1: #101113;\n}\n.foo {
border: 1px solid var(--border-1);
}`;
return run(t, input, output, { onlyColor: true });
});

/** ************************************************** **/

test('exist root element', t => {
let input = `:root {
--base-font-size: 16px;
Expand Down

0 comments on commit 59a0984

Please sign in to comment.