Compatibility API

import {
  checkCompatibility,
  assertCompatible,
  MIN_NODE_VERSION,
  type CompatibilityResult,
  type Runtime,
} from '@ppabari/strio';

See the Compatibility guide for the support matrix.

checkCompatibility

checkCompatibility(): CompatibilityResult

Inspect the current runtime and report whether secure generation is supported. Never throws.

const report = checkCompatibility();
// {
//   ok: true,
//   cryptoAvailable: true,
//   runtime: 'node',
//   nodeVersion: '20.11.0',
//   warnings: []
// }

CompatibilityResult

Field Type Description
ok boolean Whether the runtime supports secure generation.
cryptoAvailable boolean Whether crypto.getRandomValues is present.
runtime Runtime 'node' \| 'deno' \| 'bun' \| 'browser' \| 'workerd' \| 'unknown'.
nodeVersion string? Node version string, when running on Node.
warnings string[] Human-readable warnings; empty when fully compatible.

assertCompatible

assertCompatible(): void

Throw a descriptive Error if the runtime is incompatible. Call at startup to fail fast.

assertCompatible(); // throws on an unsupported runtime

MIN_NODE_VERSION

const MIN_NODE_VERSION: number // 18

The minimum supported Node.js major version.