From 1cbe0026a5624f2bc092c4ef9527809d90f67b95 Mon Sep 17 00:00:00 2001 From: Nick Amoscato Date: Wed, 7 May 2025 14:29:27 -0400 Subject: [PATCH 1/3] Add TypeScript definitions --- README.npm.md | 5 ++ count.d.ts | 146 +++++++++++++++++++++++++++++++++++++++ package.json | 30 ++++++++ tpl/help/countjs-host.md | 2 + 4 files changed, 183 insertions(+) create mode 100644 README.npm.md create mode 100644 count.d.ts create mode 100644 package.json diff --git a/README.npm.md b/README.npm.md new file mode 100644 index 00000000..c66a3bc2 --- /dev/null +++ b/README.npm.md @@ -0,0 +1,5 @@ +# GoatCounter + +This package contains the source of [GoatCounter's](https://www.goatcounter.com/) `count.js` and its corresponding TypeScript definitions. + +It facilitates [self-hosting](https://www.goatcounter.com/help/countjs-host) but does not intend to be imported as a conventional module. diff --git a/count.d.ts b/count.d.ts new file mode 100644 index 00000000..a5447a2d --- /dev/null +++ b/count.d.ts @@ -0,0 +1,146 @@ +interface Window { + /** + * GoatCounter JavaScript API + * + * @see https://www.goatcounter.com/help/js + */ + goatcounter: + | (GoatCounter.Settings & + GoatCounter.DataParameters & + GoatCounter.Methods) + | undefined; +} + +declare namespace GoatCounter { + /** + * Settings that can be defined via: + * + * - `window.goatcounter` object, declared _before_ loading `count.js` + * - ` + ``` + +### TypeScript + +To extend the global `Window` interface with a typed `goatcounter` property, configure TSConfig [`types`](https://www.typescriptlang.org/tsconfig/#types): + +```json +{ + "compilerOptions": { + "types": ["goatcounter"] + } +} +``` diff --git a/tpl/help/countjs-host.md b/tpl/help/countjs-host.md index 2b306d38..7090eba5 100644 --- a/tpl/help/countjs-host.md +++ b/tpl/help/countjs-host.md @@ -7,7 +7,7 @@ inside `