Skip to content

Commit 773320f

Browse files
committed
Added date-fns library
1 parent 43fb37c commit 773320f

17 files changed

Lines changed: 99 additions & 115 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules
22
dist
33
coverage
4-
.DS_Store
4+
.DS_Store
5+
cache

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Release Notes
22

3+
## [2.0.0 (2024-09-27)](https://github.com/axe-api/axe-api/compare/2.0.0...1.1.1)
4+
5+
- Fixed bundling issues
6+
- The [dayjs](https://day.js.org) library with [date-fns](https://date-fns.org). You _MUST_ replace the date formats:
7+
- `YYYY-MM-DD` => `yyyy-MM-dd`
8+
39
## [1.1.1 (2024-09-19)](https://github.com/axe-api/axe-api/compare/1.1.1...1.1.0)
410

511
- Security fix

demo/package-lock.json

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"dependencies": {
1313
"@babel/parser": "^7.23.6",
14-
"dayjs": "^1.11.10",
14+
"date-fns": "^4.1.0",
1515
"prettier": "^3.1.1",
1616
"react": "^18.2.0",
1717
"react-dom": "^18.2.0",

demo/src/Constants.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import dayjs from "dayjs";
1+
import { format } from "date-fns";
22

33
export const RULE_PARAMETER_MAP: Record<string, any[]> = {
44
string: [],
55
boolean: [],
66
accepted: [],
7-
after: [dayjs().format("YYYY-MM-DD")],
8-
after_or_equal: [dayjs().format("YYYY-MM-DD")],
7+
after: [format(new Date(), "yyyy-MM-dd")],
8+
after_or_equal: [format(new Date(), "yyyy-MM-dd")],
99
alpha: [],
1010
alpha_dash: [],
1111
alpha_num: [],
1212
array: [],
13-
before: [dayjs().format("YYYY-MM-DD")],
14-
before_or_equal: [dayjs().format("YYYY-MM-DD")],
13+
before: [format(new Date(), "yyyy-MM-dd")],
14+
before_or_equal: [format(new Date(), "yyyy-MM-dd")],
1515
between: [5, 10],
1616
confirmed: [],
1717
date: [],

docs/options.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ setLocales(en);
1313
setOptions({
1414
stopOnFail: true,
1515
language: "en",
16-
dateFormat: "YYYY-MM-DD",
16+
dateFormat: "yyyy-MM-dd",
1717
});
1818
```
1919

@@ -30,7 +30,7 @@ setLocales(en);
3030
setOptions({
3131
stopOnFail: true,
3232
language: "en",
33-
dateFormat: "YYYY-MM-DD",
33+
dateFormat: "yyyy-MM-dd",
3434
});
3535

3636
await validate(
@@ -40,7 +40,7 @@ await validate(
4040
{
4141
stopOnFail: false,
4242
language: "de",
43-
dateFormat: "YYYY-MM-DD",
43+
dateFormat: "yyyy-MM-dd",
4444
},
4545
);
4646
```

docs/rules.md

Lines changed: 26 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,9 @@ isAfter("your-value", "2023-01-01");
7979
:::
8080

8181
:::tip
82-
robust-validator library uses the [dayjs](https://day.js.org/) for the date validations.
82+
robust-validator library uses the [date-fns](https://date-fns.org) for the date validations.
8383

84-
You can check the possible date formats [here](https://day.js.org/docs/en/parse/string-format).
85-
:::
86-
87-
:::warning
88-
You MUST install the [dayjs](https://day.js.org/) is to your project.
89-
90-
`npm install dayjs` or `yarn add dayjs`
84+
You can check the possible date formats [here](https://date-fns.org/v4.1.0/docs/format).
9185
:::
9286

9387
| Rule | Value | `startAt` | Is valid? |
@@ -128,15 +122,9 @@ isAfterOrEqual("your-value", "2023-01-01");
128122
:::
129123

130124
:::tip
131-
robust-validator library uses the [dayjs](https://day.js.org/) for the date validations.
132-
133-
You can check the possible date formats [here](https://day.js.org/docs/en/parse/string-format).
134-
:::
135-
136-
:::warning
137-
You MUST install the [dayjs](https://day.js.org/) is to your project.
125+
robust-validator library uses the [date-fns](https://date-fns.org) for the date validations.
138126

139-
`npm install dayjs` or `yarn add dayjs`
127+
You can check the possible date formats [here](https://date-fns.org/v4.1.0/docs/format).
140128
:::
141129

142130
| Rule | Value | `startAt` | Is valid? |
@@ -329,15 +317,9 @@ isBefore("your-value", "2023-01-01");
329317
:::
330318

331319
:::tip
332-
robust-validator library uses the [dayjs](https://day.js.org/) for the date validations.
333-
334-
You can check the possible date formats [here](https://day.js.org/docs/en/parse/string-format).
335-
:::
320+
robust-validator library uses the [date-fns](https://date-fns.org) for the date validations.
336321

337-
:::warning
338-
You MUST install the [dayjs](https://day.js.org/) is to your project.
339-
340-
`npm install dayjs` or `yarn add dayjs`
322+
You can check the possible date formats [here](https://date-fns.org/v4.1.0/docs/format).
341323
:::
342324

343325
| Rule | Value | `finishAt` | Is valid? |
@@ -378,15 +360,9 @@ isBeforeOrEqual("your-value", "2023-01-01");
378360
The field under validation must be before or equal to the given date.
379361

380362
:::tip
381-
robust-validator library uses the [dayjs](https://day.js.org/) for the date validations.
382-
383-
You can check the possible date formats [here](https://day.js.org/docs/en/parse/string-format).
384-
:::
385-
386-
:::warning
387-
You MUST install the [dayjs](https://day.js.org/) is to your project.
363+
robust-validator library uses the [date-fns](https://date-fns.org) for the date validations.
388364

389-
`npm install dayjs` or `yarn add dayjs`
365+
You can check the possible date formats [here](https://date-fns.org/v4.1.0/docs/format).
390366
:::
391367

392368
| Rule | Value | `finishAt` | Is valid? |
@@ -516,39 +492,45 @@ isConfirmed("your-data");
516492

517493
The field under validation must be a valid date format which is acceptable by Javascript's Date object.
518494

495+
:::tip
496+
robust-validator library uses the [date-fns](https://date-fns.org) for the date validations.
497+
498+
You can check the possible date formats [here](https://date-fns.org/v4.1.0/docs/format).
499+
:::
500+
519501
::: code-group
520502

521503
```ts [Declarative]
522504
import { validate } from "robust-validator";
523505
// ...
524-
await validate(data, { startAt: "date:YYYY-MM-DD" });
506+
await validate(data, { startAt: "date:yyyy-MM-dd" });
525507
```
526508

527509
```ts [Function-based]
528510
import { validate, date } from "robust-validator";
529511
// ...
530-
await validate(data, { startAt: [date("YYYY-MM-DD")] });
512+
await validate(data, { startAt: [date("yyyy-MM-dd")] });
531513
```
532514

533515
```ts [Direct usage]
534516
import { isDate } from "robust-validator";
535517
// ...
536-
isDate("your-data", "YYYY-MM-DD");
518+
isDate("your-data", "yyyy-MM-dd");
537519
```
538520

539521
:::
540522

541523
| Rule | Value | Is valid? |
542524
| ----------------- | ---------------------------- | --------- |
543-
| `date:YYYY-MM-DD` | `null` | 🔴 |
544-
| `date:YYYY-MM-DD` | `undefined` | 🔴 |
545-
| `date:YYYY-MM-DD` | `2023-12-16` | 🟢 |
546-
| `date:YYYY-MM-DD` | `2023-01-01` | 🟢 |
547-
| `date:YYYY-MM-DD` | `December 16, 2023 12:00:00` | 🔴 |
548-
| `date:YYYY-MM-DD` | `2022-13-01` | 🔴 |
549-
| `date:YYYY-MM-DD` | `2022-12-32` | 🔴 |
550-
| `date:YYYY-MM-DD` | `2022-02-29` | 🔴 |
551-
| `date:YYYY-MM-DD` | `false` | 🔴 |
525+
| `date:yyyy-MM-dd` | `null` | 🔴 |
526+
| `date:yyyy-MM-dd` | `undefined` | 🔴 |
527+
| `date:yyyy-MM-dd` | `2023-12-16` | 🟢 |
528+
| `date:yyyy-MM-dd` | `2023-01-01` | 🟢 |
529+
| `date:yyyy-MM-dd` | `December 16, 2023 12:00:00` | 🔴 |
530+
| `date:yyyy-MM-dd` | `2022-13-01` | 🔴 |
531+
| `date:yyyy-MM-dd` | `2022-12-32` | 🔴 |
532+
| `date:yyyy-MM-dd` | `2022-02-29` | 🔴 |
533+
| `date:yyyy-MM-dd` | `false` | 🔴 |
552534

553535
## `digits:value`
554536

package-lock.json

Lines changed: 13 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "robust-validator",
3-
"version": "2.0.0-rc-2",
3+
"version": "2.0.0",
44
"description": "Rule-based data validation library",
55
"type": "module",
6-
"main": "dist/index.cjs",
7-
"module": "dist/index.mjs",
8-
"types": "dist/index.d.ts",
6+
"main": "dist/index.cjs",
7+
"module": "dist/index.mjs",
8+
"types": "dist/index.d.ts",
99
"exports": {
1010
".": {
11-
"import": "./dist/index.mjs",
11+
"import": "./dist/index.mjs",
1212
"require": "./dist/index.cjs",
1313
"types": "./dist/index.d.ts"
1414
}
@@ -59,7 +59,6 @@
5959
"@typescript-eslint/eslint-plugin": "^6.15.0",
6060
"@typescript-eslint/parser": "^6.15.0",
6161
"@vitest/coverage-v8": "^1.1.0",
62-
"dayjs": "^1.11.10",
6362
"eslint": "^8.56.0",
6463
"eslint-config-standard-with-typescript": "^43.0.0",
6564
"eslint-plugin-import": "^2.29.1",
@@ -81,7 +80,7 @@
8180
"typescript": "^5.3.3",
8281
"vitest": "^1.1.0"
8382
},
84-
"peerDependencies": {
85-
"dayjs": "^1.11.10"
83+
"dependencies": {
84+
"date-fns": "^4.1.0"
8685
}
8786
}

src/Options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { IOptions } from "./Interface";
33
const DEFAULT_OPTIONS: IOptions = {
44
stopOnFail: false,
55
language: "en",
6-
dateFormat: "YYYY-MM-DD",
6+
dateFormat: "yyyy-MM-dd",
77
};
88

99
let OPTIONS: IOptions = {

0 commit comments

Comments
 (0)