unsplash / intlc

Compile ICU messages into code. Supports TypeScript and JSX. No runtime.
MIT License
56 stars 3 forks source link

Add initial support for number skeletons #112

Closed samhh closed 1 year ago

samhh commented 2 years ago

Closes #20.

The following are supported as of this PR:

{n, number, ::percent}
{n, number, ::currency/USD}
{n, number, ::unit/megabyte}

"megabyte" is the only supported unit at present. It's a long list and that's a known use case for Unsplash web, but further units would be very simple to add.

The top six globally-traded currencies are supported. This PR takes the view that on balance a whitelist of currencies is, for now at least, the lesser evil, weighing between maintainability and safety.

::percent compiles to an Intl.NumberFormat constructor options object of { style: 'percent' }, which formats as a ratio (1 as 100%). We could alternatively compile to { style: 'unit', unit: 'percent' } which'd format 1 as 1%.

Further ICU number skeleton features can be supported upon a use case appearing (or a feature request for any onlookers!).

OliverJAsh commented 2 years ago

Before we start using these skeletons in unsplash-web I think it's worth running this past Carmen to check that there won't be any issues with the vendor's parsing of the ICU syntax.

samhh commented 1 year ago

Closing as stale.