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-lgr

v1.0.2

Published

A CLI used to validate links of an .md file

Downloads

2

Readme

Markdown Links

Index


1. Project description

md-links-lg is a library and command-line tool (CLI) that allows you to analyze and read one or multiple markdown format files to search for and validate the status of the links they contain, as well as obtain some statistics such as the total number of unique or broken links found.

2. Installation

To install this library, enter the following command in your terminal:

npm i md-links-lgr

3. Functionality and Usage Guide

This project consists of two parts:

1) JavaScript API

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

mdLinks(path, options)

Arguments

  • path: Corresponds to the absolute or relative path to the file or directory.

  • options: It is an object with only the "validate" property, a boolean that determines whether to validate the found links (true or false).

Return value

The function returns a promise that resolves an array of objects, where each object represents a link and contains the following properties:

With validate: false :

  • href: Found URL.
  • text: The accompanying text (<a>).
  • file: Path of the file where the link was found.

With validate: true :

  • href: Found URL.
  • text: The accompanying text (<a>).
  • file: Path of the file where the link was found.
  • status: HTTP response code.
  • ok: "fail" message in case of failure or "ok" in case of success.

Example

const mdLinks = require("md-links");

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)

The application executable can be run through the terminal as follows:

md-links <path> [options]

  • path: corresponds to the path, either absolute or relative, of the file or directory you want to analyze. On the other hand, [options] provide flexibility to customize the output according to your needs.

Options

--validate or --v

If you choose to include this option, the program will make an HTTP request to verify the validity of each link, and you will receive a report with the link, the file where it is located, the accompanying text, and its status (fail or ok).

Example:

$ md-links ./some/example.md --validate
./some/example.md http://somepage.com/2/3/ Some text ok 200 
./some/example.md https://other-page.net/some-doc.html Other text fail 404 
./some/example.md http://google.com/ Google ok 301 

--stats or --s

By selecting this option, the result will display basic statistics about the links identified in the file, such as the total number of links and the count of unique or non-repeated links.

Example:

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

--stats --validate or --s --v

If you choose both options, the result will include the previously mentioned statistics about the found links, but it will also include the count of broken links.

Example:

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

4. Test

The unit tests for this project were built using Jest, which achieved 100% coverage in statements, functions, lines, and branches.

5. Fundamentals

JavaScript, Node.js, NPM.

6. Author

Leslie Angélica Garibay Raymundo, 2023.