Skip to content

Commit 58a4bb3

Browse files
committed
Auto-generated commit
1 parent b329067 commit 58a4bb3

File tree

28 files changed

+1448
-14
lines changed

28 files changed

+1448
-14
lines changed

is-absolute-http-uri/README.md

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2021 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# isAbsoluteHttpURI
22+
23+
> Test whether a value is an absolute HTTP(S) [URI][uri].
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var isAbsoluteHttpURI = require( '@stdlib/assert/is-absolute-http-uri' );
41+
```
42+
43+
#### isAbsoluteHttpURI( value )
44+
45+
Tests whether a value is an absolute HTTP(S) [URI][uri].
46+
47+
```javascript
48+
var bool = isAbsoluteHttpURI( 'http://example.com' );
49+
// returns true
50+
51+
bool = isAbsoluteHttpURI( './beep/boop' );
52+
// returns false
53+
```
54+
55+
</section>
56+
57+
<!-- /.usage -->
58+
59+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
60+
61+
<section class="notes">
62+
63+
## Notes
64+
65+
- For more information regarding the URI scheme, see [RFC 3986][rfc-3986] and [Wikipedia][uri].
66+
- On the distinction between URI, URL, and URN, see [The Difference Between URLs and URIs][difference-url-uri].
67+
68+
</section>
69+
70+
<!-- /.notes -->
71+
72+
<!-- Package usage examples. -->
73+
74+
<section class="examples">
75+
76+
## Examples
77+
78+
<!-- eslint no-undef: "error" -->
79+
80+
```javascript
81+
var isAbsoluteHttpURI = require( '@stdlib/assert/is-absolute-http-uri' );
82+
83+
var bool = isAbsoluteHttpURI( 'https://www.google.com/' );
84+
// returns true
85+
86+
bool = isAbsoluteHttpURI( 'https://www.google.com/search?q=node.js' );
87+
// returns true
88+
89+
bool = isAbsoluteHttpURI( 'https://www.google.com#footer' );
90+
// returns true
91+
92+
bool = isAbsoluteHttpURI( '/search?q=node.js' );
93+
// returns false
94+
95+
bool = isAbsoluteHttpURI( 'C:\\Users\\nodejs\\node.js' );
96+
// returns false
97+
98+
bool = isAbsoluteHttpURI( null );
99+
// returns false
100+
```
101+
102+
</section>
103+
104+
<!-- /.examples -->
105+
106+
107+
<!-- Section for describing a command-line interface. -->
108+
109+
* * *
110+
111+
<section class="cli">
112+
113+
## CLI
114+
115+
<!-- CLI usage documentation. -->
116+
117+
<section class="usage">
118+
119+
### Usage
120+
121+
```text
122+
Usage: is-absolute-http-uri [options] [<uri>]
123+
124+
Options:
125+
126+
-h, --help Print this message.
127+
-V, --version Print the package version.
128+
--split sep Delimiter for stdin data. Default: '/\\r?\\n/'.
129+
```
130+
131+
</section>
132+
133+
<!-- /.usage -->
134+
135+
<!-- CLI usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
136+
137+
<section class="notes">
138+
139+
</section>
140+
141+
<!-- /.notes -->
142+
143+
<!-- CLI usage examples. -->
144+
145+
<section class="examples">
146+
147+
### Examples
148+
149+
```bash
150+
$ is-absolute-http-uri https://google.com
151+
true
152+
```
153+
154+
To use as a [standard stream][standard-streams],
155+
156+
```bash
157+
$ echo -n 'https://google.com' | is-absolute-http-uri
158+
true
159+
```
160+
161+
By default, when used as a [standard stream][standard-streams], the implementation assumes newline-delimited data. To specify an alternative delimiter, set the `split` option.
162+
163+
```bash
164+
$ echo -n 'https://google.com\tbeep' | is-absolute-http-uri --split '\t'
165+
true
166+
false
167+
```
168+
169+
</section>
170+
171+
<!-- /.examples -->
172+
173+
</section>
174+
175+
<!-- /.cli -->
176+
177+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
178+
179+
<section class="references">
180+
181+
</section>
182+
183+
<!-- /.references -->
184+
185+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
186+
187+
<section class="related">
188+
189+
</section>
190+
191+
<!-- /.related -->
192+
193+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
194+
195+
<section class="links">
196+
197+
[uri]: http://en.wikipedia.org/wiki/URI_scheme
198+
199+
[rfc-3986]: https://tools.ietf.org/html/rfc3986
200+
201+
[difference-url-uri]: https://danielmiessler.com/study/url-uri/
202+
203+
[standard-streams]: https://en.wikipedia.org/wiki/Standard_streams
204+
205+
</section>
206+
207+
<!-- /.links -->
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/* eslint-disable no-empty-function */
20+
21+
'use strict';
22+
23+
// MODULES //
24+
25+
var bench = require( '@stdlib/bench' );
26+
var isBoolean = require( './../../is-boolean' ).isPrimitive;
27+
var pkg = require( './../package.json' ).name;
28+
var isAbsoluteHttpURI = require( './../lib' );
29+
30+
31+
// MAIN //
32+
33+
bench( pkg, function benchmark( b ) {
34+
var values;
35+
var bool;
36+
var i;
37+
38+
values = [
39+
'http://google.com',
40+
'http://localhost/',
41+
'http://example.w3.org/path%20with%20spaces.html',
42+
'http://example.w3.org/%20',
43+
'/dashboard',
44+
'//example.w3.org/path%20with%20spaces.html',
45+
'?q=query',
46+
'#hash',
47+
'ftp://ftp.is.co.za/rfc/rfc1808.txt',
48+
'ftp://ftp.is.co.za/../../../rfc/rfc1808.txt',
49+
'http://www.ietf.org/rfc/rfc2396.txt',
50+
'ldap://[2001:db8::7]/c=GB?objectClass?one',
51+
'mailto:John.Doe@example.com',
52+
'news:comp.infosystems.www.servers.unix',
53+
'tel:+1-816-555-1212',
54+
'telnet://192.0.2.16:80/',
55+
'urn:oasis:names:specification:docbook:dtd:xml:4.1.2',
56+
5,
57+
null,
58+
void 0,
59+
true,
60+
NaN,
61+
{},
62+
[],
63+
function noop() {},
64+
'',
65+
'foo',
66+
'foo@bar',
67+
'://foo/',
68+
'1http://foo',
69+
'http://<foo>',
70+
'http:////foo.html',
71+
'http://example.w3.org/%illegal.html',
72+
'http://example.w3.org/%a',
73+
'http://example.w3.org/%a/foo',
74+
'http://example.w3.org/%at'
75+
];
76+
77+
b.tic();
78+
for ( i = 0; i < b.iterations; i++ ) {
79+
bool = isAbsoluteHttpURI( values[ i % values.length ] );
80+
if ( !isBoolean( bool ) ) {
81+
b.fail( 'should return a boolean' );
82+
}
83+
}
84+
b.toc();
85+
if ( !isBoolean( bool ) ) {
86+
b.fail( 'should return a boolean' );
87+
}
88+
b.pass( 'benchmark finished' );
89+
b.end();
90+
});

0 commit comments

Comments
 (0)