npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

deadlink

v1.1.3

Published

Find dead URLs and fragment identifiers.

Downloads

9,654

Readme

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.

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