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

@milates12/md-links

v1.1.2

Published

This is a library that allows you to find links in files with extension .md

Downloads

14

Readme

Markdown Links

Index


1. Preamble

Markdown is a very popular lightweight markup language among developers. It is used in many platforms that handle plain text (GitHub, forums, blogs, ...), and it is very common to find several files in this format in any type of repository (starting with the traditional README.md).

These Markdown files usually contain links that are often broken or no longer valid, and this greatly impairs the value of the information to be shared.

Within an open source community, we have been proposed to create a tool using Node.js, which reads and analyzes files in Markdown format, to verify the links they contain and report some stats.

2. Flowchart

Flowchart

3. Installation

CLI: npm i @milates12/md-links

4. Usage

JavaScript API

The module must be imported into the Node.js scripts as follows:

mdLinks(path, options)

const { mdLinks } = require('@milates12/md-links');
mdLinks('./Music', { validate: false });
Arguments
  • path: Absolute or relative path to the file or directory.
  • options: An object with the following properties:
    • validate: Boolean that determines if you want to validate the links found.
    • stats: Boolean that determines if you want to know the total and unique links.
Return value

With validate: false :

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

With validate: true :

  • href: URL found.
  • text: Text that appeared inside the link (<a>).
  • file: Path of the file where the link was found.
  • status: HTTP response code.
  • ok: Message fail on failure or ok on success.

With stats: true :

  • total: Links found in directory or file.
  • unique: Unique links in the file or directory.

With validate:true, stats: true:

  • total: Numbers of links found in directory or file.
  • unique: Number of unique links in the file or directory.
  • broken: Number of broken links in the file or directory.
Example (results as comments)
const mdLinks = require("md-links");

mdLinks("./some/example.md")
    // => [{ href, text, file }, ...]

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

mdLinks("./some/dir")
    // => [{ href, text, file }, { href2, text2, file2 } ...]

mdLinks("./some/example.md", { stats: true })
    // => [{ total, unique }, ...]

mdLinks("./some/example.md", { validate: true, stats: true })
    // => [{ total, unique, broken }, ...]

CLI:

The executable of our application is executed as follows through the terminal:

md-links <path-to-file> [options]

Example result without options:

$ md-links ./some/example.md
[
  {./some/example.md http://something.com/2/3/ link to something},  
  {./some/example.md https://another-thing/algun-doc.html some doc}, 
  {./some/example.md http://google.com/ Google}
]

Example result with option --validate:

[
  {./some/example.md http://something.com/2/3/ link to something 200 'OK'},  
  {./some/example.md https://another-thing/algun-doc.html some doc 404 'FAIL'}, 
  {./some/example.md http://google.com/ Google 200 'OK'}
]

Example result with option --stats:

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

Example result with option --stats --validate:

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

5. Author

Camila Cortés. (MIT License)