Skip to content

Commit

Permalink
v1.0.0-alpha14
Browse files Browse the repository at this point in the history
  • Loading branch information
greenkeeper[bot] authored and stevenvachon committed Jul 7, 2017
1 parent e014ab3 commit 786db5e
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 212 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
coverage/
lib/
node_modules/
.nyc_output/
package-lock.json
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: node_js
node_js:
- 4
- 6
- 8
- 6
- 8
script: npm run ci
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# minurl [![NPM Version][npm-image]][npm-url] ![File Size][filesize-image] [![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Dependency Status][david-image]][david-url]
# minurl [![NPM Version][npm-image]][npm-url] ![File Size][filesize-image] [![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Dependency Monitor][greenkeeper-image]][greenkeeper-url]

> Reduce and normalize the components of a [WHATWG URL](https://url.spec.whatwg.org).
> Reduce and normalize the components of a WHATWG [`URL`](https://developer.mozilla.org/en/docs/Web/API/URL).

## Installation

[Node.js](http://nodejs.org/) `>= 4` is required. To install, type this at the command line:
[Node.js](http://nodejs.org/) `>= 6` is required. To install, type this at the command line:
```shell
npm install minurl
```
Expand Down Expand Up @@ -182,10 +182,10 @@ const custom = extend(true, {}, minURL.COMMON_PROFILE, { directoryIndexes:['inde

[npm-image]: https://img.shields.io/npm/v/minurl.svg
[npm-url]: https://npmjs.org/package/minurl
[filesize-image]: https://img.shields.io/badge/size-2.4kB%20gzipped-blue.svg
[filesize-image]: https://img.shields.io/badge/size-2.5kB%20gzipped-blue.svg
[travis-image]: https://img.shields.io/travis/stevenvachon/minurl.svg
[travis-url]: https://travis-ci.org/stevenvachon/minurl
[coveralls-image]: https://img.shields.io/coveralls/stevenvachon/minurl.svg
[coveralls-url]: https://coveralls.io/github/stevenvachon/minurl
[david-image]: https://img.shields.io/david/stevenvachon/minurl.svg
[david-url]: https://david-dm.org/stevenvachon/minurl
[greenkeeper-image]: https://badges.greenkeeper.io/stevenvachon/minurl.svg
[greenkeeper-url]: https://greenkeeper.io/
110 changes: 47 additions & 63 deletions src/minurl.js → index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,43 @@ const defaultPorts = { "ftps:":990, "git:":9418, "scp:":22, "sftp:":22, "ssh:":2
const directoryIndexes = ["index.html"];
const emptyQueryValue = /([^&\?])=&/g;
const encodedSpace = /%20/g;
const multipleAmpersand = /&+/g;
const multipleSlashes = /\/{2,}/g;
const queryNames = [];
const trailingAmpersand = /&$/;
const trailingEquals = /([^&\?])=$/;
const trailingQuestion = /\?#?(?:.+)?$/;

const carefulProfile =


const defaultValue = (customOptions, optionName, ...args) =>
{
const defaultOption = evaluateValue(commonProfile[optionName], ...args);

if (customOptions != null)
{
return defined( evaluateValue(customOptions[optionName], ...args), defaultOption );
}
else
{
return defaultOption;
}
};



const filterCommon = url => url.protocol==="http:" || url.protocol==="https:";

const filterSafe = url => url.protocol === "mailto:";



const filterSpecCompliant = url =>
{
return filterSafe(url) || url.protocol==="http:" || url.protocol==="https:" || url.protocol==="ws:" || url.protocol==="wss:";
};



const carefulProfile =
{
clone: true,
defaultPorts,
Expand All @@ -42,7 +71,7 @@ const carefulProfile =
stringify: true
};

const commonProfile =
const commonProfile =
{
clone: true,
defaultPorts,
Expand All @@ -68,44 +97,7 @@ const commonProfile =



function defaultValue(customOptions, optionName, ...args)
{
const defaultOption = evaluateValue(commonProfile[optionName], ...args);

if (customOptions != null)
{
return defined( evaluateValue(customOptions[optionName], ...args), defaultOption );
}
else
{
return defaultOption;
}
}



function filterCommon(url)
{
return url.protocol==="http:" || url.protocol==="https:";
}



function filterSafe(url)
{
return url.protocol === "mailto:";
}



function filterSpecCompliant(url)
{
return filterSafe(url) || url.protocol==="http:" || url.protocol==="https:" || url.protocol==="ws:" || url.protocol==="wss:";
}



function minURL(url, options)
const minURL = (url, options) =>
{
if (!isURL.lenient(url))
{
Expand Down Expand Up @@ -156,7 +148,7 @@ function minURL(url, options)
url.hash = "";
}
}

if (url.search !== "")
{
// If not a partial implementation
Expand Down Expand Up @@ -187,7 +179,7 @@ function minURL(url, options)

// Rebuild params
// NOTE :: `searchParams.delete()` will not remove individual values
params.filter( function([name, value])
params.filter(([name, value]) =>
{
const isRemovableQuery = removeEmptyQueries && name==="" && value==="";
const isRemovableQueryName = removeEmptyQueryNames && name==="" && value!=="";
Expand All @@ -202,7 +194,7 @@ function minURL(url, options)
{
const queryNames = defaultValue(options, "queryNames");

Array.from(url.searchParams.keys()).forEach( function(param)
Array.from(url.searchParams.keys()).forEach(param =>
{
if (anyMatch(param, queryNames))
{
Expand All @@ -215,30 +207,22 @@ function minURL(url, options)

if (defaultValue(options, "removeQueryOddities", url))
{
if (url.search === "")
{
if (trailingQuestion.test(url.href))
{
// Force `href` to update
url.search = "";
}
}
else
if (url.search !== "")
{
url.search = url.search
.replace(emptyQueryValue, "$1&")
.replace(multipleAmpersand, "&") // TODO :: remove when "whatwg-url" has `URLSearchParams`
.replace(trailingAmpersand, "")
.replace(trailingEquals, "$1");
}
else if (trailingQuestion.test(url.href))
{
// Force `href` to update
url.search = "";
}
}

if (url.search !== "")
if (url.search!=="" && defaultValue(options, "plusQueries", url))
{
if (defaultValue(options, "plusQueries", url))
{
url.search = url.search.replace(encodedSpace, "+");
}
url.search = url.search.replace(encodedSpace, "+");
}

if (defaultValue(options, "removeWWW", url))
Expand Down Expand Up @@ -266,9 +250,9 @@ function minURL(url, options)
return url.href.replace(url.host + url.pathname, url.host);
}
}

return url.href;
}
};



Expand Down
31 changes: 14 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,43 @@
{
"name": "minurl",
"description": "Reduce and normalize the components of a URL.",
"version": "1.0.0-alpha13",
"version": "1.0.0-alpha14",
"license": "MIT",
"author": "Steven Vachon <contact@svachon.com> (https://www.svachon.com/)",
"main": "lib/minurl",
"repository": "stevenvachon/minurl",
"dependencies": {
"any-match": "^1.0.1",
"cloneurl": "^1.0.0-alpha3",
"cloneurl": "^1.0.0",
"deep-freeze-node": "^1.1.2",
"defined": "^1.0.0",
"evaluate-value": "^1.0.2",
"isurl": "^1.0.0-alpha5",
"isurl": "^1.0.0",
"strip-www": "^1.0.0"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-preset-es2015": "^6.24.1",
"babelify": "^7.3.0",
"browserify": "^14.4.0",
"chai": "^4.0.1",
"chai": "^4.0.2",
"coveralls": "^2.13.1",
"decache": "^4.1.0",
"gzip-size-cli": "^2.0.0",
"incomplete-url": "^1.0.2",
"mocha": "^3.4.2",
"nyc": "^11.0.2",
"uglify-js": "^3.0.15",
"universal-url": "^1.0.0-alpha",
"url-search-params": "~0.7.0",
"whatwg-url": "^5.0.0"
"nyc": "^11.0.3",
"uglify-js": "^3.0.23",
"universal-url": "^1.0.0"
},
"engines": {
"node": ">= 4"
"node": ">= 6"
},
"scripts": {
"ci": "npm run test && nyc report --reporter=text-lcov | coveralls",
"posttest": "nyc report --reporter=html && browserify lib/minurl --global-transform [ babelify --presets [ es2015 ] ] --standalone minURL | uglifyjs --compress --mangle | gzip-size",
"pretest": "babel src --out-dir=lib --presets=es2015 --source-maps=true",
"test": "nyc --reporter=text-summary mocha test --reporter=spec --check-leaks --bail"
"posttest": "nyc report --reporter=html && browserify index.js --global-transform [ babelify --presets [ es2015 ] ] --standalone minURL | uglifyjs --compress --mangle | gzip-size",
"test": "nyc --reporter=text-summary mocha test --check-leaks --bail"
},
"files": ["lib/minurl.js"],
"files": [
"index.js"
],
"keywords": [
"beautifier",
"beautify",
Expand Down

0 comments on commit 786db5e

Please sign in to comment.