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