@8ms/helpers 1.1.110 → 1.1.112

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.
@@ -10,9 +10,9 @@ const getNumber_1 = __importDefault(require("./getNumber"));
10
10
  const getPercentageIncrease = ({ comparison, current, defaultValue }) => {
11
11
  const currentValue = (0, getNumber_1.default)({ input: current });
12
12
  const comparisonValue = (0, getNumber_1.default)({ input: comparison });
13
- if (0 === currentValue) {
13
+ if (0 === comparisonValue) {
14
14
  return defaultValue;
15
15
  }
16
- return (currentValue - comparisonValue) / currentValue * 100;
16
+ return (currentValue - comparisonValue) / comparisonValue * 100;
17
17
  };
18
18
  exports.default = getPercentageIncrease;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "1.1.110",
4
+ "version": "1.1.112",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
package/util/defaultTo.js CHANGED
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const isObject_1 = __importDefault(require("lodash/isObject"));
6
7
  const getArray_1 = __importDefault(require("../array/getArray"));
7
8
  /**
8
9
  * Function to default to a value, whilst filtering through an instance
@@ -11,8 +12,8 @@ const defaultTo = ({ defaultValue, instance, keys }) => {
11
12
  const keysArray = (0, getArray_1.default)({ input: keys });
12
13
  let found = true;
13
14
  let pointer = instance;
14
- // Instance is undefined
15
- if (undefined === instance) {
15
+ // Instance is undefined or is null
16
+ if (undefined === instance || null === pointer) {
16
17
  found = false;
17
18
  }
18
19
  // Instance exists
@@ -20,12 +21,17 @@ const defaultTo = ({ defaultValue, instance, keys }) => {
20
21
  keysArray.forEach(key => {
21
22
  if (found) {
22
23
  // Sub key doesn't exist
23
- if (undefined === pointer[key]) {
24
- found = false;
24
+ if ((0, isObject_1.default)(pointer)) {
25
+ if (undefined === pointer[key] || null === pointer[key]) {
26
+ found = false;
27
+ }
28
+ // Sub key exists, update pointer
29
+ else {
30
+ pointer = pointer[key];
31
+ }
25
32
  }
26
- // Sub key exists, update pointer
27
33
  else {
28
- pointer = pointer[key];
34
+ found = false;
29
35
  }
30
36
  }
31
37
  });