Home Manual Reference Source Repository
private class | source

EasyCurrency

Extends:

evee → EasyCurrency

Plugin for automatic currency conversion, tax handling, etc.

Constructor Summary

Public Constructor
public

Creates a new instance of EasyCurrency.

Member Summary

Public Members
public
Private Members
private
private
private
private
private
private

Method Summary

Public Methods
public

async addTax(amount: js-money | Number): Promise<js-money>

Adds the current tax rate to the given amount

public

async convert(amount: js-money | Number, to: String, from: null | String): Promise<js-money>

Convert an amount to another currency.

public

format(amount: js-money | Number, currency: String | null): String

Format a value as a currency

public

Returns the active currency.

public

Returns the available currency codes.

public

Returns the current state.

public

initialize(config: Object | Config)

Start running EasyCurrency on the current page.

public

parse()

Attempts to find new money spans on the page.

public

render()

Forces all money spans to re-render.

public

Sets the active currency, and refreshs any money spans.

public

Overrides the default currency resolver, which provides information about the available currencies.

public

setFormatter(formatter: Formatter)

Overrides the default formatter.

public

setTaxRate(taxRate: type)

Sets the current tax rate.

public

Uses a default GeoserviceResolver as the currency resolver.

Private Methods
private

_processElement(el: DOMNode)

Public Constructors

public constructor() source

Creates a new instance of EasyCurrency. This class is intended to be used as a singleton, and has global side-effects - do not create multiple instances.

Public Members

public selectHelper: SelectHelper source

Private Members

private _config: Config source

private _formatter: Formatter source

private _moneySpanSet: MoneySpanSet source

private _resolver: CurrencyResolver source

private _session: Session source

private _state: State source

Public Methods

public async addTax(amount: js-money | Number): Promise<js-money> source

Adds the current tax rate to the given amount

Params:

NameTypeAttributeDescription
amount js-money | Number

Return:

Promise<js-money>

public async convert(amount: js-money | Number, to: String, from: null | String): Promise<js-money> source

Convert an amount to another currency.

Params:

NameTypeAttributeDescription
amount js-money | Number
to String
  • optional

If null, uses current currency

from null | String
  • optional

Ignored if amount is a Money object.

Return:

Promise<js-money>

public format(amount: js-money | Number, currency: String | null): String source

Format a value as a currency

Params:

NameTypeAttributeDescription
amount js-money | Number
currency String | null
  • optional

If null, uses current currency.

Return:

String

public getActiveCurrency(): String source

Returns the active currency.

Return:

String

public async getAvailableCurrencies(): String[] source

Returns the available currency codes.

Return:

String[]

public getState(): State source

Returns the current state.

Return:

State

public initialize(config: Object | Config) source

Start running EasyCurrency on the current page.

Params:

NameTypeAttributeDescription
config Object | Config

Emit:

Object

beforeInitialize(config)

Object

initialize(config)

public parse() source

Attempts to find new money spans on the page. Change moneySpanSelectors / moneySpanParser config options to modify how money spans are parsed.

Emit:

null

beforeParse

null

parse

public render() source

Forces all money spans to re-render.

Emit:

null

beforeRender

null

render

public setActiveCurrency(currency: String) source

Sets the active currency, and refreshs any money spans.

Params:

NameTypeAttributeDescription
currency String

Currency code

Emit:

String

beforeCurrencyChanged(currency)

String

currencyChanged(currency)

public setCurrencyResolver(resolver: CurrencyResolver) source

Overrides the default currency resolver, which provides information about the available currencies.

Params:

NameTypeAttributeDescription
resolver CurrencyResolver

Emit:

CurrencyResolver

currencyResolverChanged(resolver)

public setFormatter(formatter: Formatter) source

Overrides the default formatter.

Params:

NameTypeAttributeDescription
formatter Formatter

Emit:

Formatter

formatterChanged(formatter)

public setTaxRate(taxRate: type) source

Sets the current tax rate.

Params:

NameTypeAttributeDescription
taxRate type

Tax rate as a decimal percentage (i.e. 20% = 0.2)

Emit:

null

beforeChangeTaxRate

null

taxRateChanged

public useGeoserviceResolver() source

Uses a default GeoserviceResolver as the currency resolver.

Private Methods

private _processElement(el: DOMNode) source

Params:

NameTypeAttributeDescription
el DOMNode

Element to process