-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5797be
commit 12dbe48
Showing
4 changed files
with
45 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,45 @@ | ||
import appendQuery from 'append-query'; | ||
|
||
export const isObject = (obj: any) => { | ||
return typeof obj === "object" && obj !== null; | ||
}; | ||
return typeof obj === 'object' && obj !== null | ||
} | ||
|
||
export const getObjectType = (obj: any) => Object.prototype.toString.call(obj); | ||
export const getObjectType = (obj: any) => Object.prototype.toString.call(obj) | ||
|
||
export const removeUrlPostfix = (url: string) => { | ||
let res = url.split("?")?.[0] ?? ""; | ||
res = res.split("#")?.[0] ?? ""; | ||
return res; | ||
}; | ||
let res = url.split('?')?.[0] ?? '' | ||
res = res.split('#')?.[0] ?? '' | ||
return res | ||
} | ||
|
||
export const getUrlQuery = (url: string) => { | ||
const queryStr = url.split("?")?.[1] ?? ""; | ||
const queryStr = url.split('?')?.[1] ?? '' | ||
const res = Object.fromEntries( | ||
queryStr.split("&").map((part) => { | ||
return part.split("="); | ||
queryStr.split('&').map((part) => { | ||
return part.split('=') | ||
}) | ||
); | ||
return res; | ||
}; | ||
) | ||
return res | ||
} | ||
|
||
// export const appendUrlQuery = ( | ||
// url: string, | ||
// query: { [key: string]: any } | ||
// ) => { | ||
// return appendQuery(url, query) | ||
// } | ||
|
||
export const wrapUrlWithQuery = ( | ||
url: string, | ||
query: { [key: string]: any } | ||
) => { | ||
if (!query || Object.keys(query).length === 0) return url; | ||
return `${url}?${Object.entries(query).map(e => e.join('=')).join('&')}`; | ||
}; | ||
export const appendUrlQuery = ( | ||
baseUrl: string, | ||
params: Record<string, any> | ||
): string => { | ||
const Url = new URL(baseUrl); | ||
const urlParams: URLSearchParams = new URLSearchParams(Url.search); | ||
for (const key in params) { | ||
if (params[key] !== undefined) { | ||
urlParams.set(key, params[key]); | ||
} | ||
} | ||
Url.search = urlParams.toString(); | ||
return Url.toString(); | ||
}; |