You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

21 lines
404 B

import PropTypes from 'prop-types'
const Truncate = ({ text, maxlen = 12 }) => {
if (!text) {
return null
}
const truncatedText =
text.length < maxlen
? text
: text.substr(0, maxlen / 2) + '...' + text.substr(text.length - maxlen / 2)
return truncatedText
}
Truncate.propTypes = {
text: PropTypes.string.isRequired,
maxlen: PropTypes.number
}
export default Truncate