Code Monkey home page Code Monkey logo

link-exists's Introduction

GitHub Workflow Status (branch) npm npm npm bundle size GitHub

link-exists

A super lightweight JavaScript / TypeScript library to check whether a given url is valid and exists or not.

Installation

npm install link-exists

Features

A super lightweight library to validate if a given url is valid or not. Some additional features are-

  • less than 1 kb in size
  • additional configuration to validate as per custom requirement
  • supports node.js latest version
  • TypeScript and JavaScript support
  • built on ES6 modules
  • Jest test cases with 100% coverage
  • Promise based result

Usage (TypeScript)

import { linkExists } from 'link-exists';

const result = await linkExists('https://stackblogger.com');
console.log(result);
// OUTPUT true

const result = await linkExists('https://some-invalid-url.com');
console.log(result);
// OUTPUT false

const result = await linkExists('stackblogger.com');
console.log(result);
// OUTPUT false

// Configuration
const result = await linkExists('stackblogger.com', { ignoreProtocol: true });
console.log(result);
// OUTPUT true

Usage (JavaScript)

const { linkExists } = require('link-exists');

const result = await linkExists('https://stackblogger.com');
console.log(result);
// OUTPUT true

const result = await linkExists('https://some-invalid-url.com');
console.log(result);
// OUTPUT false

const result = await linkExists('stackblogger.com');
console.log(result);
// OUTPUT false

// Configuration
const result = await linkExists('stackblogger.com', { ignoreProtocol: true });
console.log(result);
// OUTPUT true

License

MIT

link-exists's People

Stargazers

 avatar

Watchers

 avatar  avatar

link-exists's Issues

Error with React vite.

I get the next error when import the library.

`
Failed to resolve entry for package "http". The package may have incorrect main/module/exports specified in its package.json. [plugin vite:dep-pre-bundle]

node_modules/esbuild/lib/main.js:1373:21:
  1373 │         let result = await callback({
       ╵                      ^

at packageEntryFailure (file:///C:/Users/luisg/dev/react/my-unsplash-react/node_modules/vite/dist/node/chunks/dep-df561101.js:28691:11)
at resolvePackageEntry (file:///C:/Users/luisg/dev/react/my-unsplash-react/node_modules/vite/dist/node/chunks/dep-df561101.js:28688:5)
at tryNodeResolve (file:///C:/Users/luisg/dev/react/my-unsplash-react/node_modules/vite/dist/node/chunks/dep-df561101.js:28419:20)
at Context.resolveId (file:///C:/Users/luisg/dev/react/my-unsplash-react/node_modules/vite/dist/node/chunks/dep-df561101.js:28180:28)
at Object.resolveId (file:///C:/Users/luisg/dev/react/my-unsplash-react/node_modules/vite/dist/node/chunks/dep-df561101.js:44207:64)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async file:///C:/Users/luisg/dev/react/my-unsplash-react/node_modules/vite/dist/node/chunks/dep-df561101.js:65837:21
at async file:///C:/Users/luisg/dev/react/my-unsplash-react/node_modules/vite/dist/node/chunks/dep-df561101.js:39941:34
at async requestCallbacks.on-resolve (C:\Users\luisg\dev\react\my-unsplash-react\node_modules\esbuild\lib\main.js:1373:22)
at async handleRequest (C:\Users\luisg\dev\react\my-unsplash-react\node_modules\esbuild\lib\main.js:729:13)

This error came from the "onResolve" callback registered here:

node_modules/esbuild/lib/main.js:1292:20:
  1292 │       let promise = setup({
       ╵                     ^

at setup (file:///C:/Users/luisg/dev/react/my-unsplash-react/node_modules/vite/dist/node/chunks/dep-df561101.js:39921:19)
at handlePlugins (C:\Users\luisg\dev\react\my-unsplash-react\node_modules\esbuild\lib\main.js:1292:21)
at buildOrContextImpl (C:\Users\luisg\dev\react\my-unsplash-react\node_modules\esbuild\lib\main.js:978:5)
at Object.buildOrContext (C:\Users\luisg\dev\react\my-unsplash-react\node_modules\esbuild\lib\main.js:786:5)
at C:\Users\luisg\dev\react\my-unsplash-react\node_modules\esbuild\lib\main.js:2186:68
at new Promise (<anonymous>)
at Object.context (C:\Users\luisg\dev\react\my-unsplash-react\node_modules\esbuild\lib\main.js:2186:27)
at Object.context (C:\Users\luisg\dev\react\my-unsplash-react\node_modules\esbuild\lib\main.js:2026:58)
at prepareEsbuildOptimizerRun (file:///C:/Users/luisg/dev/react/my-unsplash-react/node_modules/vite/dist/node/chunks/dep-df561101.js:45967:35)

The plugin "vite:dep-pre-bundle" was triggered by this import

node_modules/link-exists/dist/index.esm.js:1:13:
  1 │ import t from"http";const o=/(http(s)?:\/\/.)?(www\....

`

Regex Issue

Thanks for the library, I think there is an issue with Regex which you may want to consider. Passing as a parametter could be a quick solution imo. This is a valid url in this case: 1h2t3t4p://www.sample.com
Cheers!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.