diff --git a/camel-case.js b/camel-case.js index 23c21fd..f182de4 100644 --- a/camel-case.js +++ b/camel-case.js @@ -1,8 +1,11 @@ "use strict"; function camelCase (str) { return str.replace(/[\w-]+/g, (s) => ( - /^-?([a-z]+(?:-[a-z]+)+)$/.test(s) - ? RegExp.$1.replace( + /^-?[a-z]+(?:-[a-z]+)+$/.test(s) + ? s.replace( + /^-(ms|moz|khtml|epub|(\w+-?)*webkit)(?=-)/i, + "$1" + ).replace( /-\w/g, s => ( s[1].toUpperCase() diff --git a/package.json b/package.json index a4a5a10..b42a459 100644 --- a/package.json +++ b/package.json @@ -38,8 +38,9 @@ "check-coverage": true }, "scripts": { - "test": "nyc mocha --no-timeouts", - "debug": "mocha --inspect --debug-brk --no-timeouts" + "mocha": "mocha --no-timeouts", + "test": "nyc npm run mocha", + "debug": "npm run mocha -- --inspect-brk" }, "dependencies": { "@babel/core": "^7.0.0" @@ -52,12 +53,12 @@ "postcss-syntax": ">=0.33.0" }, "devDependencies": { - "autoprefixer": "^9.1.1", + "autoprefixer": "^9.1.5", "chai": "^4.1.2", - "codecov": "^3.0.4", - "json5": "^1.0.1", + "codecov": "^3.1.0", + "json5": "^2.0.1", "mocha": "^5.2.0", - "nyc": "^12.0.2", + "nyc": "^13.0.1", "postcss": "^7.0.2", "postcss-parser-tests": "^6.3.0", "postcss-safe-parser": "^4.0.1", diff --git a/test/camel-case.js b/test/camel-case.js index da2621c..d90e4a2 100644 --- a/test/camel-case.js +++ b/test/camel-case.js @@ -5,16 +5,19 @@ const camelCase = require("../camel-case"); const unCamelCase = require("../un-camel-case"); const data = { + borderTopLeftRadius: "border-top-left-radius", + backgroundImage: "background-image", xwebkitAnimation: "-xwebkit-animation", webkitAnimation: "-webkit-animation", epubAnimation: "-epub-animation", mozAnimation: "-moz-animation", msAnimation: "-ms-animation", - oAnimation: "-o-animation", - xAnimation: "-x-animation", + OAnimation: "-o-animation", + XAnimation: "-x-animation", webkitApp: "-webkit-app", - borderTopLeftRadius: "border-top-left-radius", - backgroundImage: "background-image", + onChange: "on-change", + OnChange: "-on-change", + zIndex: "z-index", "::selection": "::selection", "::mozSelection": "::-moz-selection", "::mozSelection,::selection": "::-moz-selection,::selection", @@ -50,12 +53,6 @@ describe("camelCase", () => { }); describe("unCamelCase", () => { - it("onChange => on-change", () => { - expect(unCamelCase("onChange")).to.equal("on-change"); - }); - it("OnChange => -on-change", () => { - expect(unCamelCase("OnChange")).to.equal("-on-change"); - }); testCases.forEach(testCase => { it(`${testCase.camel} => ${testCase.unCamel}`, () => { expect(unCamelCase(testCase.camel)).to.equal(testCase.unCamel); diff --git a/test/non-style.js b/test/non-style.js index 7b330b3..0b5e254 100644 --- a/test/non-style.js +++ b/test/non-style.js @@ -1,7 +1,7 @@ "use strict"; const spawnSync = require("child_process").spawnSync; const fs = require("fs"); -const files = spawnSync("git", ["ls-files"], {encoding: "utf8"}).stdout.match(/^.+$/gm).filter(file => file.endsWith(".js")); +const files = spawnSync("git", ["ls-files"], { encoding: "utf8" }).stdout.match(/^.+$/gm).filter(file => file.endsWith(".js")); const syntax = require("../"); const expect = require("chai").expect; diff --git a/un-camel-case.js b/un-camel-case.js index ba322c1..47b1a6e 100644 --- a/un-camel-case.js +++ b/un-camel-case.js @@ -1,13 +1,13 @@ "use strict"; function unCamelCase (str) { return str.replace(/[\w-]+/g, (s) => ( - /^[a-z]*(?:[A-Z][a-z]+)+$/.test(s) + /^[A-Z]?[a-z]*(?:[A-Z][a-z]+)+$/.test(s) ? s.replace( /[A-Z]/g, s => "-" + s.toLowerCase() ).replace( - /^(\w|ms|moz|khtml|epub|\w*webkit)-/, - "-$1-" + /^(o|ms|moz|khtml|epub|(\w+-?)*webkit)(?=-)/i, + "-$1" ) : s ));