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

@@ -9,11 +9,17 @@ import { deepClone } from '@/shared/helpers/deep-clone'
import type {
FLuentUrlPlainObject,
FluentUrlConfig,
ParseQueryOptions,
PlainObjectConstraint,
QueriesPlainObject,
StringifyQueryOptions,
} from '@/shared/types'
export class FluentUrl {
private readonly config: FluentUrlConfig
export class FluentUrl<
PQO extends PlainObjectConstraint = ParseQueryOptions,
SQO extends PlainObjectConstraint = StringifyQueryOptions,
> {
private readonly config: FluentUrlConfig<PQO, SQO>
private readonly protocol?: string
private readonly hostname?: string
private readonly paths: string[]
@@ -23,14 +29,15 @@ export class FluentUrl {
constructor(
urlOrOptions?: Partial<FLuentUrlPlainObject> | string,
config?: Partial<FluentUrlConfig>,
config?: Partial<FluentUrlConfig<PQO, SQO>>,
) {
this.config = normalizeConfig(config)
const { protocol, hostname, paths, port, fragment, queries } =
normalizeOptions({
urlOptions: urlOrOptions,
urlOrOptions,
parseQuery: this.config.parseQuery,
parseQueryOptions: this.config.parseQueryOptions,
})
this.protocol = protocol
@@ -76,8 +83,8 @@ export class FluentUrl {
public clone(
options?: Partial<FLuentUrlPlainObject>,
config?: Partial<FluentUrlConfig>,
): FluentUrl {
config?: Partial<FluentUrlConfig<PQO, SQO>>,
): FluentUrl<PQO, SQO> {
return new FluentUrl(
mergeOptions(
{