diff --git a/package.json b/package.json index da881f4..104b1bb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "axios-logger", - "version": "2.8.0", + "version": "2.8.1", "description": "Beautify Axios Logging Messages", "main": "lib/index.js", "keywords": [ diff --git a/src/common/string-builder.ts b/src/common/string-builder.ts index 16adc1a..bca4dee 100644 --- a/src/common/string-builder.ts +++ b/src/common/string-builder.ts @@ -2,7 +2,7 @@ import dateformat from 'dateformat'; import { GlobalLogConfig } from './types'; import chalk from 'chalk'; import { AxiosResponse } from "axios/index"; -import path from 'path'; +import { join } from "./utils"; class StringBuilder { private config: GlobalLogConfig; @@ -107,7 +107,7 @@ class StringBuilder { const isBaseUrlHaveSubpath = firstURL && firstURL.pathname !== '' ? true : false; if (isBaseUrlHaveSubpath && firstURL) { - return (new URL(path.join(firstURL.pathname, relativeURL as string), baseURL)).toString(); + return (new URL(join(firstURL.pathname, relativeURL as string), baseURL)).toString(); } else { return (new URL(relativeURL as string, baseURL)).toString(); } diff --git a/src/common/utils.ts b/src/common/utils.ts new file mode 100644 index 0000000..10f0fde --- /dev/null +++ b/src/common/utils.ts @@ -0,0 +1,15 @@ +export function join(...paths: string[]) { + return paths + .map((path, index) => { + if (index > 0) { + path = path.replace(/^\//, ''); // Remove leading slash from all except the first part + } + if (index < paths.length - 1) { + path = path.replace(/\/$/, ''); // Remove trailing slash from all except the last part + } + return path; + }) + .join('/') + .replace(/\/+/g, '/'); // Replace multiple slashes with a single slash + +}