From ae9f8d44709524a1c00ddb5ab1401226350b5b3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Thu, 26 Nov 2026 19:15:45 +0100 Subject: [PATCH 1/3] TypeScript Port the source and tests to TypeScript; the package now ships its type declarations (dist/index.d.ts, also exported as the "types" condition). - Exported types: Quaternion, Angles, Cartesian, Spherical, and VersorFunction (the default export, with documented helpers). - Build: @rollup/plugin-typescript for the bundles, tsc -p tsconfig.build.json for the declarations; target ES2019. CI also runs tsc and prepublishOnly, as in Plot. - Lint: typescript-eslint, with the rules Plot uses. - The bundles compute the same results as 0.2.2 (480,000 compared calls). One edge case changes: versor.delta(v0, v1, undefined) now uses alpha = 1 (it returned NaN), since the type allows an undefined alpha. Fixes #2. Supersedes #3 (thanks @clhenrick for the original definitions). --- .github/workflows/test.yml | 2 + README.md | 2 +- eslint.config.js | 7 +- package.json | 13 +- pnpm-lock.yaml | 278 +++++++++++++++++++++++- rollup.config.js | 4 +- src/index.js | 139 ------------ src/index.ts | 160 ++++++++++++++ test/{versor-test.js => versor-test.ts} | 6 +- tsconfig.build.json | 12 + tsconfig.json | 11 + vitest.config.js | 2 +- 12 files changed, 479 insertions(+), 157 deletions(-) delete mode 100644 src/index.js create mode 100644 src/index.ts rename test/{versor-test.js => versor-test.ts} (94%) create mode 100644 tsconfig.build.json create mode 100644 tsconfig.json diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 63d0c51..52d07c4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,3 +21,5 @@ jobs: - run: pnpm install - run: pnpm run test - run: pnpm run lint + - run: pnpm run tsc + - run: pnpm run prepublishOnly diff --git a/README.md b/README.md index 8c76cfe..6caf67a 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ versor.rotation(versor([30, 90, -30])); // [60, 90, 0] ``` -If you use npm, `npm install versor`. You can also download the [latest release on GitHub](https://github.com/d3/versor/releases/latest). For vanilla HTML in modern browsers, import versor from esm.sh: +If you use npm, `npm install versor`; versor is written in TypeScript, and the package includes its type declarations. You can also download the [latest release on GitHub](https://github.com/d3/versor/releases/latest). For vanilla HTML in modern browsers, import versor from esm.sh: ```html ``` @@ -67,7 +67,7 @@ If you use npm, `npm install versor`; versor is written in TypeScript, and the p For legacy environments, you can load versor’s UMD bundle from an npm-based CDN such as jsDelivr; a `versor` global is exported: ```html - +