mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 09:57:09 +00:00
Add utility function to truncate long strings
This commit is contained in:
10
lib/www/client/source/src/lib/truncate-text.js
Normal file
10
lib/www/client/source/src/lib/truncate-text.js
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
function truncateText (text, length=20) {
|
||||
if (text?.length <= length) {
|
||||
return text;
|
||||
} else {
|
||||
return text.slice(0, length/2)+"…"+text.slice(-(length/2));
|
||||
}
|
||||
}
|
||||
|
||||
export default truncateText;
|
||||
Reference in New Issue
Block a user