From 0f873bc90998632671d5b2de1e4c436af78c5fc2 Mon Sep 17 00:00:00 2001 From: lholliger <14064434+lholliger@users.noreply.github.com> Date: Wed, 30 Sep 2020 23:23:54 -0400 Subject: [PATCH] isURL --- README.md | 2 +- src/libs/isURL.ts | 12 ++++++++++++ src/mod.ts | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/libs/isURL.ts diff --git a/README.md b/README.md index 174ba72..482672b 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ Validate is a standard Deno module for validating string. * [ ] isSurrogatePair * [ ] isSvg * [ ] isTaxID -* [ ] isURL +* [x] isURL * [ ] isUUID * [ ] isUppercase * [ ] isVariableWidth diff --git a/src/libs/isURL.ts b/src/libs/isURL.ts new file mode 100644 index 0000000..0ea8905 --- /dev/null +++ b/src/libs/isURL.ts @@ -0,0 +1,12 @@ +// @ts-ignore allowing typedoc to build +import assertString from '../utils/assertString.ts'; + +export const isURL = (str: string) => { + assertString(str); + try { + new URL(str); + } catch(err) { + return false + } + return true +}; diff --git a/src/mod.ts b/src/mod.ts index e203e04..47331e0 100644 --- a/src/mod.ts +++ b/src/mod.ts @@ -22,3 +22,5 @@ export * from './libs/isBtcAddress.ts'; export * from './libs/isByteLength.ts'; // @ts-ignore allowing typedoc to build export * from './libs/isCreditCard.ts'; +// @ts-ignore allowing typedoc to build +export * from './libs/isURL.ts'; \ No newline at end of file