ng-jhipster
Version:
A Jhipster util library for Angular 2
27 lines (26 loc) • 786 B
JavaScript
import { Pipe } from '@angular/core';
export var TruncateWordsPipe = (function () {
function TruncateWordsPipe() {
}
TruncateWordsPipe.prototype.transform = function (input, words) {
if (isNaN(words)) {
return input;
}
if (words <= 0) {
return '';
}
if (input) {
var inputWords = input.split(/\s+/);
if (inputWords.length > words) {
input = inputWords.slice(0, words).join(' ') + '...';
}
}
return input;
};
TruncateWordsPipe.decorators = [
{ type: Pipe, args: [{ name: 'truncateWords' },] },
];
/** @nocollapse */
TruncateWordsPipe.ctorParameters = function () { return []; };
return TruncateWordsPipe;
}());