Reply to post: broken by design?

JavaScript spec gets strung out on padding

stephanh

broken by design?

I completely fail to see when you could ever *correctly* use padStart/padEnd.

Basically, these functions apparently simply count length by counting UTF-16 code points. So they don't work correctly if your string contains:

* Non-BMP characters (e.g. emoji)

* Double-width characters (Chinese, Japanese etc.)

* Combining characters (accents etc.)

* Let alone right-to-left languages like Arabic.

On the other hand, if you still believe that "all the world is ASCII" you'll be fine.

The correct way to deal with this would be to style your HTML so that stuff gets left or right-aligned.

That this makes it into a language standard in 2017 is ridiculous.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon