Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

truncate

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

truncate - npm Package Compare versions

Comparing version 2.1.0 to 3.0.0

.github/FUNDING.yml

2

package.json

@@ -7,3 +7,3 @@ {

"description": "Truncate text and keep urls safe",
"version": "2.1.0",
"version": "3.0.0",
"homepage": "https://github.com/FGRibreau/node-truncate",

@@ -10,0 +10,0 @@ "repository": {

Truncate
==================
[![CircleCI](https://img.shields.io/circleci/project/github/FGRibreau/node-truncate.svg)]() [![Downloads](http://img.shields.io/npm/dm/truncate.svg)](https://www.npmjs.com/package/truncate) [![available-for-advisory](https://img.shields.io/badge/available%20for%20consulting%20advisory-yes-ff69b4.svg?)](http://bit.ly/2c7uFJq) [![Twitter Follow](https://img.shields.io/twitter/follow/fgribreau.svg?style=flat)](https://twitter.com/FGRibreau) [![Get help on Codementor](https://cdn.codementor.io/badges/get_help_github.svg)](https://www.codementor.io/francois-guillaume-ribreau?utm_source=github&utm_medium=button&utm_term=francois-guillaume-ribreau&utm_campaign=github)
[![CircleCI](https://img.shields.io/circleci/project/github/FGRibreau/node-truncate.svg)]() [![Downloads](http://img.shields.io/npm/dm/truncate.svg)](https://www.npmjs.com/package/truncate) [![available-for-advisory](https://img.shields.io/badge/available%20for%20consulting%20advisory-yes-ff69b4.svg?)](http://bit.ly/2c7uFJq) [![Twitter Follow](https://img.shields.io/twitter/follow/fgribreau.svg?style=flat)](https://twitter.com/FGRibreau) [![Get help on Codementor](https://cdn.codementor.io/badges/get_help_github.svg)](https://www.codementor.io/francois-guillaume-ribreau?utm_source=github&utm_medium=button&utm_term=francois-guillaume-ribreau&utm_campaign=github) [![Slack](https://img.shields.io/badge/Slack-Join%20our%20tech%20community-17202A?logo=slack)](https://join.slack.com/t/fgribreau/shared_invite/zt-edpjwt2t-Zh39mDUMNQ0QOr9qOj~jrg)

@@ -6,0 +6,0 @@ Truncate text and keeps urls safe.

@@ -77,2 +77,33 @@ var truncate = require('./truncate');

exports['should cut off huge URLs for safety'] = function (t) {
var input, expect, actual, longString;
longString = "a".repeat(301);
input = 'Hey mailto:' + longString + '@' + longString + '.com';
actual = truncate(input, 5);
expect = 'Hey m…';
t.strictEqual(expect, actual);
// Just above the limit, should get chopped
longString = "a".repeat(3000 - 'https://'.length + 1);
input = 'Hey https://' + longString;
actual = truncate(input, 5);
expect = 'Hey h…';
t.strictEqual(expect, actual);
// Right at the limit, should be retained
longString = "a".repeat(3000 - 'https://'.length);
input = 'Hey https://' + longString;
actual = truncate(input, 5);
expect = input;
t.strictEqual(expect, actual);
// Still retain the long URL even if there's text after the long URL
input = 'Hey https://' + longString + " other text";
actual = truncate(input, 5);
expect = expect + '…'
t.strictEqual(expect, actual);
t.done();
}
exports['Not vulnerable to REDOS'] = function (t) {

@@ -79,0 +110,0 @@

@@ -49,4 +49,4 @@ /*global module:true*/

matches = URL_REGEX.exec(string);
if (!matches || (matches.index - content.length) >= remainingLength) {
// Don't try to retain URLs longer than 3k chars, well over the 99th percentile of ~347
if (!matches || (matches.index - content.length) >= remainingLength || URL_REGEX.lastIndex >= (maxLength + 3000)) {
content += string.substring(content.length, maxLength);

@@ -53,0 +53,0 @@ return __appendEllipsis(string, options, content, maxLength);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc