Skip to content

Commit

Permalink
feat: 🎸 add combineURLs
Browse files Browse the repository at this point in the history
  • Loading branch information
l246804 committed Sep 5, 2023
1 parent 7fd01be commit 8a1921b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/combineURLs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* 根据指定的 URLs 创建新的 URL
*
* @see https://github.com/axios/axios/blob/v1.x/lib/helpers/combineURLs.js
*
* @example
* ```ts
* combineURLs('/website')
* // => '/website'
*
* combineURLs('/website/', '/api')
* // => '/website/api'
* ```
*/
export default function combineURLs(baseURL: string, relativeURL = '') {
return relativeURL
? `${baseURL.replace(/\/+$/, '')}/${relativeURL.replace(/^\/+/, '')}`
: baseURL
}

0 comments on commit 8a1921b

Please sign in to comment.