Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for unit in NumberFormat #11839

Merged
merged 4 commits into from
May 17, 2022
Merged

Add support for unit in NumberFormat #11839

merged 4 commits into from
May 17, 2022

Conversation

varna
Copy link
Contributor

@varna varna commented Apr 29, 2022

NumberFormat expression uses Intl.NumberFormat and shares the same name. I casually assumed that this expressions is a simple wrapper and tried using it like this:

      'text-field': [
        'number-format',
        ['get', 'area'],
        {
          style: 'unit',
          unit: 'hectare'
        }
      ]

But it didn't work. I would like to replace options object with an actual Intl.NumberFormat, but that would be a major update. I created this pull request that unit feature could be patched in with identical API as currency:

      'text-field': [
        'number-format',
        ['get', 'area'],
        {
          unit: 'hectare'
        }
      ]

Launch Checklist

  • briefly describe the changes in this PR
  • write tests for all new functionality
  • document any changes to public APIs
  • add an entry inside this element for inclusion in the mapbox-gl-js changelog: <changelog>Add unit option to number-format expression (h/t [varna](https://github.com/varna))</changelog>

@CLAassistant
Copy link

CLAassistant commented Apr 29, 2022

CLA assistant check
All committers have signed the CLA.

@varna
Copy link
Contributor Author

varna commented May 10, 2022

I feel ignored 🤣 Do I need to tag someone?

Copy link
Contributor

@SnailBones SnailBones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for your contribution @varna! This will be a good feature to have and your code and test look great to me.

@SnailBones SnailBones linked an issue May 17, 2022 that may be closed by this pull request
@SnailBones SnailBones merged commit 3228854 into mapbox:main May 17, 2022
@varna varna deleted the patch-1 branch May 19, 2022 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add unit in number-format expression
3 participants