Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

detect-external-link

trunkcode3.5kMIT2.0.1TypeScript support: included

Node.js plugin that analyzes the given link and determines if the URL is internal or external.

detection, external-link

readme

detect-external-link

NPM version Downloads AppVeyor Build Status Downloads

JavaScript plugin that analyzes the given link and determines if the URL is internal or external. To ensure accuracy, please include a list of specified hosts that should be marked as internal. This way, the plugin can effectively differentiate between internal and external links based on the provided hosts list.

Install

Via npm

npm install detect-external-link

Via Yarn

yarn add detect-external-link

For vanilla HTML in modern browsers, import detect-external-link from jsDelivr:

<script type="module">
import detectExternalLink from 'https://cdn.jsdelivr.net/npm/detect-external-link@2/+esm';

console.log(detectExternalLink('http://test.example2.com/test/abc/', {
  'hosts': [
    'http://example.com',
    'http://test.example.com'
  ]
}));
</script>

Usage

import detectExternalLink from '/js/index.js';

const link = 'http://test.example2.com/test/abc/';
const linkOptions = {
  'hosts': [
    'http://example.com',
    'http://test.example.com'
  ]
};

console.log(detectExternalLink(link, linkOptions));

Parameters

Attributes Type Required Default Description
hosts Array Yes [] Site hostname(s) to detect external links.

changelog

detect-external-link changelog

2.0.1 - Sep 27, 2023

Bug

  • Add missing files

2.0.0 - Sep 27, 2023

Enhancement

  • Include ESM support

1.0.2 - Aug 25, 2023

Bug

  • Resolve Protocol relative URL issue

1.0.1 - Jul 26, 2023

Enhancement

  • Resolve issue with relative links

1.0.0 - Jul 25, 2023

  • Initial Release