chore(utils): improve link utils

This commit is contained in:
Benjamin Canac
2024-01-11 12:16:27 +01:00
parent 02d72df527
commit 28b736a703
4 changed files with 42 additions and 7 deletions

View File

@@ -74,3 +74,4 @@ export function looseToNumber (val: any): any {
}
export * from './lodash'
export * from './link'

View File

@@ -61,12 +61,47 @@ export const nuxtLinkProps = {
}
} as const
export const getNuxtLinkProps = (props: Record<string, unknown>) => {
const nuxtLinkPropsKeys = Object.keys(nuxtLinkProps)
return nuxtLinkPropsKeys.reduce((acc, key) => {
const uLinkProps = {
active: {
type: Boolean,
default: undefined
},
exact: {
type: Boolean,
default: false
},
exactQuery: {
type: Boolean,
default: false
},
exactHash: {
type: Boolean,
default: false
},
inactiveClass: {
type: String,
default: undefined
}
} as const
export const getNuxtLinkProps = (props) => {
const keys = Object.keys(nuxtLinkProps)
return keys.reduce((acc, key) => {
if (props[key] !== undefined) {
acc[key] = props[key]
}
return acc
}, {} as Record<string, unknown>)
}, {})
}
export const getULinkProps = (props) => {
const keys = [...Object.keys(nuxtLinkProps), ...Object.keys(uLinkProps)]
return keys.reduce((acc, key) => {
if (props[key] !== undefined) {
acc[key] = props[key]
}
return acc
}, {})
}