https://github.com/perry-mitchell/join-and-shorten
Join and shorten strings with priorities
https://github.com/perry-mitchell/join-and-shorten
concat concatenation join shorten-strings shortener
Last synced: 12 months ago
JSON representation
Join and shorten strings with priorities
- Host: GitHub
- URL: https://github.com/perry-mitchell/join-and-shorten
- Owner: perry-mitchell
- License: mit
- Created: 2017-10-17T12:44:14.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-08T15:40:03.000Z (over 8 years ago)
- Last Synced: 2025-05-27T07:17:56.033Z (about 1 year ago)
- Topics: concat, concatenation, join, shorten-strings, shortener
- Language: JavaScript
- Size: 41 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# join-and-shorten
Join and shorten strings with priorities
[](https://www.npmjs.com/package/join-and-shorten) [](https://travis-ci.org/perry-mitchell/join-and-shorten)
## About
This package was designed to shorten concatenated strings for use as IDs. It allows the specification of priorities for determining which items to remove from the string when shortening to fit a desired maximum length.
## Installation
Simply install it as a dependency using npm:
```shell
npm install join-and-shorten --save
```
## Usage
Usage is quite simple - to simply join items, you could use the following:
```javascript
const join = require("join-and-shorten");
join(["one", "two", "three"]); // "one_two_three"
```
_Notice that underscores are the default joiner of strings._
You can also customise the joining character and maximum length:
```javascript
join(["one", "two", "three"], "~", 9); // "one~two"
```
Or you can give priorities to the function so that it knows which items to strip:
```javascript
join([
["one", 2],
["two", 1],
["three", 3]
], "_", 11); // "one_three"
```
`join` also supports a strip-mode parameter, to allow for shortening by **character** instead of by **item**:
```javascript
join([
["abcdef", 2],
["123456", 3]
], ":", 10, STRIP_MODE_REMOVE_CHARACTER); // "abc:123456"
```
## Tests
Run the tests by executing `npm test`.