I'm not a JS developer, so maybe they'd do it differently, but I'd probably do a bounds check, returning early if the target length is less than the input length, then create a string of spaces that is (targetlength - inputlength) long, and return them concatenated. Quick google shows theres a string.repeat method so probably use that (does that not count as part of an stdlib?).
Also, I'd bet money that most people couldn't write most things bug free on the first try without looking stuff up unless it's trivial
That's how I imagine most people would start, but unfortunately that will break on anything beyond basic ascii strings. Arabic, Hindi, Vietnamese, etc use diacritics, combining characters and so on, and this isn't even getting into the mess of emojis and their modifiers.
It would, I was not familiar with the specific package, more so commenting on the problem at large. Even coding problems that sounds fairly straightforward can be a source of many dragons if you don't have good tools to solve them.
Also, I'd bet money that most people couldn't write most things bug free on the first try without looking stuff up unless it's trivial