feat: enhance configuration and options handling with merge functions
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
import { normalizeConfig, normalizeOptions } from '@/core/config-defaults'
|
||||
import {
|
||||
mergeConfig,
|
||||
mergeOptions,
|
||||
normalizeConfig,
|
||||
normalizeOptions,
|
||||
} from '@/core/config-defaults'
|
||||
import { deepClone } from '@/shared/helpers/deep-clone'
|
||||
import { stringifyUrl } from './serializer/url-serializer'
|
||||
|
||||
@@ -13,7 +18,7 @@ export class FluentUrl {
|
||||
|
||||
constructor(
|
||||
urlOrOptions?: Partial<FLuentUrlPlainObject> | string,
|
||||
config?: FluentUrlConfig,
|
||||
config?: Partial<FluentUrlConfig>,
|
||||
) {
|
||||
this.config = normalizeConfig(config)
|
||||
|
||||
@@ -69,18 +74,18 @@ export class FluentUrl {
|
||||
config?: FluentUrlConfig,
|
||||
): FluentUrl {
|
||||
return new FluentUrl(
|
||||
{
|
||||
protocol: options?.protocol ?? this.protocol,
|
||||
hostname: options?.hostname ?? this.hostname,
|
||||
paths: options?.paths ?? this.paths,
|
||||
port: options?.port ?? this.port,
|
||||
fragment: options?.fragment ?? this.fragment,
|
||||
queries: options?.queries ?? this.queries,
|
||||
},
|
||||
{
|
||||
parseQuery: config?.parseQuery ?? this.config.parseQuery,
|
||||
stringifyQuery: config?.stringifyQuery ?? this.config.stringifyQuery,
|
||||
},
|
||||
mergeOptions(
|
||||
{
|
||||
protocol: this.protocol,
|
||||
hostname: this.hostname,
|
||||
paths: this.paths,
|
||||
port: this.port,
|
||||
fragment: this.fragment,
|
||||
queries: this.queries,
|
||||
},
|
||||
options,
|
||||
),
|
||||
mergeConfig(this.config, config),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user