GlucoseIQ
A TypeScript data layer for glucose products: CGM analytics, design tokens, React hooks, SVG charts, test fixtures, and a CLI, with docs that run the library to draw their own report.
Built with
- TypeScript
- Node.js 24
- React 19
- Design Tokens
- SVG
- FHIR
- Vitest
- Fumadocs
- Turborepo
- Changesets

The data layer for glucose products
GlucoseIQ is a TypeScript toolkit I designed and built for glucose products. You hand it CGM readings and get back a typed report with metrics, chart-ready series, and SVG. Five packages cover the path from raw readings to pixels: the analytics core, React hooks and components, design tokens, synthetic test data, and a CLI. The docs at glucoseiq.dev run the library during the build to draw their own homepage report.
A continuous glucose monitor produces a reading every five minutes. Summarizing that stream takes metrics from the clinical literature, and most diabetes software ends up reimplementing them, usually with some of these problems:
Time in Range, AGP percentile bands, and variability metrics rewritten per project
Unit handling that silently mixes mg/dL and mmol/L in the same calculation
Analytics welded to a chart library, so the numbers can't be used anywhere else
Vendor exports from Dexcom, Libre, and Nightscout each parsed by hand
No way to test the pipeline without real patient data
GlucoseIQ grew out of Diabetic Utils. The headless core computes and returns data, and the other packages sit on top of it. Nothing in the core renders to a screen or makes a network call. The app keeps credentials, consent, transport, and storage, and GlucoseIQ normalizes the supported payloads and analyzes them.
Usable readings can still be incomplete
A week of patchy readings can still produce a Time in Range number, even when there isn't enough data to meet the consensus minimum of 14 days at 70% wear. GlucoseIQ reports validity and data sufficiency in separate fields, so an app can show the difference.
- Latest reading
- 101mg/dL
- 14-day mean
- 132mg/dL
- Variability CV
- 26.7%
- Below 70
- 0.8%
- 70–180
- 85.6%
- Above 180
- 13.7%
Enough data for a 14-day report
All expected readings are present in this synthetic sample.
Inspect the computed report
Output from analyzeGlucose() using a fixed seed and a 14-day UTC window. No patient data. Non-finite numbers appear as null in JSON. The optional percentile profile is disabled for this example.
{
"meanGlucose": 131.5,
"gmi": 6.5,
"cv": 26.7,
"sd": 35.2,
"timeInRange": {
"veryLow": {
"percentage": 0.4,
"duration": 75,
"readingCount": 15,
"averageValue": 49
},
"low": {
"percentage": 0.4,
"duration": 75,
"readingCount": 15,
"averageValue": 61
},
"inRange": {
"percentage": 85.6,
"duration": 17260,
"readingCount": 3452,
"averageValue": 121
},
"high": {
"percentage": 13.7,
"duration": 2755,
"readingCount": 551,
"averageValue": 200
},
"veryHigh": {
"percentage": 0,
"duration": 0,
"readingCount": 0,
"averageValue": null
},
"meetsTargets": {
"tirMeetsGoal": true,
"tbrLevel1Safe": true,
"tbrLevel2Safe": true,
"tarLevel1Acceptable": true,
"tarLevel2Acceptable": true,
"targetBasis": "consensus-ranges",
"overallAssessment": "excellent",
"recommendations": [
"All metrics meet consensus targets."
]
},
"summary": {
"totalReadings": 4033,
"totalDuration": 20165,
"dataQuality": "excellent"
}
},
"tightRange": {
"inRange": 69.7,
"belowRange": 0.7,
"aboveRange": 29.6,
"meetsTarget": true,
"target": 50,
"readingCount": 4033
},
"risk": {
"lbgi": 0.31024877045506144,
"hbgi": 2.460865210078005,
"adrr": 19.8,
"grade": {
"grade": 4.44,
"gradeEuglycemia": 26.94,
"gradeHyperglycemia": 71.1,
"gradeHypoglycemia": 1.96
},
"gri": {
"score": 13.1,
"zone": "A",
"hypoComponent": 2.2,
"hyperComponent": 11
},
"jIndex": 27.77,
"modd": 11.4,
"conga": 32.9
},
"dataSufficiency": {
"totalReadings": 4033,
"daysOfData": 14,
"activePercent": 100,
"meetsCGMStandard": true
},
"agpProfile": null,
"episodes": {
"hypoEvents": [
{
"type": "hypo",
"level": 2,
"startTime": "2026-05-04T02:35:00.000Z",
"endTime": "2026-05-04T03:20:00.000Z",
"durationMinutes": 45,
"extremeValue": 46,
"meanValue": 54,
"readingCount": 10
},
{
"type": "hypo",
"level": 2,
"startTime": "2026-05-09T02:35:00.000Z",
"endTime": "2026-05-09T03:20:00.000Z",
"durationMinutes": 45,
"extremeValue": 50,
"meanValue": 58,
"readingCount": 10
},
{
"type": "hypo",
"level": 2,
"startTime": "2026-05-14T02:35:00.000Z",
"endTime": "2026-05-14T03:20:00.000Z",
"durationMinutes": 45,
"extremeValue": 46,
"meanValue": 55,
"readingCount": 10
}
],
"hyperEvents": [
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-01T07:30:00.000Z",
"endTime": "2026-05-01T09:15:00.000Z",
"durationMinutes": 105,
"extremeValue": 225,
"meanValue": 211,
"readingCount": 22
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-01T13:35:00.000Z",
"endTime": "2026-05-01T14:50:00.000Z",
"durationMinutes": 75,
"extremeValue": 201,
"meanValue": 194,
"readingCount": 16
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-02T07:30:00.000Z",
"endTime": "2026-05-02T08:50:00.000Z",
"durationMinutes": 80,
"extremeValue": 201,
"meanValue": 193,
"readingCount": 17
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-02T13:25:00.000Z",
"endTime": "2026-05-02T15:15:00.000Z",
"durationMinutes": 110,
"extremeValue": 232,
"meanValue": 214,
"readingCount": 23
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-03T08:30:00.000Z",
"endTime": "2026-05-03T09:20:00.000Z",
"durationMinutes": 50,
"extremeValue": 185,
"meanValue": 183,
"readingCount": 11
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-03T14:05:00.000Z",
"endTime": "2026-05-03T15:40:00.000Z",
"durationMinutes": 95,
"extremeValue": 210,
"meanValue": 202,
"readingCount": 20
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-03T19:55:00.000Z",
"endTime": "2026-05-03T20:40:00.000Z",
"durationMinutes": 45,
"extremeValue": 196,
"meanValue": 192,
"readingCount": 10
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-04T13:45:00.000Z",
"endTime": "2026-05-04T15:00:00.000Z",
"durationMinutes": 75,
"extremeValue": 199,
"meanValue": 194,
"readingCount": 16
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-04T20:00:00.000Z",
"endTime": "2026-05-04T20:35:00.000Z",
"durationMinutes": 35,
"extremeValue": 186,
"meanValue": 184,
"readingCount": 8
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-05T07:25:00.000Z",
"endTime": "2026-05-05T08:50:00.000Z",
"durationMinutes": 85,
"extremeValue": 221,
"meanValue": 210,
"readingCount": 18
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-05T13:40:00.000Z",
"endTime": "2026-05-05T14:45:00.000Z",
"durationMinutes": 65,
"extremeValue": 198,
"meanValue": 193,
"readingCount": 14
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-05T20:30:00.000Z",
"endTime": "2026-05-05T21:10:00.000Z",
"durationMinutes": 40,
"extremeValue": 184,
"meanValue": 182,
"readingCount": 9
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-06T07:35:00.000Z",
"endTime": "2026-05-06T09:30:00.000Z",
"durationMinutes": 115,
"extremeValue": 211,
"meanValue": 203,
"readingCount": 24
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-06T14:05:00.000Z",
"endTime": "2026-05-06T15:55:00.000Z",
"durationMinutes": 110,
"extremeValue": 222,
"meanValue": 209,
"readingCount": 23
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-06T20:35:00.000Z",
"endTime": "2026-05-06T20:55:00.000Z",
"durationMinutes": 20,
"extremeValue": 184,
"meanValue": 183,
"readingCount": 5
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-07T07:40:00.000Z",
"endTime": "2026-05-07T09:30:00.000Z",
"durationMinutes": 110,
"extremeValue": 216,
"meanValue": 205,
"readingCount": 23
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-07T14:15:00.000Z",
"endTime": "2026-05-07T15:40:00.000Z",
"durationMinutes": 85,
"extremeValue": 203,
"meanValue": 195,
"readingCount": 18
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-07T20:05:00.000Z",
"endTime": "2026-05-07T20:50:00.000Z",
"durationMinutes": 45,
"extremeValue": 189,
"meanValue": 186,
"readingCount": 10
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-08T19:50:00.000Z",
"endTime": "2026-05-08T21:15:00.000Z",
"durationMinutes": 85,
"extremeValue": 207,
"meanValue": 200,
"readingCount": 18
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-09T08:05:00.000Z",
"endTime": "2026-05-09T09:35:00.000Z",
"durationMinutes": 90,
"extremeValue": 214,
"meanValue": 203,
"readingCount": 19
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-09T14:10:00.000Z",
"endTime": "2026-05-09T15:20:00.000Z",
"durationMinutes": 70,
"extremeValue": 205,
"meanValue": 197,
"readingCount": 15
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-10T07:50:00.000Z",
"endTime": "2026-05-10T09:55:00.000Z",
"durationMinutes": 125,
"extremeValue": 232,
"meanValue": 216,
"readingCount": 26
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-10T13:55:00.000Z",
"endTime": "2026-05-10T15:15:00.000Z",
"durationMinutes": 80,
"extremeValue": 204,
"meanValue": 196,
"readingCount": 17
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-10T19:55:00.000Z",
"endTime": "2026-05-10T20:55:00.000Z",
"durationMinutes": 60,
"extremeValue": 197,
"meanValue": 193,
"readingCount": 13
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-11T07:50:00.000Z",
"endTime": "2026-05-11T08:35:00.000Z",
"durationMinutes": 45,
"extremeValue": 187,
"meanValue": 185,
"readingCount": 10
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-11T13:40:00.000Z",
"endTime": "2026-05-11T14:10:00.000Z",
"durationMinutes": 30,
"extremeValue": 185,
"meanValue": 183,
"readingCount": 7
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-12T07:40:00.000Z",
"endTime": "2026-05-12T08:55:00.000Z",
"durationMinutes": 75,
"extremeValue": 197,
"meanValue": 192,
"readingCount": 16
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-12T13:55:00.000Z",
"endTime": "2026-05-12T15:15:00.000Z",
"durationMinutes": 80,
"extremeValue": 197,
"meanValue": 191,
"readingCount": 17
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-12T20:25:00.000Z",
"endTime": "2026-05-12T20:55:00.000Z",
"durationMinutes": 30,
"extremeValue": 183,
"meanValue": 182,
"readingCount": 7
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-13T07:50:00.000Z",
"endTime": "2026-05-13T09:05:00.000Z",
"durationMinutes": 75,
"extremeValue": 206,
"meanValue": 198,
"readingCount": 16
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-13T13:45:00.000Z",
"endTime": "2026-05-13T15:30:00.000Z",
"durationMinutes": 105,
"extremeValue": 220,
"meanValue": 207,
"readingCount": 22
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-14T07:40:00.000Z",
"endTime": "2026-05-14T09:40:00.000Z",
"durationMinutes": 120,
"extremeValue": 221,
"meanValue": 209,
"readingCount": 25
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-14T13:45:00.000Z",
"endTime": "2026-05-14T15:05:00.000Z",
"durationMinutes": 80,
"extremeValue": 202,
"meanValue": 196,
"readingCount": 17
},
{
"type": "hyper",
"level": 1,
"startTime": "2026-05-14T19:45:00.000Z",
"endTime": "2026-05-14T21:15:00.000Z",
"durationMinutes": 90,
"extremeValue": 205,
"meanValue": 198,
"readingCount": 19
}
],
"summary": {
"hypoCount": 3,
"hyperCount": 34,
"hypoLevel2Count": 3,
"hyperLevel2Count": 0,
"totalHypoMinutes": 135,
"totalHyperMinutes": 2585
}
},
"valid": true
}Report blocks are nullable, so the caller has to handle a percentage that might not exist. Callers check for usable readings first and sufficient coverage second.
I'm not a clinician. The library has to be clear about its limits, especially when the readings don't support a broader summary.
One glucose model, from tokens to components
@glucoseiq/tokens turns the international consensus ranges
into five named zones, from veryLow below 54 mg/dL to
veryHigh above 250. It exports the ordered zones and their
thresholds, so a legend, a scale, and a control all come from the same
model. Every zone has a color in both themes, cssVariables()
returns declarations without a selector so the app decides where the
theme lives, and TREND_GLYPHS covers the eight trend states
the connectors produce. The package has no runtime dependencies and
needs no React, CSS framework, or browser.
@glucoseiq/react follows the same rule as its docs: choose
the smallest API that fits. Five memoized hooks return typed data for a
custom chart in D3, Visx, or Canvas, and three SVG components,
AgpChart, TirBar, and TrendTile,
render a finished one. useGlucoseLive derives the latest
reading, its trend, and how stale it is, while the app still owns
fetching new readings. The docs ask for a text summary beside every
chart, so values and trends never depend on color or shape alone.
The zone thresholds are the fixed consensus defaults. Personalized, pregnancy-specific, or research ranges go through the configurable analytics in the core.
The host owns the presentation
Renderers return SVG strings for AGP charts, Time in Range bars, and trend tiles. The host decides how to embed, sanitize, or deliver that string, so the same call works in a React app, a server-rendered report, or a PDF pipeline.
Vendor formats normalize into one reading shape, and results can go out in formats other health systems already read:
Connectors for Dexcom, Libre, and Nightscout, with declared capabilities per source
FHIR and Open mHealth output for systems that speak those standards
Mixed-unit-aware APIs normalize declared mg/dL and mmol/L before calculating
CSV parsing against an explicit contract for unfamiliar exports
A CLI that analyzes a mapped CSV file and can write the AGP chart as SVG, with no application code
A separate package ships fixed-seed synthetic CGM data and scenario fixtures, so tests, demos, and documentation run on realistic glucose traces without touching anyone's real readings. The same seed always returns the same readings.
The docs site is built with Fumadocs and organized by task: start here, learn the engine, use the ecosystem, ship and operate, and the API reference. CI type-checks and runs its code samples, so if a snippet stops compiling, the build fails and the examples stay in step with the API.
Release checks and remaining API work
The core has no runtime or peer dependencies, and the release checks keep it that way:
Vitest thresholds at 100% for lines, functions, branches, and statements
A gzip budget on the reachable core ESM that fails the build when it's exceeded
Packed-package consumer tests, so what publishes is what gets tested
Releases wait on build, lint, type checking, coverage, size, consumer tests, and the docs build
GlucoseIQ is for informational, educational, and software development use. It isn't medical advice, and it isn't a medical device. The library computes numbers that look clinical, so the README, the docs, and this page all say so.
The API labels anything the project defined itself:
glucoseIQScoreis non-diagnostic. It's a project-defined score derived from GRI, and it isn't a published measurebuildAGPProfilereturns AGP-style bands, a percentile series. It doesn't produce a complete standardized AGP reportvalidis notsufficient, so data adequacy has its own field and isn't folded into a booleanEmbedding policy stays with the host, because a library that returns an SVG string can't know where it'll be placed
Packages publish under the 1.0.0-next tag. The analytics are
settled and covered by tests, and what's left before 1.0 is the public API
surface.
API example, package reference, and input contracts
Validity and sufficiency
function summarize(readings: GlucoseReading[]) {
const report = analyzeGlucose(readings, { timeZone: 'America/Detroit' })
// `valid` only means at least one usable reading survived filtering.
if (!report.valid || report.timeInRange === null) {
return { status: 'no-data' } as const
}
// Whether that data is adequate is a separate question,
// and it gets a separate field rather than folding into `valid`.
const { meetsCGMStandard, daysOfData, activePercent } =
report.dataSufficiency
if (!meetsCGMStandard) {
return { status: 'insufficient', daysOfData, activePercent } as const
}
return {
status: 'ok',
timeInRange: report.timeInRange.inRange.percentage,
gmi: report.gmi,
} as const
}Metric modules
Seventeen metric modules, each named for the published measure it implements:
AGP percentile profiles, Time in Range, and time-above and time-below episodes
Variability: MAGE, CONGA, MODD, ADRR, J-Index, M-value, GVI and PGS
Risk and control indices: GRI, GRADE, IGC, BGI, AUC
Meal response, curve shape, and active sensor percentage
Five packages
@glucoseiq/corefor analytics, connectors, interop, and SVG renderers@glucoseiq/reactfor memoized hooks and SVG components, React 18 or newer@glucoseiq/tokensfor the five-zone glucose palette, thresholds, CSS variables, and trend glyphs@glucoseiq/testingfor fixed-seed synthetic data and scenario fixtures@glucoseiq/clifor analyzing mapped CSV without writing any application code
Input contracts
The CSV parser has an explicit contract for unfamiliar exports:
A custom delimiter must be exactly one UTF-16 code unit, and double quote, NUL, carriage return, and line feed are rejected
Blank or BOM-only input returns an empty result, and so does a valid header-only file
Missing required headers throw, and individually invalid rows are skipped
Renderer dimensions must be finite positive numbers, and text values are escaped
Project notes
17 metrics
AGP, TIR, GRI, MAGE, CONGA, MODD and more, from the clinical literature
5 packages
Analytics core, React, design tokens, synthetic test data, and a CLI
Zero deps
Headless core with no runtime dependencies, held to 100% coverage