Skip to content

Commit

Permalink
Define isFirstPathPartUndefined
Browse files Browse the repository at this point in the history
There is a repeated code fragment for checking if the first path part is undefined that we should refactor.
  • Loading branch information
danieljbruce committed Sep 28, 2023
1 parent 377770b commit df3f376
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,8 @@ export namespace entity {
const splitPath = path.split(delimiter);
const firstPathPart = splitPath.shift()!;
const remainderPath = splitPath.join(delimiter).replace(/^(\.|\[\])/, '');
const isFirstPathPartUndefined =
entity.properties![firstPathPart] !== undefined;

if (
!(entity.properties && entity.properties[firstPathPart]) &&
Expand All @@ -855,7 +857,7 @@ export namespace entity {
if (
firstPathPartIsArray &&
// check also if the property in question is actually an array value.
entity.properties![firstPathPart] !== undefined &&
isFirstPathPartUndefined &&
entity.properties![firstPathPart].arrayValue &&
// check if wildcard is not applied
!hasWildCard
Expand Down Expand Up @@ -884,7 +886,7 @@ export namespace entity {
firstPathPartIsArray &&
hasWildCard &&
remainderPath === '*' &&
entity.properties![firstPathPart] !== undefined
isFirstPathPartUndefined
) {
const array = entity.properties![firstPathPart].arrayValue;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -907,7 +909,7 @@ export namespace entity {
if (
hasWildCard &&
remainderPath === '*' &&
entity.properties![firstPathPart] !== undefined
isFirstPathPartUndefined
) {
const parentEntity = entity.properties![firstPathPart].entityValue;

Expand All @@ -921,7 +923,7 @@ export namespace entity {
} else {
excludePathFromEntity(entity, firstPathPart);
}
} else if (entity.properties![firstPathPart] !== undefined) {
} else if (isFirstPathPartUndefined) {
const parentEntity = entity.properties![firstPathPart].entityValue;
excludePathFromEntity(parentEntity, remainderPath);
}
Expand Down

0 comments on commit df3f376

Please sign in to comment.