blob: 85b149263ff935519c770377a0b109272c12a4e2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
|
from typing import Any
from ..modifier import Modifier
class Truncate(Modifier):
def modify(self, value: Any, opts: list[Any]) -> Any:
if isinstance(value, str) and len(opts) > 0 and isinstance(opts[0], int):
if len(value) > opts[0]:
return f"{value[:opts[0] - 3]}..."
return value
|