Skip to content

Commit

Permalink
fix(itk-wasm-cli): enforce alpha-numeric parameter names
Browse files Browse the repository at this point in the history
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
jadh4v committed Sep 26, 2022
1 parent ddec323 commit 1be234a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
16 changes: 13 additions & 3 deletions src/core/internal/camelCase.ts
@@ -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
15 changes: 12 additions & 3 deletions src/itk-wasm-cli.js
Expand Up @@ -208,11 +208,20 @@ function run(wasmBinary, options) {
}
}


function camelCase(kebobCase) {
return kebobCase.replace(/-([a-z])/g, (kk) => {
function camelCase(param) {
// make any alphabets that follows '-' an uppercase character, and remove the corresponding hyphen
let cameledParam = param.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
}

const interfaceJsonTypeToTypeScriptType = new Map([
Expand Down

0 comments on commit 1be234a

Please sign in to comment.