Skip to content

Commit

Permalink
feat: create simplified find by property options
Browse files Browse the repository at this point in the history
  • Loading branch information
IamSebastianDev committed Nov 27, 2022
1 parent 73df391 commit 8509254
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/lib/Evaluators/evaluateFindOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,21 @@ export const evaluateFindOptions = <T extends Record<string, unknown>>(
});
};

return Object.entries(findOptions).every(([prop, evaluator]) => evaluator(document[prop], prop));
/**
* @description
* Function to evaluate a `Document` using a given set of simplified find by property options.
*
* @param { Document } document - the `Document`whose properties to check
* @param { FindOByProperty } findOptions - the passed find options to evaluate
* @returns { boolean } a boolean indicating if the `Document` satisfies the
* conditions in the find options
*/

export const evaluateFindByPropertyOptions = <T extends Record<string, unknown>>(
document: Document<T>,
findOptions: FindByProperty<T>
): boolean => {
return Object.entries(findOptions).every(([prop, evaluator]) => {
return typeof evaluator === 'function' ? evaluator(document[prop], prop) : document[prop] === evaluator;
});
};
2 changes: 1 addition & 1 deletion src/lib/Evaluators/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @format */

export { evaluateFindOptions } from './evaluateFindOptions';
export { evaluateFindOptions, evaluateFindByPropertyOptions } from './evaluateFindOptions';
export { Exactly } from './Exactly.evaluator';
export { Is } from './Is.evaluator';
export { Like } from './Like.evaluator';
Expand Down

0 comments on commit 8509254

Please sign in to comment.