Skip to content

Commit

Permalink
Change name to url-buddy
Browse files Browse the repository at this point in the history
  • Loading branch information
rpunkfu committed May 20, 2016
1 parent 08deb19 commit a5b8937
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 58 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# query-param
# url-buddy

[![Build Status](https://travis-ci.org/oskarcieslik/query-param.svg?branch=master)](https://travis-ci.org/oskarcieslik/query-param)
[![codecov.io](https://codecov.io/github/oskarcieslik/query-param/coverage.svg?branch=master)](https://codecov.io/github/oskarcieslik/query-param?branch=master)
[![npm version](https://badge.fury.io/js/query-param.svg)](https://www.npmjs.com/package/query-param)
[![Build Status](https://travis-ci.org/oskarcieslik/url-buddy.svg?branch=master)](https://travis-ci.org/oskarcieslik/url-buddy)
[![codecov.io](https://codecov.io/github/oskarcieslik/url-buddy/coverage.svg?branch=master)](https://codecov.io/github/oskarcieslik/url-buddy?branch=master)
[![npm version](https://badge.fury.io/js/url-buddy.svg)](https://www.npmjs.com/package/url-buddy)
[![Twitter Follow](https://img.shields.io/twitter/follow/rpunkfu.svg?style=social)](https://twitter.com/rpunkfu)

[![forthebadge](http://forthebadge.com/images/badges/built-with-love.svg)](https://github.com/oskarcieslik/query-param)
[![forthebadge](http://forthebadge.com/images/badges/gluten-free.svg)](https://github.com/oskarcieslik/query-param)
[![forthebadge](http://forthebadge.com/images/badges/built-with-love.svg)](https://github.com/oskarcieslik/url-buddy)
[![forthebadge](http://forthebadge.com/images/badges/gluten-free.svg)](https://github.com/oskarcieslik/url-buddy)

## Install

```bash
$ npm install --save query-param
$ npm install --save url-buddy
```

## Usage

```js
import queryParam from 'query-param';
import urlBuddy from 'url-buddy';

// That's all folks!
```
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "query-param",
"version": "0.0.0-semantically-released",
"name": "url-buddy",
"version": "0.1.0",
"description": "Parse URL strings and extract multiple properties from them.",
"main": "lib",
"repository": {
"type": "git",
"url": "https://github.com/oskarcieslik/query-param.git"
"url": "https://github.com/oskarcieslik/url-buddy.git"
},
"homepage": "https://github.com/oskarcieslik/query-param#readme",
"homepage": "https://github.com/oskarcieslik/url-buddy#readme",
"bugs": {
"url": "https://github.com/oskarcieslik/query-param/issues"
"url": "https://github.com/oskarcieslik/url-buddy/issues"
},
"author": {
"name": "Oskar Cieslik",
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const getExtractedProperties = (url) => ({
...getBaseProperties({ url, valid: true }),
});

export const queryParam = (url) => {
export const urlBuddy = (url) => {
if (!isValidUrl(url)) { return getBaseProperties({ url, valid: false }); }
return getExtractedProperties(url);
};
1 change: 0 additions & 1 deletion src/util.js
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] : '';
};
86 changes: 43 additions & 43 deletions test/index.js
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);
});
});

0 comments on commit a5b8937

Please sign in to comment.