Home Manual Reference Source Repository

src/plugins/easycurrency/config.js

  1. import Money from 'js-money';
  2.  
  3. /** Config*/
  4. class Config {
  5. /**
  6. * Construct a new config.
  7. * @param {Object} options - Properties to initialze on config.
  8. */
  9. constructor(options) {
  10. options = Object.assign({}, {
  11. defaultCurrency: 'USD',
  12. useGeoForCurrency: true,
  13. moneySpanSelectors: [
  14. '[data-money]'
  15. ],
  16. moneySpanParser: function(el, easyCurrency) {
  17. var amount = el.dataset.money;
  18. var currency = el.dataset.moneyCurrency || easyCurrency._config.defaultCurrency;
  19. delete el.dataset.money;
  20. delete el.dataset.moneyCurrency;
  21. amount = Number(amount);
  22. return new Money(amount, currency);
  23. },
  24. allowedCurrencies: 'any',
  25. }, options);
  26.  
  27. /** @type {String} Currency code, used for initial currency. */
  28. this.defaultCurrency = options.defaultCurrency;
  29. /** @type {Boolean} If true, currency will be determined via geoservice on load. */
  30. this.useGeoForCurrency = options.useGeoForCurrency;
  31. /** @type {String[]} Array of CSS selectors for finding money spans */
  32. this.moneySpanSelectors = options.moneySpanSelectors;
  33. /** @type {function(el: DOMNode, easyCurrency: src/easycurrency/main.js~EasyCurrency): js-money} Callback which determines initial money span value. */
  34. this.moneySpanParser = options.moneySpanParser;
  35. }
  36. }
  37.  
  38. /** @ignore */
  39. export default new Config();