Rename _.truncate to _.trunc to align with ES6.

This commit is contained in:
John-David Dalton
2014-05-30 12:26:52 -04:00
parent 95db668c3c
commit f4a1573586
4 changed files with 25 additions and 25 deletions

View File

@@ -63,7 +63,7 @@ A list of upcoming features is available on our [roadmap](https://github.com/lod
* [_.bind](http://lodash.com/docs#bind), [_.curry](http://lodash.com/docs#curry), [_.partial](http://lodash.com/docs#partial), &
[more](http://lodash.com/docs "_.bindKey, _.partialRight") support argument placeholders
* [_.capitalize](http://lodash.com/docs#capitalize), [_.trim](http://lodash.com/docs#trim), &
[more](http://lodash.com/docs "_.camelCase, _.endsWith, _.escapeRegExp, _.kebabCase, _.pad, _.padLeft, _.padRight, _.repeat, _.snakeCase, _.startsWith, _.trimLeft, _.trimRight, _.truncate") string methods
[more](http://lodash.com/docs "_.camelCase, _.endsWith, _.escapeRegExp, _.kebabCase, _.pad, _.padLeft, _.padRight, _.repeat, _.snakeCase, _.startsWith, _.trimLeft, _.trimRight, _.trunc") string methods
* [_.contains](http://lodash.com/docs#contains), [_.toArray](http://lodash.com/docs#toArray), &
[more](http://lodash.com/docs "_.at, _.countBy, _.every, _.filter, _.find, _.forEach, _.forEachRight, _.groupBy, _.invoke, _.map, _.max, _.min, _.pluck, _.reduce, _.reduceRight, _.reject, _.shuffle, _.size, _.some, _.sortBy, _.where") accept strings
* [_.dropWhile](http://lodash.com/docs#dropWhile), [_.takeWhile](http://lodash.com/docs#takeWhile), &

View File

@@ -7937,22 +7937,22 @@
* @returns {string} Returns the truncated string.
* @example
*
* _.truncate('hi-diddly-ho there, neighborino');
* _.trunc('hi-diddly-ho there, neighborino');
* // => 'hi-diddly-ho there, neighbo...'
*
* _.truncate('hi-diddly-ho there, neighborino', 24);
* _.trunc('hi-diddly-ho there, neighborino', 24);
* // => 'hi-diddly-ho there, n...'
*
* _.truncate('hi-diddly-ho there, neighborino', { 'length': 24, 'separator': ' ' });
* _.trunc('hi-diddly-ho there, neighborino', { 'length': 24, 'separator': ' ' });
* // => 'hi-diddly-ho there,...'
*
* _.truncate('hi-diddly-ho there, neighborino', { 'length': 24, 'separator': /,? +/ });
* _.trunc('hi-diddly-ho there, neighborino', { 'length': 24, 'separator': /,? +/ });
* //=> 'hi-diddly-ho there...'
*
* _.truncate('hi-diddly-ho there, neighborino', { 'omission': ' [...]' });
* _.trunc('hi-diddly-ho there, neighborino', { 'omission': ' [...]' });
* // => 'hi-diddly-ho there, neig [...]'
*/
function truncate(string, options) {
function trunc(string, options) {
var length = 30,
omission = '...';
@@ -8740,7 +8740,7 @@
lodash.trim = trim;
lodash.trimLeft = trimLeft;
lodash.trimRight = trimRight;
lodash.truncate = truncate;
lodash.trunc = trunc;
lodash.unescape = unescape;
lodash.uniqueId = uniqueId;

View File

@@ -265,7 +265,7 @@ function isJobId(value) {
*/
function logInline(text) {
var blankLine = _.repeat(' ', _.size(prevLine));
prevLine = text = _.truncate(text, 40);
prevLine = text = _.trunc(text, 40);
process.stdout.write(text + blankLine.slice(text.length) + '\r');
}

View File

@@ -9148,55 +9148,55 @@
/*--------------------------------------------------------------------------*/
QUnit.module('lodash.truncate');
QUnit.module('lodash.trunc');
(function() {
var string = 'hi-diddly-ho there, neighborino';
test('should truncate to a length of `30` by default', 1, function() {
strictEqual(_.truncate(string), 'hi-diddly-ho there, neighbo...');
strictEqual(_.trunc(string), 'hi-diddly-ho there, neighbo...');
});
test('should not truncate if `string` is <= `length`', 2, function() {
strictEqual(_.truncate(string, string.length), string);
strictEqual(_.truncate(string, string.length + 2), string);
strictEqual(_.trunc(string, string.length), string);
strictEqual(_.trunc(string, string.length + 2), string);
});
test('should truncate string the given length', 1, function() {
strictEqual(_.truncate(string, 24), 'hi-diddly-ho there, n...');
strictEqual(_.trunc(string, 24), 'hi-diddly-ho there, n...');
});
test('should support a `omission` option', 1, function() {
strictEqual(_.truncate(string, { 'omission': ' [...]' }), 'hi-diddly-ho there, neig [...]');
strictEqual(_.trunc(string, { 'omission': ' [...]' }), 'hi-diddly-ho there, neig [...]');
});
test('should support a `length` option', 1, function() {
strictEqual(_.truncate(string, { 'length': 4 }), 'h...');
strictEqual(_.trunc(string, { 'length': 4 }), 'h...');
});
test('should support a `separator` option', 2, function() {
strictEqual(_.truncate(string, { 'length': 24, 'separator': ' ' }), 'hi-diddly-ho there,...');
strictEqual(_.truncate(string, { 'length': 24, 'separator': /,? +/ }), 'hi-diddly-ho there...');
strictEqual(_.trunc(string, { 'length': 24, 'separator': ' ' }), 'hi-diddly-ho there,...');
strictEqual(_.trunc(string, { 'length': 24, 'separator': /,? +/ }), 'hi-diddly-ho there...');
});
test('should treat negative `length` as `0`', 4, function() {
_.each([0, -2], function(length) {
strictEqual(_.truncate(string, length), '...');
strictEqual(_.truncate(string, { 'length': length }), '...');
strictEqual(_.trunc(string, length), '...');
strictEqual(_.trunc(string, { 'length': length }), '...');
});
});
test('should coerce `length` to a number', 4, function() {
_.each(['', '4'], function(length, index) {
var actual = index ? 'h...' : '...';
strictEqual(_.truncate(string, length), actual);
strictEqual(_.truncate(string, { 'length': { 'valueOf': _.constant(length) } }), actual);
strictEqual(_.trunc(string, length), actual);
strictEqual(_.trunc(string, { 'length': { 'valueOf': _.constant(length) } }), actual);
});
});
test('should coerce `string` to a string', 2, function() {
strictEqual(_.truncate(Object(string), 4), 'h...');
strictEqual(_.truncate({ 'toString': _.constant(string) }, 5), 'hi...');
strictEqual(_.trunc(Object(string), 4), 'h...');
strictEqual(_.trunc({ 'toString': _.constant(string) }, 5), 'hi...');
});
}());
@@ -10747,7 +10747,7 @@
'trim',
'trimLeft',
'trimRight',
'truncate',
'trunc',
'unescape'
];