Skip to content

Commit

Permalink
refactor: replaces own pascal case function with sindresorhus/camelcase
Browse files Browse the repository at this point in the history
as that now properly handles unicode
  • Loading branch information
sverweij committed Oct 4, 2020
1 parent d6f10f5 commit f116694
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
23 changes: 2 additions & 21 deletions lib/rules/parameter-pattern.js
@@ -1,8 +1,8 @@
const camelcase = require("camelcase");
const _get = require("lodash.get");
const {
getValidParameterPattern,
getIdentifierReplacementPattern,
getValidConstantPattern,
} = require("./pattern-utl");
/**
* @fileoverview Enforce function parameters to adhere to a pattern
Expand All @@ -12,28 +12,9 @@ const {
function getParameterName(pParam) {
return _get(pParam, "name", _get(pParam, "left.name", "pOK"));
}
function toInitCaps(pString) {
return pString
.slice(0, 1)
.toLocaleUpperCase()
.concat(
// maybe not such a hot idea to use a function named after
// a valid constant pattern, but otoh it's a perfect fit
// maybe rename that function so it's usable in 2 spots? Copy?
pString.slice(1).match(getValidConstantPattern())
? pString.slice(1).toLocaleLowerCase()
: pString.slice(1)
);
}
// wanted to use sindresorhus/camelize for this, but that is not unicode
// compliant yet
// handles snake_case and SNAKED_ALL_CAPS
function toPascalCase(pString) {
return pString.split("_").map(toInitCaps).join("");
}

function normalizeParameterName(pString) {
return `p${toPascalCase(pString)}`;
return `p${camelcase(pString, {pascalCase:true})}`;
}

function parameterNameIsValid(pString) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -36,6 +36,7 @@
"version": "npm-run-all check depcruise:graph scm:stage"
},
"dependencies": {
"camelcase": "6.0.0",
"decamelize": "4.0.0",
"lodash.get": "4.4.2"
},
Expand Down

0 comments on commit f116694

Please sign in to comment.