Skip to content

Commit

Permalink
feat: is no a child validator (#167)
Browse files Browse the repository at this point in the history
* feat: is no a child validator

* fix: eslint

Co-authored-by: glauberbrack <[email protected]>
  • Loading branch information
glauber-brack and glauberbrack authored Oct 1, 2021
1 parent 5ac276a commit 0250ad6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/isValidBirthDate.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ We have two methods:

## Usage

Documentation based on year 2021.

```jsx
import { isValidBirthDate, isValidLegalAge } from '@platformbuilders/helpers';

Expand All @@ -31,4 +33,8 @@ isValidMinimumAge('16/06/2020', 5); // return false

isValidMinimumAge('16/06/1994', 5); // return true

isNotAChild('16/06/2020'); // return false

isNotAChild('16/06/2015'); // return false

```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@platformbuilders/validations",
"version": "0.0.15",
"version": "0.0.16",
"description": "",
"author": "Platform Builders <[email protected]>",
"repository": {
Expand Down
8 changes: 8 additions & 0 deletions src/isValidBirthDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@ export const isValidMinimumAge = (date?: string, minimumAge = 18): boolean => {
const insertedDate = DateManager(date, SCREEN_DATE);
return insertedDate.isBetween(minDate, maxDate);
};

export const isNotAChild = (date?: string, minimumAge = 5): boolean => {
const maxAge = 95;
const minDate = DateManager().subtract(maxAge, 'years');
const maxDate = DateManager().subtract(minimumAge, 'years');
const insertedDate = DateManager(date, SCREEN_DATE);
return insertedDate.isBetween(minDate, maxDate);
};

0 comments on commit 0250ad6

Please sign in to comment.