UNPKG

965 BJavaScriptView Raw
1import convert from './convert.js';
2export default class Cashify {
3 /**
4 * @constructor
5 * @param {Object} [options] Conversion options.
6 */
7 constructor(options) {
8 Object.defineProperty(this, "options", {
9 enumerable: true,
10 configurable: true,
11 writable: true,
12 value: options
13 });
14 }
15 /**
16 * Function, which converts currencies based on provided rates.
17 *
18 * @param {number | string} amount - Amount of money you want to convert.
19 * @param {Object} [options] - Conversion options.
20 * @return {number} Conversion result.
21 *
22 * @example
23 * const rates = {
24 * GBP: 0.92,
25 * EUR: 1.00,
26 * USD: 1.12
27 * };
28 *
29 * const cashify = new Cashify({base: 'EUR', rates});
30 *
31 * cashify.convert(10, {from: 'EUR', to: 'GBP'}); //=> 9.2
32 */
33 convert(amount, options) {
34 return convert(amount, { ...this.options, ...options });
35 }
36}