@driveflux/format-money 6.0.0 → 6.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/config.js CHANGED
@@ -1,20 +1,19 @@
1
1
  import { singleton } from '@driveflux/singleton';
2
- var getConfig = function() {
3
- return {
4
- defaultFormat: {
5
- currency: 'MYR',
6
- currencyDisplay: 'narrowSymbol',
7
- maximumFractionDigits: 2,
8
- minimumFractionDigits: 2
9
- },
10
- defaultLocale: 'en-MY'
11
- };
12
- };
13
- export var config = singleton('formatMoneyConfig', getConfig());
14
- export var resetConfig = function() {
2
+ const getConfig = () => ({
3
+ defaultFormat: {
4
+ currency: 'MYR',
5
+ currencyDisplay: 'narrowSymbol',
6
+ maximumFractionDigits: 2,
7
+ minimumFractionDigits: 2,
8
+ },
9
+ defaultLocale: 'en-MY',
10
+ });
11
+ export let config = singleton('formatMoneyConfig', getConfig());
12
+ export const resetConfig = () => {
15
13
  config = singleton('formatMoneyConfig', getConfig(), true);
16
14
  return config;
17
15
  };
18
- export var setConfig = function(key, value) {
16
+ export const setConfig = (key, value) => {
19
17
  config[key] = value;
20
18
  };
19
+ //# sourceMappingURL=config.js.map
package/dist/index.js CHANGED
@@ -1,73 +1,18 @@
1
- function _define_property(obj, key, value) {
2
- if (key in obj) {
3
- Object.defineProperty(obj, key, {
4
- value: value,
5
- enumerable: true,
6
- configurable: true,
7
- writable: true
8
- });
9
- } else {
10
- obj[key] = value;
11
- }
12
- return obj;
13
- }
14
- function _object_spread(target) {
15
- for(var i = 1; i < arguments.length; i++){
16
- var source = arguments[i] != null ? arguments[i] : {};
17
- var ownKeys = Object.keys(source);
18
- if (typeof Object.getOwnPropertySymbols === "function") {
19
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
20
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
21
- }));
22
- }
23
- ownKeys.forEach(function(key) {
24
- _define_property(target, key, source[key]);
25
- });
26
- }
27
- return target;
28
- }
29
- function ownKeys(object, enumerableOnly) {
30
- var keys = Object.keys(object);
31
- if (Object.getOwnPropertySymbols) {
32
- var symbols = Object.getOwnPropertySymbols(object);
33
- if (enumerableOnly) {
34
- symbols = symbols.filter(function(sym) {
35
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
36
- });
37
- }
38
- keys.push.apply(keys, symbols);
39
- }
40
- return keys;
41
- }
42
- function _object_spread_props(target, source) {
43
- source = source != null ? source : {};
44
- if (Object.getOwnPropertyDescriptors) {
45
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
46
- } else {
47
- ownKeys(Object(source)).forEach(function(key) {
48
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
49
- });
50
- }
51
- return target;
52
- }
53
- function _type_of(obj) {
54
- "@swc/helpers - typeof";
55
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
56
- }
57
1
  import { config } from './config.js';
58
2
  /**
59
3
  * Formats the money object into a string
60
4
  * @param money
61
5
  * @param locales
62
- */ export function formatMoney(money, providedOptions) {
63
- var options = _object_spread({}, config.defaultFormat);
64
- var locale = config.defaultLocale;
6
+ */
7
+ export function formatMoney(money, providedOptions) {
8
+ const options = { ...config.defaultFormat };
9
+ let locale = config.defaultLocale;
65
10
  if (typeof providedOptions === 'string') {
66
11
  options.currency = providedOptions;
67
12
  }
68
- if ((typeof providedOptions === "undefined" ? "undefined" : _type_of(providedOptions)) === 'object' && providedOptions) {
69
- for(var k in providedOptions){
70
- var key = k;
13
+ if (typeof providedOptions === 'object' && providedOptions) {
14
+ for (const k in providedOptions) {
15
+ const key = k;
71
16
  if (key === 'locales') {
72
17
  locale = providedOptions[key];
73
18
  continue;
@@ -77,25 +22,28 @@ import { config } from './config.js';
77
22
  options[key] = providedOptions[key];
78
23
  }
79
24
  }
80
- return new Intl.NumberFormat(locale, _object_spread_props(_object_spread({}, options), {
81
- style: 'currency'
82
- })).format(money);
25
+ return new Intl.NumberFormat(locale, {
26
+ ...options,
27
+ style: 'currency',
28
+ }).format(money);
83
29
  }
84
30
  /** // TODO check if there are any instances using this function, update them then remove this
85
31
  * @deprecated use formatMoney instead
86
32
  * @returns
87
- */ export var formatMoneyWithFraction = formatMoney;
33
+ */
34
+ export const formatMoneyWithFraction = formatMoney;
88
35
  /**
89
36
  *
90
37
  * @param money
91
38
  * @param fraction cannot be less than 1
92
39
  * @returns
93
- */ export var decimals = function(money) {
94
- var fraction = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 2;
40
+ */
41
+ export const decimals = (money, fraction = 2) => {
95
42
  if (fraction < 1) {
96
43
  throw new Error('Fraction cannot be less than 1');
97
44
  }
98
- var m = +money;
99
- var safe = Number.isNaN(m) ? 0 : m;
100
- return Math.round(safe * Math.pow(10, fraction)) / Math.pow(10, fraction);
45
+ const m = +money;
46
+ const safe = Number.isNaN(m) ? 0 : m;
47
+ return Math.round(safe * 10 ** fraction) / 10 ** fraction;
101
48
  };
49
+ //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@driveflux/format-money",
3
- "version": "6.0.0",
3
+ "version": "6.0.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./package.json": "./package.json",
@@ -13,11 +13,11 @@
13
13
  "dist"
14
14
  ],
15
15
  "dependencies": {
16
- "@driveflux/singleton": "2.0.0"
16
+ "@driveflux/singleton": "2.0.2"
17
17
  },
18
18
  "devDependencies": {
19
- "@driveflux/fab": "3.0.0",
20
- "@driveflux/tsconfig": "2.0.0",
19
+ "@driveflux/fab": "3.0.2",
20
+ "@driveflux/tsconfig": "2.0.2",
21
21
  "@types/node": "^22.15.16",
22
22
  "del-cli": "^6.0.0",
23
23
  "typescript": "^5.8.3"