Skip to content

Commit

Permalink
patch(n4s): replace array with counter in oneOf
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Jun 14, 2022
1 parent 28db6c7 commit 555bf85
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/n4s/src/plugins/compounds/oneOf.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { equals } from 'equals';
import type { Lazy } from 'genEnforceLazy';
import { lengthEquals } from 'lengthEquals';
import { longerThan } from 'longerThan';
import { greaterThan } from 'greaterThan';
import ruleReturn, { RuleDetailedResult } from 'ruleReturn';
import runLazyRule from 'runLazyRule';

const REQUIRED_COUNT = 1;

export function oneOf(value: unknown, ...rules: Lazy[]): RuleDetailedResult {
const passing: RuleDetailedResult[] = [];
let passingCount = 0;
rules.some(rule => {
const res = runLazyRule(rule, value);

if (res.pass) {
passing.push(res);
passingCount++;
}

if (longerThan(passing, REQUIRED_COUNT)) {
if (greaterThan(passingCount, REQUIRED_COUNT)) {
return false;
}
});

return ruleReturn(lengthEquals(passing, REQUIRED_COUNT));
return ruleReturn(equals(passingCount, REQUIRED_COUNT));
}

1 comment on commit 555bf85

@vercel
Copy link

@vercel vercel bot commented on 555bf85 Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

vest-next – ./website

vest-next-ealush.vercel.app
vest-next.vercel.app
vest-next-git-latest-ealush.vercel.app
vest-website.vercel.app

Please sign in to comment.