Socket
Book a DemoInstallSign in
Socket

check-valid-url

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

check-valid-url

A Node.js library providing URL validation functionality to check whether a given string is a valid URL.

0.1.0
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

URL Validator Kit

A Node.js module to check whether a string is a valid URL.

Installation

Install the package via npm:

npm install check-valid-url --save

Usage

Import the module into your project:


const { isUrl } = require('check-valid-url');

const url = 'https://www.example.com';
const isValidUrl = isUrl(url);

if (isValidUrl) {
  console.log('Valid URL');
} else {
  console.log('Not a valid URL');
}

The isUrl function returns true if the provided string is a valid URL; otherwise, it returns false.

API

  • isUrl(text) Checks whether the provided string text is a valid URL.

    • text: The string to be checked.

    Returns true if text is a valid URL; otherwise, returns false.

  • isValidUrl(url, callback):

    • url (string): The URL to validate.

    • callback (Function): A callback function to handle the result. Parameters:

      • err (Error | null): An error object if an error occurs; otherwise, null.
      • isValid (boolean | undefined): true if the URL responds with a successful status code; false or undefined in case of an error.

Example

isUrl: Check if a string is a valid URL.


const { isUrl } = require('check-valid-url');

const url = 'https://www.example.com';
const isValidUrl = isUrl(url);

console.log(isValidUrl); // Output: true

isValidUrl: Check if a URL responds with a successful status code (2xx or 3xx).


const { isValidUrl } = require('check-valid-url');

const url = 'https://www.example.com';
isValidUrl(url, (err, isValid) => {
    if (err) {
        console.error(err); // Handle error
    } else {
        console.log(isValid); // Output: true or false
    }
});

Testing

To run the tests, use:

npm test

Keywords

url

FAQs

Package last updated on 11 Dec 2023

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.