Skip to content

Commit 3667330

Browse files
authored
fix camelCase (stylelint#34)
1 parent 06f7906 commit 3667330

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed

camel-case.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
"use strict";
22
function camelCase (str) {
33
return str.replace(/[\w-]+/g, (s) => (
4-
/^-?([a-z]+(?:-[a-z]+)+)$/.test(s)
5-
? RegExp.$1.replace(
4+
/^-?[a-z]+(?:-[a-z]+)+$/.test(s)
5+
? s.replace(
6+
/^-(ms|moz|khtml|epub|(\w+-?)*webkit)(?=-)/i,
7+
"$1"
8+
).replace(
69
/-\w/g,
710
s => (
811
s[1].toUpperCase()

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@
3838
"check-coverage": true
3939
},
4040
"scripts": {
41-
"test": "nyc mocha --no-timeouts",
42-
"debug": "mocha --inspect --debug-brk --no-timeouts"
41+
"mocha": "mocha --no-timeouts",
42+
"test": "nyc npm run mocha",
43+
"debug": "npm run mocha -- --inspect-brk"
4344
},
4445
"dependencies": {
4546
"@babel/core": "^7.0.0"
@@ -52,12 +53,12 @@
5253
"postcss-syntax": ">=0.33.0"
5354
},
5455
"devDependencies": {
55-
"autoprefixer": "^9.1.1",
56+
"autoprefixer": "^9.1.5",
5657
"chai": "^4.1.2",
57-
"codecov": "^3.0.4",
58-
"json5": "^1.0.1",
58+
"codecov": "^3.1.0",
59+
"json5": "^2.0.1",
5960
"mocha": "^5.2.0",
60-
"nyc": "^12.0.2",
61+
"nyc": "^13.0.1",
6162
"postcss": "^7.0.2",
6263
"postcss-parser-tests": "^6.3.0",
6364
"postcss-safe-parser": "^4.0.1",

test/camel-case.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ const camelCase = require("../camel-case");
55
const unCamelCase = require("../un-camel-case");
66

77
const data = {
8+
borderTopLeftRadius: "border-top-left-radius",
9+
backgroundImage: "background-image",
810
xwebkitAnimation: "-xwebkit-animation",
911
webkitAnimation: "-webkit-animation",
1012
epubAnimation: "-epub-animation",
1113
mozAnimation: "-moz-animation",
1214
msAnimation: "-ms-animation",
13-
oAnimation: "-o-animation",
14-
xAnimation: "-x-animation",
15+
OAnimation: "-o-animation",
16+
XAnimation: "-x-animation",
1517
webkitApp: "-webkit-app",
16-
borderTopLeftRadius: "border-top-left-radius",
17-
backgroundImage: "background-image",
18+
onChange: "on-change",
19+
OnChange: "-on-change",
20+
zIndex: "z-index",
1821
"::selection": "::selection",
1922
"::mozSelection": "::-moz-selection",
2023
"::mozSelection,::selection": "::-moz-selection,::selection",
@@ -50,12 +53,6 @@ describe("camelCase", () => {
5053
});
5154

5255
describe("unCamelCase", () => {
53-
it("onChange => on-change", () => {
54-
expect(unCamelCase("onChange")).to.equal("on-change");
55-
});
56-
it("OnChange => -on-change", () => {
57-
expect(unCamelCase("OnChange")).to.equal("-on-change");
58-
});
5956
testCases.forEach(testCase => {
6057
it(`${testCase.camel} => ${testCase.unCamel}`, () => {
6158
expect(unCamelCase(testCase.camel)).to.equal(testCase.unCamel);

test/non-style.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22
const spawnSync = require("child_process").spawnSync;
33
const fs = require("fs");
4-
const files = spawnSync("git", ["ls-files"], {encoding: "utf8"}).stdout.match(/^.+$/gm).filter(file => file.endsWith(".js"));
4+
const files = spawnSync("git", ["ls-files"], { encoding: "utf8" }).stdout.match(/^.+$/gm).filter(file => file.endsWith(".js"));
55
const syntax = require("../");
66
const expect = require("chai").expect;
77

un-camel-case.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"use strict";
22
function unCamelCase (str) {
33
return str.replace(/[\w-]+/g, (s) => (
4-
/^[a-z]*(?:[A-Z][a-z]+)+$/.test(s)
4+
/^[A-Z]?[a-z]*(?:[A-Z][a-z]+)+$/.test(s)
55
? s.replace(
66
/[A-Z]/g,
77
s => "-" + s.toLowerCase()
88
).replace(
9-
/^(\w|ms|moz|khtml|epub|\w*webkit)-/,
10-
"-$1-"
9+
/^(o|ms|moz|khtml|epub|(\w+-?)*webkit)(?=-)/i,
10+
"-$1"
1111
)
1212
: s
1313
));

0 commit comments

Comments
 (0)