Skip to content

Commit

Permalink
fix: remove nodejs module "path" (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
hg-pyun authored May 29, 2024
1 parent b78f719 commit 08e8da6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
4 changes: 2 additions & 2 deletions src/common/string-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
15 changes: 15 additions & 0 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
@@ -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

}

0 comments on commit 08e8da6

Please sign in to comment.