Skip to content

Commit d49eea7

Browse files
committed
feat: add lightweight version
1 parent 148ee24 commit d49eea7

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# is-url-http
22

3-
43
![Last version](https://img.shields.io/github/tag/Kikobeats/is-url-http.svg?style=flat-square)
54
[![Build Status](https://img.shields.io/travis/Kikobeats/is-url-http/master.svg?style=flat-square)](https://travis-ci.org/Kikobeats/is-url-http)
65
[![Coverage Status](https://img.shields.io/coveralls/Kikobeats/is-url-http.svg?style=flat-square)](https://coveralls.io/github/Kikobeats/is-url-http)
@@ -28,6 +27,17 @@ isUrlHttp('mailto://kiko@beats.com') // ==> false
2827
isUrlHttp('callto:192.168.103.77+type=ip') // ==> false
2928
```
3029

30+
If you need to run the package in a browser environment, you can save some bytes using the lightweight version:
31+
32+
```js
33+
const isUrlHttp = require('is-url-http/lightweight')
34+
35+
isUrlHttp('https://kikobeats.com') // ==> true
36+
isUrlHttp('https://kikobeats.com') // ==> true
37+
isUrlHttp('mailto://kiko@beats.com') // ==> false
38+
isUrlHttp('callto:192.168.103.77+type=ip') // ==> false
39+
```
40+
3141
## License
3242

3343
**is-url-http** © [Kiko Beats](https://kikobeats.com), released under the [MIT](https://github.com/Kikobeats/is-url-http/blob/master/LICENSE.md) License.<br>

lightweight.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict'
2+
3+
const URL = global.window ? window.URL : require('url').URL
4+
const REGEX_HTTP_PROTOCOL = /^https?:\/\//i
5+
6+
module.exports = url => {
7+
try {
8+
return REGEX_HTTP_PROTOCOL.test(new URL(url).href)
9+
} catch (err) {
10+
return false
11+
}
12+
}

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"description": "Check if an URL is a valid HTTP URL.",
44
"homepage": "https://nicedoc.io/Kikobeats/is-url-http",
55
"version": "2.0.1",
6+
"browser": "lightweight.js",
67
"main": "index.js",
78
"author": {
89
"email": "josefrancisco.verdu@gmail.com",
@@ -51,7 +52,8 @@
5152
"node": ">= 8"
5253
},
5354
"files": [
54-
"index.js"
55+
"index.js",
56+
"lightweight.js"
5557
],
5658
"scripts": {
5759
"clean": "rm -rf node_modules",
@@ -77,5 +79,7 @@
7779
"*.md": [
7880
"standard-markdown"
7981
]
80-
}
82+
},
83+
"umd:main": "lightweight.js",
84+
"unpkg": "lightweight.js"
8185
}

0 commit comments

Comments
 (0)