mirror of
https://github.com/datahub-project/datahub.git
synced 2025-07-29 20:39:56 +00:00
17 lines
476 B
TypeScript
17 lines
476 B
TypeScript
![]() |
import { helper } from '@ember/component/helper';
|
||
|
|
||
|
export function splitText([string = '', maxLen = 20, separator = '...']: [string, number, string]): string {
|
||
|
const { length: strLen } = string;
|
||
|
const { length: sepLen } = separator;
|
||
|
|
||
|
if (strLen > maxLen) {
|
||
|
const splitLen = Math.floor((maxLen - sepLen) / 2);
|
||
|
|
||
|
return `${string.substr(0, splitLen).trim()}${separator}${string.substr(-splitLen).trim()}`;
|
||
|
}
|
||
|
|
||
|
return string;
|
||
|
}
|
||
|
|
||
|
export default helper(splitText);
|