Files
cellxgene/client/src/util/maybeTruncateString.js
T
Colin MegillandMatt Weiden 234f25b782 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>
2020-03-10 18:14:26 -07:00

18 lines
315 B
JavaScript

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;