Skip to content

feat(device-profiler): export formatJSON from public API #373

@groupsky

Description

@groupsky

Description

The formatJSON function is currently internal-only. It should be exported from the public API to allow programmatic use.

Current State

// packages/device-profiler/src/index.ts
// formatJSON is NOT exported

Users wanting to format scan results as JSON programmatically must either:

  • Use the CLI tool only
  • Import directly from internal path (fragile)

Proposed Change

Add to packages/device-profiler/src/index.ts:

export { formatJSON, type JSONFormatterOptions } from './json-formatter.js'

Use Case

Libraries or tools that use scanRegisters() directly may want to format results as JSON:

import { scanRegisters, formatJSON } from '@ya-modbus/device-profiler'

const results = []
await scanRegisters({
  // ... options
  onResult: (r) => results.push(r)
})

const json = formatJSON(results, {
  type: RegisterType.Holding,
  startAddress: 0,
  endAddress: 100,
  batchSize: 10,
  port: '/dev/ttyUSB0'
})

Impact

  • No breaking changes (pure addition)
  • Enables programmatic JSON formatting
  • Consistent with other exported formatters (formatProgress, formatSummary)

Related

Identified in aspected review of #<PR_NUMBER>

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions