Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/goto-bus-stop/shorten-url
omit parts of a url for friendlier display, in ~450 gzipped bytes
https://github.com/goto-bus-stop/shorten-url
url
Last synced: 27 days ago
JSON representation
omit parts of a url for friendlier display, in ~450 gzipped bytes
- Host: GitHub
- URL: https://github.com/goto-bus-stop/shorten-url
- Owner: goto-bus-stop
- License: other
- Created: 2017-10-18T19:51:21.000Z (about 7 years ago)
- Default Branch: default
- Last Pushed: 2024-07-21T13:18:21.000Z (4 months ago)
- Last Synced: 2024-10-05T16:26:21.489Z (about 1 month ago)
- Topics: url
- Language: JavaScript
- Homepage: https://npmjs.com/package/shorten-url
- Size: 15.6 KB
- Stars: 10
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# shorten-url
omit parts of a url for friendlier display
[![npm][npm-image]][npm-url]
[![travis][travis-image]][travis-url]
[![standard][standard-image]][standard-url]It's like [@sindresorhus](https://github.com/sindresorhus)'s [truncate-url](https://github.com/sindresorhus/truncate-url),
but without requiring the url and querystring modules in the browser. It's also
similar to [@williambelle](https://github.com/williambelle)'s [crop-url](https://github.com/williambelle/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:
```js
t.equal(shorten('https://www.vpro.nl/programmas/gliphoeve/documentaire-intro.html', 50),
'https://www.vpro.nl/…/documentaire-intro.html')
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/')
```[npm-image]: https://img.shields.io/npm/v/shorten-url.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/shorten-url
[travis-image]: https://img.shields.io/travis/goto-bus-stop/shorten-url.svg?style=flat-square
[travis-url]: https://travis-ci.org/goto-bus-stop/shorten-url
[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square
[standard-url]: http://npm.im/standard## Install
```
npm install shorten-url
```## Usage
```js
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](LICENSE.md)