Skip to content

Insafe v0.2.0

Choose a tag to compare

@gbaudusseau gbaudusseau released this 13 Mar 20:21

not compatible with previous release (v0.1.0)

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

  • resolves to an empty Array if the URL is valid
  • resolves to a report Array if the URL is not valid
  • 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.length) {
  console.log('not valid url: ' +res);
  } 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.length) {
  console.log('not valid url: ' +res);
  } else {
  console.log('The URL is valid.'); 
  }
}).catch(console.log);