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 🙏

© 2026 – Pkg Stats / Ryan Hefner

localized-price-parse-kit

v0.1.0

Published

Parse localized price strings into structured decimal and currency parts.

Readme

localized-price-parse-kit

License: MPL-2.0 CI

Parse localized price strings into structured decimal and currency parts.

Package quality

  • TypeScript types are generated from the source.
  • ESM-only package marked as side-effect free for bundlers.
  • CI runs npm ci, typecheck, build, and test.
  • Tested on Node.js 20 and 22 with GitHub Actions.

Demo

Try the interactive demo

import {
  isLocalizedPrice,
  parseLocalizedPrice,
  parseLocalizedPriceParts
} from "localized-price-parse-kit";

parseLocalizedPrice("€1.234,56");
// {
//   ok: true,
//   value: 1234.56,
//   decimal: "1234.56",
//   amount: { sign: 1, integer: "1234", fraction: "56", scale: 2 },
//   currency: { symbol: "€", code: "EUR" },
//   separators: { decimal: ",", group: "." }
// }

Why

Localized prices often arrive as display text: €1.234,56, US$ 1,234.56, CHF 1’234.50, 1 234,56 руб, or -$8,202.97.

This package returns a small structured result instead of only returning a JavaScript number or NaN:

  • decimal string for safe storage;
  • optional numeric value for convenience;
  • currency symbol and common ISO code when recognizable;
  • diagnostics for empty, ambiguous, or malformed input;
  • browser-friendly core with no runtime dependencies.

Install

npm install localized-price-parse-kit

API

parseLocalizedPrice(input, options?)

Returns a discriminated result instead of throwing:

type ParseLocalizedPriceResult =
  | {
      ok: true;
      input: string;
      value: number;
      decimal: string;
      amount: PriceAmountParts;
      currency: CurrencyInfo;
      separators: PriceSeparators;
      issues: [];
    }
  | {
      ok: false;
      input: string;
      value: null;
      decimal: null;
      amount: null;
      currency: CurrencyInfo;
      separators: PriceSeparators;
      issues: PriceParseIssue[];
    };

Use decimal for storage when precision matters. value is provided as a convenience JavaScript number for UI and lightweight calculations.

parseLocalizedPriceParts(input, options?)

Returns only the parsed numeric parts, or null when validation fails.

isLocalizedPrice(input, options?)

Returns true when the input can be parsed successfully.

Options

type ParseLocalizedPriceOptions = {
  decimalSeparator?: "." | "," | "auto";
  allowNegative?: boolean;
  allowCurrencyCode?: boolean;
  maxFractionDigits?: number;
};

decimalSeparator defaults to auto, which chooses the rightmost . or , as the decimal separator when both appear. If only one separator appears, a final group of one or two digits is treated as decimals; groups of three digits are treated as thousands.

Examples

parseLocalizedPrice("£1,234.56").decimal;
// "1234.56"

parseLocalizedPrice("1 234,56 руб").currency;
// { symbol: "руб", code: "RUB" }

parseLocalizedPrice("CHF 1’234.50").separators;
// { decimal: ".", group: "apostrophe" }

parseLocalizedPrice("12,34,56").ok;
// false

Notes

This is a small parser for common product, invoice, and ecommerce display prices. It is not a full CLDR implementation and does not infer locale-specific currency minor units.

Browser compatibility

The core uses only strings, objects, arrays, numbers, and regular expressions. It has no runtime dependencies and no required Node APIs.

CLI

No CLI is included. The package is meant to be embedded in import tools, forms, scrapers, ecommerce admin screens, and browser UIs.

License

MPL-2.0