-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
57 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
export const extractWithRegex = regex => (url) => { | ||
const match = url.match(regex); | ||
console.log(match); | ||
return match && match.length > 1 ? match[1] : ''; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,89 @@ | ||
import _ from 'lodash'; | ||
import { describe } from 'ava-spec'; | ||
import { queryParam } from '../src'; | ||
import { urlBuddy } from '../src'; | ||
|
||
describe('queryParam =>', (it) => { | ||
describe('urlBuddy\t\t=>', (it) => { | ||
it('returns filled object when called with proper `url`', async (t) => { | ||
t.true(_.isObject(queryParam())); | ||
t.false(_.isEmpty(queryParam('https://github.com'))); | ||
t.true(_.isObject(urlBuddy())); | ||
t.false(_.isEmpty(urlBuddy('https://github.com'))); | ||
}); | ||
}); | ||
|
||
describe('queryParam . hash =>', (it) => { | ||
describe('urlBuddy . hash\t=>', (it) => { | ||
it('returns hosts for valid urls', async (t) => { | ||
t.is(queryParam('https://google.de#Hey-oo!').hash, 'Hey-oo!'); | ||
t.is(queryParam('http://133.12.43.23#foo?bar=baz').hash, 'foo'); | ||
t.is(queryParam('ftp://133.12.4.23#').hash, ''); | ||
t.is(urlBuddy('https://google.de#Hey-oo!').hash, 'Hey-oo!'); | ||
t.is(urlBuddy('http://133.12.43.23#foo?bar=baz').hash, 'foo'); | ||
t.is(urlBuddy('ftp://133.12.4.23#').hash, ''); | ||
}); | ||
}); | ||
|
||
describe('queryParam . host =>', (it) => { | ||
describe('urlBuddy . host\t=>', (it) => { | ||
it('returns hosts for valid urls', async (t) => { | ||
t.is(queryParam('https://google.de:32000').host, 'google.de:32000'); | ||
t.is(queryParam('http://133.12.43.23:222').host, '133.12.43.23:222'); | ||
t.is(queryParam('ftp://133.12.4.23:19000').host, '133.12.4.23:19000'); | ||
t.is(urlBuddy('https://google.de:32000').host, 'google.de:32000'); | ||
t.is(urlBuddy('http://133.12.43.23:222').host, '133.12.43.23:222'); | ||
t.is(urlBuddy('ftp://133.12.4.23:19000').host, '133.12.4.23:19000'); | ||
}); | ||
}); | ||
|
||
describe('queryParam . hostname =>', (it) => { | ||
describe('urlBuddy . hostname\t=>', (it) => { | ||
it('returns hostnames for valid urls', async (t) => { | ||
t.is(queryParam('https://google.de:32000').hostname, 'google.de'); | ||
t.is(queryParam('http://133.12.43.23:222').hostname, '133.12.43.23'); | ||
t.is(queryParam('ftp://133.12.4.23:19000').hostname, '133.12.4.23'); | ||
t.is(urlBuddy('https://google.de:32000').hostname, 'google.de'); | ||
t.is(urlBuddy('http://133.12.43.23:222').hostname, '133.12.43.23'); | ||
t.is(urlBuddy('ftp://133.12.4.23:19000').hostname, '133.12.4.23'); | ||
}); | ||
}); | ||
|
||
describe('queryParam . pathname =>', (it) => { | ||
describe('urlBuddy . pathname\t=>', (it) => { | ||
it('returns pathname for urls', async (t) => { | ||
t.is(queryParam('https://github.com:100/rpunkfu#hi').pathname, '/rpunkfu'); | ||
t.is(queryParam('http://fb.com/user/likes?a=b#c').pathname, '/user/likes'); | ||
t.is(queryParam('ftp://11.12.42.23/api/users/1').pathname, '/api/users/1'); | ||
t.is(urlBuddy('https://github.com:100/rpunkfu#hi').pathname, '/rpunkfu'); | ||
t.is(urlBuddy('http://fb.com/user/likes?a=b#c').pathname, '/user/likes'); | ||
t.is(urlBuddy('ftp://11.12.42.23/api/users/1').pathname, '/api/users/1'); | ||
}); | ||
}); | ||
|
||
describe('queryParam . port =>', (it) => { | ||
describe('urlBuddy . port\t=>', (it) => { | ||
it('returns port for valid urls', async (t) => { | ||
t.is(queryParam('https://google.de:32000').port, '32000'); | ||
t.is(queryParam('http://133.12.43.23:222').port, '222'); | ||
t.is(queryParam('ftp://133.12.4.23:19000').port, '19000'); | ||
t.is(urlBuddy('https://google.de:32000').port, '32000'); | ||
t.is(urlBuddy('http://133.12.43.23:222').port, '222'); | ||
t.is(urlBuddy('ftp://133.12.4.23:19000').port, '19000'); | ||
}); | ||
}); | ||
|
||
describe('queryParam . protocol =>', (it) => { | ||
describe('urlBuddy . protocol\t=>', (it) => { | ||
it('returns protocol for valid urls', async (t) => { | ||
t.is(queryParam('https://google.de').protocol, 'https'); | ||
t.is(queryParam('http://github.com').protocol, 'http'); | ||
t.is(queryParam('ftp://133.12.4.23').protocol, 'ftp'); | ||
t.is(urlBuddy('https://google.de').protocol, 'https'); | ||
t.is(urlBuddy('http://github.com').protocol, 'http'); | ||
t.is(urlBuddy('ftp://133.12.4.23').protocol, 'ftp'); | ||
}); | ||
}); | ||
|
||
describe('queryParam . query =>', (it) => { | ||
describe('urlBuddy . query\t=>', (it) => { | ||
it('returns query as an object for passed url', async (t) => { | ||
t.deepEqual(queryParam('https://google.com/?user1=morty#admin').query, | ||
t.deepEqual(urlBuddy('https://google.com/?user1=morty#admin').query, | ||
{ user1: 'morty', admin: true }); | ||
t.deepEqual(queryParam('https://github.com/tj?tab=repositories').query, | ||
t.deepEqual(urlBuddy('https://github.com/tj?tab=repositories').query, | ||
{ tab: 'repositories' }); | ||
t.deepEqual(queryParam('https://facebook.com?').query, {}); | ||
t.deepEqual(urlBuddy('https://facebook.com?').query, {}); | ||
}); | ||
}); | ||
|
||
describe('queryParam . url =>', (it) => { | ||
it('returns exactly the same url as passed to queryParam', async (t) => { | ||
t.is(queryParam('https://github.com').url, 'https://github.com'); | ||
t.is(queryParam('https://google.com').url, 'https://google.com'); | ||
t.is(queryParam('https://nodejs.org').url, 'https://nodejs.org'); | ||
describe('urlBuddy . url\t=>', (it) => { | ||
it('returns exactly the same url as passed to urlBuddy', async (t) => { | ||
t.is(urlBuddy('https://github.com').url, 'https://github.com'); | ||
t.is(urlBuddy('https://google.com').url, 'https://google.com'); | ||
t.is(urlBuddy('https://nodejs.org').url, 'https://nodejs.org'); | ||
}); | ||
}); | ||
|
||
describe('queryParam . valid =>', (it) => { | ||
describe('urlBuddy . valid\t=>', (it) => { | ||
it('returns true for valid urls', async (t) => { | ||
t.true(queryParam('https://github.com').valid); | ||
t.true(queryParam('https://google.com').valid); | ||
t.true(queryParam('https://nodejs.org').valid); | ||
t.true(urlBuddy('https://github.com').valid); | ||
t.true(urlBuddy('https://google.com').valid); | ||
t.true(urlBuddy('https://nodejs.org').valid); | ||
}); | ||
|
||
it('returns false for invalid urls', async (t) => { | ||
t.false(queryParam('obviously I am invalid...').valid); | ||
t.false(queryParam('https://dude--do-you-even').valid); | ||
t.false(urlBuddy('obviously I am invalid...').valid); | ||
t.false(urlBuddy('https://dude--do-you-even').valid); | ||
}); | ||
}); |