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

jg-mdlinks

v1.0.0

Published

- [Markdown Links](#markdown-links) - [Índice](#índice) - [1. Preámbulo](#1-preámbulo) - [2. Instalación](#2-instalación) - [3. Descripción del proyecto](#3-descripción-del-proyecto) - [Descripción de JavaScriptAPI](#descripción-de-javasc

Downloads

6

Readme

Markdown Links

Índice


1. Preámbulo

Markdown es un lenguaje de marcado ligero my utilizado para presentar la descripción de algún proyecto. Comumente se presentan como README.md y normalmente contienen links (vínculos/ligas) que muchas veces están rotos o ya no son válidos y eso perjudica mucho el valor de la información que se quiere compartir.

A partir de ello se ha propuesto la creación una herramienta usando Node.js, que lea y analice archivos en formato Markdown, para verificar los links que contengan y reportar cuantos links posee, cuantos son únicos y cuantos están rotos.

2. Instalación

Para instalar el módulo lo realizaremos mediante npm, para ello utilizaremos el siguiente comando: npm i jg-mdlinks -g.

3. Descripción del proyecto

Para poder usar el módulo es necesario importarlo usando require('jg-mdlinks')

Descripción de JavaScriptAPI

El JavaScriptAPI es una función que retorna una promesa mdLinks(path, options) que recibe dos parámetros: en primer lugar recibe un path(ruta absoluta o relativa) y options({validate: true} o {validate: false}) el cual retorna un array de objetos por cada link. Dependiendo de si validate fuera true o false.

Con validate:false :

  • href: URL encontrada.
  • text: Texto que aparecía dentro del link (<a>).
  • file: Ruta del archivo donde se encontró el link.

Con validate:true :

  • href: URL encontrada.
  • text: Texto que aparecía dentro del link (<a>).
  • file: Ruta del archivo donde se encontró el link.
  • status: Código de respuesta HTTP.
  • ok: Mensaje fail en caso de fallo u ok en caso de éxito.

Ejemplo (resultados como comentarios)

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);

CLI (Command Line Interface - Interfaz de Línea de Comando)

El ejecutable de nuestra aplicación debe poder ejecutarse de la siguiente manera a través de la terminal: md-links <path-to-file> [options]

Como se observa el comando tiene dos argumentos <path-to-file> y [options]. El comportamiento por defecto, es decir colocando solo <path-to-file> nos permite identificar el archivo markdown (a partir de la ruta que recibe como argumento), analiza el archivo Markdown e imprime los links que vaya encontrando, junto con la ruta del archivo donde aparece y el texto que hay dentro del link.

Por ejemplo:

$ md-links ./some/example.md

md-links

Options

--validate

Si pasamos la opción --validate, el módulo realiza una petición HTTP para averiguar si el link funciona o no y nos devuelve el status y un mensaje que puede ser ok o fail

$ md-links ./some/example.md --validate

validate

--stats

Si pasamos la opción --stats el output (salida) será un texto con estadísticas básicas sobre los links.

$ md-links ./some/example.md --stats

validate

--validate --stats

También podemos combinar --validate y --stats para obtener estadísticas que necesiten de los resultados de la validación.

$ md-links ./some/example.md --stats --validate

validate

4. Diagrama de flujo

JavaScript API

API

CLI (Command Line Interface)

API