summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/truncate.pipe.ts
blob: ff49c63860cf61ecc572b3a26143cbe4f85190a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { Pipe, PipeTransform } from '@angular/core';

import _ from 'lodash';

@Pipe({
  name: 'truncate'
})
export class TruncatePipe implements PipeTransform {
  transform(value: any, length: number, omission?: string): any {
    if (!_.isString(value)) {
      return value;
    }
    omission = _.defaultTo(omission, '');
    return _.truncate(value, { length, omission });
  }
}