mirror of
https://github.com/dzeiocom/libs.git
synced 2025-06-15 20:19:21 +00:00
Add modules (#41)
* Added modules for object-utils + moved from parcel to esbuild Signed-off-by: Avior <github@avior.me> * Moved url-manager Signed-off-by: Avior <github@avior.me> * Fixed codacy error Signed-off-by: Avior <github@avior.me>
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
import { objectLoop } from '@dzeio/object-util'
|
||||
|
||||
/**
|
||||
* Easy URLs manager
|
||||
*/
|
||||
@ -314,13 +316,9 @@ export default class URLManager {
|
||||
return undefined
|
||||
}
|
||||
if (format) {
|
||||
for (const key in format) {
|
||||
if (!(key in format)) {
|
||||
continue
|
||||
}
|
||||
const replacing = format[key]
|
||||
path = path.replace(`[${key}]`, replacing)
|
||||
}
|
||||
objectLoop(format, (replacing, key) => {
|
||||
path = path?.replace(`[${key}]`, replacing)
|
||||
})
|
||||
}
|
||||
return `${(path.startsWith('/') ? '' : '/')}${path}`
|
||||
}
|
||||
@ -328,24 +326,17 @@ export default class URLManager {
|
||||
private formatQuery(options?: { queryArrayJoin?: string }) {
|
||||
let result = ''
|
||||
const queryTmp = this.query()
|
||||
|
||||
for (const key in queryTmp) {
|
||||
if (!Object.prototype.hasOwnProperty.call(queryTmp, key)) {
|
||||
continue
|
||||
}
|
||||
|
||||
const element = queryTmp[key]
|
||||
|
||||
objectLoop(queryTmp, (element, key) => {
|
||||
result += result.length === 0 ? '?' : '&'
|
||||
|
||||
if (typeof element !== 'object') {
|
||||
result += `${key}=${element}`
|
||||
continue
|
||||
return
|
||||
}
|
||||
|
||||
if (options?.queryArrayJoin) {
|
||||
result += `${key}=${element.join(options.queryArrayJoin)}`
|
||||
continue
|
||||
return
|
||||
}
|
||||
|
||||
for (let i = 0; i < element.length; i++) {
|
||||
@ -355,7 +346,7 @@ export default class URLManager {
|
||||
}
|
||||
result += `${key}=${val}`
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (!result) {
|
||||
return undefined
|
||||
|
Reference in New Issue
Block a user