New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

trunc-text

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trunc-text - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

.travis.yml

24

index.js

@@ -5,4 +5,3 @@ 'use strict';

function truncText (text, cap) {
var i;
function truncText (input, cap) {
var limit = Number(cap);

@@ -12,17 +11,14 @@ if (isNaN((limit))) {

}
var result = text;
if (result.length > limit) {
result = result.substr(0, limit);
i = result.lastIndexOf(' ');
if (i === -1) { // assume that we'd otherwise slash a word
return delimiter;
}
// truncate the last word, which may have been slashed
result = result.substr(0, i);
result += ' ' + delimiter;
if (input.length <= limit) {
return input;
}
return result;
var result = input.substr(0, limit);
var i = result.lastIndexOf(' ');
if (i === -1) { // assume that we'd otherwise slash a word
return delimiter;
}
// truncate up to the last space
return result.substr(0, i) + ' ' + delimiter;
}
module.exports = truncText;
{
"name": "trunc-text",
"description": "truncate text by length, doesn't cut words",
"version": "1.0.0",
"version": "1.0.1",
"homepage": "https://github.com/bevacqua/trunc-text",

@@ -6,0 +6,0 @@ "author": {

# trunc-text
[![Build Status](https://travis-ci.org/bevacqua/trunc-text.svg?branch=master)](https://travis-ci.org/bevacqua/trunc-text)
> truncate text by length, doesn't cut words

@@ -4,0 +6,0 @@

@@ -22,2 +22,10 @@ var test = require('ava');

test(t => {
t.same(trunc('asd ', 3), '…');
});
test(`length is 4, returns as-is, 'asd …' would be a bug because cap is len 4`, t => {
t.same(trunc('asd ', 4), 'asd ');
});
test(t => {
t.same(trunc(sw, NaN), '…');

@@ -24,0 +32,0 @@ });

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