Socket
Socket
Sign inDemoInstall

parsecurrency

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    parsecurrency

Tiny currency string parser utility


Version published
Weekly downloads
4.1K
increased by4%
Maintainers
1
Install size
4.47 kB
Created
Weekly downloads
 

Changelog

Source

[1.1.0] - 2022-11-06

Added

  • Support for positive/negative number prefix https://github.com/mktj/parsecurrency/pull/11
  • Support for french number format (narrow no-break space group separator)
  • Support for brazilian format

Changed

  • Dev dependency updates

Readme

Source

parsecurrency

Build Status npm version

Node / browser currency parser.

Extensive currency parsing utility designed to extract value, decimal separator, group separator, currency symbol, iso code and sign from currency string. It should work with most world currency formats except:

  • currencies with 3 decimals
  • currency with 2 character group separator (Swaziland Lilangeni)

Works with:

  • international currency formatting (SFr 12'345.67 or 10 000,00zł)
  • indian number system (₹1,50,000.00)
  • parsing CHF Swiss Franc (9'000.00 CHF)
  • currency symbols as a prefix / suffix with or without a space
  • currency code before or after the value, with or without space
  • positive and negative signs (before the currency)

Install

npm i parsecurrency --save

Example

const parseCurrency = require('parsecurrency');

const example1 = parseCurrency('$123,456.99USD');
// example1 =>
{
  raw: '$123,456.99USD',
  value: 123456.99,
  integer: '123,456',
  decimals: '.99',
  currency: 'USD',
  symbol: '$',
  decimalSeparator: '.',
  groupSeparator: ',',
  sign: ''
}
const example2 = parseCurrency('-¥578,349,027');
// example2 =>
{
  raw: '-¥578,349,027',
  value: -578349027,
  integer: '-578,349,027',
  decimals: '',
  currency: '',
  symbol: '¥',
  decimalSeparator: '',
  groupSeparator: ',',
  sign: '-'
}

More examples

Keywords

FAQs

Last updated on 06 Nov 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc