Socket
Socket
Sign inDemoInstall

ellipsize

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ellipsize - npm Package Compare versions

Comparing version 0.0.3 to 0.1.0

.editorconfig

20

index.js

@@ -11,17 +11,25 @@ 'use strict';

function ellipsize(str, max, ellipse, chars, truncate) {
if (str.length < max) return str;
var last = 0,
c = '';
c = '',
midMax = Math.floor(max / 2),
computedMax = truncate === 'middle' ? midMax : max;
if (str.length < max) return str;
for (var i = 0, len = str.length; i < len; i++) {
c = str.charAt(i);
if (chars.indexOf(c) !== -1) {
if (chars.indexOf(c) !== -1 && truncate !== 'middle') {
last = i;
}
if (i < max) continue;
if (i < computedMax) continue;
if (last === 0) {
return !truncate ? '' : str.substring(0, max - 1) + ellipse;
return !truncate ?
'' :
str.substring(0, computedMax - 1) + ellipse + (
truncate === 'middle' ?
str.substring(str.length - midMax, str.length) :
''
);
}

@@ -28,0 +36,0 @@

{
"name": "ellipsize",
"version": "0.0.3",
"description": "Ellipsizes a string at the nearest whitespace character near the end of allowed length",
"main": "index.js",
"scripts": {
"test": "./node_modules/mocha/bin/mocha --recursive -u tdd -R spec test/*"
},
"repository": {
"type": "git",
"url": "git@github.com:mvhenten/ellipsize.git"
},
"keywords": [
"name": "ellipsize",
"version": "0.1.0",
"description": "Ellipsizes a string at the nearest whitespace character near the end of allowed length",
"main": "index.js",
"scripts": {
"test": "./node_modules/mocha/bin/mocha --recursive -u tdd -R spec test/*"
},
"repository": {
"type": "git",
"url": "git@github.com:mvhenten/ellipsize.git"
},
"keywords": [
"ellipsize",

@@ -20,13 +20,13 @@ "ellipsis",

],
"author": "Matthijs van Henten",
"license": "MIT",
"bugs": {
"url": "https://github.com/mvhenten/ellipsize/issues"
},
"homepage": "https://github.com/mvhenten/ellipsize",
"devDependencies": {
"mocha": "~1.17.1",
"js-beautify": "~1.4.2",
"jshint": "~2.4.4"
}
"author": "Matthijs van Henten",
"license": "MIT",
"bugs": {
"url": "https://github.com/mvhenten/ellipsize/issues"
},
"homepage": "https://github.com/mvhenten/ellipsize",
"devDependencies": {
"mocha": "~1.17.1",
"js-beautify": "~1.4.2",
"jshint": "~2.4.4"
}
}
# ellipsize
[![Build Status](https://drone.io/github.com/mvhenten/ellipsize/status.png)](https://drone.io/github.com/mvhenten/ellipsize/latest)
[![Build Status](https://travis-ci.org/mvhenten/ellipsize.svg?branch=master)](https://travis-ci.org/mvhenten/ellipsize)

@@ -5,0 +5,0 @@ Ellipsizes a string near a word boundary.

@@ -103,2 +103,9 @@ 'use strict';

truncate: null
},
{
label: 'truncate settings middle',
len: 8,
string: '123456789ABCDEF',
expect: '123' + ELLIPSE + 'CDEF',
truncate: 'middle'
}

@@ -116,2 +123,50 @@ ];

test('ellipsize truncate words', function() {
var cases = [
// XXX I'm unsure what the expected behavior should actually be, here
// {
// label: 'truncate words settings off',
// len: 12,
// string: 'the quick brown fox',
// expect: '',
// truncate: false
// },
{
label: 'truncate words settings on',
len: 16,
string: 'the quick brown box',
expect: 'the quick brown' + ELLIPSE,
truncate: true
},
{
label: 'truncate words settings default',
len: 16,
string: 'the quick brown fox',
expect: 'the quick brown' + ELLIPSE,
truncate: undefined
},
{
label: 'truncate word settings default',
len: 16,
string: 'the quick brown fox',
expect: 'the quick brown' + ELLIPSE,
truncate: null
},
{
label: 'truncate words settings middle',
len: 16,
string: 'the quick brown fox',
expect: 'the qui' + ELLIPSE + 'rown fox',
truncate: 'middle'
}
];
cases.forEach(function(testCase) {
var result = ellipsize(testCase.string, testCase.len, {
truncate: testCase.truncate
});
assert.equal(result, testCase.expect);
});
});
});

Sorry, the diff of this file is not supported yet

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