-
Turbolinks makes navigating your web application faster
// app/javascript/src/helpers/price.js // Turbolinks are enabled by default in Rails, // we need to process our script on every page load // https://github.com/turbolinks/turbolinks#full-list-of-events Document.addEventListener("turbolinks:ready", () => { // Get language from html tag const lang = document.documentElement.lang; // Find all span tags with data-localize="price" const pricesOnPage = document.querySelectorAll("[data-localize=\"price\"]"); if (pricesOnPage.length > 0) { // Iterate all price span tags [...pricesOnPage].forEach(priceOnPage => { // Modify text in span tag according to current language priceOnPage.textContent = priceOnPage.textContent.toLocaleString( lang, { style: "currency", currency: "USD" } ); }) } });.
#Code Collaboration #Javascript UI Libraries #Web Application Bundler 13 social mentions
-
date-fns provides the most comprehensive yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.Pricing:
- Open Source
If you need more precise control over the display of dates and times, I recommend delegating such functionality to JavaScript by adding the date-fns library. Just create a helper and bypass data to this library like we will do with number rendering.
#Javascript UI Libraries #Web Frameworks #Developer Tools 68 social mentions