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

alicruz-mdlinks

v1.0.2

Published

Validate unbroken links from a markdown file and report some statistics

Downloads

5

Readme

alicruz-mdlinks

Contributor Covenant

alicruz-mdlinks is a module and command-line interface that verifies the links that a markdown file contains, validates that they are unbroken, and reports some statistics. Github repository AlissonCH

Installation

It is recommendable global install, to use both: API and command-line interface correctly.

npm module

alicruz-mdlinks

$ npm install --global alicruz-mdlinks

API

Parameters:

  • path absolute or relative path with a markdown file. Or directory with markdown files. It should be a string.
  • options is an object, the default value is false.

Returns:

  • An array containing objects for each link found. Each Link containing the following properties: 'href': (url), 'text' : (text associated to the link), 'file' : (path where the links were found).
  • when options = { validate : true }. Each Link containing the following properties : 'href', 'text', 'file', 'status', 'statusText'.
  • when options = { stats : true } returns an object with the following properties : 'Total': (the total links found), 'Unique': (unique links).
  • when options = { stats : true, validate : true } returns an object with the following properties : 'Total': (Total links found), 'Unique': (Unique links ), 'Broken: (Broken links found).

Examples

const mdLinks = require('alicruz-mdlinks'); // if install is local
const mdLinks = require('../alicruz-mdlinks'); // if install is global

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

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

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

mdLinks('./some/dir', {validate : true}).then(arrayOfLinks => {
 // => [{ href, text, file, status, statusText}, ...]
})
.catch( err => console.error(err))

mdLinks('./some/example.md', {stats : true }).then(arrayOfLinks => {
 // => {Total, Unique}
})
.catch( err => console.error(err))

mdLinks('./some/example.md', {stats : true, validate:true }).then(arrayOfLinks => {
 // => {Total, Unique, Broken}
})
.catch( err => console.error(err))

RESPONSE

Examples

mdLinks('./some/example.md').then( links => console.log(links))

// Console
[
 { href : 'http://somelink.com', 
   text : 'Some Link', 
   file: './some/example.md'
 },
 { href : 'http://otherthing.com', 
   text : 'Other Thing', 
   file: './some/example.md'
 },
 { href : 'http://google.com ', 
   text : 'Google', 
   file: './some/example.md'
 }
]

mdLinks('./some/example.md', {validate : true}).then( links => console.log(links))

// Console
[
 { href : 'http://somelink.com', 
   text : 'Some Link', 
   file: './some/example.md'
   status: 200,
   statusText : 'OK'
 },
 { href : 'http://otherthing.com', 
   text : 'Other Thing', 
   file: './some/example.md',
   status: 400,
   statusText : 'FAIL'
 },
 { href : 'http://google.com ', 
   text : 'Google', 
   file: './some/example.md',
   status: 200,
   statusText : 'OK'
 }
]

mdLinks('./some/example.md', {stats : true}).then( result => console.log(result))

// Console
 { 
  Total: 3, 
  Unique: 3
 }  

mdLinks('./some/example.md', {stats : true, vaidate: true}).then( result => console.log(result))

// Console
 { 
  Total: 3, 
  Unique: 3,
  Broken: 1
 } 

COMMAND LINE INTERFACE - CLI

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

Parameters:

  • path absolute or relative path with a markdown file. Or directory with markdown files. It is recommended that the path be a string to avoid path recognition problems in different execution environments.
  • options is an object, the default value is false. Could be --validate, --stats, or both.

Examples

$ md-links './some/example.md'
./some/example.md http://somelink.com Some Link
./some/example.md http://otherthing.com Other Thing
./some/example.md http://google.com Google
./some/example.md http://google.com Google

$ md-links './some/example.md' --validate 
./some/example.md http://somelink.com OK 200 Some Link 
./some/example.md http://otherthing.com FAIL 400 Other Thing
./some/example.md http://google.com OK 200 Google
./some/example.md http://google.com OK 200 Google

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

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

Contributing

Pull requests are welcome. For major changes, please open an issues first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT