@docusaurus/utils-common
Advanced tools
Comparing version 2.0.0-beta.41d9288e3 to 2.0.0-beta.41eaa690e
@@ -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; |
@@ -8,1 +8,2 @@ /** | ||
export { default as applyTrailingSlash } from './applyTrailingSlash'; | ||
export { default as uniq } from './uniq'; |
@@ -12,4 +12,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.applyTrailingSlash = void 0; | ||
exports.uniq = exports.applyTrailingSlash = void 0; | ||
var applyTrailingSlash_1 = require("./applyTrailingSlash"); | ||
Object.defineProperty(exports, "applyTrailingSlash", { enumerable: true, get: function () { return __importDefault(applyTrailingSlash_1).default; } }); | ||
var uniq_1 = require("./uniq"); | ||
Object.defineProperty(exports, "uniq", { enumerable: true, get: function () { return __importDefault(uniq_1).default; } }); |
{ | ||
"name": "@docusaurus/utils-common", | ||
"version": "2.0.0-beta.41d9288e3", | ||
"version": "2.0.0-beta.41eaa690e", | ||
"description": "Common (Node/Browser) utility functions for Docusaurus packages.", | ||
@@ -21,3 +21,3 @@ "main": "./lib/index.js", | ||
"dependencies": { | ||
"@docusaurus/types": "2.0.0-beta.41d9288e3", | ||
"@docusaurus/types": "2.0.0-beta.41eaa690e", | ||
"tslib": "^2.2.0" | ||
@@ -28,3 +28,3 @@ }, | ||
}, | ||
"gitHead": "45382af2a5c2fc03af06e0809f0e4539160b6bca" | ||
"gitHead": "2c55b3a650d826c87c1d4a6c52dcca9309ccdcb6" | ||
} |
@@ -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 @@ |
@@ -9,1 +9,2 @@ /** | ||
export {default as applyTrailingSlash} from './applyTrailingSlash'; | ||
export {default as uniq} from './uniq'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
61461
16
292
+ Added@docusaurus/types@2.0.0-beta.41eaa690e(transitive)
+ Added@types/node@22.13.1(transitive)
+ Addedajv@6.12.6(transitive)
+ Addedajv-keywords@3.5.2(transitive)
+ Addedelectron-to-chromium@1.5.96(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedschema-utils@3.3.0(transitive)
+ Addedterser@5.38.1(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addedwebpack@5.97.1(transitive)
- Removed@docusaurus/types@2.0.0-beta.41d9288e3(transitive)
- Removed@types/node@22.13.2(transitive)
- Removedelectron-to-chromium@1.5.98(transitive)
- Removedterser@5.39.0(transitive)
- Removedwebpack@5.98.0(transitive)