shorten-url
omit parts of a url for friendlier display
Last updated 3 years ago by goto-bus-stop .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install shorten-url 
SYNC missed versions from official npm registry.

shorten-url

omit parts of a url for friendlier display

npm travis standard

It's like @sindresorhus's truncate-url, but without requiring the url and querystring modules in the browser. It's also similar to @williambelle's crop-url, which is very lightweight, but it cuts off the http:// or https:// scheme and I want to keep it.

This one cuts away pieces from the URL's path and query string until it fits:

t.equal(shorten('https://www.vpro.nl/programmas/gliphoeve/documentaire-intro.html', 50),
  'https://www.vpro.nl/…/documentaire-intro.html')
t.equal(shorten('http://www.salvomag.com/unpragmatic-thoughts/?p=1738', 50),
  'http://www.salvomag.com/unpragmatic-thoughts/?…')
t.equal(shorten('https://www.reddit.com/?count=25&after=t3_76zjp1', 40),
  'https://www.reddit.com/?count=25&…')
t.equal(shorten('https://discordapp.com/channels/317475976369930241/317475976369930241', 25),
  'https://discordapp.com/…')
t.equal(shorten('http://example.com/ultra/cool/page/that-is-really-deeply/nested/', 30),
  'http://example.com/…/nested/')

Install

npm install shorten-url

Usage

var shortenUrl = require('shorten-url')

shortenUrl('https://whatever.com/a/long/path/and?also=a&long=query&string', 30)

API

shortenUrl(url, maxLength)

url is the input URL. maxLength is the maximum length of the URL.

License

Apache-2.0

Current Tags

  • 1.0.0                                ...           latest (3 years ago)

1 Versions

  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 1
This Week 1
This Month 2
Last Day 0
Last Week 1
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)

Copyright 2014 - 2017 © taobao.org |