From d630a2f5eff0578dedd61132ba38ca228388675f Mon Sep 17 00:00:00 2001 From: Laurynas Butkus Date: Sun, 16 Jul 2023 21:06:26 +0300 Subject: [PATCH] Make converter param name case insensitive --- package.json | 2 +- src/task.js | 12 +++++++++--- src/utils.js | 8 ++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index bd084d7..b1ca397 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "chai-fs": "^2.0.0", "cross-env": "^5.1.3", "eslint": "^4.19.1", - "eslint-config-airbnb": "^17.0.0", + "eslint-config-airbnb": "~17.0.0", "eslint-plugin-import": "^2.7.0", "eslint-plugin-jsx-a11y": "^6.0.2", "eslint-plugin-react": "^7.4.0", diff --git a/src/task.js b/src/task.js index 0590c97..9375ed5 100644 --- a/src/task.js +++ b/src/task.js @@ -1,4 +1,9 @@ -import { normalizeFilesParam, buildFileParam, detectFormat } from './utils'; +import { + normalizeFilesParam, + buildFileParam, + detectFormat, + detectConverter, +} from './utils'; import Result from './result'; const Task = class { @@ -22,8 +27,9 @@ const Task = class { } const fromFormat = this.fromFormat || detectFormat(params, this.toFormat); - const converter = params.converter ? `/converter/${params.converter}` : ''; - const path = `convert/${fromFormat}/to/${this.toFormat}${converter}`; + const converter = detectConverter(params); + const converterPath = converter ? `/converter/${converter}` : ''; + const path = `convert/${fromFormat}/to/${this.toFormat}${converterPath}`; const response = await this.api.client.post(path, params, timeout); return new Result(this.api, response); diff --git a/src/utils.js b/src/utils.js index cb0075b..4e54632 100644 --- a/src/utils.js +++ b/src/utils.js @@ -101,3 +101,11 @@ export const encodeFileName = (fileName) => { const str = encodeURIComponent(fileName); return str.replace(/[!'()*]/g, c => `%${c.charCodeAt(0).toString(16)}`); }; + +export const detectConverter = (params) => { + const converterKey = Object.keys(params).find(key => key.toLowerCase() === 'converter'); + + if (!converterKey) return undefined; + + return params[converterKey]; +};