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

url-join

Package Overview
Dependencies
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

url-join - npm Package Compare versions

Comparing version 4.0.1 to 5.0.0

lib/url-join.d.ts

114

lib/url-join.js

@@ -1,78 +0,70 @@

(function (name, context, definition) {
if (typeof module !== 'undefined' && module.exports) module.exports = definition();
else if (typeof define === 'function' && define.amd) define(definition);
else context[name] = definition();
})('urljoin', this, function () {
function normalize (strArray) {
var resultArray = [];
if (strArray.length === 0) { return ''; }
function normalize (strArray) {
var resultArray = [];
if (strArray.length === 0) { return ''; }
if (typeof strArray[0] !== 'string') {
throw new TypeError('Url must be a string. Received ' + strArray[0]);
}
if (typeof strArray[0] !== 'string') {
throw new TypeError('Url must be a string. Received ' + strArray[0]);
// If the first part is a plain protocol, we combine it with the next part.
if (strArray[0].match(/^[^/:]+:\/*$/) && strArray.length > 1) {
var first = strArray.shift();
strArray[0] = first + strArray[0];
}
// There must be two or three slashes in the file protocol, two slashes in anything else.
if (strArray[0].match(/^file:\/\/\//)) {
strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, '$1:///');
} else {
strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, '$1://');
}
for (var i = 0; i < strArray.length; i++) {
var component = strArray[i];
if (typeof component !== 'string') {
throw new TypeError('Url must be a string. Received ' + component);
}
// If the first part is a plain protocol, we combine it with the next part.
if (strArray[0].match(/^[^/:]+:\/*$/) && strArray.length > 1) {
var first = strArray.shift();
strArray[0] = first + strArray[0];
if (component === '') { continue; }
if (i > 0) {
// Removing the starting slashes for each component but the first.
component = component.replace(/^[\/]+/, '');
}
// There must be two or three slashes in the file protocol, two slashes in anything else.
if (strArray[0].match(/^file:\/\/\//)) {
strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, '$1:///');
if (i < strArray.length - 1) {
// Removing the ending slashes for each component but the last.
component = component.replace(/[\/]+$/, '');
} else {
strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, '$1://');
// For the last component we will combine multiple slashes to a single one.
component = component.replace(/[\/]+$/, '/');
}
for (var i = 0; i < strArray.length; i++) {
var component = strArray[i];
resultArray.push(component);
if (typeof component !== 'string') {
throw new TypeError('Url must be a string. Received ' + component);
}
}
if (component === '') { continue; }
var str = resultArray.join('/');
// Each input component is now separated by a single slash except the possible first plain protocol part.
if (i > 0) {
// Removing the starting slashes for each component but the first.
component = component.replace(/^[\/]+/, '');
}
if (i < strArray.length - 1) {
// Removing the ending slashes for each component but the last.
component = component.replace(/[\/]+$/, '');
} else {
// For the last component we will combine multiple slashes to a single one.
component = component.replace(/[\/]+$/, '/');
}
// remove trailing slash before parameters or hash
str = str.replace(/\/(\?|&|#[^!])/g, '$1');
resultArray.push(component);
// replace ? in parameters with &
var parts = str.split('?');
str = parts.shift() + (parts.length > 0 ? '?': '') + parts.join('&');
}
return str;
}
var str = resultArray.join('/');
// Each input component is now separated by a single slash except the possible first plain protocol part.
export default function urlJoin() {
var input;
// remove trailing slash before parameters or hash
str = str.replace(/\/(\?|&|#[^!])/g, '$1');
// replace ? in parameters with &
var parts = str.split('?');
str = parts.shift() + (parts.length > 0 ? '?': '') + parts.join('&');
return str;
if (typeof arguments[0] === 'object') {
input = arguments[0];
} else {
input = [].slice.call(arguments);
}
return function () {
var input;
if (typeof arguments[0] === 'object') {
input = arguments[0];
} else {
input = [].slice.call(arguments);
}
return normalize(input);
};
});
return normalize(input);
}
{
"name": "url-join",
"version": "4.0.1",
"version": "5.0.0",
"description": "Join urls and normalize as in path.join.",
"main": "lib/url-join.js",
"type": "module",
"main": "./lib/url-join.js",
"exports": "./lib/url-join.js",
"types": "./lib/url-join.d.ts",
"sideEffects": false,
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"scripts": {
"test": "mocha --require should"
},
"files": [
"lib"
],
"repository": {

@@ -20,6 +30,6 @@ "type": "git",

"devDependencies": {
"conventional-changelog": "^1.1.10",
"mocha": "^3.2.0",
"should": "~1.2.1"
"conventional-changelog": "^3.1.25",
"mocha": "^9.2.2",
"should": "~13.2.3"
}
}

@@ -1,47 +0,29 @@

Join all arguments together and normalize the resulting url.
Join all arguments together and normalize the resulting URL.
## Install
~~~
```bash
npm install url-join
~~~
```
If you want to use it directly in a browser use a CDN like [Skypack](https://www.skypack.dev/view/url-join).
## Usage
~~~javascript
var urljoin = require('url-join');
```javascript
import urlJoin from 'url-join';
var fullUrl = urljoin('http://www.google.com', 'a', '/b/cd', '?foo=123');
const fullUrl = urlJoin('http://www.google.com', 'a', '/b/cd', '?foo=123');
console.log(fullUrl);
```
~~~
Prints:
~~~
```
'http://www.google.com/a/b/cd?foo=123'
~~~
```
## Browser and AMD
It also works in the browser, you can either include ```lib/url-join.js``` in your page:
~~~html
<script src="url-join.js"></script>
<script type="text/javascript">
urljoin('http://blabla.com', 'foo?a=1')
</script>
~~~
Or using an AMD module system like requirejs:
~~~javascript
define(['path/url-join.js'], function (urljoin) {
urljoin('http://blabla.com', 'foo?a=1');
});
~~~
## License
MIT
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