Research
Recent Trends in Malicious Packages Targeting Discord
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
trim-characters
Advanced tools
Changelog
2.0.0 - Apr 30, 2021
JS
to TS
Readme
Trims text to a certain number of characters. You can define either to break-word to maintain the number of characters limit or characters limit may decrease to avoid breaking words.
Via npm
npm install trim-characters
Via Yarn
yarn add trim-characters
const trimCharacters = require('trim-characters');
import trimCharacters from 'trim-characters';
Node.js
const trimCharacters = require('trim-characters');
const text = '<h1>What is Geostatistics?</h1> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis tincidunt quam ut ligula ullamcorper interdum. Nulla malesuada purus tristique justo tristique, id posuere purus tristique. Pellentesque non magna ut libero elementum interdum vel vitae ante. Sed porta auctor urna eget venenatis. Mauris nec convallis metus. Sed at dui elit. Donec rhoncus justo neque, finibus commodo dui posuere ut. Maecenas in mi enim. Quisque maximus enim nunc.</p> <p>Donec eu ultricies ipsum. Fusce eget pellentesque urna. Vestibulum lacinia laoreet mi nec posuere. Duis vel elit elementum, scelerisque eros a, sodales eros. Praesent hendrerit neque velit, nec pretium ipsum finibus facilisis. Proin ultricies sem in sapien consectetur dictum.</p>';
const trimmedChar1 = trimCharacters(text, 70, false, '...');
const trimmedChar2 = trimCharacters(text, 70, true, '...');
console.log('Trim Characters without breaking words: ', trimmedChar1);
console.log('Trim Characters with breaking words: ', trimmedChar2);
React
import trimCharacters from 'trim-characters';
const text = '<h1>What is Geostatistics?</h1> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis tincidunt quam ut ligula ullamcorper interdum. Nulla malesuada purus tristique justo tristique, id posuere purus tristique. Pellentesque non magna ut libero elementum interdum vel vitae ante. Sed porta auctor urna eget venenatis. Mauris nec convallis metus. Sed at dui elit. Donec rhoncus justo neque, finibus commodo dui posuere ut. Maecenas in mi enim. Quisque maximus enim nunc.</p> <p>Donec eu ultricies ipsum. Fusce eget pellentesque urna. Vestibulum lacinia laoreet mi nec posuere. Duis vel elit elementum, scelerisque eros a, sodales eros. Praesent hendrerit neque velit, nec pretium ipsum finibus facilisis. Proin ultricies sem in sapien consectetur dictum.</p>';
const trimmedChar1 = trimCharacters(text, 70, false, '...');
const trimmedChar2 = trimCharacters(text, 70, true, '...');
console.log('Trim Characters without breaking words: ', trimmedChar1);
console.log('Trim Characters with breaking words: ', trimmedChar2);
Attributes | Type | Required | Default | Description |
---|---|---|---|---|
text | String | Yes | Text to trim. | |
charLength | Integer | No | 155 | Number of characters. |
breakWord | Boolean | No | true | Either to break words or not. If it is set to false then charLength may decrease to AVOID breaking words. |
more | String | No | … | What to append if the text needs to be trimmed. |
Trimmed text.
This package is tested with the Node.js
and React
Application.
FAQs
Trims text to a certain number of characters. You can define either to break-word to maintain the number of characters limit or characters limit may decrease to avoid breaking words.
We found that trim-characters 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.
Research
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
Security News
Socket CEO Feross Aboukhadijeh joins a16z partners to discuss how modern, sophisticated supply chain attacks require AI-driven defenses and explore the challenges and solutions in leveraging AI for threat detection early in the development life cycle.
Security News
NIST's new AI Risk Management Framework aims to enhance the security and reliability of generative AI systems and address the unique challenges of malicious AI exploits.