-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved predicate clarity and flexibility
- Loading branch information
Showing
7 changed files
with
1,168 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { IfProps } from './types'; | ||
|
||
export function resolveCondition(props: IfProps): boolean { | ||
if ('true' in props) return !!props.true; | ||
else if ('not' in props) return !props.not; | ||
else if ('val' in props) { | ||
if ('is' in props) return props.val === props.is; | ||
else if ('isNot' in props) return props.val !== props.isNot; | ||
else if ('above' in props) return (props.val as number) > props.above; | ||
else if ('below' in props) return (props.val as number) < props.below; | ||
else if ('atLeast' in props) return (props.val as number) >= props.atLeast; | ||
else if ('atMost' in props) return (props.val as number) <= props.atMost; | ||
} else if ('lengthOf' in props) { | ||
if ('is' in props) return props.lengthOf.length === props.is; | ||
else if ('isNot' in props) return props.lengthOf.length !== props.isNot; | ||
else if ('above' in props) return props.lengthOf.length > props.above; | ||
else if ('below' in props) return props.lengthOf.length < props.below; | ||
else if ('atLeast' in props) return props.lengthOf.length >= props.atLeast; | ||
else if ('atMost' in props) return props.lengthOf.length <= props.atMost; | ||
} else if ('all' in props) { | ||
for (const c of props.all) if (!c) return false; | ||
return true; | ||
} else if ('some' in props) { | ||
for (const c of props.some) if (c) return true; | ||
return false; | ||
} else if ('notAll' in props) { | ||
for (const c of props.notAll) if (!c) return true; | ||
return false; | ||
} else if ('none' in props) { | ||
for (const c of props.none) if (c) return false; | ||
return true; | ||
} | ||
|
||
return false; | ||
} |
Oops, something went wrong.