diff --git a/package.json b/package.json index a459b87..40375b5 100644 --- a/package.json +++ b/package.json @@ -42,37 +42,26 @@ "/packages/**/*.(js|jsx|ts|tsx)", "!/packages/*/(.dist|dist|es|lib)/**/*", "!**/*.(spec|test).*", - "!**/babel.config.js", "!**/rollup.config.js", "!**/rollup-config.ts" ] }, "dependencies": { - "@babel/core": "^7.23.3", - "@babel/eslint-parser": "^7.23.3", - "@babel/plugin-transform-runtime": "^7.23.4", - "@babel/preset-env": "^7.23.3", - "@babel/preset-react": "^7.23.3", - "@babel/preset-typescript": "^7.23.3", - "@babel/register": "^7.22.15", - "@changesets/cli": "^2.26.2", - "@manypkg/cli": "^0.21.0", - "@testing-library/jest-dom": "^6.1.4", - "@types/babel__core": "^7.20.5", - "@types/content-type": "^1.1.8", - "@types/jest": "^29.5.10", + "@changesets/cli": "^2.27.1", + "@manypkg/cli": "^0.21.2", + "@testing-library/jest-dom": "^6.4.1", + "@types/jest": "^29.5.12", "@types/jest-when": "^3.5.5", "@types/lodash": "^4.14.202", - "@types/node": "^20.9.5", - "@types/react-dom": "^18.2.17", - "@typescript-eslint/eslint-plugin": "^6.12.0", - "@typescript-eslint/parser": "^6.12.0", - "babel-plugin-import": "^1.13.8", - "core-js": "^3.33.3", - "eslint": "^8.54.0", - "eslint-config-prettier": "^9.0.0", + "@types/node": "^20.11.16", + "@types/react-dom": "^18.2.18", + "@typescript-eslint/eslint-plugin": "^6.20.0", + "@typescript-eslint/parser": "^6.20.0", + "core-js": "^3.35.1", + "eslint": "^8.56.0", + "eslint-config-prettier": "^9.1.0", "eslint-import-resolver-node": "^0.3.9", - "eslint-plugin-prettier": "^5.0.1", + "eslint-plugin-prettier": "^5.1.3", "eslint-plugin-react": "^7.33.2", "jest": "^29.7.0", "jest-environment-jsdom": "^29.7.0", @@ -80,11 +69,11 @@ "jsdom-global": "^3.0.2", "lodash": "^4.17.21", "npm-run-all": "^4.1.5", - "prettier": "^3.0.3", + "prettier": "^3.2.4", "react": "^18.2.0", "react-dom": "^18.2.0", "rimraf": "^5.0.5", - "ts-jest": "^29.1.1", - "typescript": "^5.3.2" + "ts-jest": "^29.1.2", + "typescript": "^5.3.3" } } diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json index 6906cf1..b4ffded 100644 --- a/packages/eslint-config/package.json +++ b/packages/eslint-config/package.json @@ -1,6 +1,6 @@ { "name": "@kablamo/eslint-config", - "version": "0.0.17", + "version": "0.0.18", "main": "index.js", "repository": "https://github.com/KablamoOSS/kerosene/tree/master/packages/eslint-config", "bugs": { @@ -18,22 +18,22 @@ "eslint": "^7 || ^8" }, "devDependencies": { - "eslint": "^8.54.0" + "eslint": "^8.56.0" }, "engines": { "node": ">=18.12.0" }, "dependencies": { "@kablamo/eslint-plugin": "^2.0.1", - "@typescript-eslint/eslint-plugin": "^6.12.0", - "@typescript-eslint/parser": "^6.12.0", + "@typescript-eslint/eslint-plugin": "^6.20.0", + "@typescript-eslint/parser": "^6.20.0", "eslint-config-airbnb": "^19.0.4", - "eslint-config-prettier": "^9.0.0", + "eslint-config-prettier": "^9.1.0", "eslint-import-resolver-node": "^0.3.9", "eslint-import-resolver-typescript": "^3.6.1", - "eslint-plugin-import": "^2.29.0", + "eslint-plugin-import": "^2.29.1", "eslint-plugin-jsx-a11y": "^6.8.0", - "eslint-plugin-prettier": "^5.0.1", + "eslint-plugin-prettier": "^5.1.3", "eslint-plugin-react": "^7.33.2", "eslint-plugin-react-hooks": "^4.6.0" } diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 3b427f9..2819cef 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -18,7 +18,7 @@ "eslint": "^7 || ^8" }, "devDependencies": { - "@types/eslint": "^8.44.7", - "eslint": "^8.54.0" + "@types/eslint": "^8.56.2", + "eslint": "^8.56.0" } } diff --git a/packages/kerosene-test/package.json b/packages/kerosene-test/package.json index 904c64e..aea182e 100644 --- a/packages/kerosene-test/package.json +++ b/packages/kerosene-test/package.json @@ -1,6 +1,6 @@ { "name": "@kablamo/kerosene-test", - "version": "0.0.15", + "version": "0.0.16", "repository": "https://github.com/KablamoOSS/kerosene/tree/master/packages/kerosene-test", "bugs": { "url": "https://github.com/KablamoOSS/kerosene/issues" @@ -46,9 +46,9 @@ "utils" ], "dependencies": { - "@kablamo/kerosene": "^0.0.39", + "@kablamo/kerosene": "^0.0.40", "@types/lodash": "^4.14.202", - "@types/sinon": "^17.0.2", + "@types/sinon": "^17.0.3", "lodash": "^4.17.21", "sinon": "^17.0.1" }, diff --git a/packages/kerosene-ui/.npmignore b/packages/kerosene-ui/.npmignore index ac74439..d251757 100644 --- a/packages/kerosene-ui/.npmignore +++ b/packages/kerosene-ui/.npmignore @@ -1,6 +1,5 @@ __snapshots__ config -babel.config.js rollup-config.ts rollup.config.js **.spec.ts diff --git a/packages/kerosene-ui/package.json b/packages/kerosene-ui/package.json index ec52eac..bd5df23 100644 --- a/packages/kerosene-ui/package.json +++ b/packages/kerosene-ui/package.json @@ -35,31 +35,31 @@ "node": ">=18.12.0" }, "dependencies": { - "@kablamo/kerosene": "^0.0.39", + "@kablamo/kerosene": "^0.0.40", "@types/lodash": "^4.14.202", "esbuild-register": "^3.5.0", "lodash": "^4.17.21", "use-sync-external-store": "^1.2.0" }, "devDependencies": { - "@kablamo/kerosene-test": "^0.0.15", + "@kablamo/kerosene-test": "^0.0.16", "@kablamo/rollup-plugin-resolve-externals": "^0.0.2", "@optimize-lodash/rollup-plugin": "^4.0.4", "@sinonjs/fake-timers": "^11.2.2", - "@tanstack/react-query": "^5.12.2", - "@testing-library/dom": "^9.3.3", - "@testing-library/react": "^14.1.2", - "@testing-library/user-event": "^14.5.1", + "@tanstack/react-query": "^5.18.0", + "@testing-library/dom": "^9.3.4", + "@testing-library/react": "^14.2.1", + "@testing-library/user-event": "^14.5.2", "@types/sinonjs__fake-timers": "^8.1.5", "@types/use-sync-external-store": "^0.0.6", - "esbuild": "^0.19.11", + "esbuild": "^0.20.0", "jest-sandbox": "^1.1.2", "jest-when": "^3.6.0", "react": "^18.2.0", "react-dom": "^18.2.0", - "react-error-boundary": "^4.0.11", - "rollup": "^4.5.1", - "rollup-plugin-esbuild": "^6.1.0" + "react-error-boundary": "^4.0.12", + "rollup": "^4.9.6", + "rollup-plugin-esbuild": "^6.1.1" }, "peerDependencies": { "@tanstack/react-query": ">=5.0.0 <6.0.0", diff --git a/packages/kerosene-ui/src/types/index.ts b/packages/kerosene-ui/src/types/index.ts index 9af0912..68d81eb 100644 --- a/packages/kerosene-ui/src/types/index.ts +++ b/packages/kerosene-ui/src/types/index.ts @@ -2,12 +2,11 @@ * Unwraps the decorated typings from a decorator-wrapped components to provide the original type of the underlying * component. Useful in unit testing when stubbing decorators with the identity function. */ -export type UnwrapComponent = T extends React.MemoExoticComponent< - infer TMemoComponent -> - ? UnwrapComponent - : T extends React.LazyExoticComponent - ? UnwrapComponent - : "WrappedComponent" extends keyof T - ? UnwrapComponent - : T; +export type UnwrapComponent = + T extends React.MemoExoticComponent + ? UnwrapComponent + : T extends React.LazyExoticComponent + ? UnwrapComponent + : "WrappedComponent" extends keyof T + ? UnwrapComponent + : T; diff --git a/packages/kerosene-ui/src/utils/getSafeAreaInsets.ts b/packages/kerosene-ui/src/utils/getSafeAreaInsets.ts index 6e2cc50..6171d97 100644 --- a/packages/kerosene-ui/src/utils/getSafeAreaInsets.ts +++ b/packages/kerosene-ui/src/utils/getSafeAreaInsets.ts @@ -22,7 +22,7 @@ export default function getSafeAreaInsets(): SafeAreaInsets { return SIDES.reduce( (acc, side) => ({ ...acc, - [side]: (computed[side] && parseInt(computed[side]!, 10)) || 0, + [side]: (computed[side] && parseInt(computed[side], 10)) || 0, }), {} as Partial as SafeAreaInsets, ); diff --git a/packages/kerosene/package.json b/packages/kerosene/package.json index 2203dfd..ad32c0a 100644 --- a/packages/kerosene/package.json +++ b/packages/kerosene/package.json @@ -1,6 +1,6 @@ { "name": "@kablamo/kerosene", - "version": "0.0.39", + "version": "0.0.40", "repository": "https://github.com/KablamoOSS/kerosene/tree/master/packages/kerosene", "bugs": { "url": "https://github.com/KablamoOSS/kerosene/issues" @@ -32,20 +32,21 @@ "dependencies": { "@types/lodash": "^4.14.202", "content-type": "^1.0.5", - "core-js-pure": "^3.33.3", - "date-fns": "^2.30.0", + "core-js-pure": "^3.35.1", + "date-fns": "^3.3.1", "lodash": "^4.17.21" }, "devDependencies": { "@kablamo/rollup-plugin-resolve-externals": "^0.0.2", "@optimize-lodash/rollup-plugin": "^4.0.4", "@sinonjs/fake-timers": "^11.2.2", + "@types/content-type": "^1.1.8", "@types/seed-random": "^2.2.4", - "esbuild": "^0.19.11", + "esbuild": "^0.20.0", "esbuild-register": "^3.5.0", "jest-when": "^3.6.0", - "rollup": "^4.5.1", - "rollup-plugin-esbuild": "^6.1.0", + "rollup": "^4.9.6", + "rollup-plugin-esbuild": "^6.1.1", "seed-random": "^2.2.0" }, "peerDependencies": {}, diff --git a/packages/kerosene/readme.md b/packages/kerosene/readme.md index beb3f0b..59e9320 100644 --- a/packages/kerosene/readme.md +++ b/packages/kerosene/readme.md @@ -42,27 +42,27 @@ Otherwise, immutably removes that item from the array. ### `SECOND` -1000 milliseconds +Milliseconds in one second (1,000). ### `MINUTE` -60,000 milliseconds +Milliseconds in one minute (60,000). ### `HOUR` -3,600,000 milliseconds +Milliseconds in one hour (3,600,000). ### `DAY` -86,400,000 milliseconds +Milliseconds in one 24-hour day (86,400,000). ### `Month` -A 0-indexed enum for the months of the Gregorian Calendar +A 0-indexed enum for the months of the Gregorian Calendar. ### `DayOfWeek` -A 0-indexed enum for the days of the week +A 0-indexed enum for the days of the week, starting at Sunday. ### `getCalendarWeeks(month, startOfWeek)` diff --git a/packages/kerosene/src/datetime/constants.ts b/packages/kerosene/src/datetime/constants.ts index 8d66a6b..1bf9b25 100644 --- a/packages/kerosene/src/datetime/constants.ts +++ b/packages/kerosene/src/datetime/constants.ts @@ -1,15 +1,48 @@ -export const SECOND = 1_000; +import { + daysInWeek, + millisecondsInDay, + millisecondsInHour, + millisecondsInMinute, + millisecondsInSecond, + monthsInYear, +} from "date-fns/constants"; -export const MINUTE = 60 * SECOND; +/** + * Milliseconds in one second + */ +export const SECOND = millisecondsInSecond; -export const HOUR = 60 * MINUTE; +/** + * Milliseconds in one minute + */ +export const MINUTE = millisecondsInMinute; -export const DAY = 24 * HOUR; +/** + * Milliseconds in one hour + */ +export const HOUR = millisecondsInHour; -export const DAYS_PER_WEEK = 7; +/** + * Milliseconds in one 24-hour day + * + * Be aware of the [falsehoods programmers believe about time](https://gist.github.com/timvisee/fcda9bbdff88d45cc9061606b4b923ca). + * Not all days have 24 hours. + */ +export const DAY = millisecondsInDay; -export const MONTHS_PER_YEAR = 12; +/** + * Number of days in one week + */ +export const DAYS_PER_WEEK = daysInWeek; +/** + * Number of months in one year + */ +export const MONTHS_PER_YEAR = monthsInYear; + +/** + * A 0-indexed enum for the months of the Gregorian Calendar + */ export enum Month { JANUARY = 0, FEBRUARY, @@ -25,6 +58,9 @@ export enum Month { DECEMBER, } +/** + * A 0-indexed enum for the days of the week, starting at Sunday + */ export enum DayOfWeek { SUNDAY = 0, MONDAY, diff --git a/packages/kerosene/src/datetime/getCalendarWeeks.ts b/packages/kerosene/src/datetime/getCalendarWeeks.ts index 423c925..e3fb386 100644 --- a/packages/kerosene/src/datetime/getCalendarWeeks.ts +++ b/packages/kerosene/src/datetime/getCalendarWeeks.ts @@ -28,6 +28,8 @@ export type CalendarWeeks = * to the timezone of the environment). * @param month Date for the month * @param firstDayOfWeek 0-indexed `DayOfWeek` + * + * @deprecated Use a library like `react-aria-components` which accounts for internationalisation */ export default function getCalendarWeeks( month: Date | number, diff --git a/packages/kerosene/src/string/domSafeJson.spec.ts b/packages/kerosene/src/string/domSafeJson.spec.ts index bc7c351..ff4b22c 100644 --- a/packages/kerosene/src/string/domSafeJson.spec.ts +++ b/packages/kerosene/src/string/domSafeJson.spec.ts @@ -1,12 +1,12 @@ import domSafeJson from "./domSafeJson"; describe("domSafeJson", () => { - it("should escape the opening angle bracket", () => { + it("should escape ampersand and angle brackets", () => { expect( domSafeJson({ - field: "", + field: "&", }), - ).toBe('{"field":"\\u003c/script>"}'); + ).toBe('{"field":"\\u0026\\u003c/script\\u003e"}'); }); it("should escape unicode characters in the range 007f to ffff", () => { diff --git a/packages/kerosene/src/string/domSafeJson.ts b/packages/kerosene/src/string/domSafeJson.ts index 6ffd2b8..7a6ba12 100644 --- a/packages/kerosene/src/string/domSafeJson.ts +++ b/packages/kerosene/src/string/domSafeJson.ts @@ -3,7 +3,7 @@ import escape from "./escape"; /** * These characters are unsafe */ -const UNSAFE_CHARACTERS_REGEX = /([<\u007f-\uffff])/g; +const UNSAFE_CHARACTERS_REGEX = /([&><\u007f-\uffff])/g; /** * Like `JSON.stringify(value)`, but escaped for safe insertion into the DOM, such as inside a `