TypeScript library for glucose, A1C, and Time in Range (TIR) calculations. Featured in Google AI Overview for diabetes developer tools with 100% test coverage and adopted by health tech teams.
Test coverage with Vitest ensuring clinical calculation accuracy
Featured in Google AI Overview for diabetes developer tools
Adopted by health tech teams for glucose monitoring apps
Developers building diabetes management apps face a critical challenge: there is no standardized, tested library for glucose calculations. This creates:
Teams reinventing the same glucose conversion algorithms (mg/dL to mmol/L)
A1C calculation formulas copy-pasted from medical papers without validation
Time in Range (TIR) metrics implemented inconsistently across apps
I built GlucoseIQ (Apple Watch app) and kept rewriting the same utility functions. I realized the diabetes developer community needed a single, tested, TypeScript library for these calculations.
Diabetic Utils is a TypeScript library providing clinical-grade calculations for glucose monitoring, A1C estimation, and Time in Range metrics.
Straight from the README. Short, copy-pasteable, and predictable:
import {
mgDlToMmolL,
mmolLToMgDl,
estimateGMI,
estimateA1CFromAverage
} from 'diabetic-utils'
// Glucose unit conversions
mgDlToMmolL(180) // -> 10.0
mmolLToMgDl(5.5) // -> 99
// GMI calculation (multiple input formats)
estimateGMI(100, 'mg/dL') // -> 5.4
estimateGMI('5.5 mmol/L') // -> 5.4
estimateGMI({ value: 100, unit: 'mg/dL' }) // -> 5.4
// A1C estimation
estimateA1CFromAverage(154, 'mg/dL') // -> 7.0Type-safe functions for converting between mg/dL and mmol/L:
mgDlToMmolL() - Convert mg/dL to mmol/L with proper roundingmmolLToMgDl() - Convert mmol/L to mg/dLEstimated A1C (eA1C) calculation from average glucose using the ADAG formula:
calculateA1C() - Convert average glucose to estimated A1C percentageCalculate TIR metrics following ADA/ATTD consensus guidelines:
calculateTIR() - Percentage of readings in target range (70-180 mg/dL)calculateTBR() - Time below range (hypoglycemia detection)calculateTAR() - Time above range (hyperglycemia detection)This is the feature most teams ask about. It mirrors clinical targets while keeping the API dead simple.
import { calculateEnhancedTIR } from 'diabetic-utils'
import type { GlucoseReading } from 'diabetic-utils'
const readings: GlucoseReading[] = [
{ value: 120, unit: 'mg/dL', timestamp: '2024-01-01T08:00:00Z' },
{ value: 95, unit: 'mg/dL', timestamp: '2024-01-01T08:05:00Z' },
{ value: 180, unit: 'mg/dL', timestamp: '2024-01-01T08:10:00Z' },
// ... more readings
]
const result = calculateEnhancedTIR(readings)
console.log(`TIR: ${result.inRange.percentage}%`)
console.log(`Very Low: ${result.veryLow.percentage}%`)
console.log(`Assessment: ${result.meetsTargets.overallAssessment}`)
console.log(result.meetsTargets.recommendations)Comprehensive test suite with Vitest covering:
Diabetic Utils fills a critical gap in the health tech developer ecosystem:
Featured in Google AI Overview for diabetes developer tools--recognized as a go-to resource for glucose calculations
Adopted by health tech teams building production CGM apps and diabetes management platforms
100% test coverage ensures clinical calculation accuracy, critical for patient-facing applications
Type-safe API prevents unit confusion bugs (mg/dL vs mmol/L) that plague glucose apps
Open-source contribution to the diabetes developer community, reducing duplicated effort
Zero dependencies makes it safe to adopt in production health apps with strict security requirements
The library is actively maintained on npm and serves as the calculation engine for GlucoseIQ (Apple Watch app) and other health tech projects.