Skip to content

Commit

Permalink
format hex color code #41
Browse files Browse the repository at this point in the history
  • Loading branch information
Masaaki Morishita committed Dec 31, 2015
1 parent 660b357 commit 31d5643
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/formatValues.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var isHex = require('./util').isHex

function formatProperties (decl) {
var isDataUrl = (/data:.+\/(.+);base64,(.*)/).test(decl.value)

Expand All @@ -12,6 +14,10 @@ function formatProperties (decl) {
}
decl.value = decl.value.trim().replace(/[+\-*/%](?=\$|\()/g, ' $& ')

if (isHex(decl.value)) {
decl.value = decl.value.toLowerCase()
}

if (decl.important) {
decl.raws.important = " !important"
}
Expand Down
8 changes: 8 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var hexRegex = require('hex-color-regex')

function inAtRule (rule) {
var ret = false
var current = rule.parent
Expand Down Expand Up @@ -26,5 +28,11 @@ function getNestedRulesNum (rule) {
}


function isHex (str) {
return hexRegex({exact: true}).test(str)
}


module.exports.inAtRule = inAtRule
module.exports.getNestedRulesNum = getNestedRulesNum
module.exports.isHex = isHex
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"dependencies": {
"editorconfig-indent": "^0.3.0",
"find-config": "0.3.0",
"hex-color-regex": "^1.0.3",
"minimist": "^1.1.2",
"postcss": "^5.0.6",
"postcss-scss": "^0.1.0",
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/color-hex-lowercase.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.foo{color:#ABCDEF}
3 changes: 3 additions & 0 deletions test/fixtures/color-hex-lowercase.out.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.foo {
color: #abcdef;
}
1 change: 1 addition & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ test('sass-if-else')
test('sass-if-else-2')
test('media-indent')
test('media-indent-with-import')
test('color-hex-lowercase')

0 comments on commit 31d5643

Please sign in to comment.