{"id":21033759,"url":"https://github.com/aurelticot/react-advanced-number","last_synced_at":"2026-05-21T04:05:35.704Z","repository":{"id":51157088,"uuid":"350122592","full_name":"aurelticot/react-advanced-number","owner":"aurelticot","description":"React component displaying a number with advanced options such as highlighting the differences with the previous value, a privacy mode, etc.","archived":false,"fork":false,"pushed_at":"2021-05-20T22:11:49.000Z","size":449,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-22T10:19:08.886Z","etag":null,"topics":["currency","formatting","number","price","privacy","react"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aurelticot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-21T21:22:38.000Z","updated_at":"2022-05-05T08:34:10.000Z","dependencies_parsed_at":"2022-09-05T23:51:43.619Z","dependency_job_id":null,"html_url":"https://github.com/aurelticot/react-advanced-number","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aurelticot%2Freact-advanced-number","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aurelticot%2Freact-advanced-number/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aurelticot%2Freact-advanced-number/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aurelticot%2Freact-advanced-number/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aurelticot","download_url":"https://codeload.github.com/aurelticot/react-advanced-number/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243475370,"owners_count":20296713,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["currency","formatting","number","price","privacy","react"],"created_at":"2024-11-19T12:59:37.069Z","updated_at":"2026-05-21T04:05:35.675Z","avatar_url":"https://github.com/aurelticot.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-advanced-number\n\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/c8a75e531a8e4078ac81322f80b39379)](https://www.codacy.com/gh/aurelticot/react-advanced-number/dashboard?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=aurelticot/react-advanced-number\u0026amp;utm_campaign=Badge_Grade)\n[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/c8a75e531a8e4078ac81322f80b39379)](https://www.codacy.com/gh/aurelticot/react-advanced-number/dashboard?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=aurelticot/react-advanced-number\u0026utm_campaign=Badge_Coverage)\n[![CI](https://github.com/aurelticot/react-advanced-number/actions/workflows/ci.yml/badge.svg)](https://github.com/aurelticot/react-advanced-number/actions/workflows/ci.yml)\n\nReact component formatting and displaying a number with advanced features such as highlighting the differences with the previous value, a privacy mode, etc.\n\nThe component has no dependency (except the obvious peer dep of react itself). The formatting relies on the [Intl.NumberFormat API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat). All the options of the API are provided as props of this component.\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Formatting](#formatting)\n- [Features](#features)\n  - [Privacy Mode](#privacy-mode)\n  - [Diff Highlighting](#diff-highlighting)\n  - [Muted Decimals](#muted-decimals)\n  - [Small Decimals](#small-decimals)\n- [Styling](#styling)\n- [All Together](#all-together)\n- [License](#license)\n\n## Installation\n\nreact-advanced-number is available as an [npm package](https://www.npmjs.com/package/react-advanced-number)\n\n```\nnpm install react-advanced-number\n```\n\n## Usage\n\nIn it's simplest form:\n\n```jsx\nimport React from \"react\";\nimport { AdvancedNumber } from \"react-advanced-number\";\n\nfunction App() {\n  return \u003cAdvancedNumber value={1234.56} /\u003e;\n}\n```\n\n![Usage](/doc/basic-usage.png)\n\n## Formatting\n\nThe component uses the native API [Intl.NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat). All the options are available as props.\n\n```jsx\nfunction App() {\n  return (\n    \u003cAdvancedNumber\n      value={1234.56}\n      options={{\n        style: \"currency\",\n        currency: \"USD\",\n        currencyDisplay: \"narrowSymbol\",\n      }}\n    /\u003e\n  );\n}\n```\n\n![Usage](/doc/currency-formatting.png)\n\n_Note_: the prop `significantDecimalDigits`, when provided, is a shorthand to overwrite both the props `options.minimumFractionDigits` and `options.maximumFractionDigits`.\n\n_Note_: Check the browser support for the [Intl.NumberFormat API](https://caniuse.com/?search=NumberFormat).\n\n## Features\n\n### Privacy Mode\n\nBlur the number when enabled. Perfect for sensitive information to be visually hidden/revealled when relevant.\n\n```jsx\nfunction App() {\n  return (\n    \u003c\u003e\n      \u003cAdvancedNumber value={1234.56} privacyMode={false} /\u003e\n      \u003cAdvancedNumber value={1234.56} privacyMode={true} /\u003e\n    \u003c/\u003e\n  );\n}\n```\n\n![Usage](/doc/privacy-mode.png)\n\nThe default shadow color is `#7C7C7CD9`, you can change it with the optional prop `privacyShadowColor`\n\n```jsx\nfunction App() {\n  return (\n    \u003cAdvancedNumber\n      value={1234.56}\n      privacyMode={true}\n      privacyShadowColor=\"#03A9F4CC\"\n    /\u003e\n  );\n}\n```\n\n![Usage](/doc/privacy-mode-custom.png)\n\n_Note_: currently, it only changes the CSS properties, the number is still in the markup.\n\n### Diff Highlighting\n\nHighlighting a difference between the value and a previous value. Interesting when displaying changing prices.\n\n```jsx\nfunction App() {\n  return \u003cAdvancedNumber value={1234.56} previousValue={1235.89} /\u003e;\n}\n```\n\n![Usage](/doc/diff-highlighting.png)\n\nThe default color for a positive difference is `#4CAF50` and for a negative difference is `#F44336`. You can change them with the optional props `positiveColor` and `negativeColor`.\n\n```jsx\nfunction App() {\n  const positive = \"#03A9F4\";\n  const negative = \"#C238DA\";\n\n  return (\n    \u003c\u003e\n      \u003cAdvancedNumber\n        value={1234.56}\n        previousValue={1233.89}\n        positiveColor={positive}\n        negativeColor={negative}\n      /\u003e\n      \u003cAdvancedNumber\n        value={1234.56}\n        previousValue={1234.59}\n        positiveColor={positive}\n        negativeColor={negative}\n      /\u003e\n    \u003c/\u003e\n  );\n}\n```\n\n![Usage](/doc/diff-highlighting-custom.png)\n\n### Muted Decimals\n\nDisplaying muted decimals between a significant number and the total number of decimals. They are slightly lighter to distinguish them from the significant digits.\n\n```jsx\nfunction App() {\n  return (\n    \u003cAdvancedNumber\n      value={1234.56}\n      showMutedDecimals\n      significantDecimalDigits={2}\n      maxDecimalDigits={6}\n    /\u003e\n  );\n}\n```\n\n![Usage](/doc/muted-decimals.png)\n\nIf you wonder why, I think it's a nice way to homogenize the display of values with different significant number of decimals, as it happens often in price values.\n\n```jsx\nfunction App() {\n  return (\n    \u003c\u003e\n      \u003cAdvancedNumber value={1234.567} /\u003e\n      \u003cAdvancedNumber\n        value={1234.567}\n        showMutedDecimals\n        significantDecimalDigits={2}\n        maxDecimalDigits={6}\n      /\u003e\n      \u003cAdvancedNumber\n        value={0.1234}\n        showMutedDecimals\n        significantDecimalDigits={4}\n        maxDecimalDigits={6}\n      /\u003e\n    \u003c/\u003e\n  );\n}\n```\n\n![Usage](/doc/muted-decimals-comparison.png)\n\n_Note_: The feature requires the following to be enabled: `showMutedDecimals === true`, `maxDecimalDigits \u003e significantDecimalDigits` and `options.notation === 'standard`.\n\n_Note_: `significantDecimalDigits` is actually optional, a default value is defined by the [Intl.NumberFormat API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat).\n\n### Small Decimals\n\nRepresent the decimals smaller than the interger part for the number.\n\n```jsx\nfunction App() {\n  return \u003cAdvancedNumber value={1234.56} smallDecimals /\u003e;\n}\n```\n\n![Usage](/doc/small-decimals.png)\n\n## Styling\n\nThe root element is a `span` receiving the props you will pass it to. Therefore `className` and `style` can be use to style the component.\n\n```jsx\nfunction App() {\n  return \u003cAdvancedNumber value={1234.56} style={{ fontFamily: \"monospace\" }} /\u003e;\n}\n```\n\n![Usage](/doc/styling.png)\n\n## All Together\n\n```jsx\nfunction App() {\n  return (\n    \u003cAdvancedNumber\n      value={1234.56}\n      previousValue={1233.89}\n      options={{\n        style: \"currency\",\n        currency: \"USD\",\n        currencyDisplay: \"narrowSymbol\",\n      }}\n      style={{ fontFamily: \"monospace\" }}\n      smallDecimals\n      showMutedDecimals\n      significantDecimalDigits={2}\n      maxDecimalDigits={6}\n    /\u003e\n  );\n}\n```\n\n![Usage](/doc/complete-usage.png)\n\n## License\n\nThis project is licensed under the terms of the\n[MIT license](/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faurelticot%2Freact-advanced-number","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faurelticot%2Freact-advanced-number","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faurelticot%2Freact-advanced-number/lists"}