Have ideas to improve npm?Join in the discussion! »

    crop-url

    4.0.0 • Public • Published

    crop-url

    Build Status Coverage Status Dependencies Status NPM version

    Truncate a url so that it doesn't appear so long visually.

    Install

    npm i crop-url

    Usage

    const cropUrl = require('crop-url');
    
    let url = cropUrl('http://www.foobar.com/abc/def/ghi/index.html', 26);
    console.log(url) //=> 'foobar.com/…/index.html'
    
    url = cropUrl('https://www.foobar.com/abc/def/ghi/jkl/', 26);
    console.log(url) //=> 'foobar.com/abc/def/…/jkl/'
    
    url = cropUrl('http://www.foobar.com/abc/def/ghi/jkl/', 1);
    console.log(url) //=> 'foobar.com/…/jkl/'
    
    url = cropUrl('http://www.foobar.com/search/?q=foo&page=bar', 35);
    console.log(url) //=> 'foobar.com/search/?q=foo&page=bar'
    
    url = cropUrl('http://www.foobar.com/search/?q=foo&page=bar', 20);
    console.log(url) //=> 'foobar.com/…/?q=foo…'
    
    url = cropUrl('http://www.foobar.com/search/?q=foo&page=bar', 12);
    console.log(url) //=> 'foobar.com/…/?…'
    
    url = cropUrl('http://www.foobar.com/foo-bar-foo-bar.html', 12);
    console.log(url) //=> 'foobar.com/foo…'

    Contributing

    Contributions are always welcome.

    See Contributing.

    Developer

    License

    The MIT License (MIT)

    Install

    npm i crop-url

    DownloadsWeekly Downloads

    80

    Version

    4.0.0

    License

    MIT

    Unpacked Size

    6.44 kB

    Total Files

    5

    Last publish

    Collaborators

    • avatar