From: Eduardo San Martin Morote Date: Sun, 10 Aug 2025 16:44:26 +0000 (+0200) Subject: refactor: identity fn X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=18ccc0017431faf341af9e87a0c4fd8acb991a75;p=thirdparty%2Fvuejs%2Frouter.git refactor: identity fn --- diff --git a/packages/router/src/experimental/route-resolver/matchers/matcher-pattern.ts b/packages/router/src/experimental/route-resolver/matchers/matcher-pattern.ts index 083902a1..e898ad4d 100644 --- a/packages/router/src/experimental/route-resolver/matchers/matcher-pattern.ts +++ b/packages/router/src/experimental/route-resolver/matchers/matcher-pattern.ts @@ -1,3 +1,4 @@ +import { identityFn } from '../../../utils' import { encodeParam } from '../../../encoding' import { warn } from '../../../warning' import { decode, MatcherQueryParams } from '../resolver-abstract' @@ -289,13 +290,10 @@ export class MatcherPatternPathCustomParams< var currentMatch = (match[i + 1] as string | undefined) ?? null var value = paramOptions.repeat - ? (currentMatch?.split('/') || []).map( - // using just decode makes the type inference fail - v => decode(v) - ) + ? (currentMatch?.split('/') || []).map(decode) : decode(currentMatch) - params[paramName] = (paramOptions.get || (v => v))( + params[paramName] = (paramOptions.get || identityFn)( value // NOTE: paramName and paramOptions are not connected from TS point of view ) @@ -325,7 +323,7 @@ export class MatcherPatternPathCustomParams< const paramName = this.paramsKeys[paramIndex++] const paramOptions = this.params[paramName] const value: ReturnType> = ( - paramOptions.set || (v => v) + paramOptions.set || identityFn )(params[paramName]) return Array.isArray(value) diff --git a/packages/router/src/utils/index.ts b/packages/router/src/utils/index.ts index c6d62209..b9cf4f72 100644 --- a/packages/router/src/utils/index.ts +++ b/packages/router/src/utils/index.ts @@ -5,6 +5,15 @@ import { RawRouteComponent, } from '../types' +/** + * Identity function that returns the value as is. + * + * @param v - the value to return + * + * @internal + */ +export const identityFn = (v: T) => v + export * from './env' /**