feat: enhance configuration and options handling with merge functions
This commit is contained in:
@@ -2,7 +2,9 @@ import { parseQuery, stringifyQuery } from '@/core/serializer/query-serializer'
|
||||
import { deepClone } from '@/shared/helpers/deep-clone'
|
||||
import { parseUrl } from './serializer/url-serializer'
|
||||
|
||||
export function normalizeConfig(config?: FluentUrlConfig): FluentUrlConfig {
|
||||
export function normalizeConfig(
|
||||
config?: Partial<FluentUrlConfig>,
|
||||
): FluentUrlConfig {
|
||||
return {
|
||||
parseQuery: config?.parseQuery ?? parseQuery,
|
||||
stringifyQuery: config?.stringifyQuery ?? stringifyQuery,
|
||||
@@ -31,3 +33,27 @@ export function normalizeOptions(args: {
|
||||
queries: deepClone(urlOrOptions?.queries) ?? Object.create(null),
|
||||
}
|
||||
}
|
||||
|
||||
export function mergeConfig(
|
||||
current: FluentUrlConfig,
|
||||
merge?: Partial<FluentUrlConfig>,
|
||||
): FluentUrlConfig {
|
||||
return {
|
||||
parseQuery: merge?.parseQuery ?? current.parseQuery,
|
||||
stringifyQuery: merge?.stringifyQuery ?? current.stringifyQuery,
|
||||
}
|
||||
}
|
||||
|
||||
export function mergeOptions(
|
||||
current: FLuentUrlPlainObject,
|
||||
merge?: Partial<FLuentUrlPlainObject>,
|
||||
): FLuentUrlPlainObject {
|
||||
return {
|
||||
protocol: merge?.protocol ?? current.protocol,
|
||||
hostname: merge?.hostname ?? current.hostname,
|
||||
paths: merge?.paths ?? current.paths,
|
||||
port: merge?.port ?? current.port,
|
||||
fragment: merge?.fragment ?? current.fragment,
|
||||
queries: merge?.queries ?? current.queries,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user