-
-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add symbol, undefined and null predicates #28
Conversation
source/index.ts
Outdated
@@ -49,6 +61,15 @@ Object.defineProperties(main, { | |||
boolean: { | |||
get: () => new BooleanPredicate() | |||
}, | |||
symbol: { | |||
get: () => new Predicate('symbol') | |||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's put symbol
after null
as it's not as common to check for it.
Fixed. I'm also thinking in refactoring the const predicateMap = new Map<string, () => Predicate>([
['string', () => new StringPredicate()],
['number', () => new NumberPredicate()],
['boolean', () => new BooleanPredicate()],
['array', () => new ArrayPredicate()],
['date', () => new DatePredicate()]
]);
for (const propertyKey of Array.from(predicateMap.keys())) {
Object.defineProperty(main, propertyKey, {
get: predicateMap.get(propertyKey)
});
} It feels easier to maintain. |
Could also be: const predicateMap = new Map<string, Predicate>([
['string', StringPredicate],
['number', NumberPredicate],
['boolean', BooleanPredicate],
['array', ArrayPredicate],
['date', DatePredicate]
]);
for (const propertyKey of Array.from(predicateMap.keys())) {
Object.defineProperty(main, propertyKey, {
get: () => new predicateMap.get(propertyKey)
});
} |
But I don't think it's worth it. Now it's just a tiny bit more boilerplate, but much clearer. |
True 👌 |
Completed all the primitive predicates by adding
symbol
,undefined
andnull
.