Conversions, A1C & GMI
Unit conversions and A1C / eAG / GMI estimation.
15 functions
a1cDelta
a1cDelta(current: number, previous: number): numberCalculates the change (delta) between two A1C values.
| Parameter | Description |
|---|---|
current | Current A1C |
previous | Previous A1C |
Returns — Delta (current - previous)
Throws — If either value is invalid
a1cToGMI
a1cToGMI(a1c: number): numberConverts A1C to Glucose Management Indicator (GMI).
| Parameter | Description |
|---|---|
a1c | A1C value |
Returns — GMI value
See: https://diatribe.org/glucose-management-indicator-gmi
a1cTrend
a1cTrend(readings: number[]): "increasing" | "decreasing" | "stable" | "insufficient data"Determines the trend of A1C values over time.
| Parameter | Description |
|---|---|
readings | Array of A1C values (chronological order) |
Returns — 'increasing' | 'decreasing' | 'stable' | 'insufficient data'
convertGlucoseUnit
convertGlucoseUnit(__namedParameters: { … }): ConversionResultConverts clinical glucose value between mg/dL and mmol/L. Used for clinical interoperability and analytics.
Returns — Object with converted value and new unit
Throws — If value is not a finite number or is negative/zero
Throws — If unit is not a supported glucose unit
See: https://wwwn.cdc.gov/Nchs/Data/Nhanes/Public/2021/DataFiles/BIOPRO_L.htm
estimateA1CFromAverage
estimateA1CFromAverage(avgGlucose: number, unit?: GlucoseUnit): numberEstimates A1C from average glucose.
| Parameter | Description |
|---|---|
avgGlucose | Average glucose value |
unit | Glucose unit (mg/dL or mmol/L) |
Returns — Estimated A1C
See: https://www.cdc.gov/diabetes/managing/managing-blood-sugar/a1c.html
estimateA1CFromAvgGlucose
estimateA1CFromAvgGlucose(avgMgDl: number): numberConverts clinical average glucose (mg/dL) to estimated A1C (percentage). Used for clinical analytics and patient reporting.
| Parameter | Description |
|---|---|
avgMgDl | Average glucose in mg/dL |
Returns — Estimated A1C value (percentage)
See: https://www.cdc.gov/diabetes/managing/managing-blood-sugar/a1c.html
estimateAvgGlucoseFromA1C
estimateAvgGlucoseFromA1C(a1c: number): numberConverts clinical A1C value (percentage) to estimated average glucose (mg/dL). Used for clinical analytics and patient reporting.
| Parameter | Description |
|---|---|
a1c | A1C value (percentage) |
Returns — Estimated average glucose in mg/dL
See: https://www.cdc.gov/diabetes/managing/managing-blood-sugar/a1c.html
estimateEAG
estimateEAG(a1c: number): numberEstimates eAG (estimated average glucose, mg/dL) from clinical A1C value. Throws if input is negative. Used for clinical and research reporting.
| Parameter | Description |
|---|---|
a1c | A1C value (percentage) |
Returns — Estimated average glucose (mg/dL)
Throws — If a1c is negative
See: https://www.cdc.gov/diabetes/managing/managing-blood-sugar/a1c.html
estimateGMI
estimateGMI(valueOrOptions: string | number | EstimateGMIOptions, unit?: GlucoseUnit): numberEstimate Glucose Management Indicator (GMI) from average glucose.
| Parameter | Description |
|---|---|
valueOrOptions | Glucose value, string, or options object |
unit | Glucose unit (if value is a number) |
Returns — GMI value
Throws — If unit is required but not provided when input is a number.
Throws — If the glucose unit is unsupported.
Throws — If the glucose value is not a positive number.
See: https://diatribe.org/glucose-management-indicator-gmi
formatA1C
formatA1C(val: number): stringFormats a clinical A1C value as a percent string (e.g., "7.2%"). Used for clinical reporting and display.
| Parameter | Description |
|---|---|
val | A1C value (percentage) |
Returns — A1C as string with percent sign
getA1CCategory
getA1CCategory(a1c: number, thresholds?: { … }): "normal" | "prediabetes" | "diabetes" | "invalid"Returns the clinical category for an A1C value (normal, prediabetes, diabetes, or invalid). Uses ADA thresholds by default, but allows custom cutoffs for research or population-specific use.
| Parameter | Description |
|---|---|
a1c | A1C value (percentage) |
thresholds | Optional custom thresholds: { normalMax?: number; prediabetesMax?: number } |
Returns — 'normal' | 'prediabetes' | 'diabetes' | 'invalid'
isA1CInTarget
isA1CInTarget(a1c: number, target?: [number, number], thresholds?: { … }): booleanChecks if an A1C value is within a target range.
| Parameter | Description |
|---|---|
a1c | A1C value |
target | [min, max] range (default: [6.5, 7.0]) |
thresholds | Optional custom thresholds: { min?: number; max?: number } |
Returns — True if in target range
isValidA1C
isValidA1C(value: unknown): booleanValidates a clinical A1C value (percentage). Ensures value is within physiologically plausible range for clinical analytics.
| Parameter | Description |
|---|---|
value | Candidate A1C value |
Returns — True if value is a valid A1C percentage
mgDlToMmolL
mgDlToMmolL(val: number): numberConverts clinical glucose value from mg/dL to mmol/L. Used for international interoperability and reporting.
| Parameter | Description |
|---|---|
val | Glucose value in mg/dL |
Returns — Value in mmol/L
Throws — If val is not a finite number or is negative/zero
const result = mgDlToMmolL(180)
console.log(result) // 10.0See: https://wwwn.cdc.gov/Nchs/Data/Nhanes/Public/2021/DataFiles/BIOPRO_L.htm
mmolLToMgDl
mmolLToMgDl(val: number): numberConverts clinical glucose value from mmol/L to mg/dL. Used for international interoperability and reporting.
| Parameter | Description |
|---|---|
val | Glucose value in mmol/L |
Returns — Value in mg/dL
Throws — If val is not a finite number or is negative/zero
const result = mmolLToMgDl(5.5)
console.log(result) // 99See: https://wwwn.cdc.gov/Nchs/Data/Nhanes/Public/2021/DataFiles/BIOPRO_L.htm