UNPKG

@eastsideco/escshopify

Version:

WIP JS library for Shopify, containing a variety of useful functionality.

40 lines (36 loc) 1.53 kB
import Money from 'js-money'; /** Config*/ class Config { /** * Construct a new config. * @param {Object} options - Properties to initialze on config. */ constructor(options) { options = Object.assign({}, { defaultCurrency: 'USD', useGeoForCurrency: true, moneySpanSelectors: [ '[data-money]' ], moneySpanParser: function(el, easyCurrency) { var amount = el.dataset.money; var currency = el.dataset.moneyCurrency || easyCurrency._config.defaultCurrency; delete el.dataset.money; delete el.dataset.moneyCurrency; amount = Number(amount); return new Money(amount, currency); }, allowedCurrencies: 'any', }, options); /** @type {String} Currency code, used for initial currency. */ this.defaultCurrency = options.defaultCurrency; /** @type {Boolean} If true, currency will be determined via geoservice on load. */ this.useGeoForCurrency = options.useGeoForCurrency; /** @type {String[]} Array of CSS selectors for finding money spans */ this.moneySpanSelectors = options.moneySpanSelectors; /** @type {function(el: DOMNode, easyCurrency: src/easycurrency/main.js~EasyCurrency): js-money} Callback which determines initial money span value. */ this.moneySpanParser = options.moneySpanParser; } } /** @ignore */ export default new Config();