Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function getWidth (path, isRetina) {
try {
const image = await (isAbsoluteUrl(path) ? getRemoteBuffer(path) : fs.readFile(path))
const { width } = sizeOf(image)
if (!width) { return 'auto' }
return isRetina ? Math.round(width / 2) : width
} catch (e) {
return 'auto' // if we fail fall back to auto
}
}
export const Link = ({ href, ...props }) =>
isHash(href) || isAbsoluteURL(href) ? (
// eslint-disable-next-line
<a href="{href}">
) : (
)
</a>
export default function Link({ nav, to, skipPrefetch, ...props }) {
let shouldReload = false;
const path = typeof to === 'string' ? to : to.pathname;
const isPathAbsolute = isAbsolute(path);
const Component = nav ? NavLink : RouterLink;
const [prefetchFlag, setPrefetchFlag] = useState(false);
function prefetch() {
if (prefetchFlag) {
return;
}
if (!isPathAbsolute) {
const matchingRoutes = matchRoutes(path, Link.routes);
const components = matchingRoutes.map(({ component }) =>
component.preload()
);
Promise.all(components).catch(() => {
shouldReload = true;
const Logo = () => {
const isAbsolute = isAbsoluteUrl(config.homeLink)
const Element = isAbsolute ? React.DOM.a : Link
const props = {
className: 'logo',
[isAbsolute ? 'href' : 'to']: config.homeLink,
rel: isAbsolute ? 'noopener nofollow' : null
}
return (
<element>
<img src="{config.logo}">
<img src="{config.logoMobile}">
</element>
)
}
export const RouterLinkOrAnchor: React.FunctionComponent = props =>
typeof props.to === 'string' && isAbsoluteUrl(props.to) ? <a href="{props.to}"> :
</a>
public convertFirefoxSourceToPath(source: FirefoxDebugProtocol.Source): string | undefined {
if (!source) return undefined;
if (source.addonID && this.addonConfig && (source.addonID === this.addonConfig.id)) {
let sourcePath = this.removeQueryString(path.join(this.addonConfig.path, source.addonPath!));
log.debug(`Addon script path: ${sourcePath}`);
return sourcePath;
} else if (source.isSourceMapped && source.generatedUrl && source.url && !isAbsoluteUrl(source.url)) {
let originalPathOrUrl = source.url;
if (path.isAbsolute(originalPathOrUrl)) {
log.debug(`Sourcemapped absolute path: ${originalPathOrUrl}`);
if (isWindowsPlatform) {
originalPathOrUrl = path.normalize(originalPathOrUrl);
}
return originalPathOrUrl;
} else {
let generatedUrl = source.generatedUrl;
function isExternalLink(external_link, href) {
if (typeof external_link === 'undefined' || external_link === null) {
return isAbsoluteUrl(href);
}
return external_link;
}
function Link({ to = '', href = to, children, ...props }) {
const isAbsoluteLink = isAbsoluteURL(href)
return isAbsoluteLink ? (
<a href="{href}">
{children}
</a>
) : (
{children}
)
}