@darkpos/utils 1.0.7 → 1.0.8
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/lib/hooks/useLocalization.js +8 -0
- package/lib/math.js +8 -9
- package/package.json +2 -2
|
@@ -44,5 +44,13 @@ module.exports = (settings = {}) => {
|
|
|
44
44
|
dateFormat,
|
|
45
45
|
hour12
|
|
46
46
|
),
|
|
47
|
+
getFormat: monthAndDateFormat => {
|
|
48
|
+
const date = monthAndDateFormat
|
|
49
|
+
? utils.monthAndDateFormatPattern(locale)
|
|
50
|
+
: utils.dateFormatPattern(locale);
|
|
51
|
+
let format = `${date}, HH:mm`;
|
|
52
|
+
if (hour12 === 'true') format += ' A';
|
|
53
|
+
return format;
|
|
54
|
+
},
|
|
47
55
|
};
|
|
48
56
|
};
|
package/lib/math.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
const Decimal = require('decimal.js');
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const getDefaultNumbers = numbers => {
|
|
4
|
+
if (!Array.isArray(numbers)) return [];
|
|
5
|
+
return numbers.map(num => num || 0);
|
|
6
|
+
};
|
|
7
|
+
|
|
4
8
|
const add = (...args) => {
|
|
5
9
|
if (!args || !Array.isArray(args) || !args.length)
|
|
6
10
|
throw new Error('Invalid argument');
|
|
7
11
|
|
|
8
|
-
const
|
|
12
|
+
const numbers = getDefaultNumbers(args);
|
|
13
|
+
const sum = numbers.reduce(
|
|
9
14
|
(acc, current) => acc.add(Decimal(current)),
|
|
10
15
|
Decimal(0)
|
|
11
16
|
);
|
|
12
17
|
|
|
13
|
-
// console.log('add =>', args, ' : ', sum);
|
|
14
18
|
return Decimal(sum.toFixed(2, 1)).toNumber();
|
|
15
19
|
};
|
|
16
20
|
|
|
@@ -19,18 +23,16 @@ const sub = (...args) => {
|
|
|
19
23
|
if (!args || !Array.isArray(args) || !args.length)
|
|
20
24
|
throw new Error('Invalid argument');
|
|
21
25
|
|
|
22
|
-
const numbers =
|
|
26
|
+
const numbers = getDefaultNumbers(args);
|
|
23
27
|
const first = numbers.shift();
|
|
24
28
|
const sum = numbers.reduce(
|
|
25
29
|
(acc, current) => acc.sub(Decimal(current)),
|
|
26
30
|
Decimal(first)
|
|
27
31
|
);
|
|
28
32
|
|
|
29
|
-
// console.log('sub =>', args, ' : ', sum);
|
|
30
33
|
return Decimal(sum.toFixed(2, 1)).toNumber();
|
|
31
34
|
};
|
|
32
35
|
|
|
33
|
-
//
|
|
34
36
|
const mul = (...args) => {
|
|
35
37
|
if (!args || !Array.isArray(args) || !args.length)
|
|
36
38
|
throw new Error('Invalid argument');
|
|
@@ -40,11 +42,9 @@ const mul = (...args) => {
|
|
|
40
42
|
Decimal(1)
|
|
41
43
|
);
|
|
42
44
|
|
|
43
|
-
// console.log('mul =>', args, ' : ', sum);
|
|
44
45
|
return Decimal(sum.toFixed(2, 1)).toNumber();
|
|
45
46
|
};
|
|
46
47
|
|
|
47
|
-
//
|
|
48
48
|
const div = (...args) => {
|
|
49
49
|
if (!args || !Array.isArray(args) || !args.length)
|
|
50
50
|
throw new Error('Invalid argument');
|
|
@@ -56,7 +56,6 @@ const div = (...args) => {
|
|
|
56
56
|
Decimal(first)
|
|
57
57
|
);
|
|
58
58
|
|
|
59
|
-
// console.log('div =>', args, ' : ', sum);
|
|
60
59
|
return Decimal(sum.toFixed(2, 1)).toNumber();
|
|
61
60
|
};
|
|
62
61
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darkpos/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "General purpose utilities",
|
|
5
5
|
"author": "Dark POS",
|
|
6
6
|
"homepage": "https://gitlab.com/darkpos/packages/dark#readme",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"eslint-plugin-prettier": "^4.0.0",
|
|
40
40
|
"prettier": "^2.7.0"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "1c4565d3c097c833093794654d8adc18e37767b9"
|
|
43
43
|
}
|