@ecomplus/utils
Version:
JS utility functions to E-Com Plus (not only) related apps
39 lines • 1.4 kB
TypeScript
export default formatMoney;
/**
* @method
* @memberof ecomUtils
* @name formatMoney
* @description Parse price number to formatted currency string.
* @param {number|Object.<string, *>} value - Price number or body object (product or variation)
* @param {string|null} [currency=$ecomConfig.get('currency')] - Currency code such as 'BRL'
* @param {string} [lang=$ecomConfig.get('lang')] - Snake case language code, eg.: 'en_us', 'pt_br'
* @returns {string}
*
* @example
* // With number as value
* ecomUtils.formatMoney(10.6)
* // => $10.60
* ecomUtils.formatMoney(10.6, 'BRL')
* // => R$10.60
* ecomUtils.formatMoney(10.6, 'BRL', 'pt_br')
* // => R$ 10,60
*
* @example
* // With product, variation or cart item object as value
* // Full object ref.: https://developers.e-com.plus/docs/api/#/store/products/
* ecomUtils.formatMoney({ sku: 'TEST', name: 'Test', price: 140.56 })
* // => $140.56
*
* @example
* // You can also set the configured lang and currency first
* $ecomConfig.set('lang', 'pt_br')
* $ecomConfig.set('currency', 'BRL')
* $ecomConfig.set('currency_symbol', 'R$')
* // Then call `formatMoney` without expliciting currency and lang
* ecomUtils.formatMoney(10.6)
* // => R$ 10,60
*/
declare function formatMoney(value: number | {
[x: string]: any;
}, currency?: string | null, lang?: string): string;
//# sourceMappingURL=format-money.d.ts.map