hyphens: Only with Javascript [closed]

Is there a way to achive exactly the same thing hyphens: auto; in css does with pure Javascript?

I already found libraries for that, such as Hyphenopoly, but it does not work as I excpected it.
Can someone provide a solution or an idea, how to solve this issue?

Thank you all in advance.

I tried to solve it via Hyphenopoly, but it is very complex and primarily for speperating every word, not only the words that breaks at the end of a certain width.