{"id":27977005,"url":"https://github.com/lemoncode/fonk-previous-date-validator","last_synced_at":"2025-07-21T09:33:26.313Z","repository":{"id":57126698,"uuid":"215031490","full_name":"Lemoncode/fonk-previous-date-validator","owner":"Lemoncode","description":"Previous date validator for https://github.com/Lemoncode/fonk","archived":false,"fork":false,"pushed_at":"2020-10-31T13:44:58.000Z","size":39,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-07-13T18:46:09.211Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Lemoncode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-14T11:56:08.000Z","updated_at":"2020-10-31T13:45:00.000Z","dependencies_parsed_at":"2022-08-31T11:52:48.631Z","dependency_job_id":null,"html_url":"https://github.com/Lemoncode/fonk-previous-date-validator","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/Lemoncode/fonk-previous-date-validator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lemoncode%2Ffonk-previous-date-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lemoncode%2Ffonk-previous-date-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lemoncode%2Ffonk-previous-date-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lemoncode%2Ffonk-previous-date-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lemoncode","download_url":"https://codeload.github.com/Lemoncode/fonk-previous-date-validator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lemoncode%2Ffonk-previous-date-validator/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266276136,"owners_count":23903981,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-08T01:44:16.132Z","updated_at":"2025-07-21T09:33:26.291Z","avatar_url":"https://github.com/Lemoncode.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fonk-previous-date-validator\n\n[![CircleCI](https://badgen.net/github/status/Lemoncode/fonk-previous-date-validator/master?icon=circleci\u0026label=circleci)](https://circleci.com/gh/Lemoncode/fonk-previous-date-validator/tree/master)\n[![NPM Version](https://badgen.net/npm/v/@lemoncode/fonk-previous-date-validator?icon=npm\u0026label=npm)](https://www.npmjs.com/package/@lemoncode/fonk-previous-date-validator)\n[![bundle-size](https://badgen.net/bundlephobia/min/@lemoncode/fonk-previous-date-validator)](https://bundlephobia.com/result?p=@lemoncode/fonk-previous-date-validator)\n\nThis is a [fonk](https://github.com/Lemoncode/fonk) microlibrary that brings validation capabilities to:\n\n- Validate if a field of a form is previous to a certain date.\n\nHow to install it:\n\n```bash\nnpm install @lemoncode/fonk-previous-date-validator --save\n```\n\nHow to add it to an existing form validation schema:\n\nWe have the following form model:\n\n```\nconst myFormValues = {\n  product: 'shoes',\n  purchaseDate: new Date('2019-02-10'),\n}\n```\n\nThe validator must be configured with the following required arguments:\n\n```javascript\nexport interface CustomArgs {\n  date: Date;\n  parseStringToDateFn?: (value: string) =\u003e Date;\n  inclusive?: boolean;\n}\n```\n\nThese are the default arguments:\n\n```javascript\nlet defaultCustomArgs: CustomArgs = {\n  date: null,\n  parseStringToDateFn: null,\n  inclusive: false,\n};\n```\n\nWe can add a previousDate validation to the myFormValues\n\n```javascript\nimport { previousDate } from '@lemoncode/fonk-previous-date-validator';\n\nconst validationSchema = {\n  field: {\n    purchaseDate: [\n      {\n        validator: previousDate.validator,\n        customArgs: { date: new Date('2019-03-10') },\n      },\n    ],\n  },\n};\n```\n\nYou can customize the error message displayed in two ways:\n\n- Globally, replace the default error message in all validationSchemas (e.g. porting to spanish):\n\n```javascript\nimport { previousDate } from '@lemoncode/fonk-previous-date-validator';\n\npreviousDate.setErrorMessage('El campo debe de ser numérico');\n```\n\n- Locally just override the error message for this validationSchema:\n\n```javascript\nimport { previousDate } from '@lemoncode/fonk-previous-date-validator';\n\nconst validationSchema = {\n  field: {\n    purchaseDate: [\n      {\n        validator: previousDate.validator,\n        message: 'Error message only updated for the validation schema',\n        customArgs: { date: new Date('2019-03-10') },\n      },\n    ],\n  },\n};\n```\n\nThis validator compare [Date](https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/Date) values. If your model use dates as string format, you can provide the `parseStringToDateFn` method.\n\n```javascript\nimport { previousDate } from '@lemoncode/fonk-previous-date-validator';\n\nconst validationSchema = {\n  field: {\n    purchaseDate: [\n      {\n        validator: previousDate.validator,\n        customArgs: {\n          date: new Date('2019-03-10T00:00:00'),\n          parseStringToDateFn: value =\u003e new Date(value),\n        },\n      },\n    ],\n  },\n};\n```\n\nOr if you are using some third party library like _moment_, _date-fns_, etc:\n\n```diff\nimport { previousDate } from '@lemoncode/fonk-previous-date-validator';\n+ import parse from 'date-fns/parse'\n\nconst validationSchema = {\n  field: {\n    purchaseDate: [\n      {\n        validator: previousDate.validator,\n        customArgs: {\n          date: new Date('2019-03-10T00:00:00'),\n-         parseStringToDateFn: value =\u003e new Date(value),\n+         parseStringToDateFn: value =\u003e parse(value, 'yyyy-MM-dd HH:mm:ss', new Date()),\n        },\n      },\n    ],\n  },\n};\n```\n\nYou can specify the custom arguments in two ways:\n\n- Locally just customize the arguments for this validationSchema:\n\n```javascript\nimport { previousDate } from '@lemoncode/fonk-previous-date-validator';\n\nconst validationSchema = {\n  field: {\n    purchaseDate: [\n      {\n        validator: previousDate.validator,\n        customArgs: {\n          date: new Date('2019-03-10'),\n          parseStringToDateFn: value =\u003e new Date(value),\n        },\n      },\n    ],\n  },\n};\n```\n\n- Globally, replace the default custom arguments in all validationSchemas:\n\n```javascript\nimport { previousDate } from '@lemoncode/fonk-previous-date-validator';\n\npreviousDate.setCustomArgs({ parseStringToDateFn: (value) =\u003e new Date(value) ) });\n\n// OR\n\npreviousDate.setCustomArgs({ date: new Date() });\n\n// OR\n\npreviousDate.setCustomArgs({ inclusive: true });\n\n// OR\n\npreviousDate.setCustomArgs({\n  date: new Date(),\n  parseStringToDateFn: value =\u003e new Date(value),\n  inclusive: true,\n});\n\n```\n\nPlease, refer to [fonk](https://github.com/Lemoncode/fonk) to know more.\n\n## License\n\n[MIT](./LICENSE)\n\n# About Basefactor + Lemoncode\n\nWe are an innovating team of Javascript experts, passionate about turning your ideas into robust products.\n\n[Basefactor, consultancy by Lemoncode](http://www.basefactor.com) provides consultancy and coaching services.\n\n[Lemoncode](http://lemoncode.net/services/en/#en-home) provides training services.\n\nFor the LATAM/Spanish audience we are running an Online Front End Master degree, more info: http://lemoncode.net/master-frontend\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flemoncode%2Ffonk-previous-date-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flemoncode%2Ffonk-previous-date-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flemoncode%2Ffonk-previous-date-validator/lists"}