Skip to content

Commit

Permalink
updating naming
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar committed Mar 15, 2022
1 parent ce05394 commit 4727a77
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/plugins/expressions/common/util/get_by_alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,29 @@

export const ALL_NAMESPACES = '*';

export function getByAlias<T extends { name?: string; aliases?: string[]; namespace?: string }>(
interface Node {
name?: string;
aliases?: string[];
namespace?: string;
}

export function getByAlias<T extends Node>(
node: T[] | Record<string, T>,
nodeName: string,
nameSpace?: string
nodeNamespace?: string
): T | undefined {
const lowerCaseName = nodeName.toLowerCase();
return Object.values(node).find(({ name, aliases, namespace }) => {
if (!name) return false;
if (name.toLowerCase() === lowerCaseName) {
if (!namespace || nameSpace === ALL_NAMESPACES || namespace === nameSpace) return true;
if (!namespace || nodeNamespace === ALL_NAMESPACES || namespace === nodeNamespace) {
return true;
}
}
return (aliases || []).some((alias) => {
return (
alias.toLowerCase() === lowerCaseName &&
(!namespace || nameSpace === ALL_NAMESPACES || namespace === nameSpace)
(!namespace || nodeNamespace === ALL_NAMESPACES || namespace === nodeNamespace)
);
});
});
Expand Down

0 comments on commit 4727a77

Please sign in to comment.