vue2-filters
Version:
A collection of Vue.js filters
15 lines (12 loc) • 331 B
JavaScript
/**
* Truncate at the given || default length
*
* 'lorem ipsum dolor' => 'lorem ipsum dol...'
*/
function truncate (value, length) {
length = length || 15
if( !value || typeof value !== 'string' ) return ''
if( value.length <= length) return value
return value.substring(0, length) + '...'
}
export default truncate