deadlink
v1.1.3
Published
Find dead URLs and fragment identifiers.
Downloads
9,654
Readme
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.
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();
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
}
});
});
The same as deadlink.resolve()
but limited to URL resolution.
deadlink.resolveURLs([
'http://gajus.com/foo',
'http://gajus.com/bar'
]);
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.
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.
deadlink.matchURLs(inputString)
collects all URLs from a string. This function is a wrapper around URL RegExp match()
.
Download using NPM:
npm install deadlink