mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-01 02:08:12 +08:00
Conditionally truncate category string (#1206)
* maybe truncate string * add string formatting to test * correct import * destructuring * add maxlength * test * Respond to feedback from @bkmartinjr Co-authored-by: Matt Weiden <538456+mweiden@users.noreply.github.com>
This commit is contained in:
co-authored by
Matt Weiden
parent
28ddb60b2f
commit
234f25b782
@@ -0,0 +1,18 @@
|
||||
const maybeTruncateString = (str, maxLength) => {
|
||||
|
||||
let truncatedString = null;
|
||||
if (
|
||||
str.length > maxLength
|
||||
) {
|
||||
truncatedString = `${str.slice(
|
||||
0,
|
||||
maxLength / 2
|
||||
)}…${str.slice(
|
||||
-maxLength / 2
|
||||
)}`;
|
||||
}
|
||||
|
||||
return truncatedString || str;
|
||||
}
|
||||
|
||||
export default maybeTruncateString;
|
||||
Reference in New Issue
Block a user