npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

sugarsense-glucose-units

v0.1.1

Published

Blood glucose unit conversion (mg/dL to mmol/L), CGM trend arrows, glucose zone classification, time in range and GMI helpers. Zero dependencies. Extracted from the Sugar Sense CGM monitoring app.

Readme

sugarsense-glucose-units

Blood glucose unit conversion (mg/dL to mmol/L and back), CGM trend arrows, glucose zone classification, time in range and GMI helpers. Zero dependencies, works in Node and every bundler, ships CommonJS, ESM and TypeScript types.

Extracted from Sugar Sense, a CGM monitoring app for iOS, Apple Watch and Android that connects to FreeStyle Libre, Dexcom and Nightscout and shares glucose with family in real time. These are the exact conventions the app uses in production, published so other diabetes tools can reuse them instead of re-deriving the math.

This library is informational only. It contains no insulin dosing logic and gives no medical advice.

Install

npm install sugarsense-glucose-units

Usage

import {
  mgdlToMmol,
  formatGlucose,
  trendArrow,
  classifyZone,
  timeInRange,
  gmi,
  isStale,
} from 'sugarsense-glucose-units';

mgdlToMmol(100);          // 5.55
formatGlucose(120, 'mmol'); // '6.7'  (display form, 1 decimal)
trendArrow(2);            // '↘'
classifyZone(65);         // 'low'
gmi(154);                 // 6.99  (approximates lab A1C, %)
isStale(readingMs);       // true when older than 15 minutes

timeInRange([50, 60, 100, 150, 200, 300]);
// {
//   total: 6,
//   counts:  { veryLow: 1, low: 1, inRange: 2, high: 1, veryHigh: 1 },
//   percent: { veryLow: 16.7, low: 16.7, inRange: 33.3, high: 16.7, veryHigh: 16.7 }
// }

CommonJS works the same way: const units = require('sugarsense-glucose-units').

Conventions

These match the Sugar Sense production apps and backend:

  • All math is done in mg/dL; mmol/L is a display conversion (factor 0.0555, shown with 1 decimal).
  • Trend codes are integers 1 to 5: 1 ↓ falling fast, 2 ↘ falling, 3 → steady, 4 ↗ rising, 5 ↑ rising fast (the same scheme Dexcom, Libre and Nightscout data can be normalized to).
  • Zones: veryLow | low | inRange | high | veryHigh, with boundaries inclusive on the out-of-range side (a value exactly at the low limit is low, exactly at the high limit is high).
  • Default thresholds are 55 / 70 / 180 / 250 mg/dL (DEFAULT_THRESHOLDS), aligned with ADA guidance. Every function accepts custom thresholds.
  • Stale rule: a reading older than 15 minutes should be treated as "no current data".

API

| Function | Description | |---|---| | mgdlToMmol(mgdl) | mg/dL to mmol/L, unrounded number | | mmolToMgdl(mmol) | mmol/L to mg/dL, rounded to a whole number | | formatGlucose(mgdl, unit?) | display string: 'mgdl' whole number, 'mmol' 1 decimal | | trendArrow(code) / trendName(code) | arrow symbol / name for trend codes 1 to 5 | | classifyZone(mgdl, thresholds?) | 'veryLow' \| 'low' \| 'inRange' \| 'high' \| 'veryHigh' | | timeInRange(readings, thresholds?) | five-band counts + percentages over an array of readings | | inRangePercent(readings, thresholds?) | percent strictly inside the target band, null when empty | | gmi(meanMgdl) | Glucose Management Indicator (Bergenstal et al., 2018) | | isStale(timeMs, nowMs?, staleMinutes?) | staleness check, 15 min default | | MMOL_PER_MGDL, DEFAULT_THRESHOLDS, TREND_ARROWS, TREND_NAMES | constants |

About Sugar Sense

Sugar Sense turns CGM data into real-time monitoring for the whole family: glucose on the lock screen and Apple Watch, low and high alerts, an automated emergency call on urgent lows, and a Care Circle so loved ones can follow along. There is also a web dashboard and a free download page.

License

MIT