Java Script library for shortening links depending on the search phrase.
- Very easy to understand
- Configurable max length of link
- Only one dependency
- download from GitHub
- npm:
npm install links-shortener
makeURLShorter - main function for shortening link. Parameters:
- link
- searchValue
- maxLength
See examples below
The examples below showing how the link is shortening depending on where the search phrase (searchValue) is.
var linkShortener = require('links-shortener');
var link = "http://www.subdomain.domain.com/directory2018/home/test/cat3?param1¶m2¶m3#lastpartofverylongurl";
var maxLength = 40; // max lenght of link
var searchValue = 'com';
var shortenedLink = linkShortener.makeURLShorter(link, searchValue, maxLength);
console.log(shortenedLink);
//prints 'www.subdomain.domain.com/directory2018/home/test/cat3?param1¶m2¶m3#lastpartofverylongurl'
var searchValue = 'test';
var shortenedLink = linkShortener.makeURLShorter(link, searchValue, maxLength);
console.log(shortenedLink);
// prints '...domain.domain.com/...home/test/cat3?param1¶m2¶m3#lastpartofverylongurl'
var searchValue = 'param2';
var shortenedLink = linkShortener.makeURLShorter(link, searchValue, maxLength);
console.log(shortenedLink);
// prints '...domain.com/directory...?...ram1¶m2¶m#lastpartofverylongurl'
var searchValue = 'part';
var shortenedLink = linkShortener.makeURLShorter(link, searchValue, maxLength);
console.log(shortenedLink);
//prints '...ain.com/direct...?param1...#lastpartofverylongurl'