
Security News
Feross on Risky Business Weekly Podcast: npm’s Ongoing Supply Chain Attacks
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
@opuscapita/format-utils
Advanced tools
Formatting functions in JS
npm install --save @opuscapita/format-utils
View the DEMO
The default build with compiled styles in the .js file. Also minified version available in the lib/umd directory.
You need to configure your module loader to use cjs
or es
fields of the package.json to use these module types.
Also you need to configure sass loader, since all the styles are in sass format.
Function name | Description | Input | Output |
---|---|---|---|
getCurrencyDecimals | Get a number of decimal digits for a currency | currency code :: string | decimals :: number |
getFXRateDecimals | Get a number of decimal digits for a FX rate | FX rate :: [number, string] | decimals :: number |
getLocalDateTime | Get local date and time from ISO 8601 timestamp | UTC timestamp :: string | timestamp :: date |
formatCurrencyAmount | Format amount according to its currency | amount :: [number, string], options :: object (optional) | amount :: string |
formatDate | Format date to a chosen format | date :: string, date format :: string | date :: string |
formatDateToISO | Format localized date string to ISO timestamp | date :: string, date format :: string (optional), sign of strict date format :: boolean (optional), default value :: string (optional), default date format :: string (optional) | ISO date :: string |
formatFloatToFixedDecimals | Format an input to a float with fixed number of decimals | value to format :: [number, string], decimals :: number | formatted value :: string |
formatFXRate | Format FX rate | FX rate :: [string, number] | FX rate :: string |
formatNumber | Format number with separators and decimals | value :: [number, float, string], options :: object (optional) | amount :: string |
escapeSpecialCharacters | Format string containing special characters by escaping them | string | string |
Option key | Value | Default | Description |
---|---|---|---|
currency | string (optional) | Currency code to get number of decimals from | |
decimals | string (optional) | 2 | Number of decimals, overrides currency decimals |
thousandSeparator | string (optional) | Thousand separator | |
decimalSeparator | string (optional) | '.' | Decimal separator |
Option key | Value | Default | Description |
---|---|---|---|
decimals | string (optional) | 0 | Number of decimals |
thousandSeparator | string (optional) | Thousand separator | |
decimalSeparator | string (optional) | '.' | Decimal separator |
import React from 'react';
import { getCurrencyDecimals } from '@opuscapita/format-utils';
export default function FormatUtilsExamples() {
return (
<p>
getCurrencyDecimals('EUR') = {getCurrencyDecimals('EUR')}
</p>
);
}
import React from 'react';
import FormatUtils from '@opuscapita/format-utils';
export default function FormatUtilsExamples() {
return (
<p>
FormatUtils.formatCurrencyAmount(432432.23423, { currency: 'EUR' }) = {FormatUtils.formatCurrencyAmount(432432.23423, { currency: 'EUR' })}
</p>
<p>
FormatUtils.formatFloatToFixedDecimals(1234.12345, 2) = {FormatUtils.formatFloatToFixedDecimals(1234.12345, 2)}
</p>
);
}
FAQs
OpusCapita JS formatting utilities
We found that @opuscapita/format-utils demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 27 open source maintainers collaborating on the project.
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.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.