From f41153ce24621828965698820dab4ec9cd5f957c Mon Sep 17 00:00:00 2001 From: dzmitry-duboyski Date: Wed, 24 Jul 2024 05:13:20 +0400 Subject: [PATCH] Add params renaming function --- src/utils/renameParams.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/utils/renameParams.ts 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