Open-sourcing locale-to-number.js

George Kamtziridis
fromScratch Studio
3 min readMar 12, 2022

--

Today’s world is very demanding and complicated. That’s why modern software requirements are challenging too. There is a huge number of digital products out there used by millions or even billions of people. Software development teams manage to design and implement these highly complex products in relatively short periods of time, while also making sure (most of the time) their products will work as expected. And as time passes, the requirements grow more and more complex, but the effort needed to produce such solutions stays pretty much the same. How is that possible?

The answer lies in the fact that new software is built upon existing software packages or modules. There are tons of open-source packages available to use under certain licenses. When a problem arises or a new feature seems to be not so trivial, the development team has to decide if it’s worth using an already existing package or if it would be better to build it from scratch. However, in some cases there is only the last option available.

At fromScratch Studio, we had the opportunity to encounter such a case. While working on a Javascript project, we wanted to convert decimal literal numbers to strings with respect to the user’s locale. For instance, the number 123456.789 in German locale must be translated as “123.456,789”, in contrast with the English locale where it must be translated as “123,456.789”. After a bit of searching, we’ve found that this is already implemented in Javascript by the Number.toLocaleString() function. This function takes 2 arguments: the decimal literal number and the user’s locale. It outputs the string representation of the given number based on the given locale. However, we, also, wanted to convert such representations back to decimal literal numbers. The Number class does not provide this utility and by researching what’s accessible online, we could not find a robust solution capable of handling these cases.

So, we decided to build it from scratch (pun intended). We sat down as a team and organized the project rigorously by following all open-source guidelines as strictly as possible. By a happy coincidence, the actual development began during the Hacktorberfest event that is organized by DigitalOcean for the last 8 years. By taking part in Hacktoberfest, we have managed to transform a plain development cycle to a more thrilling and enthusiastic challenge, where all team members could actively contribute to a unique and promising open-source Javascript library. And of course, get free t-shirts at the end of the Hacktoberfest event. The contributions were not only code-related, since the orchestration of the project takes a lot of time as well.

Finally, the tasks were set and the goals were met. The locale-to-number.js library was created and is now published as a npm package. In short:

locale-to-number.js is a library that aids developers to convert string representations of numbers, in a certain locale, to decimal literal numbers. The exact opposite operation is available either by the Intl.NumberFormat() constructor or the Number.toLocaleString() function. However, converting them back to decimal is not trivial. That’s where locale-to-number.js comes into play.

You can check the links below for more information about the package. Keep in mind, this is just the first release of the library. New features like supporting Arabic locale, including Typescript type information and many more will be introduced in the near future. So, make sure to keep an eye out.

Github: https://github.com/fromScratchStudioGr/locale-to-number.js

NPM: https://www.npmjs.com/package/@fromscratch-studio-gr/locale-to-number.js

--

--

George Kamtziridis
fromScratch Studio

Full Stack Software Engineer and Data Scientist at fromScratch Studio. BEng, MEng (Electrical Engineering/Computer Engineering) MSc (Artificial Intelligence)