{"id":24494715,"url":"https://github.com/bwca/package_iso-datestring-validator","last_synced_at":"2025-04-14T02:51:50.597Z","repository":{"id":37702258,"uuid":"195491106","full_name":"Bwca/package_iso-datestring-validator","owner":"Bwca","description":"The goal of the package is to provide lightweight tools for validating strings denotings dates and time. It includes ISO 8601 datestring validation, simple YYYY-MM-DD date validation and time validation in hh:mm:ss.fff format. See details in readme.","archived":false,"fork":false,"pushed_at":"2023-03-15T11:40:28.000Z","size":1198,"stargazers_count":5,"open_issues_count":5,"forks_count":2,"subscribers_count":0,"default_branch":"develop","last_synced_at":"2024-04-30T01:20:22.414Z","etag":null,"topics":["date","validation","validator"],"latest_commit_sha":null,"homepage":"","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/Bwca.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-06T03:03:03.000Z","updated_at":"2024-06-18T20:06:57.251Z","dependencies_parsed_at":"2024-06-18T20:06:50.251Z","dependency_job_id":"9a712f10-046a-482c-bfe4-da00c48d5285","html_url":"https://github.com/Bwca/package_iso-datestring-validator","commit_stats":null,"previous_names":["bwca/iso-datestring-validator"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bwca%2Fpackage_iso-datestring-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bwca%2Fpackage_iso-datestring-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bwca%2Fpackage_iso-datestring-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bwca%2Fpackage_iso-datestring-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bwca","download_url":"https://codeload.github.com/Bwca/package_iso-datestring-validator/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248813827,"owners_count":21165631,"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":["date","validation","validator"],"created_at":"2025-01-21T20:16:56.991Z","updated_at":"2025-04-14T02:51:50.576Z","avatar_url":"https://github.com/Bwca.png","language":"TypeScript","funding_links":["https://www.buymeacoffee.com/bwca"],"categories":[],"sub_categories":[],"readme":"# iso-datestring-validator\n\n## What is it\n\nA simple package for validating strings denoting dates and time, including ISO 8601 format. The package provides the following functions:\n\n1. **Date validation**. YYYY-MM-DD format from 0001-01-01 to 9999-12-31, leap year friendly. Custom digit separators and null separators supported: YYYY/MM/DD or YYYYMMDD is no problem.\n\n2. **Time validation**. HH:mm:ss.fff±hh:mm format, seconds, fractions of seconds and timezone offset being optional. Custom digit separators supported for HHmmss as well (no custom separator for fractions, it is dot).\n\n**Caveat**: do not use '-' and '+' as separators when validating time with timezone. I am reluctant to fix this unless it is an issue.\n\n```js\nisValidTime('14-45-15.000+00-00', '-', true);\n// will yield wrong result\n```\n\n3. **Year-month validation**.\n\n4. **ISO 8601 datestring validation** with timezones, with and without separators:\n\n- 2019-07-09T15:03:36.000+00:00\n- 2019-07-09T15:03:36Z\n- 20190709T150336Z\n\n## Installation\n\n```js\nnpm i --save iso-datestring-validator\n```\n\nor\n\n```js\nyarn add iso-datestring-validator\n```\n\n## Import\n\n```ts\nimport * as isoDatestringValidator from 'iso-datestring-validator';\n```\n\nalternatively you can import the function that you need separately:\n\n```ts\nimport {\n  isValidDate,\n  isValidISODateString,\n  isValidTime,\n  isValidYearMonth,\n} from 'iso-datestring-validator';\n```\n\n## Usage\n\n### Date validation\n\nPass a **YYYY-MM-DD** date string to the **isValidDate** function to check it. To validate dates that use a custom digit separator, pass it as the second argument.\n\n```ts\nimport { isValidDate } from 'iso-datestring-validator';\n\nisValidDate('2019-01-31');\n// true\n\nisValidDate('20190131');\n// false, no custom digit separator provided, hyphen separator not found in the string\n\nisValidDate('20190131', '');\n// true\n\nisValidDate('2019/01/31', '/');\n// true\n```\n\n### Time validation\n\nTime string in HH:mm:ss.fff±hh:mm format can be validated with the **isValidTime** function. Seconds and fractions are optional. However, if using fractions min number of numbers is 1 and max is 9. Zone offset is optional as well, its check is switched off by default.\n\n```ts\nimport { isValidTime } from 'iso-datestring-validator';\n\nisValidTime('13:00');\n// true\n\nisValidTime('13:00:00');\n// true\n\nisValidTime('13:00:00.000000000');\n// true\n\n// pass time, separator and boolean flag to enable zone offset check\nisValidTime('14:45:15.000+00:00', ':', true);\n// true\n\n// you can take advantage of default separator if you pass undefined as second param\nisValidTime('14:45:15.000+00:00', undefined, true);\n// true\n\nisValidTime('144515.000Z', '', true);\n// true\n```\n\n### Year and month validation\n\nThese are validated by the **isValidYearMonth** function. Rules same as in the previous case: a string **YYYY-MM** and a custom digit separator if required.\n\n```ts\nimport { isValidYearMonth } from 'iso-datestring-validator';\n\nisValidYearMonth('2019/01', '/');\n// true\n\nisValidYearMonth('2019-01');\n// true\n```\n\n### ISO 8601 datestring validation\n\nPass a string to **isValidISODateString** to see if it is valid.\n\n```ts\nimport { isValidISODateString } from 'iso-datestring-validator';\n\nisValidISODateString('2019-07-09T15:03:36.000+00:00');\n// true\n\nisValidISODateString('20190709T150336Z');\n// true\n```\n\nThat's all about this package. Have fun, feel free to contribute with some test :]\n\n[![\"Buy Me A Coffee\"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/bwca)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbwca%2Fpackage_iso-datestring-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbwca%2Fpackage_iso-datestring-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbwca%2Fpackage_iso-datestring-validator/lists"}