Skip to content

gajus/deadlink

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Travis build status NPM version

Find dead URLs and fragment identifiers (URLs with a hash and a corresponding ID element in the resulting document).

Deadlink is using a combination of header inspection, data inspection (2015-08-06: mmmagic has been temporary removed until issues with iojs 3.0.0 are resolved) and content length inspection to determine if the content exists, when to listen for the response, and when to bail out.

Deadlink is using jsdom to load the document and execute it. Therefore, resolving fragment identifiers will work even if the element IDs of the resulting document are generated dynamically after DOMContentLoaded event.

Contents

Usage

This guide explains the most common use case, without going into details about the properties of the intermediate results. Some of these properties are useful for further analyzes, such as knowing when to load the document to extract the IDs for fragment identification.

Refer to the test cases for the detail explanation of Deadlink behavior.

var Deadlink = require('deadlink'),
    deadlink = Deadlink();

Resolving URLs and Fragment Identifiers

This is a convenience wrapper to resolve a collection of URLs, including the fragment identifier when it is part of the URL. URL/Fragment Identifier is resolved with a promise that in turn resolves to Deadlink.Resolution.

var promises = deadlink.resolve([
    'http://gajus.com/foo',
    'http://gajus.com/bar',
    'http://gajus.com/#foo',
    'http://gajus.com/#bar'
]);

Use Promise.all to construct a promise that resolves when all of the promises in the collection are resolved. Deadlink.Resolution of a successful resolution does not have an error property.

Promise.all(promises).then(function () {
    promises.forEach(function (Resolution) {
        if (!Resolution.error) {
            // OK
        }
    });
});

Resolving URLs

The same as deadlink.resolve() but limited to URL resolution.

deadlink.resolveURLs([
    'http://gajus.com/foo',
    'http://gajus.com/bar'
]);

Special Case

There is one special case when promise for a valid response can be rejected.

It is rejected if Content-Type is text/html and content length is larger than 5MB. Deadlink is storing the response of text/html in case resolveFragmentIdentifierURL will be referring to the said URL in future. If you foresee this as an issue, raise an issue stating your use case.

Resolving Fragment Identifiers

The same as deadlink.resolve() but limited to Fragment Identifier resolution.

deadlink.resolveFragmentIdentifierURLs([
    'http://gajus.com/#foo',
    'http://gajus.com/#bar'
]);

The resolution object reflects the type of the resource:

Deadlink.URLResolution
Deadlink.FragmentIdentifierDocumentResolution
Deadlink.FragmentIdentifierURLResolution

All of these objects extend from Deadlink.Resolution.

The test cases explain what properties and when do each of these objects have.

Matching URLs

deadlink.matchURLs(inputString) collects all URLs from a string. This function is a wrapper around URL RegExp match().

Download

Download using NPM:

npm install deadlink

About

Find dead URLs and fragment identifiers.

Resources

License

Stars

Watchers

Forks

Packages

No packages published