String.prototype.localeCompare() without native code?

Hello there!

In some application, I’m currently using native code to wrap String.prototype.localeCompare in order for a model name starting with an accent like “É” not to end up after a name starting with a “V” for example.

Using a port doesn’t really makes sense to me (please correct me if I’m wrong).
I assume the best way would be to reimplement locale-based sorting in some localization package, but I have no idea of the amount of work required to do so…

Does this already exist somewhere?
Or is somebody already planning to implement it in its own package?

Thank you :slight_smile:

1 Like

update: does this do the trick?


I just switched the native code with and everything seems to work as expected.

Thanks @Dan_Abrams!

1 Like

This package doesn’t take locales into account at all. It just removes diacritics for comparing. Maybe it does the trick for the OP but in any case it would be interesting to know how to interface with this function from Elm.

1 Like

@Hector Definitely! (although I’m quite happy with the current solution)

I think the way you’d interface with the function depends on your use case. If you wanted to sort a list, it might be reasonable to send the list through a port and sort it using localeCompare, then send back the sorted list and store it in your model.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.