Currency String Parser

1.1.1 · abandoned · verified Sun Apr 19

The `parsecurrency` package provides a minimalist utility for parsing currency strings, extracting components such as the numerical value, currency symbol, decimal and group separators, and ISO code. Currently at version 1.1.1, the package was last updated over six years ago and appears to be abandoned, with no active development or maintenance. While it supports many common international currency formats, including Indian numbering, it has explicit limitations, notably an inability to process currencies with three decimal places or two-character group separators. Due to its age, it primarily supports CommonJS imports, and users should be aware of potential compatibility issues in modern ESM-only environments and the lack of ongoing security patches or feature enhancements.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates parsing various currency string formats, including positive and negative values, with different symbols, group, and decimal separators, returning a structured object.

const parseCurrency = require('parsecurrency');

// Example 1: Standard international format with symbol and ISO code
const result1 = parseCurrency('$123,456.99USD');
console.log('Example 1:', result1);
/*
Output:
{
  raw: '$123,456.99USD',
  value: 123456.99,
  integer: '123,456',
  decimals: '.99',
  currency: 'USD',
  symbol: '$',
  decimalSeparator: '.',
  groupSeparator: ',',
  sign: ''
}
*/

// Example 2: Negative value with symbol prefix
const result2 = parseCurrency('-¥578,349,027');
console.log('Example 2:', result2);
/*
Output:
{
  raw: '-¥578,349,027',
  value: -578349027,
  integer: '-578,349,027',
  decimals: '',
  currency: '',
  symbol: '¥',
  decimalSeparator: '',
  groupSeparator: ',',
  sign: '-'
}
*/

// Example 3: European format with space as group separator and comma as decimal
const result3 = parseCurrency('10 000,00zł');
console.log('Example 3:', result3);
/*
Output:
{
  raw: '10 000,00zł',
  value: 10000,
  integer: '10 000',
  decimals: ',00',
  currency: 'zł',
  symbol: '',
  decimalSeparator: ',',
  groupSeparator: ' ',
  sign: ''
}
*/

view raw JSON →