diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 31046fe..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/recommended", - "plugin:react-hooks/recommended", - "prettier" - ], - "parser": "@typescript-eslint/parser", - "plugins": ["@typescript-eslint"], - "root": true -} diff --git a/.oxlintrc.json b/.oxlintrc.json new file mode 100644 index 0000000..f5f7f56 --- /dev/null +++ b/.oxlintrc.json @@ -0,0 +1,7 @@ +{ + "plugins": ["react", "typescript"], + "env": { + "browser": true, + "es2022": true + } +} diff --git a/.vscode/settings.json b/.vscode/settings.json index 421ccb2..7498ec9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,5 @@ { "editor.codeActionsOnSave": ["source.organizeImports", "source.fixAll"], - "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.defaultFormatter": "oxc.vscode-oxc", "editor.formatOnSave": true } diff --git a/package.json b/package.json index a645562..d0c8f43 100644 --- a/package.json +++ b/package.json @@ -11,18 +11,14 @@ "ci:publish": "pnpm publish --access public --filter=\\!www --recursive && pnpm changeset tag", "ci:version": "pnpm changeset version", "dev": "turbo run dev", - "lint": "eslint . --ext ts,tsx", + "format": "oxfmt --write .", + "lint": "oxlint .", "test": "turbo run test" }, "devDependencies": { "@changesets/cli": "^2.28.1", - "@typescript-eslint/eslint-plugin": "^5.62.0", - "@typescript-eslint/parser": "^5.62.0", - "eslint": "^8.57.1", - "eslint-config-prettier": "^8.10.0", - "eslint-plugin-react-hooks": "^4.6.2", - "prettier": "^2.8.8", - "prettier-plugin-tailwindcss": "^0.2.8", + "oxfmt": "^0.36.0", + "oxlint": "^1.51.0", "turbo": "^2.5.0", "typescript": "^5.8.3" }, diff --git a/packages/core/src/clamp.ts b/packages/core/src/clamp.ts index d6b6b1c..b2b7b79 100644 --- a/packages/core/src/clamp.ts +++ b/packages/core/src/clamp.ts @@ -1,22 +1,26 @@ import { Temporal } from "@js-temporal/polyfill"; -export function clamp< - Value extends Temporal.PlainDate | Temporal.PlainDateTime ->(value: Value, minValue?: Value, maxValue?: Value) { +export function clamp( + value: Value, + minValue?: Value, + maxValue?: Value, +) { if ( minValue && - Temporal[ - value instanceof Temporal.PlainDate ? "PlainDate" : "PlainDateTime" - ].compare(value, minValue) < 0 + Temporal[value instanceof Temporal.PlainDate ? "PlainDate" : "PlainDateTime"].compare( + value, + minValue, + ) < 0 ) { return minValue; } if ( maxValue && - Temporal[ - value instanceof Temporal.PlainDate ? "PlainDate" : "PlainDateTime" - ].compare(value, maxValue) > 0 + Temporal[value instanceof Temporal.PlainDate ? "PlainDate" : "PlainDateTime"].compare( + value, + maxValue, + ) > 0 ) { return maxValue; } diff --git a/packages/core/src/getCalendarMonthDateRange.ts b/packages/core/src/getCalendarMonthDateRange.ts index 8e5a12c..1f11def 100644 --- a/packages/core/src/getCalendarMonthDateRange.ts +++ b/packages/core/src/getCalendarMonthDateRange.ts @@ -4,11 +4,7 @@ import { getMonthStartDate } from "./getMonthStartDate"; type Value = Temporal.PlainDate | Temporal.PlainDateTime; -export function getCalendarMonthDateRange( - value: Value, - rollover: boolean, - startOfWeek: number -) { +export function getCalendarMonthDateRange(value: Value, rollover: boolean, startOfWeek: number) { const start = getMonthStartDate(value); const end = getMonthEndDate(value); diff --git a/packages/core/src/getHours.ts b/packages/core/src/getHours.ts index 149a781..887811c 100644 --- a/packages/core/src/getHours.ts +++ b/packages/core/src/getHours.ts @@ -3,7 +3,7 @@ import { Temporal } from "@js-temporal/polyfill"; export function getHours( value?: Temporal.PlainDateTime, minValue?: Temporal.PlainDateTime, - maxValue?: Temporal.PlainDateTime + maxValue?: Temporal.PlainDateTime, ) { const hours: { hour: number; @@ -15,16 +15,14 @@ export function getHours( !!value && !!minValue && (Temporal.PlainDate.compare(value, minValue) < 0 || - (value.toPlainDate().equals(minValue.toPlainDate()) && - i < minValue.hour)); + (value.toPlainDate().equals(minValue.toPlainDate()) && i < minValue.hour)); const isAfterMaxValue = !isBeforeMinValue && !!value && !!maxValue && (Temporal.PlainDate.compare(value, maxValue) > 0 || - (value.toPlainDate().equals(maxValue.toPlainDate()) && - i > maxValue.hour)); + (value.toPlainDate().equals(maxValue.toPlainDate()) && i > maxValue.hour)); hours.push({ hour: i, diff --git a/packages/core/src/getMinutes.ts b/packages/core/src/getMinutes.ts index e2a3e62..d8ce770 100644 --- a/packages/core/src/getMinutes.ts +++ b/packages/core/src/getMinutes.ts @@ -3,7 +3,7 @@ import { Temporal } from "@js-temporal/polyfill"; export function getMinutes( value?: Temporal.PlainDateTime, minValue?: Temporal.PlainDateTime, - maxValue?: Temporal.PlainDateTime + maxValue?: Temporal.PlainDateTime, ) { const minutes: { minute: number; @@ -28,7 +28,7 @@ export function getMinutes( microsecond: 0, nanosecond: 0, }), - minValue + minValue, ) <= 0 && (value.hour < minValue.hour || minute < minValue.minute) ) { @@ -57,7 +57,7 @@ export function getMinutes( microsecond: 0, nanosecond: 0, }), - maxValue + maxValue, ) >= 0 && (value.hour > maxValue.hour || minute > maxValue.minute) ) { diff --git a/packages/core/src/getMonths.ts b/packages/core/src/getMonths.ts index 722d6a7..4faccbd 100644 --- a/packages/core/src/getMonths.ts +++ b/packages/core/src/getMonths.ts @@ -5,7 +5,7 @@ export function getMonths( locale: Parameters[0], referenceValue: Temporal.PlainDate, minValue?: Temporal.PlainDate, - maxValue?: Temporal.PlainDate + maxValue?: Temporal.PlainDate, ) { const longMonthFormatter = new Intl.DateTimeFormat(locale, { month: "long", diff --git a/packages/core/src/getWeekdays.ts b/packages/core/src/getWeekdays.ts index 2433a8f..ab667d3 100644 --- a/packages/core/src/getWeekdays.ts +++ b/packages/core/src/getWeekdays.ts @@ -4,12 +4,9 @@ import { temporalToDate } from "./temporalToDate"; export function getWeekdays( locale: Parameters[0], - startOfWeek: number + startOfWeek: number, ) { - const firstDayOfWeek = getFirstDayOfWeek( - Temporal.Now.plainDateISO(), - startOfWeek - ); + const firstDayOfWeek = getFirstDayOfWeek(Temporal.Now.plainDateISO(), startOfWeek); const longWeekdayFormatter = new Intl.DateTimeFormat(locale, { weekday: "long", diff --git a/packages/core/src/getYears.ts b/packages/core/src/getYears.ts index cf2cc84..4ca6c74 100644 --- a/packages/core/src/getYears.ts +++ b/packages/core/src/getYears.ts @@ -1,9 +1,6 @@ import { Temporal } from "@js-temporal/polyfill"; -export function getYears( - minValue: Temporal.PlainDate, - maxValue: Temporal.PlainDate -) { +export function getYears(minValue: Temporal.PlainDate, maxValue: Temporal.PlainDate) { const years: number[] = []; for (let i = minValue.year; i < maxValue.year + 1; i += 1) { diff --git a/packages/core/src/temporalToDate.ts b/packages/core/src/temporalToDate.ts index 94fdafe..db3a56e 100644 --- a/packages/core/src/temporalToDate.ts +++ b/packages/core/src/temporalToDate.ts @@ -14,6 +14,6 @@ export function temporalToDate(value: Value) { value.hour, value.minute, value.second, - value.millisecond + value.millisecond, ); } diff --git a/packages/core/test/clamp.test.ts b/packages/core/test/clamp.test.ts index 1c4380e..379deaf 100644 --- a/packages/core/test/clamp.test.ts +++ b/packages/core/test/clamp.test.ts @@ -8,7 +8,7 @@ test("clamp (PlainDate, unbounded)", () => { year: 2022, month: 2, day: 2, - }) + }), ); expect(result instanceof Temporal.PlainDate).toBe(true); @@ -19,8 +19,8 @@ test("clamp (PlainDate, unbounded)", () => { year: 2022, month: 2, day: 2, - }) - ) + }), + ), ).toBe(true); }); @@ -35,7 +35,7 @@ test("clamp (PlainDate, before min)", () => { year: 2022, month: 2, day: 2, - }) + }), ); expect(result instanceof Temporal.PlainDate).toBe(true); @@ -46,8 +46,8 @@ test("clamp (PlainDate, before min)", () => { year: 2022, month: 2, day: 2, - }) - ) + }), + ), ).toBe(true); }); @@ -62,7 +62,7 @@ test("clamp (PlainDate, after min)", () => { year: 2022, month: 2, day: 2, - }) + }), ); expect(result instanceof Temporal.PlainDate).toBe(true); @@ -73,8 +73,8 @@ test("clamp (PlainDate, after min)", () => { year: 2022, month: 2, day: 3, - }) - ) + }), + ), ).toBe(true); }); @@ -90,7 +90,7 @@ test("clamp (PlainDate, before max)", () => { year: 2022, month: 2, day: 4, - }) + }), ); expect(result instanceof Temporal.PlainDate).toBe(true); @@ -101,8 +101,8 @@ test("clamp (PlainDate, before max)", () => { year: 2022, month: 2, day: 2, - }) - ) + }), + ), ).toBe(true); }); @@ -118,7 +118,7 @@ test("clamp (PlainDate, after max)", () => { year: 2022, month: 2, day: 4, - }) + }), ); expect(result instanceof Temporal.PlainDate).toBe(true); @@ -129,8 +129,8 @@ test("clamp (PlainDate, after max)", () => { year: 2022, month: 2, day: 4, - }) - ) + }), + ), ).toBe(true); }); @@ -141,7 +141,7 @@ test("clamp (PlainDateTime, unbounded)", () => { month: 2, day: 2, hour: 2, - }) + }), ); expect(result instanceof Temporal.PlainDateTime).toBe(true); @@ -153,8 +153,8 @@ test("clamp (PlainDateTime, unbounded)", () => { month: 2, day: 2, hour: 2, - }) - ) + }), + ), ).toBe(true); }); @@ -171,7 +171,7 @@ test("clamp (PlainDateTime, before min)", () => { month: 2, day: 2, hour: 2, - }) + }), ); expect(result instanceof Temporal.PlainDateTime).toBe(true); @@ -183,8 +183,8 @@ test("clamp (PlainDateTime, before min)", () => { month: 2, day: 2, hour: 2, - }) - ) + }), + ), ).toBe(true); }); @@ -201,7 +201,7 @@ test("clamp (PlainDateTime, after min)", () => { month: 2, day: 2, hour: 2, - }) + }), ); expect(result instanceof Temporal.PlainDateTime).toBe(true); @@ -213,8 +213,8 @@ test("clamp (PlainDateTime, after min)", () => { month: 2, day: 2, hour: 3, - }) - ) + }), + ), ).toBe(true); }); @@ -232,7 +232,7 @@ test("clamp (PlainDateTime, before max)", () => { month: 2, day: 2, hour: 2, - }) + }), ); expect(result instanceof Temporal.PlainDateTime).toBe(true); @@ -244,8 +244,8 @@ test("clamp (PlainDateTime, before max)", () => { month: 2, day: 2, hour: 1, - }) - ) + }), + ), ).toBe(true); }); @@ -263,7 +263,7 @@ test("clamp (PlainDateTime, after max)", () => { month: 2, day: 2, hour: 2, - }) + }), ); expect(result instanceof Temporal.PlainDateTime).toBe(true); @@ -275,7 +275,7 @@ test("clamp (PlainDateTime, after max)", () => { month: 2, day: 2, hour: 2, - }) - ) + }), + ), ).toBe(true); }); diff --git a/packages/core/test/dateToTemporal.test.ts b/packages/core/test/dateToTemporal.test.ts index e85e534..f982b4e 100644 --- a/packages/core/test/dateToTemporal.test.ts +++ b/packages/core/test/dateToTemporal.test.ts @@ -15,7 +15,7 @@ test("dateToTemporal", () => { minute: 30, second: 45, millisecond: 600, - }) - ) + }), + ), ).toBe(true); }); diff --git a/packages/core/test/getCalendarMonthDateRange.test.ts b/packages/core/test/getCalendarMonthDateRange.test.ts index 6623424..c093dd8 100644 --- a/packages/core/test/getCalendarMonthDateRange.test.ts +++ b/packages/core/test/getCalendarMonthDateRange.test.ts @@ -10,7 +10,7 @@ test("getCalendarMonthDateRange (without rollover)", () => { day: 7, }), false, - 7 + 7, ); expect( @@ -19,8 +19,8 @@ test("getCalendarMonthDateRange (without rollover)", () => { year: 2022, month: 3, day: 1, - }) - ) + }), + ), ).toBe(true); expect( @@ -29,8 +29,8 @@ test("getCalendarMonthDateRange (without rollover)", () => { year: 2022, month: 3, day: 31, - }) - ) + }), + ), ).toBe(true); }); @@ -42,7 +42,7 @@ test("getCalendarMonthDateRange (with rollover)", () => { day: 7, }), true, - 7 + 7, ); expect( @@ -51,8 +51,8 @@ test("getCalendarMonthDateRange (with rollover)", () => { year: 2022, month: 6, day: 26, - }) - ) + }), + ), ).toBe(true); expect( @@ -61,7 +61,7 @@ test("getCalendarMonthDateRange (with rollover)", () => { year: 2022, month: 8, day: 6, - }) - ) + }), + ), ).toBe(true); }); diff --git a/packages/core/test/getFirstDayOfWeek.test.ts b/packages/core/test/getFirstDayOfWeek.test.ts index 2e2afc2..c6c36e7 100644 --- a/packages/core/test/getFirstDayOfWeek.test.ts +++ b/packages/core/test/getFirstDayOfWeek.test.ts @@ -9,7 +9,7 @@ test("getFirstDayOfWeek (startOfWeek = 7)", () => { month: 4, day: 1, }), - 7 + 7, ); expect(firstDayOfWeek.dayOfWeek).toEqual(7); @@ -20,8 +20,8 @@ test("getFirstDayOfWeek (startOfWeek = 7)", () => { year: 2022, month: 3, day: 27, - }) - ) + }), + ), ).toBe(true); }); @@ -32,7 +32,7 @@ test("getFirstDayOfWeek (startOfWeek = 6)", () => { month: 4, day: 1, }), - 6 + 6, ); expect(firstDayOfWeek.dayOfWeek).toEqual(6); @@ -43,7 +43,7 @@ test("getFirstDayOfWeek (startOfWeek = 6)", () => { year: 2022, month: 3, day: 26, - }) - ) + }), + ), ).toBe(true); }); diff --git a/packages/core/test/getHours.test.ts b/packages/core/test/getHours.test.ts index d17fd13..2a610a7 100644 --- a/packages/core/test/getHours.test.ts +++ b/packages/core/test/getHours.test.ts @@ -24,7 +24,7 @@ test("getHours (year before, with min)", () => { month: 4, day: 2, hour: 6, - }) + }), ); for (let i = 0; i < 24; i += 1) { @@ -46,7 +46,7 @@ test("getHours (month before, with min)", () => { month: 4, day: 2, hour: 6, - }) + }), ); for (let i = 0; i < 24; i += 1) { @@ -68,7 +68,7 @@ test("getHours (day before, with min)", () => { month: 4, day: 2, hour: 6, - }) + }), ); for (let i = 0; i < 24; i += 1) { @@ -90,7 +90,7 @@ test("getHours (same day, with min)", () => { month: 4, day: 2, hour: 6, - }) + }), ); for (let i = 0; i < 24; i += 1) { @@ -117,7 +117,7 @@ test("getHours (day after, with min)", () => { month: 4, day: 2, hour: 6, - }) + }), ); for (let i = 0; i < 24; i += 1) { @@ -139,7 +139,7 @@ test("getHours (month after, with min)", () => { month: 4, day: 2, hour: 6, - }) + }), ); for (let i = 0; i < 24; i += 1) { @@ -161,7 +161,7 @@ test("getHours (year after, with min)", () => { month: 4, day: 2, hour: 6, - }) + }), ); for (let i = 0; i < 24; i += 1) { @@ -184,7 +184,7 @@ test("getHours (year before, with max)", () => { month: 4, day: 2, hour: 18, - }) + }), ); for (let i = 0; i < 24; i += 1) { @@ -207,7 +207,7 @@ test("getHours (month before, with max)", () => { month: 4, day: 2, hour: 18, - }) + }), ); for (let i = 0; i < 24; i += 1) { @@ -230,7 +230,7 @@ test("getHours (day before, with max)", () => { month: 4, day: 2, hour: 18, - }) + }), ); for (let i = 0; i < 24; i += 1) { @@ -253,7 +253,7 @@ test("getHours (same day, with max)", () => { month: 4, day: 2, hour: 18, - }) + }), ); for (let i = 0; i < 24; i += 1) { @@ -281,7 +281,7 @@ test("getHours (day after, with max)", () => { month: 4, day: 2, hour: 18, - }) + }), ); for (let i = 0; i < 24; i += 1) { @@ -304,7 +304,7 @@ test("getHours (month after, with max)", () => { month: 4, day: 2, hour: 18, - }) + }), ); for (let i = 0; i < 24; i += 1) { @@ -327,7 +327,7 @@ test("getHours (year after, with max)", () => { month: 4, day: 2, hour: 18, - }) + }), ); for (let i = 0; i < 24; i += 1) { @@ -355,7 +355,7 @@ test("getHours (year before, with min and max)", () => { month: 4, day: 2, hour: 18, - }) + }), ); for (let i = 0; i < 24; i += 1) { @@ -383,7 +383,7 @@ test("getHours (month before, with min and max)", () => { month: 4, day: 2, hour: 18, - }) + }), ); for (let i = 0; i < 24; i += 1) { @@ -411,7 +411,7 @@ test("getHours (day before, with min and max)", () => { month: 4, day: 2, hour: 18, - }) + }), ); for (let i = 0; i < 24; i += 1) { @@ -439,7 +439,7 @@ test("getHours (same day, with min and max)", () => { month: 4, day: 2, hour: 18, - }) + }), ); for (let i = 0; i < 24; i += 1) { @@ -472,7 +472,7 @@ test("getHours (day after, with min and max)", () => { month: 4, day: 2, hour: 18, - }) + }), ); for (let i = 0; i < 24; i += 1) { @@ -500,7 +500,7 @@ test("getHours (month after, with min and max)", () => { month: 4, day: 2, hour: 18, - }) + }), ); for (let i = 0; i < 24; i += 1) { @@ -528,7 +528,7 @@ test("getHours (year after, with min and max)", () => { month: 4, day: 2, hour: 18, - }) + }), ); for (let i = 0; i < 24; i += 1) { diff --git a/packages/core/test/getMinutes.test.ts b/packages/core/test/getMinutes.test.ts index 019c87e..ca64af8 100644 --- a/packages/core/test/getMinutes.test.ts +++ b/packages/core/test/getMinutes.test.ts @@ -26,7 +26,7 @@ test("getMinutes (year before, with min)", () => { day: 2, hour: 2, minute: 15, - }) + }), ); for (let i = 0; i < 60; i += 1) { @@ -50,7 +50,7 @@ test("getMinutes (month before, with min)", () => { day: 2, hour: 2, minute: 15, - }) + }), ); for (let i = 0; i < 60; i += 1) { @@ -74,7 +74,7 @@ test("getMinutes (day before, with min)", () => { day: 2, hour: 2, minute: 15, - }) + }), ); for (let i = 0; i < 60; i += 1) { @@ -98,7 +98,7 @@ test("getMinutes (hour before, with min)", () => { day: 2, hour: 2, minute: 15, - }) + }), ); for (let i = 0; i < 60; i += 1) { @@ -122,7 +122,7 @@ test("getMinutes (same hour, with min)", () => { day: 2, hour: 2, minute: 15, - }) + }), ); for (let i = 0; i < 60; i += 1) { @@ -151,7 +151,7 @@ test("getMinutes (hour after, with min)", () => { day: 2, hour: 2, minute: 15, - }) + }), ); for (let i = 0; i < 60; i += 1) { @@ -175,7 +175,7 @@ test("getMinutes (day after, with min)", () => { day: 2, hour: 2, minute: 15, - }) + }), ); for (let i = 0; i < 60; i += 1) { @@ -199,7 +199,7 @@ test("getMinutes (month after, with min)", () => { day: 2, hour: 2, minute: 15, - }) + }), ); for (let i = 0; i < 60; i += 1) { @@ -223,7 +223,7 @@ test("getMinutes (year after, with min)", () => { day: 2, hour: 2, minute: 15, - }) + }), ); for (let i = 0; i < 60; i += 1) { @@ -248,7 +248,7 @@ test("getMinutes (year before, with max)", () => { day: 2, hour: 2, minute: 45, - }) + }), ); for (let i = 0; i < 60; i += 1) { @@ -273,7 +273,7 @@ test("getMinutes (month before, with max)", () => { day: 2, hour: 2, minute: 45, - }) + }), ); for (let i = 0; i < 60; i += 1) { @@ -298,7 +298,7 @@ test("getMinutes (day before, with max)", () => { day: 2, hour: 2, minute: 45, - }) + }), ); for (let i = 0; i < 60; i += 1) { @@ -323,7 +323,7 @@ test("getMinutes (hour before, with max)", () => { day: 2, hour: 2, minute: 45, - }) + }), ); for (let i = 0; i < 60; i += 1) { @@ -348,7 +348,7 @@ test("getMinutes (same hour, with max)", () => { day: 2, hour: 2, minute: 45, - }) + }), ); for (let i = 0; i < 60; i += 1) { @@ -378,7 +378,7 @@ test("getMinutes (hour after, with max)", () => { day: 2, hour: 2, minute: 45, - }) + }), ); for (let i = 0; i < 60; i += 1) { @@ -403,7 +403,7 @@ test("getMinutes (day after, with max)", () => { day: 2, hour: 2, minute: 45, - }) + }), ); for (let i = 0; i < 60; i += 1) { @@ -428,7 +428,7 @@ test("getMinutes (month after, with max)", () => { day: 2, hour: 2, minute: 45, - }) + }), ); for (let i = 0; i < 60; i += 1) { @@ -453,7 +453,7 @@ test("getMinutes (year after, with max)", () => { day: 2, hour: 2, minute: 45, - }) + }), ); for (let i = 0; i < 60; i += 1) { @@ -484,7 +484,7 @@ test("getMinutes (year before, with min and max)", () => { day: 2, hour: 2, minute: 45, - }) + }), ); for (let i = 0; i < 60; i += 1) { @@ -515,7 +515,7 @@ test("getMinutes (month before, with min and max)", () => { day: 2, hour: 2, minute: 45, - }) + }), ); for (let i = 0; i < 60; i += 1) { @@ -546,7 +546,7 @@ test("getMinutes (day before, with min and max)", () => { day: 2, hour: 2, minute: 45, - }) + }), ); for (let i = 0; i < 60; i += 1) { @@ -577,7 +577,7 @@ test("getMinutes (hour before, with min and max)", () => { day: 2, hour: 2, minute: 45, - }) + }), ); for (let i = 0; i < 60; i += 1) { @@ -608,7 +608,7 @@ test("getMinutes (same hour, with min and max)", () => { day: 2, hour: 2, minute: 45, - }) + }), ); for (let i = 0; i < 60; i += 1) { @@ -644,7 +644,7 @@ test("getMinutes (hour after, with min and max)", () => { day: 2, hour: 2, minute: 45, - }) + }), ); for (let i = 0; i < 60; i += 1) { @@ -675,7 +675,7 @@ test("getMinutes (day after, with min and max)", () => { day: 2, hour: 2, minute: 45, - }) + }), ); for (let i = 0; i < 60; i += 1) { @@ -706,7 +706,7 @@ test("getMinutes (month after, with min and max)", () => { day: 2, hour: 2, minute: 45, - }) + }), ); for (let i = 0; i < 60; i += 1) { @@ -737,7 +737,7 @@ test("getMinutes (year after, with min and max)", () => { day: 2, hour: 2, minute: 45, - }) + }), ); for (let i = 0; i < 60; i += 1) { diff --git a/packages/core/test/getMonthEndDate.test.ts b/packages/core/test/getMonthEndDate.test.ts index 78864f3..5457c28 100644 --- a/packages/core/test/getMonthEndDate.test.ts +++ b/packages/core/test/getMonthEndDate.test.ts @@ -8,7 +8,7 @@ test("getMonthEndDate", () => { year: 2022, month: 3, day: 7, - }) + }), ); expect( @@ -17,7 +17,7 @@ test("getMonthEndDate", () => { year: 2022, month: 3, day: 31, - }) - ) + }), + ), ).toBe(true); }); diff --git a/packages/core/test/getMonthStartDate.test.ts b/packages/core/test/getMonthStartDate.test.ts index f20bb96..eff7298 100644 --- a/packages/core/test/getMonthStartDate.test.ts +++ b/packages/core/test/getMonthStartDate.test.ts @@ -8,7 +8,7 @@ test("getMonthStartDate (PlainDate)", () => { year: 2022, month: 3, day: 7, - }) + }), ); expect( @@ -17,8 +17,8 @@ test("getMonthStartDate (PlainDate)", () => { year: 2022, month: 3, day: 1, - }) - ) + }), + ), ).toBe(true); }); @@ -29,7 +29,7 @@ test("getMonthStartDate (PlainDateTime)", () => { month: 3, day: 7, hour: 2, - }) + }), ); expect( @@ -38,7 +38,7 @@ test("getMonthStartDate (PlainDateTime)", () => { year: 2022, month: 3, day: 1, - }) - ) + }), + ), ).toBe(true); }); diff --git a/packages/core/test/getMonths.test.ts b/packages/core/test/getMonths.test.ts index 644a9a6..15aa73d 100644 --- a/packages/core/test/getMonths.test.ts +++ b/packages/core/test/getMonths.test.ts @@ -9,7 +9,7 @@ test("getMonths (unbounded)", () => { year: 2022, month: 4, day: 1, - }) + }), ); expect(months[2].month).equal(3); @@ -49,7 +49,7 @@ test("getMonths (with min)", () => { year: 2022, month: 4, day: 1, - }) + }), ); expect(months[2].month).equal(3); @@ -90,7 +90,7 @@ test("getMonths (with max)", () => { year: 2022, month: 4, day: 1, - }) + }), ); expect(months[2].month).equal(3); @@ -135,7 +135,7 @@ test("getMonths (with min and max)", () => { year: 2022, month: 4, day: 1, - }) + }), ); expect(months[2].month).equal(3); diff --git a/packages/core/test/getWeekdays.test.ts b/packages/core/test/getWeekdays.test.ts index fc77b5a..53c4d57 100644 --- a/packages/core/test/getWeekdays.test.ts +++ b/packages/core/test/getWeekdays.test.ts @@ -4,9 +4,7 @@ import { getWeekdays } from "../src/getWeekdays"; test("getWeekdays (startOfWeek = 7)", () => { const weekdays = getWeekdays("en-US", 7); - expect(weekdays.map(({ dayOfWeek }) => dayOfWeek)).toEqual([ - 7, 1, 2, 3, 4, 5, 6, - ]); + expect(weekdays.map(({ dayOfWeek }) => dayOfWeek)).toEqual([7, 1, 2, 3, 4, 5, 6]); expect(weekdays.map(({ longName }) => longName)).toEqual([ "Sunday", @@ -22,9 +20,7 @@ test("getWeekdays (startOfWeek = 7)", () => { test("getWeekdays (startOfWeek = 6)", () => { const weekdays = getWeekdays("en-US", 6); - expect(weekdays.map(({ dayOfWeek }) => dayOfWeek)).toEqual([ - 6, 7, 1, 2, 3, 4, 5, - ]); + expect(weekdays.map(({ dayOfWeek }) => dayOfWeek)).toEqual([6, 7, 1, 2, 3, 4, 5]); expect(weekdays.map(({ longName }) => longName)).toEqual([ "Saturday", diff --git a/packages/core/test/getYears.test.ts b/packages/core/test/getYears.test.ts index 656d08b..0119c6a 100644 --- a/packages/core/test/getYears.test.ts +++ b/packages/core/test/getYears.test.ts @@ -13,7 +13,7 @@ test("getYears", () => { year: 2024, month: 4, day: 1, - }) + }), ); expect(years).toEqual([2020, 2021, 2022, 2023, 2024]); diff --git a/packages/core/test/temporalToDate.test.ts b/packages/core/test/temporalToDate.test.ts index 02ea7aa..8192718 100644 --- a/packages/core/test/temporalToDate.test.ts +++ b/packages/core/test/temporalToDate.test.ts @@ -8,7 +8,7 @@ test("temporalToDate (PlainDate)", () => { year: 2022, month: 3, day: 31, - }) + }), ); expect(date.getFullYear()).toEqual(2022); @@ -30,7 +30,7 @@ test("temporalToDate (PlainDateTime)", () => { minute: 30, second: 45, millisecond: 600, - }) + }), ); expect(date.getFullYear()).toEqual(2022); diff --git a/packages/react/src/Calendar.tsx b/packages/react/src/Calendar.tsx index 76364f7..6e8743d 100644 --- a/packages/react/src/Calendar.tsx +++ b/packages/react/src/Calendar.tsx @@ -1,9 +1,5 @@ import { Temporal } from "@js-temporal/polyfill"; -import { - getCalendarMonthDateRange, - getMonthStartDate, - getWeekdays, -} from "@tempocal/core"; +import { getCalendarMonthDateRange, getMonthStartDate, getWeekdays } from "@tempocal/core"; import * as React from "react"; import { CSSProperties } from "react"; import { Locale } from "./useTempocal"; @@ -19,28 +15,19 @@ type MonthProps = { startOfWeek?: number; value: Value; calendarProps?: () => Omit< - React.DetailedHTMLProps< - React.HTMLAttributes, - HTMLUListElement - >, + React.DetailedHTMLProps, HTMLUListElement>, "style" >; headerProps?: (props: { date: Temporal.PlainDate; - }) => Omit< - React.DetailedHTMLProps, HTMLLIElement>, - "style" - >; + }) => Omit, HTMLLIElement>, "style">; renderHeader?: (props: { date: Temporal.PlainDate }) => React.ReactNode; weekdayProps?: (props: { dayOfWeek: number; longName: string; shortName: string; narrowName: string; - }) => React.DetailedHTMLProps< - React.LiHTMLAttributes, - HTMLLIElement - >; + }) => React.DetailedHTMLProps, HTMLLIElement>; renderWeekday?: (props: { dayOfWeek: number; longName: string; @@ -52,10 +39,7 @@ type MonthProps = { disabled: boolean; plainDateLike: Temporal.PlainDateLike; }) => Omit< - React.DetailedHTMLProps< - React.ButtonHTMLAttributes, - HTMLLIElement - >, + React.DetailedHTMLProps, HTMLLIElement>, "style" >; renderDay?: (props: { @@ -65,10 +49,7 @@ type MonthProps = { }) => React.ReactNode; footerProps?: (props: { date: Temporal.PlainDate; - }) => Omit< - React.DetailedHTMLProps, HTMLLIElement>, - "style" - >; + }) => Omit, HTMLLIElement>, "style">; renderFooter?: (props: { date: Temporal.PlainDate }) => React.ReactNode; }; @@ -97,7 +78,7 @@ export function Calendar({ }) { const months = React.useMemo( () => [...Array(Math.max(0, monthsBefore) + 1 + Math.max(0, monthsAfter))], - [monthsAfter, monthsBefore] + [monthsAfter, monthsBefore], ); return ( @@ -147,22 +128,16 @@ function Month({ }: MonthProps) { const { start, end } = React.useMemo( () => getCalendarMonthDateRange(value, rollover, startOfWeek), - [rollover, startOfWeek, value] + [rollover, startOfWeek, value], ); const monthStartDate = React.useMemo(() => getMonthStartDate(value), [value]); - const weekdays = React.useMemo( - () => getWeekdays(locale, startOfWeek), - [locale, startOfWeek] - ); + const weekdays = React.useMemo(() => getWeekdays(locale, startOfWeek), [locale, startOfWeek]); const days = React.useMemo( - () => - [...Array(start.until(end).days + 1)].map((_, day) => - start.add({ days: day }) - ), - [end, start] + () => [...Array(start.until(end).days + 1)].map((_, day) => start.add({ days: day })), + [end, start], ); const firstDay = days.at(0); @@ -216,25 +191,20 @@ function Month({ ))} {daysToPadAfter > 0 && firstDay && ( <> - {[...Array(Math.floor(daysToPadAfter / firstDay.daysInWeek))].map( - (_, index) => ( - - ) - )} + {[...Array(Math.floor(daysToPadAfter / firstDay.daysInWeek))].map((_, index) => ( + + ))} )} {renderFooter && ( diff --git a/packages/react/src/useTempocal.ts b/packages/react/src/useTempocal.ts index db3bee4..14b5679 100644 --- a/packages/react/src/useTempocal.ts +++ b/packages/react/src/useTempocal.ts @@ -1,11 +1,5 @@ import { Temporal } from "@js-temporal/polyfill"; -import { - clamp, - getHours, - getMinutes, - getMonths, - getYears, -} from "@tempocal/core"; +import { clamp, getHours, getMinutes, getMonths, getYears } from "@tempocal/core"; import * as React from "react"; export type ClampMode = "always" | "value-change" | "never"; @@ -23,36 +17,34 @@ export type DateTimeRange = type RequiredValue = Mode extends "date" ? Temporal.PlainDate : Mode extends "daterange" - ? DateRange - : Mode extends "datetime" - ? Temporal.PlainDateTime - : Mode extends "datetimerange" - ? DateTimeRange - : never; + ? DateRange + : Mode extends "datetime" + ? Temporal.PlainDateTime + : Mode extends "datetimerange" + ? DateTimeRange + : never; type ChangeValue = Mode extends "date" ? Temporal.PlainDate | Temporal.PlainDateLike : Mode extends "daterange" - ? - | Temporal.PlainDate - | Temporal.PlainDateLike - | [Temporal.PlainDate, Temporal.PlainDate] - | [undefined, undefined] - : Mode extends "datetime" - ? Temporal.PlainDateTime | Temporal.PlainDateTimeLike - : Mode extends "datetimerange" - ? - | Temporal.PlainDateTime - | Temporal.PlainDateTimeLike - | [Temporal.PlainDateTime, Temporal.PlainDateTime] - | [undefined, undefined] - : never; + ? + | Temporal.PlainDate + | Temporal.PlainDateLike + | [Temporal.PlainDate, Temporal.PlainDate] + | [undefined, undefined] + : Mode extends "datetime" + ? Temporal.PlainDateTime | Temporal.PlainDateTimeLike + : Mode extends "datetimerange" + ? + | Temporal.PlainDateTime + | Temporal.PlainDateTimeLike + | [Temporal.PlainDateTime, Temporal.PlainDateTime] + | [undefined, undefined] + : never; export type Locale = string; -export function useTempocal< - Mode extends "date" | "daterange" | "datetime" | "datetimerange" ->({ +export function useTempocal({ clampCalendarValue, clampSelectedValue, locale, @@ -66,8 +58,8 @@ export function useTempocal< clampSelectedValue?: Mode extends "date" ? ClampMode : Mode extends "datetime" - ? ClampMode - : never; + ? ClampMode + : never; locale: Locale; maxValue?: Temporal.PlainDate | Temporal.PlainDateTime; minValue?: Temporal.PlainDate | Temporal.PlainDateTime; @@ -93,12 +85,8 @@ export function useTempocal< } return getYears( - minValue instanceof Temporal.PlainDateTime - ? minValue.toPlainDate() - : minValue, - maxValue instanceof Temporal.PlainDateTime - ? maxValue.toPlainDate() - : maxValue + minValue instanceof Temporal.PlainDateTime ? minValue.toPlainDate() : minValue, + maxValue instanceof Temporal.PlainDateTime ? maxValue.toPlainDate() : maxValue, ); }, [maxValue, minValue]); @@ -106,12 +94,8 @@ export function useTempocal< return getMonths( locale, calendarValue, - minValue instanceof Temporal.PlainDateTime - ? minValue.toPlainDate() - : minValue, - maxValue instanceof Temporal.PlainDateTime - ? maxValue.toPlainDate() - : maxValue + minValue instanceof Temporal.PlainDateTime ? minValue.toPlainDate() : minValue, + maxValue instanceof Temporal.PlainDateTime ? maxValue.toPlainDate() : maxValue, ); }, [calendarValue, locale, maxValue, minValue]); @@ -149,19 +133,15 @@ export function useTempocal< const clampedValue = clamp( nextCalendarValue, - minValue instanceof Temporal.PlainDateTime - ? minValue.toPlainDate() - : minValue, - maxValue instanceof Temporal.PlainDateTime - ? maxValue.toPlainDate() - : maxValue + minValue instanceof Temporal.PlainDateTime ? minValue.toPlainDate() : minValue, + maxValue instanceof Temporal.PlainDateTime ? maxValue.toPlainDate() : maxValue, ); setCalendarValue(clampedValue); return clampedValue; }, - [clampCalendarValue, maxValue, minValue] + [clampCalendarValue, maxValue, minValue], ); const onChangeCalendarValue = React.useCallback( @@ -176,16 +156,12 @@ export function useTempocal< return updateCalendarValue(calendarValue.with(params)); }, - [calendarValue, updateCalendarValue] + [calendarValue, updateCalendarValue], ); const updateSelectedValue = React.useCallback( ( - nextSelectedValue: - | Temporal.PlainDate - | Temporal.PlainDateTime - | DateRange - | DateTimeRange + nextSelectedValue: Temporal.PlainDate | Temporal.PlainDateTime | DateRange | DateTimeRange, ) => { if ( !clampSelectedValue || @@ -205,16 +181,14 @@ export function useTempocal< return clampedValue; }, - [clampSelectedValue, maxValue, minValue, setValue] + [clampSelectedValue, maxValue, minValue, setValue], ); const onChangeSelectedValue = React.useCallback( (params: ChangeValue): RequiredValue => { if (Array.isArray(params)) { if (!["daterange", "datetimerange"].includes(mode)) { - throw new Error( - `Received an array in onChangeSelectedValue but mode is ${mode}` - ); + throw new Error(`Received an array in onChangeSelectedValue but mode is ${mode}`); } if (!params[0] && !params[1]) { @@ -237,10 +211,8 @@ export function useTempocal< } else { throw new Error( `Received an array of mixed values in onChangeSelectedValue but expected a pair of ${ - mode === "daterange" - ? "Temporal.PlainDate" - : "Temporal.PlainDateTime" - }` + mode === "daterange" ? "Temporal.PlainDate" : "Temporal.PlainDateTime" + }`, ); } @@ -248,10 +220,7 @@ export function useTempocal< } const nextValue = (() => { - if ( - params instanceof Temporal.PlainDate || - params instanceof Temporal.PlainDateTime - ) { + if (params instanceof Temporal.PlainDate || params instanceof Temporal.PlainDateTime) { return params; } @@ -280,7 +249,7 @@ export function useTempocal< return updateSelectedValue(nextValue) as RequiredValue; }, - [mode, setValue, updateSelectedValue, value] + [mode, setValue, updateSelectedValue, value], ); const previousClampSelectedValue = React.useRef(clampSelectedValue); @@ -318,14 +287,8 @@ export function useTempocal< return { calendarProps: { locale, - maxValue: - maxValue instanceof Temporal.PlainDateTime - ? maxValue.toPlainDate() - : maxValue, - minValue: - minValue instanceof Temporal.PlainDateTime - ? minValue.toPlainDate() - : minValue, + maxValue: maxValue instanceof Temporal.PlainDateTime ? maxValue.toPlainDate() : maxValue, + minValue: minValue instanceof Temporal.PlainDateTime ? minValue.toPlainDate() : minValue, value: calendarValue, }, years, diff --git a/packages/react/test/useTempocal.test.ts b/packages/react/test/useTempocal.test.ts index 8c3fd42..03c5be4 100644 --- a/packages/react/test/useTempocal.test.ts +++ b/packages/react/test/useTempocal.test.ts @@ -16,7 +16,7 @@ test("useTempocal", () => { mode: "date", setValue: (v: Temporal.PlainDate) => (value = v), value, - }) + }), ); expect(Object.keys(result.current).length).toBe(7); @@ -32,8 +32,8 @@ test("useTempocal", () => { year: 2022, month: 4, day: 15, - }) - ) + }), + ), ).toBe(true); expect( @@ -42,8 +42,8 @@ test("useTempocal", () => { year: 2022, month: 4, day: 15, - }) - ) + }), + ), ).toBe(true); expect(result.current.years).deep.equal([]); @@ -64,8 +64,8 @@ test("useTempocal", () => { year: 2023, month: 7, day: 15, - }) - ) + }), + ), ).toBe(true); }); @@ -75,8 +75,8 @@ test("useTempocal", () => { year: 2023, month: 7, day: 15, - }) - ) + }), + ), ).toBe(true); // onChangeSelectedValue @@ -94,8 +94,8 @@ test("useTempocal", () => { year: 2021, month: 1, day: 1, - }) - ) + }), + ), ).toBe(true); }); @@ -105,7 +105,7 @@ test("useTempocal", () => { year: 2021, month: 1, day: 1, - }) - ) + }), + ), ).toBe(true); }); diff --git a/packages/www/components/AnchorHeader.tsx b/packages/www/components/AnchorHeader.tsx index 7948990..d0002a8 100644 --- a/packages/www/components/AnchorHeader.tsx +++ b/packages/www/components/AnchorHeader.tsx @@ -1,12 +1,6 @@ import { LinkIcon } from "@heroicons/react/24/outline"; -export function AnchorHeader({ - children, - id, -}: { - children: string; - id: string; -}) { +export function AnchorHeader({ children, id }: { children: string; id: string }) { return (

