npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-native-format-kit

v1.0.0

Published

Controlled currency input/text/hook utilities for React Native with Intl formatting and validation.

Readme

react-native-format-kit npm version

Currency input utilities for React Native with controlled formatting, masking, validation, display helpers, and styling hooks built on Intl.NumberFormat. No external deps beyond React/React Native.

Intl note: On older Android versions you may need an Intl polyfill (e.g. @formatjs/intl-numberformat).

Installation

npm install react-native-format-kit

API Overview

  • Components: CurrencyInput (editable), CurrencyText (display-only)
  • Hook: useCurrencyInput
  • Utilities: formatCurrency, parseCurrencyFromDigits, stripToDigits, getDecimalSeparator

CurrencyInput

A controlled TextInput that formats on every change and keeps the caret at the end.

Props

| Prop | Type | Required | Default | Notes | | --- | --- | --- | --- | --- | | currency | string | Yes | — | ISO currency code | | value | number \| null | Yes | — | Controlled value | | onChangeValue | (value: number \| null) => void | Yes | — | Fired on parsed value change | | locale | string | No | device/runtime | Locale for Intl.NumberFormat | | fractionDigits | number | No | 2 | Legacy single min/max fraction setting | | minimumFractionDigits | number | No | fractionDigits or 2 | Formatting only | | maximumFractionDigits | number | No | fractionDigits or 2 | Formatting and parsing scale | | mask | "currency" \| "none" | No | "currency" | currency shows formatted value; none shows raw digits with locale decimal | | minimumValue | number | No | — | Clamp lower bound | | maximumValue | number | No | — | Clamp upper bound | | maxDigits | number | No | — | Caps integer digits; extras ignored and raise error | | allowNegative | boolean | No | false | - toggles sign when true; otherwise ignored/clamped | | validate | (value: number \| null) => string \| null | No | — | Custom validation message | | error | string \| null | No | — | External error overrides internal/custom | | onValidationError | (message: string \| null) => void | No | — | Fires when effective error changes | | showErrorText | boolean | No | false | Renders inline error | | onChangeText | (formatted: string) => void | No | — | Formatted string change | | onChangeRawText | (rawDigits: string) => void | No | — | Digits-only change | | keyboardType | TextInputProps["keyboardType"] | No | "numeric" | Override if needed | | testID, accessibilityLabel | string | No | — | Passed through | | Other TextInputProps | — | No | — | Forwarded except value, onChangeText, keyboardType |

Styling props

| Prop | Type | Default | Notes | | --- | --- | --- | --- | | defaultBorderColor | string | #ccc | Idle border | | focusBorderColor | string | #2d7ff9 | Focused border | | errorBorderColor | string | #d14343 | Error border | | containerStyle | StyleProp<ViewStyle> | — | Outer wrapper | | inputContainerStyle | StyleProp<ViewStyle> | — | Border container | | inputContainerFocusedStyle | StyleProp<ViewStyle> | — | Applied on focus | | inputContainerErrorStyle | StyleProp<ViewStyle> | — | Applied on error | | inputStyle | StyleProp<TextStyle> | — | TextInput styling | | label | string | — | Shown as placeholder; floats on focus/value | | floatingLabel | boolean | true | Toggle floating behavior | | labelStyle | StyleProp<TextStyle> | — | Label text styling | | labelContainerStyle | StyleProp<ViewStyle> | — | Label wrapper styling | | labelBackgroundColor | string | white | Background behind floated label | | errorTextStyle | StyleProp<TextStyle> | — | Inline error text; default color #d14343, fontSize 14 | | errorContainerStyle | StyleProp<ViewStyle> | — | Inline error container; default marginTop 6 |

Behavior highlights

  • Digits-only parsing; non-digits ignored. - toggles sign only when allowNegative is true.
  • Clearing input sets value to null.
  • mask="currency" shows Intl-formatted currency. mask="none" shows raw digits with locale decimal separator (no symbol/grouping).
  • minimumFractionDigits/maximumFractionDigits control formatting; parsing uses maximumFractionDigits.

Usage

<CurrencyInput
  currency="USD"
  locale="en-US"
  value={value}
  onChangeValue={setValue}
  onChangeText={(t) => console.log("formatted", t)}
  onChangeRawText={(d) => console.log("digits", d)}
  allowNegative
  maxDigits={6}
  minimumFractionDigits={0}
  maximumFractionDigits={2}
  showErrorText
  label="Amount"
  defaultBorderColor="#ddd"
  focusBorderColor="#2d7ff9"
  errorBorderColor="#e55353"
  inputContainerStyle={{ backgroundColor: "#fafafa" }}
  labelStyle={{ color: "#444" }}
/>

CurrencyText

Display-only formatter for currency values.

  • value: number | null (required)
  • currency: string (required)
  • locale?: string
  • fractionDigits?, minimumFractionDigits?, maximumFractionDigits?
  • placeholder?: string
  • Plus all TextProps
<CurrencyText value={value} currency="EUR" locale="de-DE" placeholder="-" />

Hook: useCurrencyInput

Logic-only hook for parsing/formatting/validation/masking.

Options

  • Required: currency: string
  • Optional: value?: number | null, locale?, fractionDigits?, minimumFractionDigits?, maximumFractionDigits?, minimumValue?, maximumValue?, allowNegative?, maxDigits?, mask?, validate?

Returns

  • value: number | null
  • text: string
  • rawDigits: string
  • error: string | null
  • handleChangeText(text: string)
  • setValue(value: number | null)
const { text, value, rawDigits, error, handleChangeText, setValue } = useCurrencyInput({
  currency: "USD",
  locale: "en-US",
  allowNegative: true,
  maximumFractionDigits: 2,
  maxDigits: 6,
})

Utilities

import {
  formatCurrency,
  parseCurrencyFromDigits,
  stripToDigits,
  getDecimalSeparator,
} from "react-native-format-kit"

formatCurrency(12.34, { currency: "USD", locale: "en-US", minimumFractionDigits: 2, maximumFractionDigits: 2 })

parseCurrencyFromDigits("1234", {
  currency: "USD",
  maximumFractionDigits: 2,
  allowNegative: true,
  isNegative: true,
  minimumValue: 0,
  maximumValue: 100,
  maxDigits: 5,
})

stripToDigits("€1,234.56") // "123456"
getDecimalSeparator("de-DE") // ","

Validation rules

  • maxDigits caps integer digits; extra integer digits are ignored and trigger "Maximum digits is X".
  • allowNegative=false clamps negatives to min (default 0); - is ignored.
  • minimumValue / maximumValue clamp the value; internal errors reflect bounds.
  • validate(value) can return a custom error string; error prop overrides internal/custom.
  • onValidationError fires whenever the effective error message changes.