Skip to content

FormaJS v1.1.0: Introducing new Formatters and Massive Optimization

Choose a tag to compare

@MenesesEvandro MenesesEvandro released this 04 Nov 14:26
· 16 commits to main since this release
82798fe

We are excited to announce version 1.1.0! This is the first major update since the v1.0 launch and focuses on two key areas: expanding the library beyond validation by introducing a new and powerful Formatters category, and a drastic optimization of the package size.

The library's unpacked size has been reduced from 1.34 MB to 454.1 kB (a ~66% reduction)! This makes the library much lighter and faster for all users in production.

🚀 New Formatters (formatters/)

They are the "inverse" of our validators and parsers, using internationalization (i18n) rules to format data cleanly.

  • formatCurrency: Converts a number (e.g., 1234.50) into a locale-aware currency string (e.g., "R$ 1.234,56" or "$1,234.50").
  • formatDate: Converts a Date object into a formatted string (e.g., "31/10/2025") using the new masks.date rule from i18n.
  • formatPostalCode: Formats ZIP/Postal code digits (e.g., "01001000") into the locale's mask (e.g., "01001-000").
  • formatMobileNumber: Formats mobile number digits using the local or international masks (e.g., "+55 (11) 98765-4321").
  • formatTaxId: Formats a Tax ID (CPF, CNPJ, SSN) using the option.type to select the correct mask (e.g., "###.###.###-##").

📐 Architectural Improvements (Formatter Support)

To make the formatters possible without hardcoding logic:

  • The locale files (e.g., pt-BR.json and en-US.json) now contain a centralized masks object, which defines the formats for postalcode, mobileNumber, date, and taxId.
  • The applyFormatMask utility was added to apply format masks consistently.

🛠️ New Sanitizers

  • Added the padStart and padEnd sanitizers. They are essential utilities, perfect for preparing data before formatting (e.g., adding leading zeros to a CPF before calling formatTaxId).

This release completes the planned feature set for v1.x. The next step will be the evolution to v2.0, focusing on schema validation (chaining)!

Full Changelog: v1.0.0...v1.1.0