@docusaurus/utils-common
Advanced tools
Comparing version 2.0.0-beta.af3640dca to 2.0.0-beta.b54ec7238
@@ -10,4 +10,4 @@ "use strict"; | ||
function applyTrailingSlash(path, trailingSlash) { | ||
// Never apply trailing slash to an anchor link | ||
if (path.startsWith('#')) { | ||
// Never apply trailing slash to an anchor link | ||
return path; | ||
@@ -28,7 +28,10 @@ } | ||
const [pathname] = path.split(/[#?]/); | ||
const newPathname = trailingSlash | ||
? addTrailingSlash(pathname) | ||
: removeTrailingSlash(pathname); | ||
// Never transform '/' to '' | ||
const newPathname = pathname === '/' | ||
? '/' | ||
: trailingSlash | ||
? addTrailingSlash(pathname) | ||
: removeTrailingSlash(pathname); | ||
return path.replace(pathname, newPathname); | ||
} | ||
exports.default = applyTrailingSlash; |
{ | ||
"name": "@docusaurus/utils-common", | ||
"version": "2.0.0-beta.af3640dca", | ||
"version": "2.0.0-beta.b54ec7238", | ||
"description": "Common (Node/Browser) utility functions for Docusaurus packages.", | ||
@@ -21,3 +21,3 @@ "main": "./lib/index.js", | ||
"dependencies": { | ||
"@docusaurus/types": "2.0.0-beta.af3640dca", | ||
"@docusaurus/types": "2.0.0-beta.b54ec7238", | ||
"tslib": "^2.2.0" | ||
@@ -28,3 +28,3 @@ }, | ||
}, | ||
"gitHead": "6c6cc9296c98af43245cad38053d6703e700c610" | ||
"gitHead": "c6e8e4791a712d9af474ab03453e50a035dd0757" | ||
} |
@@ -17,6 +17,16 @@ /** | ||
test('should apply to /', () => { | ||
test('should not apply to /', () => { | ||
expect(applyTrailingSlash('/', true)).toEqual('/'); | ||
expect(applyTrailingSlash('/', false)).toEqual(''); | ||
expect(applyTrailingSlash('/', false)).toEqual('/'); | ||
expect(applyTrailingSlash('/', undefined)).toEqual('/'); | ||
expect(applyTrailingSlash('/?query#anchor', true)).toEqual( | ||
'/?query#anchor', | ||
); | ||
expect(applyTrailingSlash('/?query#anchor', false)).toEqual( | ||
'/?query#anchor', | ||
); | ||
expect(applyTrailingSlash('/?query#anchor', undefined)).toEqual( | ||
'/?query#anchor', | ||
); | ||
}); | ||
@@ -23,0 +33,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
58918
226
+ Added@docusaurus/types@2.0.0-beta.b54ec7238(transitive)
- Removed@docusaurus/types@2.0.0-beta.af3640dca(transitive)