handling is string an url

This commit is contained in:
NCanggoro 2023-10-11 16:31:15 +07:00
parent 8eee747a3b
commit 1c65b5b237
2 changed files with 7 additions and 1 deletions

View File

@ -7,3 +7,8 @@ export function handleAxiosError(error: AxiosError) {
export function enumKeys<O extends object, K extends keyof O = keyof O>(obj: O): K[] { export function enumKeys<O extends object, K extends keyof O = keyof O>(obj: O): K[] {
return Object.keys(obj).filter(k => Number.isNaN(+k)) as K[]; return Object.keys(obj).filter(k => Number.isNaN(+k)) as K[];
} }
export function isUrl(val: string): boolean {
var urlPattern = /^https:\/\/[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/;
return urlPattern.test(val);
}

View File

@ -1,8 +1,9 @@
import useAutosizeTextArea from "./useAutosizeTextArea"; import useAutosizeTextArea from "./useAutosizeTextArea";
import { handleAxiosError, enumKeys } from "./common"; import { handleAxiosError, enumKeys, isUrl } from "./common";
export { export {
useAutosizeTextArea, useAutosizeTextArea,
handleAxiosError, handleAxiosError,
enumKeys, enumKeys,
isUrl
} }