MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / truncate

Function truncate

apps/start/src/utils/truncate.ts:1–16  ·  view source on GitHub ↗
(
  str: string,
  len: number,
  mode: 'start' | 'end' | 'middle' = 'end',
)

Source from the content-addressed store, hash-verified

1export function truncate(
2 str: string,
3 len: number,
4 mode: 'start' | 'end' | 'middle' = 'end',
5) {
6 if (str.length <= len) {
7 return str;
8 }
9 if (mode === 'start') {
10 return `...${str.slice(-len)}`;
11 }
12 if (mode === 'middle') {
13 return `${str.slice(0, len / 2)}...${str.slice(-len / 2)}`;
14 }
15 return `${str.slice(0, len)}...`;
16}

Callers 3

ChartFunction · 0.90
renderLabelFunction · 0.90
OverviewUserJourneyFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected