# convert-to-jcamp

> Convert strings into JCAMP

Latest version **7.0.2** (published 2026-09-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install convert-to-jcamp
pnpm add convert-to-jcamp
yarn add convert-to-jcamp
bun add convert-to-jcamp
```

## Health

**Score 60/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 7.0.2 |
| Published | 2026-09-18 |
| First published | 2017-07-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 4 |
| Unpacked size | 153.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | targos, lpatiny, cheminfo-bot, stropitek, maasencioh |

## Links

- npm: https://www.npmjs.com/package/convert-to-jcamp
- Repository: https://github.com/cheminfo/convert-to-jcamp
- Homepage: https://github.com/cheminfo/convert-to-jcamp#readme
- Issues: https://github.com/cheminfo/convert-to-jcamp/issues
- npm.io page: https://npm.io/package/convert-to-jcamp

## Dependencies (4)

- [ml-matrix](https://npm.io/package/ml-matrix.md) ^6.15.0
- [is-any-array](https://npm.io/package/is-any-array.md) ^3.0.0
- [cheminfo-types](https://npm.io/package/cheminfo-types.md) ^1.16.0
- [ml-spectra-processing](https://npm.io/package/ml-spectra-processing.md) ^14.35.1

## Recent versions

- 7.0.2 (latest) — 2026-09-18
- 5.4.7-pre.1687358927 (pre) — 2023-06-21
- 7.0.1 — 2026-07-06
- 7.0.0 — 2026-04-16
- 6.0.0 — 2025-05-16
- 5.4.11 — 2024-08-27
- 5.4.10 — 2024-03-16
- 5.4.9 — 2023-09-05
- 5.4.7 — 2023-06-22
- 5.4.6 — 2023-04-30
- 5.4.5-pre.1682565924 — 2023-04-27
- 5.4.5 — 2023-04-25
- 5.4.4-pre.1682183140 — 2023-04-22
- 5.4.4 — 2023-04-20
- 5.4.3 — 2023-04-10
- … 39 more at https://npm.io/package/convert-to-jcamp/versions

## README

# convert-to-jcamp

Convert strings into JCAMP.

<h3 align="center">

  <a href="https://www.zakodium.com">
    <img src="https://www.zakodium.com/brand/zakodium-logo-white.svg" width="50" alt="Zakodium logo" />
  </a>

  <p>
    Maintained by <a href="https://www.zakodium.com">Zakodium</a>
  </p>

[![NPM version][npm-image]][npm-url]
[![build status][ci-image]][ci-url]
[![Test coverage][codecov-image]][codecov-url]
[![npm download][download-image]][download-url]
[![DOI](https://www.zenodo.org/badge/98869235.svg)](https://www.zenodo.org/badge/latestdoi/98869235)

</h3>

## Installation

`$ npm install convert-to-jcamp`

## Usage

### From Variables

```js
import { fromVariables } from 'convert-to-jcamp';
const variables = {
  x: {
    data: [1, 2, 3, 4],
    label: 'x value',
    units: 'x unit',
    isDependent: false,
  },
  y: { data: [2, 3, 4, 5], label: 'y value', units: 'y unit' },
};

const jcamp = fromVariables(variables, {
  forceNtuples: true,
  meta: {
    meta1: 'value1',
    meta2: 'value2',
  },
  info: {
    title: 'Hello world',
    dataType: 'TEST',
  },
});
```

There are two functions for NMR. `from1DNMRVariables`
and `from2DNMRVariables` generate a NMR JCAMP file from variables.

```js
import { from2DNMRVariables } from 'convert-to-jcamp';

const variables = {
  y: {
    data: [1, 2],
    symbol: 'F1',
    label: 'y',
    units: 'Hz a',
    isDependent: false,
  },
  x: {
    data: [0, 1, 2, 3, 4],
    symbol: 'F2',
    label: 'x',
    units: 'Hz',
    isDependent: false,
  },
  z: {
    data: [
      [2, 3, 4, 5, 7],
      [1, 2, 3, 4, 5],
    ],
    symbol: 'Y',
    label: 'z',
    units: 'arbitrary',
    isDependent: true,
  },
};

const jcamp = from2DNMRVariables(variables, {
  xyEncoding: 'DIFDUP',
  nmrInfo: {
    title: '2D NMR',
    owner: 'cheminfo',
    dataType: 'nD NMR SPECTRUM',
    origin: 'lab',
  },
  meta: {
    NUC1: '1H',
    NUC2: '13C',
    SFO1: 400, // Spectrometer frequency for F2 (MHz)
    SFO2: 100, // Spectrometer frequency for F1 (MHz)
  }, // Optional: additional metadata
  info: { '.OBSERVE NUCLEUS': '1H', '.OBSERVER FREQUENCY': 400 }, // Optional: additional JCAMP info fields
});
```

```js
import { from1DNMRVariables } from 'convert-to-jcamp';
const variables = {
  x: {
    data: xMultiply(data.x, observeFrequency),
    label: 'Frequencies',
    units: 'Hz',
    symbol: 'X',
    isDependent: false,
  },
  r: {
    data: data.re,
    label: 'real data',
    units: 'arbitratry units',
    symbol: 'R',
    isDependent: true,
  },
  i: {
    data: data.im,
    label: 'imaginary data',
    units: 'arbitratry units',
    symbol: 'I',
    isDependent: true,
  },
};

const jcamp = from1DNMRVariables(variables, {
  xyEncoding: 'DIFDUP',
  nmrInfo: {
    title: 'jcamp 1D',
    owner: 'cheminfo',
    dataType: 'NMR Spectrum',
    origin: 'lab',
    isFid: false, // true for FID, false for spectrum
    baseFrequency: 600, // MHz
    originFrequency: 600, // MHz
    nucleus: '1H',
    // Optional fields:
    // digitalFilter, decim, dspfvs, frequencyOffset, baseFrequency, spectralWidth, solvent, scaleFactor
  },
  meta: { SFO1: 400, NUC1: '1H' }, // Optional: additional metadata would be with ##$ prefix
  // info: { ... }, // Optional: additional JCAMP info fields would be with ## prefix
});
```

An example for 1D NMR [bruker-to-jcamp](https://github.com/cheminfo/convert-to-jcamp/tree/main/demo/bruker-to-jcamp.ts) conversion is in the [demo folder](https://github.com/cheminfo/convert-to-jcamp/tree/main/demo)

```bash
npm install
node demo/bruker-to-jcamp.ts
```

## [API Documentation](https://cheminfo.github.io/convert-to-jcamp/)

## License

[MIT](./LICENSE)

[npm-image]: https://img.shields.io/npm/v/convert-to-jcamp.svg?style=flat-square
[npm-url]: https://npmjs.org/package/convert-to-jcamp
[ci-image]: https://github.com/cheminfo/convert-to-jcamp/actions/workflows/nodejs.yml/badge.svg
[ci-url]: https://github.com/cheminfo/convert-to-jcamp/actions/workflows/nodejs.yml
[codecov-image]: https://img.shields.io/codecov/c/github/cheminfo/convert-to-jcamp.svg?style=flat-square
[codecov-url]: https://codecov.io/gh/cheminfo/convert-to-jcamp
[download-image]: https://img.shields.io/npm/dm/convert-to-jcamp.svg?style=flat-square
[download-url]: https://npmjs.org/package/convert-to-jcamp

---
_Source: https://npm.io/package/convert-to-jcamp · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
