mvhenten / ellipsize

Ellipsizes a string at the nearest whitespace character near the end of allowed length
MIT License
43 stars 5 forks source link

Returns empty string #11

Open mswebdesign opened 2 years ago

mswebdesign commented 2 years ago

If I apply ellipsize like this, an empty string is returned:

ellipsize( 'Digitale Bildung durch Computational Thinking: Der Erwerb fächerübergreifender Problemlösekompetenz zugunsten eines reflektiert-partizipativen Medienumgangs in der spannenden Welt von Coding und Robotik - Angebot eines Praxisworkshops für Grundschullehrkräfte anlässlich des Digitaltags 2022', 160, { truncate: false } )

mc-alt commented 2 years ago

This string appears to truncate correctly in an older version (0.2.0).

I've put together a potential fix as a PR

The basic problem appears to be that the 160th character in that string is a space. The code gets confused and thinks that it failed to find any breakpoints it can use.

mswebdesign commented 2 years ago

Yep, works like a charm. Please merge. Thanx!