Skip to content
Permalink
Browse files

Fix `isUrlString` logic (#186)

* fix: Fix `isUrlString`

* Add `^` to regex

Co-Authored-By: Hiroyuki ANAI <pirosikick@gmail.com>
  • Loading branch information...
zaki-yama and pirosikick committed Aug 20, 2019
1 parent c6fb274 commit 3018cba6c6925ea9e7d5c207a149933278df4f2e
Showing with 3 additions and 3 deletions.
  1. +1 −3 src/util.ts
  2. +2 −0 test/util-test.ts
@@ -1,7 +1,5 @@
export function isUrlString(str: string): boolean {
return /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/i.test(
str
);
return /^https?:\/\/.*/i.test(str);
}

export async function wait(ms: number): Promise<void> {
@@ -5,9 +5,11 @@ describe("util", () => {
describe("isUrlString", () => {
it("should return true if the string is URL", () => {
assert(isUrlString("https://example.com") === true);
assert(isUrlString("http://localhost:8000") === true);
});
it("should return false if the string is not URL", () => {
assert(isUrlString("example.com") === false);
assert(isUrlString("js/desktop.js") === false);
});
});

0 comments on commit 3018cba

Please sign in to comment.
You can’t perform that action at this time.