is-localhost-ip
Comprehensively checks whether given DNS name or IPv4/IPv6 address belongs to local machine
Main difference from other libraries here is comprehensiveness: we start from simple RegExp checks, then fallbacks DNS resolver (so it works with something like john.dev remapped locally).
Requires Node 10+, 100% code coverage
Installation
npm i is-localhost-ip
yarn add is-localhost-ip
Example
const isLocalhost = require('is-localhost-ip');
(async () => {
await isLocalhost("127.0.0.1");
await isLocalhost("::ffff:127.0.0.1");
await isLocalhost("192.168.0.12");
await isLocalhost("184.55.123.2");
await isLocalhost("tino.local");
await isLocalhost("localhost");
await isLocalhost("microsoft.com");
})();