UNPKG

@newrelic/gatsby-theme-newrelic

Version:

[![Community Project header](https://github.com/newrelic/opensource-website/raw/master/src/images/categories/Community_Project.png)](https://opensource.newrelic.com/oss-category/#community-project)

17 lines (12 loc) 540 B
export const stripTrailingSlash = (path) => path.replace(/\/$/, ''); export const addLeadingSlash = (path) => path.startsWith('/') ? path : `/${path}`; export const addTrailingSlash = (path) => { // we don't care about the origin in this case. We just want to manipulate the path const dummyOrigin = 'https://example.com'; const url = new URL(path, dummyOrigin); if (!url.pathname.endsWith('/') && !url.pathname.match(/\.[a-zA-Z]+$/)) { url.pathname = `${url.pathname}/`; } return url.href.replace(url.origin, ''); };