Git Product home page Git Product logo

check-anything's Introduction

Check Anything ๐Ÿ‘

Total Downloads Latest Stable Version

npm i check-anything

Check anything from URLs to Email addresses.

Usage

import { isUrl, isHttpsUrl, isEmail } from 'check-anything'

isHttpsUrl('https://github.com') // true

isUrl('ftp://foo.bar/baz') // true

isEmail('[email protected]') // true

Https vs Http vs FTP vs other URLs

You usually want to use isHttpsUrl instead of isUrl. It will limit the URLs to just regular https:// urls and also has the smallest footprint.

isHttpsUrl

isHttpsUrl is opiniated, it will return false for the following list to keep the source code small and simple.

  • http URLs
  • ftp URLs
  • IP URLs (existing of only numbers)
  • password URLs
  • mailto URLs
import { isHttpsUrl } from 'check-anything'

// returns true:
isHttpsUrl('https://github.com')
isHttpsUrl('https://ใ‚ฎใƒƒใƒˆใƒใƒ–.com') // special characters in domain
isHttpsUrl('https://github.com/ใ‚ฎใƒƒใƒˆใƒใƒ–') // special characters in URI

// returns false:
isHttpsUrl('http://github.com') // http
isHttpsUrl('ftp://foo.bar/baz') // ftp
isHttpsUrl('https://142.42.1.1/') // ip
isHttpsUrl('https://userid:[email protected]') // password
isHttpsUrl('mailto:[email protected]') // mailto URLs

isUrl

isUrl on the other hand will return true for all of these, except for the mailto: URL.

import { isUrl } from 'check-anything'

// returns true:
isUrl('https://github.com')
isUrl('https://ใ‚ฎใƒƒใƒˆใƒใƒ–.com') // special characters in domain
isUrl('https://github.com/ใ‚ฎใƒƒใƒˆใƒใƒ–') // special characters in URI
isUrl('http://github.com') // http
isUrl('ftp://foo.bar/baz') // ftp
isUrl('https://142.42.1.1/') // ip
isUrl('https://userid:[email protected]') // password

// returns false:
isUrl('mailto:[email protected]') // mailto URLs

TODO

Let me know if you are interested in any of these functions, I will consider adding them:

  • isProbableUrl โ€” to allow URLs like 'github.com' without protocol (has chance of failure though)
  • isFtpUrl
  • isPasswordUrl
  • isIpUrl
  • isMailtoUrl

Meet the family (more tiny utils with TS support)

check-anything's People

Contributors

mesqueeb avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

check-anything's Issues

Could this be rolled into is-what?

This seems to have a title that is basically interchangeable with https://github.com/mesqueeb/is-what. That makes me think that these two packages fulfill similar purposes. is-what โ†” check-anything.

Could the two projects be merged? There's already some string testing functions in is-what, so I think these few functions would mesh well!

isUrl()
isHttpsUrl()

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.