-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(utils): 新增 isBlobUrl 检测传入值是否是 Blob URL
- Loading branch information
Showing
4 changed files
with
33 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { isBlobUrl } from './isBlobUrl' | ||
|
||
describe('isBlobUrl', () => { | ||
test('表现正常', () => { | ||
expect( | ||
isBlobUrl( | ||
'blob:https://example.org/9115d58c-bcda-ff47-86e5-083e9a215304', | ||
), | ||
).toBeTrue() | ||
expect(isBlobUrl('blob:foo')).toBeFalse() | ||
expect(isBlobUrl('http://foo.bar')).toBeFalse() | ||
}) | ||
}) |
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,17 @@ | ||
/** | ||
* 检测传入值是否是 Blob URL,也称 Object URL。 | ||
* | ||
* @public | ||
* @param value 要检测的值 | ||
* @returns 返回检测结果 | ||
* @example | ||
* ```typescript | ||
* isBlobUrl('http://foo.bar') // => false | ||
* isBlobUrl('blob:https://example.org/9115d58c-bcda-ff47-86e5-083e9a215304') // => true | ||
* ``` | ||
*/ | ||
export function isBlobUrl(value: string) { | ||
return isBlobUrl.regex.test(value) | ||
} | ||
|
||
isBlobUrl.regex = /^blob:.+\/[\w-]{36,}(?:#.+)?$/ |
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