diff options
Diffstat (limited to 'src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/truncate.pipe.ts')
-rw-r--r-- | src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/truncate.pipe.ts | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/truncate.pipe.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/truncate.pipe.ts new file mode 100644 index 000000000..ff49c6386 --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/truncate.pipe.ts @@ -0,0 +1,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 }); + } +} |