mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-11 08:07:26 +02:00
refactor(v2): purify normalizeUrl (#4814)
Co-authored-by: Nam Hoang Le <nam.hoang.le@mgm-tp.com>
This commit is contained in:
parent
fa7aa08100
commit
e85ec1ab12
2 changed files with 6 additions and 3 deletions
|
@ -69,7 +69,7 @@ describe('load utils', () => {
|
|||
});
|
||||
|
||||
test('simpleHash', () => {
|
||||
const asserts = {
|
||||
const asserts: Record<string, string> = {
|
||||
'': 'd41',
|
||||
'/foo-bar': '096',
|
||||
'/foo/bar': '1df',
|
||||
|
@ -230,7 +230,9 @@ describe('load utils', () => {
|
|||
});
|
||||
expect(idx(obj, ['translation', 'enabled'])).toEqual(true);
|
||||
expect(
|
||||
idx(obj, ['translation', variable]).map((lang) => lang.tag),
|
||||
idx(obj, ['translation', variable]).map(
|
||||
(lang: {tag: string}) => lang.tag,
|
||||
),
|
||||
).toEqual(['en', 'ja']);
|
||||
expect(idx(test, ['arr', 0])).toEqual(1);
|
||||
expect(idx(undefined)).toBeUndefined();
|
||||
|
@ -350,6 +352,7 @@ describe('load utils', () => {
|
|||
});
|
||||
|
||||
expect(() =>
|
||||
// @ts-expect-error undefined for test
|
||||
normalizeUrl(['http:example.com', undefined]),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Url must be a string. Received undefined"`,
|
||||
|
|
|
@ -199,7 +199,7 @@ export function getSubFolder(file: string, refDir: string): string | null {
|
|||
}
|
||||
|
||||
export function normalizeUrl(rawUrls: string[]): string {
|
||||
const urls = rawUrls;
|
||||
const urls = [...rawUrls];
|
||||
const resultArray = [];
|
||||
|
||||
let hasStartingSlash = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue