GlucoseIQ
API Reference@glucoseiq/core

Glucose Values & Formatting

Validation, guards, alignment, labels, and formatting.

calculateHOMAIR

Import: @glucoseiq/core

calculateHOMAIR(glucose: number, insulin: number): { interpretation: string; value: number }

Calculates HOMA-IR (Homeostatic Model Assessment for Insulin Resistance) from fasting glucose and insulin.

Formula: HOMA-IR = (fasting glucose [mg/dL] × fasting insulin [µIU/mL]) / 405

Returns the calculated value with the function's cutoff label. The result does not diagnose insulin resistance.

Returns: Object with numeric HOMA-IR value and interpretation label.

Throws: If glucose or insulin are invalid (non-finite, zero, or negative).

See:

ParameterDescription
glucoseFasting glucose value in mg/dL. Must be a positive finite number.
insulinFasting insulin value in µIU/mL. Must be a positive finite number.

checkGlycemicAlignment

Import: @glucoseiq/core

checkGlycemicAlignment(a1c: number, glucose: number, insulin: number): { disclaimer: string; estimatedAverageGlucose: number; flags: string[]; homaIR: { interpretation: string; value: number }; recommendation: string }

Compares A1C-derived estimated average glucose with fasting glucose and calculates HOMA-IR from fasting glucose and insulin. Returns both calculated values, flags from fixed comparison rules, and an informational disclaimer. The result does not diagnose a condition.

Returns: Object with estimated average glucose (mg/dL), HOMA-IR result object, flags array, recommendation string, and disclaimer.

Throws: If any input value is invalid (non-finite, zero, or negative).

See: CDC: eAG formula

ParameterDescription
a1cA1C value (percentage). Must be a positive finite number.
glucoseFasting glucose value in mg/dL. Must be a positive finite number.
insulinFasting insulin value in µIU/mL. Must be a positive finite number.

formatDate

Import: @glucoseiq/core

formatDate(iso: string, timeZone?: string): string

Formats a UTC ISO 8601 timestamp in the requested IANA time zone.

Returns: Localized date/time string (e.g., 'Mar 20, 2024, 06:00 AM')

Throws: If the ISO string is invalid or cannot be parsed

Throws: If the time zone is invalid

ParameterDescription
isoISO 8601 timestamp string (e.g., '2024-03-20T10:00:00Z')
timeZoneOptional IANA time zone (e.g., 'America/New_York')

formatGlucose

Import: @glucoseiq/core

formatGlucose(val: number, unit: GlucoseUnit, options: { digits?: number; suffix?: boolean } = {}): string

Formats a numeric glucose value with optional rounding and a unit suffix.

Returns: Formatted glucose string (e.g., '5.5 mmol/L', '120 mg/dL')

See: https://wwwn.cdc.gov/Nchs/Data/Nhanes/Public/2021/DataFiles/BIOPRO_L.htm

ParameterDescription
valGlucose value (number)
unitGlucose unit ('mg/dL' or 'mmol/L')
optionsFormatting options: { digits?: number; suffix?: boolean } (default: { digits: 0, suffix: true })

formatPercentage

Import: @glucoseiq/core

formatPercentage(val: number, digits: number = 1): string

Formats a number with fixed decimal places and a percent sign.

Returns: Formatted percentage string (e.g., '85.0%')

ParameterDescription
valValue to format (fraction or percent)
digitsNumber of decimal places (default: 1)

getGlucoseLabel

Import: @glucoseiq/core

getGlucoseLabel(val: number, unit: GlucoseUnit = MG_DL, thresholds?: { hyper?: { mgdl?: number; mmoll?: number }; hypo?: { mgdl?: number; mmoll?: number } }): 'normal' | 'low' | 'high'

Returns 'low', 'normal', or 'high' from the configured thresholds for the value's unit.

Returns: 'low', 'normal', or 'high' based on configured thresholds

