Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

url-parse

Package Overview
Dependencies
Maintainers
3
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

url-parse - npm Package Compare versions

Comparing version 1.0.5 to 1.1.0

55

index.js

@@ -6,3 +6,4 @@ 'use strict';

, qs = require('querystringify')
, relativere = /^\/(?!\/)/;
, relativere = /^\/(?!\/)/
, protocolre = /^([a-z0-9.+-]+:)?(\/\/)?(.*)$/i; // actual protocol is first match

@@ -24,3 +25,2 @@ /**

['?', 'query'], // Extract from the back.
['//', 'protocol', 2, 1, 1], // Extract from the front.
['/', 'pathname'], // Extract from the back.

@@ -33,2 +33,26 @@ ['@', 'auth', 1], // Extract from the front.

/**
* @typedef ProtocolExtract
* @type Object
* @property {String} protocol Protocol matched in the URL, in lowercase
* @property {Boolean} slashes Indicates whether the protocol is followed by double slash ("//")
* @property {String} rest Rest of the URL that is not part of the protocol
*/
/**
* Extract protocol information from a URL with/without double slash ("//")
*
* @param {String} address URL we want to extract from.
* @return {ProtocolExtract} Extracted information
* @private
*/
function extractProtocol(address) {
var match = protocolre.exec(address);
return {
protocol: match[1] ? match[1].toLowerCase() : '',
slashes: !!match[2],
rest: match[3] ? match[3] : ''
};
}
/**

@@ -41,4 +65,4 @@ * The actual URL instance. Instead of returning an object we've opted-in to

* @param {String} address URL we want to parse.
* @param {Boolean|function} parser Parser for the query string.
* @param {Object} location Location defaults for relative paths.
* @param {Object|String} location Location defaults for relative paths.
* @param {Boolean|Function} parser Parser for the query string.
* @api public

@@ -79,2 +103,8 @@ */

