From 46bd7ba3bfbc315204d50f795bad724d84d0e872 Mon Sep 17 00:00:00 2001 From: Mister-Hope Date: Wed, 22 May 2024 16:29:52 +0800 Subject: [PATCH] chore: rename new methods --- packages/client/src/router/resolveRoute.ts | 4 ++-- packages/client/src/router/resolveRouteFullPath.ts | 4 ++-- packages/shared/src/utils/routes/index.ts | 2 +- .../routes/{resolveRoutePathInfo.ts => resolvePathInfo.ts} | 4 ++-- ...resolveRoutePathInfo.spec.ts => resolvePathInfo.spec.ts} | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) rename packages/shared/src/utils/routes/{resolveRoutePathInfo.ts => resolvePathInfo.ts} (69%) rename packages/shared/tests/routes/{resolveRoutePathInfo.spec.ts => resolvePathInfo.spec.ts} (75%) diff --git a/packages/client/src/router/resolveRoute.ts b/packages/client/src/router/resolveRoute.ts index 8cacd9aac5..38e3313e22 100644 --- a/packages/client/src/router/resolveRoute.ts +++ b/packages/client/src/router/resolveRoute.ts @@ -1,4 +1,4 @@ -import { resolveRoutePathInfo } from '@vuepress/shared' +import { resolvePathInfo } from '@vuepress/shared' import { routes } from '../internal/routes.js' import type { Route, RouteMeta } from '../types/index.js' import { resolveRoutePath } from './resolveRoutePath.js' @@ -17,7 +17,7 @@ export const resolveRoute = ( currentPath?: string, ): ResolvedRoute => { // get only the pathname from the path - const [pathname, hashAndQueries] = resolveRoutePathInfo(path) + const [pathname, hashAndQueries] = resolvePathInfo(path) // resolve the route path const routePath = resolveRoutePath(pathname, currentPath) diff --git a/packages/client/src/router/resolveRouteFullPath.ts b/packages/client/src/router/resolveRouteFullPath.ts index a07441899a..a1ab501de6 100644 --- a/packages/client/src/router/resolveRouteFullPath.ts +++ b/packages/client/src/router/resolveRouteFullPath.ts @@ -1,4 +1,4 @@ -import { resolveRoutePathInfo } from '@vuepress/shared' +import { resolvePathInfo } from '@vuepress/shared' import { resolveRoutePath } from './resolveRoutePath.js' /** @@ -8,7 +8,7 @@ export const resolveRouteFullPath = ( path: string, currentPath?: string, ): string => { - const [pathname, hashAndQueries] = resolveRoutePathInfo(path) + const [pathname, hashAndQueries] = resolvePathInfo(path) return resolveRoutePath(pathname, currentPath) + hashAndQueries } diff --git a/packages/shared/src/utils/routes/index.ts b/packages/shared/src/utils/routes/index.ts index 4ec0e91b53..dfa2112b2f 100644 --- a/packages/shared/src/utils/routes/index.ts +++ b/packages/shared/src/utils/routes/index.ts @@ -2,4 +2,4 @@ export * from './inferRoutePath' export * from './normalizeRoutePath.js' export * from './resolveLocalePath.js' export * from './resolveRoutePathFromUrl.js' -export * from './resolveRoutePathInfo.js' +export * from './resolvePathInfo.js' diff --git a/packages/shared/src/utils/routes/resolveRoutePathInfo.ts b/packages/shared/src/utils/routes/resolvePathInfo.ts similarity index 69% rename from packages/shared/src/utils/routes/resolveRoutePathInfo.ts rename to packages/shared/src/utils/routes/resolvePathInfo.ts index 65b0b68bad..99ab36c9c7 100644 --- a/packages/shared/src/utils/routes/resolveRoutePathInfo.ts +++ b/packages/shared/src/utils/routes/resolvePathInfo.ts @@ -1,9 +1,9 @@ const SPLIT_CHAR_REGEXP = /(#|\?)/ /** - * Extract pathname / hash and queries from a full route path + * Extract pathname / hash and queries from a relative URL */ -export const resolveRoutePathInfo = ( +export const resolvePathInfo = ( path: string, ): [pathname: string, hashAndQueries: string] => { const [pathname, ...hashAndQueries] = path.split(SPLIT_CHAR_REGEXP) diff --git a/packages/shared/tests/routes/resolveRoutePathInfo.spec.ts b/packages/shared/tests/routes/resolvePathInfo.spec.ts similarity index 75% rename from packages/shared/tests/routes/resolveRoutePathInfo.spec.ts rename to packages/shared/tests/routes/resolvePathInfo.spec.ts index 5577bd8c09..a71f71b5e0 100644 --- a/packages/shared/tests/routes/resolveRoutePathInfo.spec.ts +++ b/packages/shared/tests/routes/resolvePathInfo.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest' -import { resolveRoutePathInfo } from '../../src/index.js' +import { resolvePathInfo } from '../../src/index.js' const testCases: [string, [string, string]][] = [ ['/a/b/c/', ['/a/b/c/', '']], @@ -12,10 +12,10 @@ const testCases: [string, [string, string]][] = [ ['/a/index.html?a=1#b', ['/a/index.html', '?a=1#b']], ] -describe('should resolve route path info correctly', () => { +describe('should resolve path info correctly', () => { testCases.forEach(([source, expected]) => { it(`${source} -> ${expected}`, () => { - expect(resolveRoutePathInfo(source)).toEqual(expected) + expect(resolvePathInfo(source)).toEqual(expected) }) }) })