25 lines
734 B
TypeScript
25 lines
734 B
TypeScript
import type { LocationQuery } from 'vue-router'
|
|
|
|
export const PAGE_SIZES = [5, 25, 50, 100]
|
|
export const DEFAULT_PAGE_SIZE = 25
|
|
export const SEARCH_MAX_LENGTH = 200
|
|
|
|
const POSITIVE_INTEGER = /^[1-9]\d*$/
|
|
|
|
export function firstQueryValue(value: LocationQuery[string] | undefined) {
|
|
const single = Array.isArray(value) ? value[0] : value
|
|
return single ?? ''
|
|
}
|
|
|
|
export function parsePositiveInteger(value: string) {
|
|
return POSITIVE_INTEGER.test(value) ? Number(value) : null
|
|
}
|
|
|
|
export function sameRouteQuery(left: LocationQuery, right: Record<string, string>) {
|
|
const leftKeys = Object.keys(left)
|
|
return (
|
|
leftKeys.length === Object.keys(right).length &&
|
|
leftKeys.every((key) => firstQueryValue(left[key]) === right[key])
|
|
)
|
|
}
|