feathers-utils 2.1.2 → 2.1.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/dist/index.cjs CHANGED
@@ -16,7 +16,7 @@ const _debounce = require('lodash/debounce.js');
16
16
  const _isObject = require('lodash/isObject.js');
17
17
 
18
18
  function mergeArrays(targetArr, sourceArr, handle, prependKey, actionOnEmptyIntersect) {
19
- if (!sourceArr || !targetArr) {
19
+ if (!sourceArr && !targetArr) {
20
20
  return;
21
21
  }
22
22
  if (handle === "target") {
@@ -33,9 +33,9 @@ function mergeArrays(targetArr, sourceArr, handle, prependKey, actionOnEmptyInte
33
33
  const arr = targetArr.concat(sourceArr);
34
34
  return [...new Set(arr)];
35
35
  } else if (handle === "intersect" || handle === "intersectOrFull") {
36
- const targetIsArray = !targetArr || !Array.isArray(targetArr);
37
- const sourceIsArray = !sourceArr || !Array.isArray(sourceArr);
38
- if ((targetIsArray || sourceIsArray) && handle === "intersect") {
36
+ const targetIsNotArray = !targetArr || !Array.isArray(targetArr);
37
+ const sourceIsNotArray = !sourceArr || !Array.isArray(sourceArr);
38
+ if ((targetIsNotArray || sourceIsNotArray) && handle === "intersect") {
39
39
  if (actionOnEmptyIntersect) {
40
40
  actionOnEmptyIntersect(
41
41
  targetArr,
@@ -45,8 +45,8 @@ function mergeArrays(targetArr, sourceArr, handle, prependKey, actionOnEmptyInte
45
45
  }
46
46
  return;
47
47
  }
48
- if (handle === "intersectOrFull") {
49
- const val = !targetIsArray ? targetArr : sourceArr;
48
+ if (targetIsNotArray || sourceIsNotArray) {
49
+ const val = !targetIsNotArray ? targetArr : sourceArr;
50
50
  return val;
51
51
  }
52
52
  return targetArr.filter((val) => sourceArr.includes(val));
package/dist/index.mjs CHANGED
@@ -14,7 +14,7 @@ import _debounce from 'lodash/debounce.js';
14
14
  import _isObject from 'lodash/isObject.js';
15
15
 
16
16
  function mergeArrays(targetArr, sourceArr, handle, prependKey, actionOnEmptyIntersect) {
17
- if (!sourceArr || !targetArr) {
17
+ if (!sourceArr && !targetArr) {
18
18
  return;
19
19
  }
20
20
  if (handle === "target") {
@@ -31,9 +31,9 @@ function mergeArrays(targetArr, sourceArr, handle, prependKey, actionOnEmptyInte
31
31
  const arr = targetArr.concat(sourceArr);
32
32
  return [...new Set(arr)];
33
33
  } else if (handle === "intersect" || handle === "intersectOrFull") {
34
- const targetIsArray = !targetArr || !Array.isArray(targetArr);
35
- const sourceIsArray = !sourceArr || !Array.isArray(sourceArr);
36
- if ((targetIsArray || sourceIsArray) && handle === "intersect") {
34
+ const targetIsNotArray = !targetArr || !Array.isArray(targetArr);
35
+ const sourceIsNotArray = !sourceArr || !Array.isArray(sourceArr);
36
+ if ((targetIsNotArray || sourceIsNotArray) && handle === "intersect") {
37
37
  if (actionOnEmptyIntersect) {
38
38
  actionOnEmptyIntersect(
39
39
  targetArr,
@@ -43,8 +43,8 @@ function mergeArrays(targetArr, sourceArr, handle, prependKey, actionOnEmptyInte
43
43
  }
44
44
  return;
45
45
  }
46
- if (handle === "intersectOrFull") {
47
- const val = !targetIsArray ? targetArr : sourceArr;
46
+ if (targetIsNotArray || sourceIsNotArray) {
47
+ const val = !targetIsNotArray ? targetArr : sourceArr;
48
48
  return val;
49
49
  }
50
50
  return targetArr.filter((val) => sourceArr.includes(val));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feathers-utils",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
4
4
  "description": "Some utils for projects using '@feathersjs/feathers'",
5
5
  "author": "fratzinger",
6
6
  "repository": {
@@ -8,7 +8,7 @@ export function mergeArrays<T>(
8
8
  prependKey?: Path,
9
9
  actionOnEmptyIntersect?: ActionOnEmptyIntersect
10
10
  ): T[] | undefined {
11
- if (!sourceArr || !targetArr) {
11
+ if (!sourceArr && !targetArr) {
12
12
  return;
13
13
  }
14
14
  if (handle === "target") {
@@ -25,10 +25,10 @@ export function mergeArrays<T>(
25
25
  const arr = targetArr.concat(sourceArr);
26
26
  return [...new Set(arr)];
27
27
  } else if (handle === "intersect" || handle === "intersectOrFull") {
28
- const targetIsArray = !targetArr || !Array.isArray(targetArr);
29
- const sourceIsArray = !sourceArr || !Array.isArray(sourceArr);
28
+ const targetIsNotArray = !targetArr || !Array.isArray(targetArr);
29
+ const sourceIsNotArray = !sourceArr || !Array.isArray(sourceArr);
30
30
 
31
- if ((targetIsArray || sourceIsArray) && handle === "intersect") {
31
+ if ((targetIsNotArray || sourceIsNotArray) && handle === "intersect") {
32
32
  if (actionOnEmptyIntersect) {
33
33
  actionOnEmptyIntersect(
34
34
  targetArr as unknown,
@@ -39,12 +39,12 @@ export function mergeArrays<T>(
39
39
  return;
40
40
  }
41
41
 
42
- if (handle === "intersectOrFull") {
43
- const val = !targetIsArray ? targetArr : sourceArr;
42
+ if (targetIsNotArray || sourceIsNotArray) {
43
+ const val = !targetIsNotArray ? targetArr : sourceArr;
44
44
  return val;
45
45
  }
46
46
 
47
- return targetArr.filter((val) => sourceArr.includes(val));
47
+ return targetArr!.filter((val) => sourceArr!.includes(val));
48
48
  }
49
49
  return undefined;
50
50
  }