@prefecthq/vue-compositions
Version:
A collection of reusable vue compositions.
32 lines • 1.29 kB
JavaScript
import { isRouteParamClass, isRouteParamClassTuple } from '../useRouteQueryParam/formats';
import { useRouteQueryParam } from '../useRouteQueryParam/useRouteQueryParam';
export function useRouteQueryParams(schema, defaultValue, prefix) {
return getSchemaRouteQueryParams(schema, defaultValue, prefix);
}
export function isRouteParamSchema(value) {
return !isRouteParamClass(value);
}
function getSchemaRouteQueryParams(schema, defaultValue, prefix) {
const prefixed = (key) => {
if (prefix) {
return `${prefix}.${key}`;
}
return key;
};
const params = Object.keys(schema).reduce((params, key) => {
const property = schema[key];
const propertyDefault = defaultValue[key];
if (isRouteParamClass(property) || isRouteParamClassTuple(property)) {
params[key] = useRouteQueryParam(prefixed(key), property, propertyDefault);
return params;
}
if (isRouteParamSchema(property)) {
const defaultSchemaValue = (propertyDefault ?? {});
params[key] = getSchemaRouteQueryParams(property, defaultSchemaValue, prefixed(key));
return params;
}
return params;
}, {});
return params;
}
//# sourceMappingURL=useRouteQueryParams.js.map