Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

is-whatwg-url

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-whatwg-url

Can be parsed or not by whatwg url module.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

is-whatwg-url

Can be parsed or not by whatwg url module.

Why

whatwg-url constructor throw error for normal string. is-whatwg-url is just validater for whatwg-url constructor.

Usage

const isURL = require('is-whatwg-url');
const { URL } = require('url');

isURL('apple'); // false
new URL('apple'); // throw Error Invalid URL

isURL('/apple'); // false
new URL('/apple'); // throw Error Invalid URL

isURL('//apple'); // false
new URL('//apple'); // throw Error Invalid URL

isURL('://apple'); // false
new URL('://apple'); // throw Error Invalid URL

isURL('a://apple'); // true
new URL('a://apple'); // success

isURL('a://apple://banana'); // true
new URL('a://apple://banana'); // success

How it works

check input string have protocol:// prefix. protocol should not be empty string.

Caveats

This module does not guarantee that input is URL or not. It just check can be parsed or not.

Alt.

consider using try-catch instead of this is-whatwg-url module.

let url;
try {
  url = new URL('apple');
} catch (err) {
  url = null;
}
  • Node URL Api
  • whatwg-url
  • URL Standard

Keywords

FAQs

Package last updated on 16 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc