Skip to content

Commit

Permalink
refactor: dedups uniq
Browse files Browse the repository at this point in the history
  • Loading branch information
sverweij committed Mar 21, 2024
1 parent e366da8 commit 5bb969f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 28 deletions.
17 changes: 7 additions & 10 deletions src/enrich/derive/folders/aggregate-to-folders.mjs
Expand Up @@ -10,6 +10,7 @@ import {
object2Array,
} from "./utl.mjs";
import IndexedModuleGraph from "#graph-utl/indexed-module-graph.mjs";
import { uniq } from "#utl/array-util.mjs";

function upsertCouplings(pAllDependents, pNewDependents) {
pNewDependents.forEach((pNewDependent) => {
Expand Down Expand Up @@ -53,13 +54,11 @@ function sumCounts(pAll, pCurrent) {
}

function getFolderLevelCouplings(pCouplingArray) {
return Array.from(
new Set(
pCouplingArray.map((pCoupling) =>
dirname(pCoupling.name) === "."
? pCoupling.name
: dirname(pCoupling.name),
),
return uniq(
pCouplingArray.map((pCoupling) =>
dirname(pCoupling.name) === "."
? pCoupling.name
: dirname(pCoupling.name),
),
).map((pCoupling) => ({ name: pCoupling }));
}
Expand Down Expand Up @@ -95,9 +94,7 @@ function deNormalizeInstability(pFolder, _, pAllFolders) {
}),
};
}
function uniq(pArray) {
return [...new Set(pArray)];
}

function getSinks(pFolders) {
const lKnownFolders = new Set(pFolders.map(({ name }) => name));
const lAllFolders = uniq(
Expand Down
14 changes: 6 additions & 8 deletions src/extract/resolve/merge-manifests.mjs
@@ -1,3 +1,5 @@
import { uniq } from "#utl/array-util.mjs";

/* eslint-disable security/detect-object-injection */
function normalizeManifestKeys(pManifest) {
let lReturnValue = pManifest;
Expand All @@ -19,9 +21,7 @@ function mergeDependencyKey(pClosestDependencyKey, pFurtherDependencyKey) {
}

function mergeDependencyArray(pClosestDependencyKey, pFurtherDependencyKey) {
return Array.from(
new Set(pClosestDependencyKey.concat(pFurtherDependencyKey)),
);
return uniq(pClosestDependencyKey.concat(pFurtherDependencyKey));
}

function isInterestingKey(pKey) {
Expand All @@ -35,11 +35,9 @@ function getDependencyKeys(pPackage) {
}

function getJointUniqueDependencyKeys(pClosestPackage, pFurtherPackage) {
return Array.from(
new Set(
getDependencyKeys(pClosestPackage).concat(
getDependencyKeys(pFurtherPackage),
),
return uniq(
getDependencyKeys(pClosestPackage).concat(
getDependencyKeys(pFurtherPackage),
),
);
}
Expand Down
9 changes: 3 additions & 6 deletions src/graph-utl/consolidate-module-dependencies.mjs
@@ -1,16 +1,13 @@
import reject from "lodash/reject.js";
import compare from "./compare.mjs";
import { uniq } from "#utl/array-util.mjs";

function mergeDependency(pLeftDependency, pRightDependency) {
return {
...pLeftDependency,
...pRightDependency,
dependencyTypes: Array.from(
new Set(
pLeftDependency.dependencyTypes.concat(
pRightDependency.dependencyTypes,
),
),
dependencyTypes: uniq(
pLeftDependency.dependencyTypes.concat(pRightDependency.dependencyTypes),
),
rules: pLeftDependency.rules
.concat(pRightDependency?.rules ?? [])
Expand Down
5 changes: 1 addition & 4 deletions src/main/options/normalize.mjs
@@ -1,14 +1,11 @@
/* eslint-disable security/detect-object-injection */
import { normalizeREProperties } from "../helpers.mjs";
import defaults from "./defaults.mjs";
import { uniq } from "#utl/array-util.mjs";

const DEFAULT_CACHE_FOLDER = "node_modules/.cache/dependency-cruiser";
const DEFAULT_CACHE_STRATEGY = "metadata";

function uniq(pArray) {
return [...new Set(pArray)];
}

function normalizeFilterOption(pFilterOption) {
let lReturnValue = pFilterOption || {};

Expand Down
4 changes: 4 additions & 0 deletions src/utl/array-util.mjs
Expand Up @@ -9,3 +9,7 @@
export function intersects(pLeftArray, pRightArray) {
return pLeftArray.some((pLeftItem) => pRightArray.includes(pLeftItem));
}

export function uniq(pArray) {
return [...new Set(pArray)];
}

0 comments on commit 5bb969f

Please sign in to comment.