Skip to content

Commit 515d51c

Browse files
committed
Update README.md
Added method documentation from original perldoc
1 parent 4832e78 commit 515d51c

File tree

1 file changed

+87
-22
lines changed

1 file changed

+87
-22
lines changed

README.md

Lines changed: 87 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,92 @@ npm install valid-url
3737
```
3838

3939
## Methods
40+
```javascript
41+
/*
42+
* @Function isUri(value)
43+
*
44+
* @Synopsis is the value a well-formed uri?
45+
* @Description
46+
Returns the untainted URI if the test value appears to be well-formed. Note that
47+
you may really want one of the more practical methods like is_http_uri or is_https_uri,
48+
since the URI standard (RFC 3986) allows a lot of things you probably don't want.
49+
* @Arguments
50+
* value The potential URI to test.
51+
*
52+
* @Returns The untainted RFC 3986 URI on success, undefined on failure.
53+
* @Notes
54+
This function does not make any attempt to check whether the URI is accessible
55+
or 'makes sense' in any meaningful way. It just checks that it is formatted
56+
correctly.
57+
*
58+
*/
4059

41-
`
42-
isUri(value)
43-
`
44-
**accepts** value as string to be checked as any protocol url
45-
**returns** undefined if is not url, returns RFC 3986 url if valid
46-
47-
`
48-
isHttpUri(value, allowHttps)
49-
`
50-
**accepts** *value* as string to be checked as HTTP url, *allowHttps* as boolean to include https urls *(optional)*
51-
**returns** undefined if is not url, returns RFC 3986 url if valid
52-
53-
`
54-
isHttpsUri(value)
55-
`
56-
**accepts** value as string to be checked as HTTPS url
57-
**returns** undefined if is not url, returns RFC 3986 url if valid
60+
61+
/*
62+
* @Function isHttpUri(value)
63+
* @Synopsis is the value a well-formed HTTP uri?
64+
* @Description
65+
Specialized version of isUri() that only likes http:// urls. As a result, it can
66+
also do a much more thorough job validating. Also, unlike isUri() it is more
67+
concerned with only allowing real-world URIs through. Things like relative
68+
hostnames are allowed by the standards, but probably aren't wise. Conversely,
69+
null paths aren't allowed per RFC 2616 (should be '/' instead), but are allowed
70+
by this function.
71+
72+
This function only works for fully-qualified URIs. /bob.html won't work.
73+
See RFC 3986 for the appropriate method to turn a relative URI into an absolute
74+
one given its context.
75+
76+
Returns the untainted URI if the test value appears to be well-formed.
77+
78+
Note that you probably want to either call this in combo with is_https_uri(). i.e.
79+
80+
if(isHttpUri(uri) || isHttpsUri(uri)) console.log('Good');
81+
82+
or use the convenience method isWebUri which is equivalent.
83+
84+
* @Arguments
85+
* value The potential URI to test.
86+
*
87+
* @Returns The untainted RFC 3986 URI on success, undefined on failure.
88+
* @Notes
89+
This function does not make any attempt to check whether the URI is accessible
90+
or 'makes sense' in any meaningful way. It just checks that it is formatted
91+
correctly.
92+
*/
93+
94+
95+
96+
/*
97+
* @Function isHttpsUri(value)
98+
* @Synopsis is the value a well-formed HTTPS uri?
99+
* @Description
100+
See is_http_uri() for details. This version only likes the https URI scheme.
101+
Otherwise it's identical to is_http_uri()
102+
* @Arguments
103+
* value The potential URI to test.
104+
*
105+
* @Returns The untainted RFC 3986 URI on success, undefined on failure.
106+
* @Notes
107+
This function does not make any attempt to check whether the URI is accessible
108+
or 'makes sense' in any meaningful way. It just checks that it is formatted
109+
correctly.
110+
*/
111+
112+
113+
/*
114+
* @Function isWebUri(value)
115+
* @Synopsis is the value a well-formed HTTP or HTTPS uri?
116+
* @Description
117+
This is just a convenience method that combines isHttpUri and isHttpsUri
118+
to accept most common real-world URLs.
119+
* @Arguments
120+
* value The potential URI to test.
121+
*
122+
* @Returns The untainted RFC 3986 URI on success, undefined on failure.
123+
* @Notes
124+
This function does not make any attempt to check whether the URI is accessible
125+
or 'makes sense' in any meaningful way. It just checks that it is formatted
126+
correctly.
127+
*/
58128

59-
`
60-
isWebUri(value)
61-
`
62-
**accepts** value as string to be checked as HTTP or HTTPS url
63-
**returns** undefined if is not url, returns RFC 3986 url if valid

0 commit comments

Comments
 (0)