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

md-links-alim

v1.4.0

Published

Command Line Tool to extract and validate links from markdown files

Downloads

3

Readme

Markdown Links

Description

This is a project designed to locate and extract the links from markdown files given a path using Node.js. It can also verify the status of every link by making a fetch HTTP request.
The project facilitates an API and a CLI tool.

How to install

It can be installed by running the following in the terminal
npm install md-links-alim

How to use

This projects consists of two parts:

1. JavaScript API

The module can be imported into other Node.js scripts and offers the following interface:

mdLinks(path, options)

Arguments

  • path : Absolute or relative path to a file or directory.
  • options : An object with only the following property:
    • validate : A boolean to determinate if the links found will be validated or not.

Return value

This function will return a promise resolving to an array of objects, where each object represents a link and has the following properties

With validate:false :

  • href : URL found.
  • text : Text within the link (<a>).
  • file : Path of the file where the link was found.

With validate:true :

  • href : URL found.
  • text : Text within the link (<a>).
  • file : Path of the file where the link was found.
  • status : Code of the HTTP response.
  • ok : Message indicating the status of the link.

Example (with results as comments)

import { mdLinks } from "md-links-alim";

mdLinks("./some/example.md")
  .then((links) => {
    // => [{ href, text, file }, ...]
  })
  .catch(console.error);

mdLinks("./some/example.md", { validate: true })
  .then((links) => {
    // => [{ href, text, file, status, ok }, ...]
  })
  .catch(console.error);

mdLinks("./some/dir")
  .then((links) => {
    // => [{ href, text, file }, ...]
  })
  .catch(console.error);

2. CLI (Command Line Interface)

This app can be executed from the terminal as the following: md-links <path-to-file> [options]

For example:

$ md-links-alim ./some/example.md
------------------------------
URL: http://something.com/2/3/
Text: Link to something
File: ./some/example.md
------------------------------
URL: https://something-else.net/algun-doc.html
Text: some doc
File: ./some/example.md
------------------------------
URL: http://google.com/
Text: Google
File: ./some/example.md

If the text of the link is longer than 50 characters, it will be cut short and add ....

Options

--validate

When using the option --validate, the module must make a HTTP request to find if the link works or not. If the link redirects to an URL that works it will be considered as ok.

For example:

$ md-links ./some/example.md --validate
------------------------------
URL: http://something.com/2/3/
Text: Link to something
File: ./some/example.md
Status: OK
Status Code: 200
------------------------------
URL: https://something-else.net/algun-doc.html
Text: some doc
File: ./some/example.md
Status: Not Found
Status Code: 404
------------------------------
URL: http://google.com/
Text: Google
File: ./some/example.md
Status: OK
Status Code: 200
--stats

When using the option --stats, the output will indicate the total of links found and how many are unique.

$ md-links ./some/example.md --stats
Total: 3
Unique: 3

The options --validate and stats can also be combined to obtain stats that require the HTTP validation.

$ md-links ./some/example.md --stats --validate
Total: 3
Unique: 3
Broken: 1

Flowchart

For the JS API:
Flowchart for the API

For the CLI:
Flowchart for the CLI

Author

Hi! My name is Ana Ibarra.
You can find me on LinkedIn