Skip to content

Commit 1d585fb

Browse files
committed
Fix style errors
1 parent 9362208 commit 1d585fb

File tree

2 files changed

+75
-83
lines changed

2 files changed

+75
-83
lines changed

index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
'use strict';
1+
'use strict'
22

3-
var url = require ( 'url' );
3+
var url = require('url')
44

5-
module.exports = function ( str ) {
6-
if ( typeof str !== 'string' ) {
7-
throw new TypeError ( 'Expected a string, not ' + typeof str );
5+
module.exports = function (str) {
6+
if (typeof str !== 'string') {
7+
throw new TypeError('Expected a string, not ' + typeof str)
88
}
99

10-
var urlObj = url.parse ( str );
10+
var urlObj = url.parse(str)
1111

12-
return Boolean ( urlObj.protocol ) && Boolean ( urlObj.slashes ) === false;
13-
};
12+
return Boolean(urlObj.protocol) && Boolean(urlObj.slashes) === false
13+
}

test.js

Lines changed: 67 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,71 @@
1-
'use strict';
1+
import test from 'ava'
2+
import m from './'
23

3-
import test from 'ava';
4-
import m from './';
4+
test('expected a string', t => {
5+
t.throws(() => m(), 'Expected a string, not undefined')
6+
t.throws(() => m([]), 'Expected a string, not object')
7+
t.throws(() => m({}), 'Expected a string, not object')
8+
})
59

6-
test ( 'expected a string', t => {
10+
test('check url protocol without slashes', t => {
11+
t.true(m('mailto:info@mail.com'))
12+
t.true(m('news:rec.gardens.roses'))
13+
t.true(m('xmpp:user@host?message&subject=hi&body=Hello%20World&thread=abc123'))
14+
t.true(m('data:image/gif;base64,R0lGODlhyAAiALMDfD0QAADs='))
15+
t.true(m('tel:9008007060'))
16+
t.true(m('cid:foo4*foo1@bar.net'))
17+
t.true(m('mid:960830.1639@XIson.com/partA.960830.1639@XIson.com'))
18+
t.true(m('skype:login?chat'))
19+
t.true(m('smsto:8881234567?body=hello!'))
20+
t.true(m('bitcoin:19UBzu6Bt4bsx7eTb7eryFWKJ7TF8Bwtnf'))
21+
})
722

8-
t.throws ( () => m (), 'Expected a string, not undefined' );
9-
t.throws ( () => m ( [] ), 'Expected a string, not object' );
10-
t.throws ( () => m ( {} ), 'Expected a string, not object' );
23+
test('check url protocol with slashes', t => {
24+
t.false(m('site.com'))
25+
t.false(m('http://admin:pass@site.com'))
26+
t.false(m('http://admin:pass@site.com:3000'))
27+
t.false(m('http://admin:pass@site.com:3000/a'))
28+
t.false(m('http://admin:pass@site.com:3000/a/b/./c'))
29+
t.false(m('http://admin:pass@site.com:3000/a/b/../c'))
30+
t.false(m('http://admin:pass@site.com:3000/a/b/../c/d.js'))
31+
t.false(m('//site.com'))
32+
t.false(m('//site.com:3000'))
33+
t.false(m('//site.com:3000/a'))
34+
t.false(m('//site.com:3000/a/b/./c'))
35+
t.false(m('//site.com:3000/a/b/../c'))
36+
t.false(m('//site.com:3000/a/b/../c/d.js'))
37+
t.false(m('//admin:pass@site.com'))
38+
t.false(m('//admin:pass@site.com:3000'))
39+
t.false(m('//admin:pass@site.com:3000/a'))
40+
t.false(m('//admin:pass@site.com:3000/a/b/./c'))
41+
t.false(m('//admin:pass@site.com:3000/a/b/../c'))
42+
t.false(m('//admin:pass@site.com:3000/a/b/../c/d.js'))
1143

12-
} );
13-
14-
test ( 'check url protocol without slashes', t => {
15-
16-
t.true ( m ( 'mailto:info@mail.com' ) );
17-
t.true ( m ( 'news:rec.gardens.roses' ) );
18-
t.true ( m ( 'xmpp:user@host?message&subject=hi&body=Hello%20World&thread=abc123' ) );
19-
t.true ( m ( 'data:image/gif;base64,R0lGODlhyAAiALMDfD0QAADs=' ) );
20-
t.true ( m ( 'tel:9008007060' ) );
21-
t.true ( m ( 'cid:foo4*foo1@bar.net' ) );
22-
t.true ( m ( 'mid:960830.1639@XIson.com/partA.960830.1639@XIson.com' ) );
23-
t.true ( m ( 'skype:login?chat' ) );
24-
t.true ( m ( 'smsto:8881234567?body=hello!' ) );
25-
t.true ( m ( 'bitcoin:19UBzu6Bt4bsx7eTb7eryFWKJ7TF8Bwtnf' ) );
26-
27-
} );
28-
29-
test ( 'check url protocol with slashes', t => {
30-
31-
t.false ( m ( 'site.com' ) );
32-
t.false ( m ( 'http://admin:pass@site.com' ) );
33-
t.false ( m ( 'http://admin:pass@site.com:3000' ) );
34-
t.false ( m ( 'http://admin:pass@site.com:3000/a' ) );
35-
t.false ( m ( 'http://admin:pass@site.com:3000/a/b/./c' ) );
36-
t.false ( m ( 'http://admin:pass@site.com:3000/a/b/../c' ) );
37-
t.false ( m ( 'http://admin:pass@site.com:3000/a/b/../c/d.js' ) );
38-
t.false ( m ( '//site.com' ) );
39-
t.false ( m ( '//site.com:3000' ) );
40-
t.false ( m ( '//site.com:3000/a' ) );
41-
t.false ( m ( '//site.com:3000/a/b/./c' ) );
42-
t.false ( m ( '//site.com:3000/a/b/../c' ) );
43-
t.false ( m ( '//site.com:3000/a/b/../c/d.js' ) );
44-
t.false ( m ( '//admin:pass@site.com' ) );
45-
t.false ( m ( '//admin:pass@site.com:3000' ) );
46-
t.false ( m ( '//admin:pass@site.com:3000/a' ) );
47-
t.false ( m ( '//admin:pass@site.com:3000/a/b/./c' ) );
48-
t.false ( m ( '//admin:pass@site.com:3000/a/b/../c' ) );
49-
t.false ( m ( '//admin:pass@site.com:3000/a/b/../c/d.js' ) );
50-
51-
t.false ( m ( 'ftp://user:password@host:port/path' ) );
52-
t.false ( m ( 'http://test.com' ) );
53-
t.false ( m ( 'http://test.com:1234' ) );
54-
t.false ( m ( 'http://test.com:1234/a' ) );
55-
t.false ( m ( 'http://test.com:1234/a/b/./c' ) );
56-
t.false ( m ( 'http://test.com:1234/a/b/../c' ) );
57-
t.false ( m ( 'http://test.com:1234/a/b/../c/d.js' ) );
58-
t.false ( m ( 'rtmp://mycompany.com/vod/mp4:mycoolvideo.mov' ) );
59-
t.false ( m ( 'sftp://root@test.com/home/test/' ) );
60-
t.false ( m ( 'rtsp://ip_address/MediaInput/h264' ) );
61-
t.false ( m ( 'https://test.com' ) );
62-
t.false ( m ( 'gopher://gopher.cc.lehigh.edu' ) );
63-
t.false ( m ( 'nntp://news.cs.hut.fi/alt.html/239157' ) );
64-
t.false ( m ( 'irc://foobar.org:6665/secret,needkey' ) );
65-
t.false ( m ( 'smb://host/share/' ) );
66-
t.false ( m ( 'prospero://host:port/hsoname;field=value' ) );
67-
t.false ( m ( 'telnet://user:password@host:port/' ) );
68-
t.false ( m ( 'wais://vega.lib.ncsu.edu/alawon.src?nren' ) );
69-
t.false ( m ( 'file://localhost/etc/fstab' ) );
70-
t.false ( m ( 'afp://myserver.mydomain.com/Sharepoint/Folder' ) );
71-
t.false ( m ( 'nfs://server:port/path' ) );
72-
t.false ( m ( 'TN3270://TN3270site:23/' ) );
73-
t.false ( m ( 'z3950://habanero.nhm.ukans.edu/kubirds/search?query=(@attr%201=1%20"falco")' ) );
74-
t.false ( m ( 'ed2k://|file|The_Two_Towers-The_Purist_Edit-Trailer.avi|14997504|965c013e991ee246d63d45ea71954c4d|/' ) );
75-
t.false ( m ( 'market://details?id=package_name' ) );
76-
t.false ( m ( 'steam://install/id' ) );
77-
t.false ( m ( 'tg://addstickers?set=vk_nichosi' ) );
78-
79-
} );
44+
t.false(m('ftp://user:password@host:port/path'))
45+
t.false(m('http://test.com'))
46+
t.false(m('http://test.com:1234'))
47+
t.false(m('http://test.com:1234/a'))
48+
t.false(m('http://test.com:1234/a/b/./c'))
49+
t.false(m('http://test.com:1234/a/b/../c'))
50+
t.false(m('http://test.com:1234/a/b/../c/d.js'))
51+
t.false(m('rtmp://mycompany.com/vod/mp4:mycoolvideo.mov'))
52+
t.false(m('sftp://root@test.com/home/test/'))
53+
t.false(m('rtsp://ip_address/MediaInput/h264'))
54+
t.false(m('https://test.com'))
55+
t.false(m('gopher://gopher.cc.lehigh.edu'))
56+
t.false(m('nntp://news.cs.hut.fi/alt.html/239157'))
57+
t.false(m('irc://foobar.org:6665/secret,needkey'))
58+
t.false(m('smb://host/share/'))
59+
t.false(m('prospero://host:port/hsoname;field=value'))
60+
t.false(m('telnet://user:password@host:port/'))
61+
t.false(m('wais://vega.lib.ncsu.edu/alawon.src?nren'))
62+
t.false(m('file://localhost/etc/fstab'))
63+
t.false(m('afp://myserver.mydomain.com/Sharepoint/Folder'))
64+
t.false(m('nfs://server:port/path'))
65+
t.false(m('TN3270://TN3270site:23/'))
66+
t.false(m('z3950://habanero.nhm.ukans.edu/kubirds/search?query=(@attr%201=1%20"falco")'))
67+
t.false(m('ed2k://|file|The_Two_Towers-The_Purist_Edit-Trailer.avi|14997504|965c013e991ee246d63d45ea71954c4d|/'))
68+
t.false(m('market://details?id=package_name'))
69+
t.false(m('steam://install/id'))
70+
t.false(m('tg://addstickers?set=vk_nichosi'))
71+
})

0 commit comments

Comments
 (0)