JSPM

posthtml-shorten

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 13
  • Score
    100M100P100Q47023F
  • License ISC

A PostHTML plugin to shorten URLs in HTML elements

Package Exports

  • posthtml-shorten

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (posthtml-shorten) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

posthtml-shorten

Build Status Coverage Status

A PostHTML plugin to shorten URLs in HTML elements.

Usage

var posthtml = require('posthtml');
var shorten = require('posthtml-shorten');

var shortener = {
  shorten: function(url, callback) {
    callback(null, url.replace('goog', 'gog'));
  }
};

var options = {
  shortener: shortener, // Must contain a `shorten` function
  tag: ['a', 'img', 'body'] // Allowed tags for URL shortening
  attribute: ['href', 'src'], // Attributes to replace on the elements
};

posthtml()
  .use(shorten(options))
  .process('<a href="google.com">Google</a>')
  .then(function(result) {
    console.log(result.html); //=> '<a href="gogle.com">Google</a>'
  });