Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@internationalized/number

Package Overview
Dependencies
Maintainers
2
Versions
722
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@internationalized/number

Internationalized number formatting and parsing utilities

  • 3.0.0-nightly-db51509aa-240910
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.6M
decreased by-0.63%
Maintainers
2
Weekly downloads
 
Created
Source

@internationalized/number

This package is part of react-spectrum. See the repo for more details.

NumberParser

The NumberParser class can be used perform locale-aware parsing of numbers from Unicode strings, as well as validation of partial user input. It automatically detects the numbering system used in the input, and supports parsing decimals, percentages, currency values, and units according to the locale.

Parsing

import {NumberParser} from '@internationalized/number';

let parser = new NumberParser('en-US', {style: 'percent'});
parser.parse('10%'); // -> 0.1

Validation

import {NumberParser} from '@internationalized/number';

let parser = new NumberParser('en-US', {style: 'unit', unit: 'inch'});
parser.isValidPartialNumber('10 '); // -> true
parser.isValidPartialNumber('10 in'); // -> true
parser.isValidPartialNumber('10 i'); // -> false
parser.isValidPartialNumber('10 x'); // -> false

Detecting the numbering system

import {NumberParser} from '@internationalized/number';

let parser = new NumberParser('en-US', {style: 'decimal'});
parser.getNumberingSystem('١٢') // -> 'arabic'

NumberFormatter

The NumberFormatter class is a wrapper around Intl.NumberFormat providing additional options, polyfills, and caching for performance. It provides the exact same interface as Intl.NumberFormat, so it is a drop-in replacement. Please see the MDN docs linked above for more details.

We currently polyfill the following features:

  • The signDisplay option
  • The unit style, currently only for the degree unit in the narrow style

FAQs

Package last updated on 10 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc