Skip to content

Commit

Permalink
perf: undefinedChecks
Browse files Browse the repository at this point in the history
  • Loading branch information
jy95 committed May 2, 2024
1 parent eb93157 commit 64381ee
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/translators/countCountMax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { extractTimingRepeat } from "../internal/extractTimingRepeat";
import {
isNotUndefined,
noUndefinedInArray,
allUndefinedInArray,
} from "../internal/undefinedChecks";

// Types
Expand All @@ -24,7 +25,7 @@ export function transformCountCountMaxToText({
let countMax = repeat.countMax;

// Do nothing if no count, I am not a wizard
if (count === undefined && countMax === undefined) {
if (allUndefinedInArray(count, countMax)) {
return undefined;
}

Expand Down
3 changes: 2 additions & 1 deletion src/translators/frequencyFrequencyMax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { extractTimingRepeat } from "../internal/extractTimingRepeat";
import {
isNotUndefined,
noUndefinedInArray,
allUndefinedInArray,
} from "../internal/undefinedChecks";

// Types
Expand All @@ -24,7 +25,7 @@ export function transformFrequencyFrequencyMaxToText({
let max = repeat.frequencyMax;

// Do nothing if no frequency / frequencyMax, I am not a wizard
if (frequency === undefined && max === undefined) {
if (allUndefinedInArray(frequency, max)) {
return undefined;
}

Expand Down
5 changes: 3 additions & 2 deletions src/translators/offsetWhen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { fromListToString } from "../utils/fromListToString";
import { extractTimingRepeat } from "../internal/extractTimingRepeat";
import { isArrayEmpty } from "../internal/isEmptyArray";
import { isNotUndefined } from "../internal/undefinedChecks";

// Types
import type { DisplayOrderParams, I18N } from "../types";
Expand Down Expand Up @@ -46,7 +47,7 @@ function extractTime(minutes: number) {

// Function to transform offset into a string
function transformOffset(i18next: I18N, offset?: number): string | undefined {
if (offset === undefined || offset <= 0) {
if (!isNotUndefined(offset) || offset <= 0) {
return undefined;
}

Expand Down Expand Up @@ -93,7 +94,7 @@ export function transformOffsetWhenToText({
let repeat = extractTimingRepeat(dos);

// If empty, return undefined
if (repeat === undefined) {
if (!isNotUndefined(repeat)) {
return undefined;
}

Expand Down

0 comments on commit 64381ee

Please sign in to comment.