Skip to content
DiveComputerKit
Browser · Node

Parse dive data in the browser and in Node.

A TypeScript package that parses raw dive data in the browser and in Node.

Language
TypeScript
Platforms
Browsers, Node 18 and later
Install
npm
Transport
None, parse only

Install

Add the package

The package is an ES module with TypeScript declarations and a sidecar .wasm of about 220 KB. The module covers every libdivecomputer device family.

npm
npm install libdivecomputer-wasm
parse.ts
import * as libdc from "libdivecomputer-wasm";

const raw = new Uint8Array(await file.arrayBuffer());

// The parsed dive, in the shared output schema.
const dive = await libdc.parseDive(raw, "shearwater_petrel");
console.log(dive.maxDepth, dive.duration, dive.samples);

// The .dive envelope holds the dive and the original blob.
const envelope = await libdc.parseDiveToEnvelope(raw, parser);
lookup.ts
// Resolve a parser from a vendor and a model.
await libdc.parserTypeFor("Shearwater", "Perdix");
// -> "shearwater_petrel"

// List every device the parser recognises.
await libdc.listParsers();
// -> [{ vendor, product, parserType, transports }, ...]

API

Five functions

Every function is async, because the WebAssembly module loads once on first use. A parse that the bytes do not support rejects with a typed error. The package never returns a partial dive.

Function Result
parseDive(data, parserType) The parsed dive
parseDiveToEnvelope(data, parserType, options?) A .dive envelope
parserTypeFor(vendor, model) The parser for a device
listParsers() Every supported device descriptor
init(moduleArg?) Preload the WebAssembly module

Command line

The same parser, from a shell

A Node command line comes with the package. Use it for scripted parsing, and to read a capture without any code.

libdc-parse
libdc-parse dive.bin --parser shearwater_petrel            # summary
libdc-parse dive.bin --parser shearwater_petrel --json     # the dive
libdc-parse dive.bin --parser shearwater_petrel --envelope # a .dive
libdc-parse --list-parsers                                 # devices

What the package does

  • One module covers every libdivecomputer device family.
  • The output uses the same schema as the Swift library and the Kotlin library.
  • A .dive envelope holds the parsed dive and the original blob together.
  • A Node command line parses a file without any code.

What it does not do

  • The package parses only. It does not download from a device over Bluetooth, serial, or USB.
  • Some parsers need a device time context that a bare per-dive blob does not carry. Such a parse fails with an error.
  • When a device reports no timezone, the package reads the wall clock as UTC. The result stays deterministic.

License the WebAssembly package

A license covers the WebAssembly package, one license per app. Tell us what you build. You get a quote, the terms, and access to the package.