-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(itk-wasm-cli): enforce alpha-numeric parameter names
Change function camelCase() to additionally remove non-alphanumeric chars. Also throw error if the final string is empty (sanitization for parameter names).
- Loading branch information
Showing
2 changed files
with
25 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
function camelCase (kebobCase: string): string { | ||
return kebobCase.replace(/-([a-z])/g, (kk) => { | ||
return kk[1].toUpperCase() | ||
}) | ||
// make any alphabets that follows '-' an uppercase character, and remove the corresponding hyphen | ||
let cameledParam = kebobCase.replace(/-([a-z])/g, (kk) => { | ||
return kk[1].toUpperCase(); | ||
}); | ||
|
||
// remove all non-alphanumeric characters | ||
const outParam = cameledParam.replace(/([^0-9a-z])/ig, '') | ||
|
||
// check if resulting string is empty | ||
if(outParam === '') { | ||
console.error(`Resulting string is empty.`) | ||
} | ||
return outParam | ||
} | ||
|
||
export default camelCase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters