Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f1093f
commit b6698ca
Showing
10 changed files
with
52 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { isPlainObject } from './types'; | ||
|
||
export function ensureObject(value?: any) { | ||
return isPlainObject(value) ? value : {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,8 @@ | ||
import { AxiosRequestConfig } from '../core/Axios'; | ||
import { isPlainObject } from './types'; | ||
import { buildURL } from './buildURL'; | ||
import { combineURL } from './combineURL'; | ||
import { dynamicURL } from './dynamicURL'; | ||
|
||
export function transformURL(config: AxiosRequestConfig) { | ||
const fullPath = dynamicURL( | ||
combineURL(config.baseURL, config.url), | ||
config.params, | ||
isPlainObject(config.data) ? config.data : {}, | ||
); | ||
const fullPath = combineURL(config.baseURL, config.url); | ||
return buildURL(fullPath, config.params, config.paramsSerializer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { describe, test, expect } from 'vitest'; | ||
import { ensureObject } from '@/helpers/ensureObject'; | ||
|
||
describe('src/helpers/ensureObject.ts', () => { | ||
test('应该始终返回对象', () => { | ||
expect(ensureObject()).toEqual({}); | ||
expect(ensureObject(1)).toEqual({}); | ||
expect(ensureObject('')).toEqual({}); | ||
expect(ensureObject([])).toEqual({}); | ||
expect(ensureObject(new Date())).toEqual({}); | ||
}); | ||
|
||
test('应该返回对象参数', () => { | ||
expect(ensureObject({ a: 1 })).toEqual({ a: 1 }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters