Hey everybody! 👋
The other day I found myself writing
a function to format numbers. The first question was: What is the right way to format a number? There should be a standard or something. 🤔 Googled a bit and found about
the Unicode CLDR Project. They have a huge amount of structured data, and I surely found the data I was looking for. 🤓
Now, seeing all that data, I thought: Wow! Wouldn’t it be cool to have an Elm library that’l hold all that? elm-cldr? 🎩 Oh, it’d be enormous… What if I only need number formatting? Oh, I know: elm-cldr-numbers! and elm-cldr-dates! and elm-cldr-localenames! and… Ooooh yeah!! 🤠
Then I remember that the CLDR website was saying that they provide data for apps and operating systems. Hm… shouldn’t it be there already somewhere in the OS? 🤔 Googled a bit more and found that browsers already have that as
window.Intl and MDN says it has quite good support, down to IE11. Couldn’t believe that one, so spun up my Windows VM and pasted a snippet into IE11’s console: it worked! 👽
Hm… OK… Now, it’d really be quite cool to build all those elm-cldr-* things that I imagined, wouldn’t it make more sense to reuse what’s already there? What would it be like to use that? OK, let’s go native! A couple hours later
I got myself Native.Intl. 😎
Now, looking at all this I begun wondering what would it be like to have it in the Elm standard library, and inevitably found Evan’s 2 threads (
one and
two) about the philosophy around native in Elm, and I kind of see his point about keeping Elm high-quality, but how about cases like this where we’re not talking about JS libraries but about browser’s native APIs like Intl? 🤔
It’d probably be not that hard to get
that data packaged into a few Elm libraries, hopefully not-that-large each, but it’d still end up growing the final app bundles, and probably some compilation time during the hundreds of refreshes a day that a dev does…😳 So I’m not entirely sure it’s a constructive idea. 😶
So although for my little toy-project I can just use Elm native, how about long-term? What would make more sense? I mean these two options:
- implement Elm libraries using the CLDR data
- hope that window.Intl will some day become part of Elm standard library
What are some pros and cons? Are there any other options people have considered? 🤔