diff --git a/src/utils/renameParams.ts b/src/utils/renameParams.ts new file mode 100644 index 0000000..7945891 --- /dev/null +++ b/src/utils/renameParams.ts @@ -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 +} \ No newline at end of file