I was about to say you could figure this kind of thing out with Intl.Segmenter but then saw it was a different problem. Nice.
Now you just have to update it to the just-released Unicode 17.
Nice