From 7863e4ff4d7ff3c70050afe316890100ac68df52 Mon Sep 17 00:00:00 2001 From: Luc Patiny Date: Wed, 28 Aug 2024 15:41:22 +0200 Subject: [PATCH] feat: keep meta information from netcdf --- src/Chromatogram.js | 8 ++++---- src/__tests__/chromatoToJcamp.test.js | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Chromatogram.js b/src/Chromatogram.js index 655ee09..d22ceab 100644 --- a/src/Chromatogram.js +++ b/src/Chromatogram.js @@ -19,7 +19,8 @@ import { getMzVsTimesMatrix } from './util/getMzVsTimesMatrix'; import { integrate } from './util/integrate'; export class Chromatogram { - constructor(times, series) { + constructor(times, series, options = {}) { + this.meta = options.meta || {}; this.series = {}; this.times = []; if (!isAnyArray(times)) { @@ -237,9 +238,8 @@ export class Chromatogram { } export function fromJSON(json) { - let series = json.series; - let times = json.times; - let chromatogram = new Chromatogram(times); + const { series, times, meta = {} } = json; + let chromatogram = new Chromatogram(times, undefined, { meta }); if (Array.isArray(series)) { for (let i = 0; i < series.length; i++) { diff --git a/src/__tests__/chromatoToJcamp.test.js b/src/__tests__/chromatoToJcamp.test.js index db5353d..1580dfd 100644 --- a/src/__tests__/chromatoToJcamp.test.js +++ b/src/__tests__/chromatoToJcamp.test.js @@ -34,6 +34,7 @@ test('chromatoToJcamp', () => { title: 'Total ion chromatogram', dataType: 'Chromatogram', }, + meta: chromatogram.meta, }); - expect(jcamp.split(/\n/)).toHaveLength(4529); + expect(jcamp.split(/\n/)).toHaveLength(4558); });