Documentation

BX.Currency.Core

ES6 extension for handling currencies and their formats.

BX.Currency.Core

Methods

Method Description Available from version
BX.Currency.Core.getCurrencyList(): CurrencyItem[] Static method. Returns internal list of currencies.
BX.Currency.Core.setCurrencyFormat(currency: string, format, replace: boolean): void Static method. Defines format for specific currency. Parameters:
  • currency - currency ID;
  • format - currency format as [link=11066464]CCurrencyLang::GetFormatDescription()[/link];
  • replace - rewrite format, if already defined.
BX.Currency.Core.setCurrencies(currencies: [], replace: boolean) Static method. Defines formats for several currencies simultaneously. Parameters:
  • currencies - list of currencies with formats. Each array element - object with two fields:
    • CURRENCY - currency ID;
    • FORMAT - format description as [link=11066464]CCurrencyLang::GetFormatDescription()[/link].
  • replace - rewrite format, if already defined.
BX.Currency.Core.getCurrencyFormat(currency: string) Static method. Returns currency format. Parameters:
  • currency - currency ID.
BX.Currency.Core.getCurrencyIndex(currency: string): number Static method. Returns currency position in an internal currency list. Parameters:
  • currency - currency ID.
BX.Currency.Core.getPriceControl(control: Element, currency: string) Static method. Allows formatting currency, by taking HTML-element as numerical value. Parameters:
  • control - the value that is inserted into string for currency format template as the number;
  • currency - currency ID.

Example:
the page has an element <h1 id="currency">3000</h1>:
const el = document.getElementById('currency');
CurrencyCore.getPriceControl(el, 'USD');
// returns string "<h1 id="currency">3000</h1> ₽"
22.500.0
BX.Currency.Core.clearCurrency(currency: string): number Static method. Deletes currency format by code from internal list (if available). Parameters:
  • currency - currency code.
BX.Currency.Core.clean() Static method. Clears internal list.
BX.Currency.Core.currencyFormat(price: number, currency: string, useTemplate: boolean) Static method. Formats the price. Parameters:
  • price - price value;
  • currency - currency ID;
  • useTemplate - use the template. Available values:
    • false - show price value only;
    • true - show fully formatted price.
BX.Currency.Core.loadCurrencyFormat(currency) Static method. Asynchronous format upload. Parameters:
  • currency - currency ID.

Example

example.js
import {CurrencyCore} from 'currency.currency-core';

export class Example
{
    constructor(currencyId: string)
    {
        this.currencyFormat = CurrencyCore.loadCurrencyFormat(currencyId);
    }
}



© «Bitrix24», 2001-2024
Up