feat: enhance configuration handling and add type definitions for query and URL serializers
This commit is contained in:
@@ -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(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user