// extract protocol information before running the instructions
var extracted = extractProtocol(address);
url.protocol = extracted.protocol || location.protocol || '';
url.slashes = extracted.slashes || location.slashes;
address = extracted.rest;
for (; i < instructions.length; i++) {

@@ -150,4 +180,8 @@ instruction = instructions[i];

*
* @param {String} prop Property we need to adjust.
* @param {Mixed} value The newly assigned value.
* @param {String} prop Property we need to adjust.
* @param {Mixed} value The newly assigned value.
* @param {Boolean|Function} fn When setting the query, it will be the function used to parse
* the query.
* When setting the protocol, double slash will be removed from
* the final url if it is true.
* @returns {URL}

@@ -187,2 +221,5 @@ * @api public

}
} else if ('protocol' === part) {
url.protocol = value;
url.slashes = !fn;
} else {

@@ -208,4 +245,8 @@ url[part] = value;

, url = this
, result = url.protocol +'//';
, protocol = url.protocol;
if (protocol && protocol.charAt(protocol.length - 1) !== ':') protocol += ':';
var result = protocol + (url.slashes ? '//' : '');
if (url.username) {

@@ -212,0 +253,0 @@ result += url.username;

2

lolcation.js

@@ -22,3 +22,3 @@ 'use strict';

*
* @param {Object} loc Optional default location object.
* @param {Object|String} loc Optional default location object.
* @returns {Object} lolcation object.

@@ -25,0 +25,0 @@ * @api public

{
"name": "url-parse",
"version": "1.0.5",
"version": "1.1.0",
"description": "Small footprint URL parser that works seamlessly across Node.js and browser environments",

@@ -37,9 +37,9 @@ "main": "index.js",

"devDependencies": {
"assume": "1.3.x",
"browserify": "12.0.x",
"assume": "1.4.x",
"browserify": "13.0.x",
"istanbul": "0.4.x",
"mocha": "2.3.x",
"mocha": "2.4.x",
"pre-commit": "1.1.x",
"zuul": "3.7.x"
"zuul": "3.10.x"
}
}
# url-parse
[![Made by unshift](https://img.shields.io/badge/made%20by-unshift-00ffcc.svg?style=flat-square)](http://unshift.io)[![Version npm](https://img.shields.io/npm/v/url-parse.svg?style=flat-square)](http://browsenpm.org/package/url-parse)[![Build Status](https://img.shields.io/travis/unshiftio/url-parse/master.svg?style=flat-square)](https://travis-ci.org/unshiftio/url-parse)[![Dependencies](https://img.shields.io/david/unshiftio/url-parse.svg?style=flat-square)](https://david-dm.org/unshiftio/url-parse)[![Coverage Status](https://img.shields.io/coveralls/unshiftio/url-parse/master.svg?style=flat-square)](https://coveralls.io/r/unshiftio/url-parse?branch=master)[![IRC channel](https://img.shields.io/badge/IRC-irc.freenode.net%23unshift-00a8ff.svg?style=flat-square)](https://webchat.freenode.net/?channels=unshift)

@@ -11,11 +12,12 @@

Since `0.1` we've moved away from using the DOM's `<a>` element for URL parsing
and moving to a full Regular Expression solution. The main reason for this
change is to make the URL parser available in different JavaScript environments
as you don't always have access to the DOM like `Worker` environments. This
module still have a really small foot print as this module's main intention is
to be bundled with client-side code. The only problem however with a RegExp
based solution is that it required a lot of lookups causing major problems in
FireFox. So the last and the current solution was a pure string parsing
solution which chops up the URL in smaller pieces.
In version `0.1` we moved from a DOM based parsing solution, using the `<a>`
element, to a full Regular Expression solution. The main reason for this was
to make the URL parser available in different JavaScript environments as you
don't always have access to the DOM. An example of such environment is the
[`Worker`](https://developer.mozilla.org/en/docs/Web/API/Worker) interface.
The RegExp based solution didn't work well as it required a lot of lookups
causing major problems in FireFox. In version `1.0.0` we ditched the RegExp
based solution in favor of a pure string parsing solution which chops up the
URL into smaller pieces. This module still has a really small footprint as it
has been designed to be used on the client side.

@@ -26,3 +28,3 @@ In addition to URL parsing we also expose the bundled `querystringify` module.

This module is designed to be used using either browserify or node.js it's
This module is designed to be used using either browserify or Node.js it's
released in the public npm registry and can be installed using:

@@ -45,3 +47,3 @@

To parse an URL simply call the `URL` method with the URL that needs to be
transformed in to an object.
transformed into an object.

@@ -53,6 +55,18 @@ ```js

The `new` keyword is optional but it will save you an extra function invocation.
In the example above we've demonstrated the URL interface, but as said in the
module description we also support the node.js interface. So you could also use
the library in this way:
The constructor takes the following arguments:
- `url` (`String`): A string representing an absolute or relative URL.
- `baseURL` (`Object` | `String`): An object or string representing
the base URL to use in case `url` is a relative URL. This argument is
optional and defaults to [`location`](https://developer.mozilla.org/en-US/docs/Web/API/Location)
in the browser.
- `parser` (`Boolean` | `Function`): This argument is optional and specifies
how to parse the query string. By default it is `false` so the query string
is not parsed. If you pass `true` the query string is parsed using the
embedded `querystringify` module. If you pass a function the query string
will be parsed using this function.
As said above we also support the Node.js interface so you can also use the
library in this way:
```js

@@ -115,10 +129,7 @@ 'use strict';

1. We have unit tests setup which run under Node.js using the normal `npm test`
command.
2. Code coverage can be run manually using `npm run coverage`
3. For browser testing we use `testling` to startup a test server. We do assume
that you `testling` installed globally, if not please run `npm install -g
testling` and after that `testling -u` in the root of this repository. When
you visit the outputted URL all unit tests that were written from the Node
can now be ran inside browsers.
1. We have unit tests that run under Node.js. You can run these tests with the
`npm test` command.
2. Code coverage can be run manually using `npm run coverage`.
3. For browser testing we use Sauce Labs and `zuul`. You can run browser tests
using the `npm run test-browser` command.

@@ -125,0 +136,0 @@ ## License

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc