@docusaurus/utils
Advanced tools
Comparing version 2.0.0-alpha.64 to 2.0.0-alpha.65
@@ -246,2 +246,4 @@ "use strict"; | ||
const resultArray = []; | ||
let hasStartingSlash = false; | ||
let hasEndingSlash = false; | ||
// If the first part is a plain protocol, we combine it with the next part. | ||
@@ -263,12 +265,21 @@ if (urls[0].match(/^[^/:]+:\/*$/) && urls.length > 1) { | ||
if (component === '') { | ||
if (i === urls.length - 1 && hasEndingSlash) { | ||
resultArray.push('/'); | ||
} | ||
// eslint-disable-next-line | ||
continue; | ||
} | ||
if (i > 0) { | ||
// Removing the starting slashes for each component but the first. | ||
component = component.replace(/^[/]+/, ''); | ||
if (component !== '/') { | ||
if (i > 0) { | ||
// Removing the starting slashes for each component but the first. | ||
component = component.replace(/^[/]+/, | ||
// Special case where the first element of rawUrls is empty ["", "/hello"] => /hello | ||
component[0] === '/' && !hasStartingSlash ? '/' : ''); | ||
} | ||
hasEndingSlash = component[component.length - 1] === '/'; | ||
// Removing the ending slashes for each component but the last. | ||
// For the last component we will combine multiple slashes to a single one. | ||
component = component.replace(/[/]+$/, i < urls.length - 1 ? '' : '/'); | ||
} | ||
// Removing the ending slashes for each component but the last. | ||
// For the last component we will combine multiple slashes to a single one. | ||
component = component.replace(/[/]+$/, i < urls.length - 1 ? '' : '/'); | ||
hasStartingSlash = true; | ||
resultArray.push(component); | ||
@@ -275,0 +286,0 @@ } |
{ | ||
"name": "@docusaurus/utils", | ||
"version": "2.0.0-alpha.64", | ||
"version": "2.0.0-alpha.65", | ||
"description": "Node utility functions for Docusaurus packages", | ||
@@ -26,3 +26,3 @@ "main": "./lib/index.js", | ||
}, | ||
"gitHead": "5fdf3979c3595115109fc2e249ced846368c1f75" | ||
"gitHead": "deb65e2bd92a9b11fe067c7dc30b3d49b7828b5c" | ||
} |
@@ -262,2 +262,18 @@ /** | ||
{ | ||
input: ['/', ''], | ||
output: '/', | ||
}, | ||
{ | ||
input: ['', '/'], | ||
output: '/', | ||
}, | ||
{ | ||
input: ['/'], | ||
output: '/', | ||
}, | ||
{ | ||
input: [''], | ||
output: '', | ||
}, | ||
{ | ||
input: ['/', '/'], | ||
@@ -310,2 +326,30 @@ output: '/', | ||
}, | ||
{ | ||
input: ['/', '', 'hello', '', '/', '/', '', '/', '/world'], | ||
output: '/hello/world', | ||
}, | ||
{ | ||
input: ['', '', '/tt', 'ko', 'hello'], | ||
output: '/tt/ko/hello', | ||
}, | ||
{ | ||
input: ['', '///hello///', '', '///world'], | ||
output: '/hello/world', | ||
}, | ||
{ | ||
input: ['', '/hello/', ''], | ||
output: '/hello/', | ||
}, | ||
{ | ||
input: ['', '/', ''], | ||
output: '/', | ||
}, | ||
{ | ||
input: ['///', '///'], | ||
output: '/', | ||
}, | ||
{ | ||
input: ['/', '/hello/world/', '///'], | ||
output: '/hello/world/', | ||
}, | ||
]; | ||
@@ -312,0 +356,0 @@ asserts.forEach((testCase) => { |
@@ -285,2 +285,5 @@ /** | ||
let hasStartingSlash = false; | ||
let hasEndingSlash = false; | ||
// If the first part is a plain protocol, we combine it with the next part. | ||
@@ -306,2 +309,5 @@ if (urls[0].match(/^[^/:]+:\/*$/) && urls.length > 1) { | ||
if (component === '') { | ||
if (i === urls.length - 1 && hasEndingSlash) { | ||
resultArray.push('/'); | ||
} | ||
// eslint-disable-next-line | ||
@@ -311,11 +317,19 @@ continue; | ||
if (i > 0) { | ||
// Removing the starting slashes for each component but the first. | ||
component = component.replace(/^[/]+/, ''); | ||
if (component !== '/') { | ||
if (i > 0) { | ||
// Removing the starting slashes for each component but the first. | ||
component = component.replace( | ||
/^[/]+/, | ||
// Special case where the first element of rawUrls is empty ["", "/hello"] => /hello | ||
component[0] === '/' && !hasStartingSlash ? '/' : '', | ||
); | ||
} | ||
hasEndingSlash = component[component.length - 1] === '/'; | ||
// Removing the ending slashes for each component but the last. | ||
// For the last component we will combine multiple slashes to a single one. | ||
component = component.replace(/[/]+$/, i < urls.length - 1 ? '' : '/'); | ||
} | ||
// Removing the ending slashes for each component but the last. | ||
// For the last component we will combine multiple slashes to a single one. | ||
component = component.replace(/[/]+$/, i < urls.length - 1 ? '' : '/'); | ||
hasStartingSlash = true; | ||
resultArray.push(component); | ||
@@ -322,0 +336,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1299474
11
1368