diff --git a/packages/www/components/Checkbox.tsx b/packages/www/components/Checkbox.tsx index 2738fc3..e6af49e 100644 --- a/packages/www/components/Checkbox.tsx +++ b/packages/www/components/Checkbox.tsx @@ -4,10 +4,11 @@ export function Checkbox({ hint, label, ...props -}: React.DetailedHTMLProps< - React.InputHTMLAttributes, - HTMLInputElement -> & { hint?: string; id: string; label: string }) { +}: React.DetailedHTMLProps, HTMLInputElement> & { + hint?: string; + id: string; + label: string; +}) { return (
diff --git a/packages/www/components/Code.tsx b/packages/www/components/Code.tsx index 70ebdd2..42694a2 100644 --- a/packages/www/components/Code.tsx +++ b/packages/www/components/Code.tsx @@ -2,27 +2,11 @@ import classnames from "classnames"; import { Highlight, themes } from "prism-react-renderer"; import { GitHubLogo } from "./GitHubLogo"; -export function CodeBlock({ - children, - href, -}: { - children: string | undefined; - href?: string; -}) { +export function CodeBlock({ children, href }: { children: string | undefined; href?: string }) { return ( - + {({ className, style, tokens, getLineProps, getTokenProps }) => ( -
+        
           {href && (
             
{href && ( - {(i + 1) - .toString() - .padStart(tokens.length.toString().length, "0")} + {(i + 1).toString().padStart(tokens.length.toString().length, "0")} )} {line.map((token, key) => ( @@ -55,9 +37,5 @@ export function CodeBlock({ } export function Code({ children }: { children: string }) { - return ( - - {children} - - ); + return {children}; } diff --git a/packages/www/components/Example.tsx b/packages/www/components/Example.tsx index 0248127..f169fad 100644 --- a/packages/www/components/Example.tsx +++ b/packages/www/components/Example.tsx @@ -22,23 +22,20 @@ export function Example({ className={classnames( "flex flex-col sm:grid gap-4 items-start", "auto-rows-min grid-cols-[min-content,1fr]", - "2xl:grid-cols-[min-content,1fr,2fr]" + "2xl:grid-cols-[min-content,1fr,2fr]", )} >

{title}

{client ? demo : null}
@@ -47,7 +44,7 @@ export function Example({ className={classnames( "w-full overflow-auto rounded text-sm", "row-start-3 col-start-1 col-span-2", - "2xl:row-start-2 2xl:col-start-3" + "2xl:row-start-2 2xl:col-start-3", )} > {rawContent} diff --git a/packages/www/components/ExternalLink.tsx b/packages/www/components/ExternalLink.tsx index c5923ea..175aab9 100644 --- a/packages/www/components/ExternalLink.tsx +++ b/packages/www/components/ExternalLink.tsx @@ -1,12 +1,6 @@ import { ArrowTopRightOnSquareIcon } from "@heroicons/react/24/outline"; -export default function ExternalLink({ - children, - href, -}: { - children: string; - href: string; -}) { +export default function ExternalLink({ children, href }: { children: string; href: string }) { return (
, - HTMLInputElement -> & { hint?: string; id: string; label: string }) { +}: React.DetailedHTMLProps, HTMLInputElement> & { + hint?: string; + id: string; + label: string; +}) { return (
diff --git a/packages/www/components/Select.tsx b/packages/www/components/Select.tsx index e198d3c..47b45f7 100644 --- a/packages/www/components/Select.tsx +++ b/packages/www/components/Select.tsx @@ -4,10 +4,10 @@ export function Select({ className, label, ...props -}: React.DetailedHTMLProps< - React.SelectHTMLAttributes, - HTMLSelectElement -> & { id: string; label: string }) { +}: React.DetailedHTMLProps, HTMLSelectElement> & { + id: string; + label: string; +}) { return (

@@ -119,10 +109,7 @@ export function Sidebar() { ))}
- +
diff --git a/packages/www/examples/Basic.tsx b/packages/www/examples/Basic.tsx index 19cd6f2..ea4c730 100644 --- a/packages/www/examples/Basic.tsx +++ b/packages/www/examples/Basic.tsx @@ -8,7 +8,7 @@ export function Basic() { year: 2021, month: 11, day: 25, - }) + }), ); const { calendarProps } = useTempocal({ diff --git a/packages/www/examples/DateInput.tsx b/packages/www/examples/DateInput.tsx index 4567483..bf30f62 100644 --- a/packages/www/examples/DateInput.tsx +++ b/packages/www/examples/DateInput.tsx @@ -19,15 +19,10 @@ export function DateInput() { year: 2021, month: 11, day: 25, - }) + }), ); - const { - calendarProps, - months, - onChangeCalendarValue, - onChangeSelectedValue, - } = useTempocal({ + const { calendarProps, months, onChangeCalendarValue, onChangeSelectedValue } = useTempocal({ locale, mode: "date", setValue, @@ -46,15 +41,11 @@ export function DateInput() { .toString() .padStart(2, "0")}-${value.day.toString().padStart(2, "0")}`} /> -