
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
friendly-truncate
Advanced tools
Human-friendly truncation preferring word boundaries and the middle of the string.
Truncate strings in the middle, at a word boundary if possible, so that the string is at most the specified length.
Supports strings with unicode characters, including surrogate pairs, and supports customisable joining character and word boundaries.
var truncate = require('friendly-truncate');
for(var i = 0; i < 46; i++){
console.log(truncate.truncateMiddle('the quick brown fox jumps over the lazy dog', i));
}
// output:
//
// …
// t…
// t…g
// th…g
// th…og
// the…og
// the…dog
// the…dog
// the … dog
// the q… dog
// the q…y dog
// the qu…y dog
// the quick…dog
// the quick…dog
// the quick…dog
// the quick…dog
// the quic…lazy dog
// the quick…lazy dog
// the quick…lazy dog
// the quick…lazy dog
// the quick brown…dog
// the quick…the lazy dog
// the quick…the lazy dog
// the quick brown…lazy dog
// the quick brown…lazy dog
// the quick brown…lazy dog
// the quick…over the lazy dog
// the quick brown fox…lazy dog
// the quick brown…the lazy dog
// the quick brown…the lazy dog
// the quick brown…the lazy dog
// the quick brown fox…the lazy dog
// the quick brown…over the lazy dog
// the quick brown fox jumps…lazy dog
// the quick brown fox jumps…lazy dog
// the quick brown fox jumps…lazy dog
// the quick brown fox…over the lazy dog
// the quick brown fox jumps…the lazy dog
// the quick brown…jumps over the lazy dog
// the quick brown…jumps over the lazy dog
// the quick brown…jumps over the lazy dog
// the quick brown…jumps over the lazy dog
// the quick brown fox jumps over the lazy dog
// the quick brown fox jumps over the lazy dog
// the quick brown fox jumps over the lazy dog
truncate.truncateMiddle(string, length, options)Supported options:
/[\s.\-_,;:]/gThe length is interpreted in code units, as is normal for javascript strings. (i.e. an emoji or other character consisting of a surrogate pair is considered length two.)
truncate.truncateEnd(string, length, options)Supported options:
/[\s.\-_,;:]/gThe length is interpreted in code units, as is normal for javascript strings. (i.e. an emoji or other character consisting of a surrogate pair is considered length two.)
truncate.truncateMiddle('Lorem ipsum dolor sit amet', 10, {join:'-', tolerance:5})
// 'Lorem-amet'
truncate.truncateMiddle('/a/very/long/path/with/lots/of/parts', 20, {tolerance:8, boundary:/\//g})
// '/a/very/long…parts'
FAQs
Human-friendly truncation preferring word boundaries and the middle of the string.
The npm package friendly-truncate receives a total of 1,856 weekly downloads. As such, friendly-truncate popularity was classified as popular.
We found that friendly-truncate demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.