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

strict-money-parse

v1.0.3

Published

Strict TypeScript library for parsing monetary values from strings with evidence-based currency detection

Readme

strict-money-parse

npm version npm downloads Bundle Size TypeScript License: MIT Build Status

Strict TypeScript library for parsing monetary values from strings with evidence-based currency detection.

Originally developed for MoneyConvert.net.

Table of contents

Installation

npm install strict-money-parse
# or
yarn add strict-money-parse
# or
pnpm add strict-money-parse
# or
bun add strict-money-parse

Node.js >= 18 is required.

🚀 Quick Start

import { parsePriceString } from "strict-money-parse";

// Basic usage
parsePriceString("€1,234.56");
parsePriceString("1.234,56 €");
parsePriceString("USD 99.99");
parsePriceString("¥125,000");

API

parsePriceString(input, options?)

Parses a single price string and returns the best match.

Parameters:

  • input (string): The string to parse (e.g., "$10.50", "1 200 RUB").
  • options (ParseOptions?): Optional configuration object. See Options below.

Returns: ParseResult

type CurrencyStatus = "CONFIRMED" | "AMBIGUOUS" | "UNKNOWN";

type ParseResult = {
  status: CurrencyStatus;       // Confidence level of the currency detection
  rawAmount: number | null;     // The parsed numeric value (e.g., 10.5)
  currency: string | null;      // ISO 4217 code (e.g., "USD") or symbol if unknown
  symbol: string | null;        // The detected currency symbol (e.g., "$")
  currencyHints: string[];      // List of potential currency codes if ambiguous
  evidence: {
    matchedText: string;        // The substring that was parsed
    normalizedText: string;     // Text after normalization
    amountToken?: string;       // The numeric part as a string
    isoCodeFound?: string;      // Detected ISO code
    symbolFound?: string;       // Detected symbol
  };
};

parsePriceCandidates(input, options?)

Finds all potential price candidates in a string. Useful when the input might contain multiple prices or noise.

Parameters:

  • input (string): The text to search.
  • options (ParseCandidatesOptions?): Configuration object. Extends ParseOptions with:
    • maxCandidates (number?): Maximum number of candidates to return.

Returns: Candidate[] (Array of ParseResult with additional scoring info)

type Candidate = ParseResult & {
  score: number;       // Relevance score
  indexStart: number;  // Start index in the original string
  indexEnd: number;    // End index in the original string
};

buildCurrencyTables()

Pre-builds currency data tables.

Returns: CurrencyTables

Usage: If you are parsing thousands of strings, you can build the tables once and pass them to parsePriceString via options to improve performance.

import { buildCurrencyTables, parsePriceString } from "strict-money-parse";

const tables = buildCurrencyTables(); // Build once

// Reuse in loop
data.forEach(str => {
  parsePriceString(str, { tables });
});

Options

The options object allows you to fine-tune the parsing behavior.

domain

  • Type: "price" | "fx" | "crypto"
  • Default: "price"
  • Description: Sets the default maxFractionDigits based on the expected domain.
    • price: 2 decimal places (standard retail prices).
    • fx: 4 decimal places (foreign exchange rates).
    • crypto: 8 decimal places (cryptocurrencies).

maxFractionDigits

  • Type: number
  • Default: Depends on domain (2, 4, or 8).
  • Description: Explicitly limits the number of decimal places allowed. If the number in the string has more decimal places than this, it might be split or parsed differently. Overrides the domain default.

maxSymbolDistance

  • Type: number
  • Default: 6
  • Description: The maximum number of characters allowed between the currency symbol/code and the numeric value. Useful to avoid matching unrelated symbols far from the number.

ignorePercentages

  • Type: boolean
  • Default: true
  • Description: If true, ignores numeric values followed immediately by a % sign (e.g., "50% off").

tables

  • Type: CurrencyTables
  • Default: undefined (tables are built on the fly)
  • Description: Pre-computed currency tables from buildCurrencyTables(). Pass this to avoid rebuilding tables for every call.

Notes

  • domain does not map website domains like amazon.ca to a currency. It only selects a precision profile (price/fx/crypto).
  • ISO 4217 currency list (src/data/iso4217.json) last downloaded: 2026-01-02.
  • Real-world HTML-based test notes: REAL_WORLD_HTML_TESTS.md
  • Third-party notices: THIRD_PARTY_NOTICES.md

License

MIT. See LICENSE.