Giter Club home page Giter Club logo

is-absolute-url's Introduction

is-absolute-url

Check if a URL is absolute

Install

$ npm install is-absolute-url

Usage

import isAbsoluteUrl from 'is-absolute-url';

isAbsoluteUrl('https://sindresorhus.com/foo/bar');
//=> true

isAbsoluteUrl('//sindresorhus.com');
//=> false

isAbsoluteUrl('foo/bar');
//=> false

Related

See is-relative-url for the inverse.


Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.

is-absolute-url's People

Contributors

alexbrasetvik avatar andybelltree avatar bendingbender avatar kevva avatar kyleamathews avatar morellodev avatar richienb avatar sindresorhus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

is-absolute-url's Issues

Compatibility problem with IE11

It seems that there is a compatibility issue when moving the library from 2.1 to 3.0 with IE 11

It seems like that IE11 does not support the Arrow function used within this new version

Move the regex declaration outside the function

Hi @sindresorhus, this might be a very little performance improvement, but it makes the code even clearer. Instead of inlining the regex for testing absolute urls inside the body of the function, it would be better to extract it outside and then referencing it:

const ABSOLUTE_URL_REGEX = /^[a-zA-Z][a-zA-Z\d+\-.]*?:/;

export default function isAbsoluteUrl(url) {
  ...
  return ABSOLUTE_URL_REGEX.test(url);
}

Only allow HTTP URLs by default

isAbsoluteUrl('javascript:throw%20document.cookie') // true

Although this might be technically correct (?), it seems like it's not what most people would think of as an absolute URL, and it could lead to a false sense of security that the input has been validated as a 'real' URL.

Possible solutions:

  • Release a new major version that ensures the protocol is http or https
    • Maybe with an option like { allowNonHttp: true } for people who want the old behaviour.
  • Or just add a warning in the readme that this will return true for any protocol, even javascript:.

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.