See: https://www.diabetes.co.uk/diabetes_care/blood-sugar-level-ranges.html

ParameterDescription
valGlucose value (number)
unitGlucose unit ('mg/dL' or 'mmol/L'), default: 'mg/dL'
thresholdsOptional custom thresholds for hypo/hyper ({ hypo?: { mgdl?: number; mmoll?: number }, hyper?: { mgdl?: number; mmoll?: number } })

isEstimateGMIOptions

Import: @glucoseiq/core

isEstimateGMIOptions(input: unknown): input is EstimateGMIOptions

Type guard for EstimateGMIOptions. Requires a positive finite value and one of the two supported glucose units.

Returns: True if input is a valid EstimateGMIOptions object.

ParameterDescription
inputCandidate value to validate.

isHyper

Import: @glucoseiq/core

isHyper(val: number, unit: GlucoseUnit = MG_DL, thresholds?: { mgdl?: number; mmoll?: number }): boolean

Returns whether a glucose value is above the configured hyperglycemia threshold for its unit.

Returns: True if value is above the hyperglycemia threshold

See: https://www.diabetes.co.uk/diabetes_care/blood-sugar-level-ranges.html

ParameterDescription
valGlucose value (number)
unitGlucose unit ('mg/dL' or 'mmol/L'), default: 'mg/dL'
thresholdsOptional custom thresholds ({ mgdl?: number; mmoll?: number })

isHypo

Import: @glucoseiq/core

isHypo(val: number, unit: GlucoseUnit = MG_DL, thresholds?: { mgdl?: number; mmoll?: number }): boolean

Returns whether a glucose value is below the configured hypoglycemia threshold for its unit.

Returns: True if value is below the hypoglycemia threshold

See: https://www.diabetes.co.uk/diabetes_care/blood-sugar-level-ranges.html

ParameterDescription
valGlucose value (number)
unitGlucose unit ('mg/dL' or 'mmol/L'), default: 'mg/dL'
thresholdsOptional custom thresholds ({ mgdl?: number; mmoll?: number })

isValidGlucoseString

Import: @glucoseiq/core

isValidGlucoseString(input: unknown): input is string

Returns whether a string contains a positive finite number followed by one of the two supported glucose units. It checks only the declared string format and the positive, finite numeric bound.

Returns: True when input matches the supported glucose string format

See: https://wwwn.cdc.gov/Nchs/Data/Nhanes/Public/2021/DataFiles/BIOPRO_L.htm

ParameterDescription
inputValue to check

isValidGlucoseValue

Import: @glucoseiq/core

isValidGlucoseValue(value: unknown, unit: unknown): boolean

Validates a glucose value and unit. Ensures value is a positive finite number and unit is supported.

Returns: True if value and unit are valid

ParameterDescription
valueGlucose value to validate
unitGlucose unit to validate

isValidInsulin

Import: @glucoseiq/core

isValidInsulin(value: unknown): value is number

Returns whether a value is finite and greater than 0 but less than 1000 µIU/mL. This is an input bound, not a reference interval.

Returns: True when the value satisfies the input bound

ParameterDescription
valueCandidate insulin value

parseGlucoseString

Import: @glucoseiq/core

parseGlucoseString(input: string): { unit: GlucoseUnit; value: number }

Parses a glucose string (e.g., "100 mg/dL", "5.5 mmol/L") into value and unit. Accepts only a positive finite value and a supported glucose unit.

Returns: Object with numeric value and validated unit

Throws: If input string is invalid or not in expected format

import { parseGlucoseString } from '@glucoseiq/core'

const input: string = '100 mg/dL'
const reading = parseGlucoseString(input) // { value: 100, unit: 'mg/dL' }

See: https://wwwn.cdc.gov/Nchs/Data/Nhanes/Public/2021/DataFiles/BIOPRO_L.htm

ParameterDescription
inputString in the format "value unit" (e.g., "100 mg/dL")

On this page