Add isAbsoluteURL
This commit is contained in:
15
snippets/isAbsoluteURL.md
Normal file
15
snippets/isAbsoluteURL.md
Normal file
@ -0,0 +1,15 @@
|
||||
### isAbsoluteURL
|
||||
|
||||
Returns `true` if the given string is an absolute URL, `false` otherwise.
|
||||
|
||||
Use a regular expression to test if the string is an absolute URL.
|
||||
|
||||
```js
|
||||
const isAbsoluteURL = str => /^[a-z][a-z0-9+.-]*:/.test(str);
|
||||
```
|
||||
|
||||
```js
|
||||
isAbsoluteURL('https://google.com'); // true
|
||||
isAbsoluteURL('ftp://www.myserver.net'); // true
|
||||
isAbsoluteURL('/foo/bar'); // false
|
||||
```
|
||||
Reference in New Issue
Block a user