Skip to content

Commit

Permalink
Add params renaming function
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-duboyski committed Jul 24, 2024
1 parent 5032a02 commit f41153c
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/utils/renameParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
*
* ### Renaming captcha parameters
*
* Description: parameter names used in the API may differ from those used in the library, in such cases parameter names are renamed in accordance with those used in the API.
*
* @param params - captcha parameters as an object
* @returns returns new object with renamed params
*
*/
export default function renameParams(params: any) {
let newParams: any = new Object();

/**
* Captcha parameters that need to be renamed before sent to the API.
*/
const replaceParams: any = {
"cols" : "recaptchacols",
"rows" : "recaptcharows",
"minClicks" : "min_clicks",
"maxClicks" : "max_clicks",
"canSkip" : "can_no_answer",
"previousId" : "previousID"
}

for(let key in params) {
if(replaceParams.hasOwnProperty(key)) {
newParams[replaceParams[key]] = params[key]
} else {
newParams[key] = params[key]
}
}

return newParams
}

0 comments on commit f41153c

Please sign in to comment.