feat: enhance configuration handling and add type definitions for query and URL serializers

This commit is contained in:
2026-03-02 00:13:29 -05:00
parent 8cf5bfd9ec
commit 66d6a98ac4
7 changed files with 109 additions and 43 deletions

View File

@@ -1,9 +1,17 @@
import type { QuerySerializer } from '@/shared/types'
import type {
ParseQuery,
PlainObjectConstraint,
StringifyQuery,
} from '@/shared/types'
export const parseQuery: QuerySerializer['parseQuery'] = () => {
export function parseQuery<T extends PlainObjectConstraint>(): ReturnType<
ParseQuery<T>
> {
throw new Error('Not implemented')
}
export const stringifyQuery: QuerySerializer['stringifyQuery'] = () => {
export function stringifyQuery<T extends PlainObjectConstraint>(): ReturnType<
StringifyQuery<T>
> {
throw new Error('Not implemented')
}

View File

@@ -1,4 +1,9 @@
import type { FLuentUrlPlainObject, UrlSerializer } from '@/shared/types'
import type {
FLuentUrlPlainObject,
ParseUrlArgs,
PlainObjectConstraint,
StringifyUrlArgs,
} from '@/shared/types'
const URLTypesObj = {
absolute: 'absolute',
@@ -11,7 +16,11 @@ type URLTypes = (typeof URLTypesObj)[keyof typeof URLTypesObj]
const defaultProtocol = 'https'
const defaultHost = 'example.com'
export const parseUrl: UrlSerializer['parseUrl'] = ({ str, parseQuery }) => {
export function parseUrl<T extends PlainObjectConstraint>({
str,
parseQuery,
parseQueryOptions,
}: ParseUrlArgs<T>): FLuentUrlPlainObject {
const urlString = str.trim()
const urlType: URLTypes = urlString.startsWith('//')
@@ -64,11 +73,15 @@ export const parseUrl: UrlSerializer['parseUrl'] = ({ str, parseQuery }) => {
url.hash !== '' ? url.hash.replace('#', '') : undefined
urlPlainObject.queries =
url.search !== '' ? parseQuery(url.search) : Object.create(null)
url.search !== ''
? parseQuery(url.search, parseQueryOptions)
: Object.create(null)
return urlPlainObject
}
export const stringifyUrl: UrlSerializer['stringifyUrl'] = (_args) => {
export function stringifyUrl<T extends PlainObjectConstraint>(
_args: StringifyUrlArgs<T>,
): string {
throw new Error('Not implemented')
}