Fix truncate tests
Reviewed By: bestander Differential Revision: D3424960 fbshipit-source-id: 0f434d80e6e26cfc9f01800c266dd1a3710fe459
This commit is contained in:
parent
2151dfbb24
commit
3f1bca7d26
|
@ -11,27 +11,25 @@
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var merge = require('merge');
|
|
||||||
|
|
||||||
type truncateOptions = {
|
type truncateOptions = {
|
||||||
breakOnWords: boolean;
|
breakOnWords: boolean;
|
||||||
minDelta: number;
|
minDelta: number;
|
||||||
elipsis: string;
|
elipsis: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultOptions = {
|
const defaultOptions = {
|
||||||
breakOnWords: true,
|
breakOnWords: true,
|
||||||
minDelta: 10, // Prevents truncating a tiny bit off the end
|
minDelta: 10, // Prevents truncating a tiny bit off the end
|
||||||
elipsis: '...',
|
elipsis: '...',
|
||||||
};
|
};
|
||||||
|
|
||||||
// maxChars (including ellipsis)
|
// maxChars (including ellipsis)
|
||||||
var truncate = function(
|
const truncate = function(
|
||||||
str: ?string,
|
str: ?string,
|
||||||
maxChars: number,
|
maxChars: number,
|
||||||
options: truncateOptions
|
options: truncateOptions
|
||||||
): ?string {
|
): ?string {
|
||||||
options = merge(defaultOptions, options);
|
options = Object.assign({}, defaultOptions, options);
|
||||||
if (str && str.length &&
|
if (str && str.length &&
|
||||||
str.length - options.minDelta + options.elipsis.length >= maxChars) {
|
str.length - options.minDelta + options.elipsis.length >= maxChars) {
|
||||||
str = str.slice(0, maxChars - options.elipsis.length + 1);
|
str = str.slice(0, maxChars - options.elipsis.length + 1);
|
||||||
|
|
Loading…
Reference in New Issue