@8ms/helpers 1.5.1 → 1.5.3
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/number/format.d.ts +11 -0
- package/number/format.js +23 -0
- package/number/getDivide.js +6 -2
- package/number/getPercentIncrease.d.ts +6 -5
- package/number/getPercentIncrease.js +6 -2
- package/package.json +1 -2
- package/swr/isData.js +3 -1
- package/swr/isError.js +1 -1
- package/number/getPercent.d.ts +0 -9
- package/number/getPercent.js +0 -18
- package/number/getRounded.d.ts +0 -9
- package/number/getRounded.js +0 -22
package/number/format.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const getNumber_1 = __importDefault(require("./getNumber"));
|
|
7
|
+
/**
|
|
8
|
+
* Take a given number and format it.
|
|
9
|
+
*/
|
|
10
|
+
const format = (props) => {
|
|
11
|
+
const inputValue = (0, getNumber_1.default)({
|
|
12
|
+
input: props.input,
|
|
13
|
+
});
|
|
14
|
+
const options = {
|
|
15
|
+
minimumFractionDigits: undefined !== props?.minDp ? props?.minDp : 0,
|
|
16
|
+
maximumFractionDigits: undefined !== props?.maxDp ? props?.maxDp : 2,
|
|
17
|
+
notation: true === props?.compact ? "compact" : "standard",
|
|
18
|
+
};
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
return Intl.NumberFormat('en-GB', options)
|
|
21
|
+
.format(inputValue);
|
|
22
|
+
};
|
|
23
|
+
exports.default = format;
|
package/number/getDivide.js
CHANGED
|
@@ -8,8 +8,12 @@ const getNumber_1 = __importDefault(require("./getNumber"));
|
|
|
8
8
|
* Shorthand function to divide number, but fallback if the divisor is 0.
|
|
9
9
|
*/
|
|
10
10
|
const getDivide = ({ defaultValue = 0, divisor, numerator }) => {
|
|
11
|
-
const numeratorInt = (0, getNumber_1.default)({
|
|
12
|
-
|
|
11
|
+
const numeratorInt = (0, getNumber_1.default)({
|
|
12
|
+
input: numerator
|
|
13
|
+
});
|
|
14
|
+
const divisorInt = (0, getNumber_1.default)({
|
|
15
|
+
input: divisor
|
|
16
|
+
});
|
|
13
17
|
if (0 === divisorInt) {
|
|
14
18
|
return defaultValue;
|
|
15
19
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
* Formula to work out the percentage increase/decrease.
|
|
3
|
-
*/
|
|
4
|
-
declare const getPercentageIncrease: ({ comparison, current, defaultValue }: {
|
|
1
|
+
type GetPercentageIncrease = {
|
|
5
2
|
comparison: any;
|
|
6
3
|
current: any;
|
|
7
4
|
defaultValue: number;
|
|
8
|
-
}
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Formula to work out the percentage increase/decrease.
|
|
8
|
+
*/
|
|
9
|
+
declare const getPercentageIncrease: ({ comparison, current, defaultValue }: GetPercentageIncrease) => number;
|
|
9
10
|
export default getPercentageIncrease;
|
|
@@ -8,8 +8,12 @@ const getNumber_1 = __importDefault(require("./getNumber"));
|
|
|
8
8
|
* Formula to work out the percentage increase/decrease.
|
|
9
9
|
*/
|
|
10
10
|
const getPercentageIncrease = ({ comparison, current, defaultValue }) => {
|
|
11
|
-
const currentValue = (0, getNumber_1.default)({
|
|
12
|
-
|
|
11
|
+
const currentValue = (0, getNumber_1.default)({
|
|
12
|
+
input: current
|
|
13
|
+
});
|
|
14
|
+
const comparisonValue = (0, getNumber_1.default)({
|
|
15
|
+
input: comparison
|
|
16
|
+
});
|
|
13
17
|
if (0 === comparisonValue) {
|
|
14
18
|
return defaultValue;
|
|
15
19
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@8ms/helpers",
|
|
3
3
|
"license": "UNLICENSED",
|
|
4
|
-
"version": "1.5.
|
|
4
|
+
"version": "1.5.3",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
|
|
@@ -38,7 +38,6 @@
|
|
|
38
38
|
"babel-jest": "29.6.3",
|
|
39
39
|
"jest": "29.6.3",
|
|
40
40
|
"node-fetch": "3.3.2",
|
|
41
|
-
"numbro": "2.3.6",
|
|
42
41
|
"timezone-mock": "1.3.6",
|
|
43
42
|
"ts-node": "10.9.1",
|
|
44
43
|
"tslib": "2.6.2",
|
package/swr/isData.js
CHANGED
|
@@ -3,5 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
/**
|
|
4
4
|
* Check to see if a single SWR has an error.
|
|
5
5
|
*/
|
|
6
|
-
const isData = ({ swr }) => undefined === swr.error
|
|
6
|
+
const isData = ({ swr }) => (undefined === swr.error || null === swr.error) &&
|
|
7
|
+
undefined !== swr.data &&
|
|
8
|
+
'undefined' !== swr.data;
|
|
7
9
|
exports.default = isData;
|
package/swr/isError.js
CHANGED
|
@@ -3,5 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
/**
|
|
4
4
|
* Check to see if a single SWR has an error.
|
|
5
5
|
*/
|
|
6
|
-
const isError = ({ swr }) => undefined !== swr.error;
|
|
6
|
+
const isError = ({ swr }) => undefined !== swr.error && null !== swr.error;
|
|
7
7
|
exports.default = isError;
|
package/number/getPercent.d.ts
DELETED
package/number/getPercent.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const getNumber_1 = __importDefault(require("./getNumber"));
|
|
7
|
-
/**
|
|
8
|
-
* Get the percentage of two numbers.
|
|
9
|
-
*/
|
|
10
|
-
const getPercent = ({ defaultValue = 0, divisor, value }) => {
|
|
11
|
-
const cleanValue = (0, getNumber_1.default)({ input: value });
|
|
12
|
-
const cleanDivisor = (0, getNumber_1.default)({ input: divisor });
|
|
13
|
-
if (0 === cleanDivisor) {
|
|
14
|
-
return defaultValue;
|
|
15
|
-
}
|
|
16
|
-
return cleanValue / cleanDivisor;
|
|
17
|
-
};
|
|
18
|
-
exports.default = getPercent;
|
package/number/getRounded.d.ts
DELETED
package/number/getRounded.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const getNumber_1 = __importDefault(require("./getNumber"));
|
|
7
|
-
/**
|
|
8
|
-
* Round a number using the Numbro library.
|
|
9
|
-
*/
|
|
10
|
-
const getRounded = ({ decimalPlaces, input }) => {
|
|
11
|
-
const numbro = require('numbro');
|
|
12
|
-
const inputNumber = (0, getNumber_1.default)({ defaultValue: 0, input });
|
|
13
|
-
const stringNumber = numbro(inputNumber)
|
|
14
|
-
.format({
|
|
15
|
-
average: false,
|
|
16
|
-
mantissa: decimalPlaces,
|
|
17
|
-
thousandSeparated: false,
|
|
18
|
-
trimMantissa: true,
|
|
19
|
-
});
|
|
20
|
-
return Number(stringNumber);
|
|
21
|
-
};
|
|
22
|
-
exports.default = getRounded;
|