@docusaurus/utils-common
Advanced tools
Comparing version 2.0.0-beta.4a6de5cf7 to 2.0.0-beta.4d93c894f
@@ -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; | ||
@@ -22,2 +22,5 @@ } | ||
} | ||
function handleTrailingSlash(str, trailing) { | ||
return trailing ? addTrailingSlash(str) : removeTrailingSlash(str); | ||
} | ||
// undefined = legacy retrocompatible behavior | ||
@@ -29,7 +32,6 @@ if (typeof trailingSlash === 'undefined') { | ||
const [pathname] = path.split(/[#?]/); | ||
const newPathname = trailingSlash | ||
? addTrailingSlash(pathname) | ||
: removeTrailingSlash(pathname); | ||
// Never transform '/' to '' | ||
const newPathname = pathname === '/' ? '/' : handleTrailingSlash(pathname, trailingSlash); | ||
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.4a6de5cf7", | ||
"version": "2.0.0-beta.4d93c894f", | ||
"description": "Common (Node/Browser) utility functions for Docusaurus packages.", | ||
@@ -21,3 +21,3 @@ "main": "./lib/index.js", | ||
"dependencies": { | ||
"@docusaurus/types": "2.0.0-beta.4a6de5cf7", | ||
"@docusaurus/types": "2.0.0-beta.4d93c894f", | ||
"tslib": "^2.2.0" | ||
@@ -28,3 +28,3 @@ }, | ||
}, | ||
"gitHead": "ee2049596f0431c410304749aeada97f1dcfc311" | ||
"gitHead": "ecfcf28f57a78c8ac798d08e6c2f59f72a85a0b3" | ||
} |
@@ -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
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
61618
351425
16
290
28
7
233
+ Added@docusaurus/types@2.0.0-beta.4d93c894f(transitive)
+ Addedelectron-to-chromium@1.5.57(transitive)
- Removed@docusaurus/types@2.0.0-beta.4a6de5cf7(transitive)
- Removedelectron-to-chromium@1.5.55(transitive)