Skip to content

Commit b8f35c9

Browse files
committed
feat(shared): add isLinkFtp util
1 parent f129bc5 commit b8f35c9

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { isLinkFtp } from '@vuepress/shared'
2+
3+
const testCases: [string, ReturnType<typeof isLinkFtp>][] = [
4+
['ftp://foobar.com', true],
5+
['https://foobar.com', false],
6+
['http://foobar.com', false],
7+
['//foobar.com', false],
8+
['foobar.com', false],
9+
['/foo/bar', false],
10+
]
11+
12+
describe('shared > isLinkFtp', () => {
13+
describe('should determine ftp link correctly', () => {
14+
testCases.forEach(([source, expected]) => {
15+
it(`link: ${source}`, () => {
16+
expect(isLinkFtp(source)).toBe(expected)
17+
})
18+
})
19+
})
20+
})

packages/@vuepress/shared/src/utils/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export * from './formatDateString'
77
export * from './htmlEscape'
88
export * from './htmlUnescape'
99
export * from './isLinkExternal'
10+
export * from './isLinkFtp'
1011
export * from './isLinkHttp'
1112
export * from './isLinkMailto'
1213
export * from './isLinkTel'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Determine a link is ftp link or not
3+
*/
4+
export const isLinkFtp = (link: string): boolean => link.startsWith('ftp://')

0 commit comments

Comments
 (0)