-
Notifications
You must be signed in to change notification settings - Fork 923
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: meteorlxy <meteor.lxy@foxmail.com>
- Loading branch information
1 parent
70ae76a
commit 518fd7d
Showing
12 changed files
with
40 additions
and
92 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** | ||
* Determine a link has protocol or not | ||
*/ | ||
export const isLinkWithProtocol = (link: string): boolean => | ||
/^[a-z][a-z0-9+.-]*:/.test(link) |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { isLinkWithProtocol } from '../src/index.js' | ||
|
||
const testCases: [string, ReturnType<typeof isLinkWithProtocol>][] = [ | ||
['ftp://foobar.com', true], | ||
['ms-windows-store://home', true], | ||
['mailto:foobar', true], | ||
['tel:foobar', true], | ||
['https://foobar.com', true], | ||
['http://foobar.com', true], | ||
['foobar.com', false], | ||
['/foo/bar', false], | ||
['../foo/bar', false], | ||
['//foobar.com', false], | ||
] | ||
|
||
describe('shared > isLinkWithProtocol', () => { | ||
describe('should determine link with protocol correctly', () => { | ||
testCases.forEach(([source, expected]) => { | ||
it(`link: ${source}`, () => { | ||
expect(isLinkWithProtocol(source)).toBe(expected) | ||
}) | ||
}) | ||
}) | ||
}) |