GithubHelp home page GithubHelp logo

isabella232 / insafe Goto Github PK

View Code? Open in Web Editor NEW

This project forked from w3c/insafe

0.0 0.0 0.0 108 KB

Insafe is a Node.js package which resolves and checks that an URL is well-formed.

License: MIT License

JavaScript 100.00%

insafe's Introduction

npm version License Build Status Coverage Status Dependency Status devDependency Status

Insafe logo

Insafe is a Node.js package which resolves and checks that an URL is well-formed.

Features

  • URL resolution: w3.org -> http://w3.org
  • DNS check
  • HTTP/HTTPS check (customizable)
  • Host blacklist
  • Host whitelist

Installation

npm install insafe

Usage

Insafe is a JavaScript Promise-based API.

It exposes a check(options) function that returns a Promise. This Promise will resolve to an object containing:

  • resolved url String
  • status (true if well formed, else false) Boolean
  • error report Array

or rejects with the unexpected errors the checker encountered when checking the URL

Example:

var insafe = require('insafe');

insafe.check({
	url: 'example.com'
}).then(function (res) {
  if(res.status == false) {
  console.log('not valid url: ' +res.url);
  } else {
  console.log('The URL is valid.');
  }
}).catch(console.log);

Several options are available to check the URL:

  • url (required): a String.
  • statusCodesAccepted: an Array of accepted HTTP(S) status codes. See the default config.
  • statusCodesRefused: an Array of refused HTTP(S) status codes. See the default config.
  • blacklist: an Array of blacklisted hosts.
  • whitelist: an Array of whitelisted hosts.

Example:

var insafe = require('insafe');

insafe.check({
    url: 'http://www.w3.org/',
    statusCodesAccepted: ["404"],
    statusCodesRefused: ["301", "203"],
    blacklist: ['h4ck3rz.org'],
    whitelist: ['www.w3.org', 'example.com']
}).then(function (res) {
  if(res.status == false) {
  console.log('not valid url: ' +res.url);
  } else {
  console.log('The URL is valid.');
  }
}).catch(console.log);

insafe's People

Contributors

astorije avatar dontcallmedom avatar gbaudusseau avatar guibbs avatar qwertychouskie avatar tripu avatar vivienlacourba avatar

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.