From 2daa3630427c2a34d4e81c18e085106746934cc3 Mon Sep 17 00:00:00 2001 From: Luc Patiny Date: Wed, 2 Oct 2024 12:30:42 +0200 Subject: [PATCH] chore: update dependencies --- .eslintrc.yml | 1 - .ncurc.yml | 5 +++ eslint.config.mjs | 16 ++++++++ package.json | 6 +-- src/AnalysesManager.ts | 11 ++++-- src/Analysis.ts | 38 ++++++++++++------- src/__tests__/AnalysesManager.test.ts | 4 +- src/__tests__/Analysis.test.ts | 6 +-- .../AnalysisManager.distinct.test.ts | 4 +- src/from/__tests__/fromJcamp.callback.test.ts | 4 +- src/from/__tests__/fromJcamp.link.test.ts | 4 +- src/from/__tests__/fromJcamp.test.ts | 4 +- src/from/__tests__/fromText.test.ts | 4 +- src/from/fromJcamp.ts | 12 +++--- src/from/fromText.ts | 3 +- src/jsgraph/__tests__/getJSGraph.test.ts | 4 +- src/jsgraph/addStyle.ts | 2 +- src/jsgraph/getJSGraph.ts | 2 + src/jsgraph/getNormalizationAnnotations.ts | 9 +++-- src/reactPlot/getReactPlotJSON.ts | 3 ++ src/types/SpectrumSelector.ts | 6 ++- src/util/autoPeakPicking.ts | 6 ++- src/util/convertUnit.ts | 6 +-- src/util/ensureRegexp.ts | 6 +-- src/util/getNormalizedSpectrum.ts | 4 +- src/util/getXYSpectra.ts | 16 ++++---- src/util/getXYSpectrum.ts | 2 + src/util/peakPicking.ts | 6 ++- 28 files changed, 124 insertions(+), 70 deletions(-) delete mode 100644 .eslintrc.yml create mode 100644 .ncurc.yml create mode 100644 eslint.config.mjs diff --git a/.eslintrc.yml b/.eslintrc.yml deleted file mode 100644 index bc57d11..0000000 --- a/.eslintrc.yml +++ /dev/null @@ -1 +0,0 @@ -extends: cheminfo-typescript diff --git a/.ncurc.yml b/.ncurc.yml new file mode 100644 index 0000000..7ac3054 --- /dev/null +++ b/.ncurc.yml @@ -0,0 +1,5 @@ +dep: 'prod,dev' +reject: + # https://github.com/cheminfo/eslint-config/issues/49 + - eslint + - react-plot diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..e58ce4f --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,16 @@ +import cheminfo from 'eslint-config-cheminfo-typescript'; +import globals from 'globals'; + +export default [ + ...cheminfo, + { + languageOptions: { + globals: { + ...globals.node, + }, + }, + rules: { + "unicorn/no-object-as-default-parameter": "off", + } + } +] \ No newline at end of file diff --git a/package.json b/package.json index e2800a3..9bb7866 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "build": "npm run tsc && cheminfo-build -r CommonSpectrum", "check-types": "tsc --noEmit", "clean": "rimraf lib lib-esm", - "eslint": "eslint src --ext ts --cache", + "eslint": "eslint src", "eslint-fix": "npm run eslint -- --fix", "prepack": "npm run tsc", "prettier": "prettier --check src", @@ -49,10 +49,10 @@ "@types/js-quantities": "^1.6.6", "cheminfo-build": "^1.2.0", "eslint": "^8.57.0", - "eslint-config-cheminfo-typescript": "^12.4.0", + "eslint-config-cheminfo-typescript": "^15.0.1", "jest-matcher-deep-close-to": "^3.0.2", "prettier": "^3.3.3", - "rimraf": "^5.0.5", + "rimraf": "^6.0.1", "typescript": "^5.4.5" }, "dependencies": { diff --git a/src/AnalysesManager.ts b/src/AnalysesManager.ts index 6cdba26..e7138ac 100644 --- a/src/AnalysesManager.ts +++ b/src/AnalysesManager.ts @@ -157,7 +157,7 @@ export class AnalysesManager { for (const spectrum of this.getSpectra()) { if (spectrum.variables) { for (const [, variable] of Object.entries(spectrum.variables)) { - appendDistinctValue(values, variable.label.replace(/\s+[[(].*$/, '')); + appendDistinctValue(values, variable.label.replace(/\s+[([].*$/, '')); } } } @@ -198,6 +198,7 @@ export class AnalysesManager { /** * Remove the analysis from the AnalysesManager for the specified id + * @param id */ public removeAnalysis(id: string) { const index = this.getAnalysisIndex(id); @@ -207,6 +208,7 @@ export class AnalysesManager { /** * Returns the index of the analysis in the analyses array + * @param id */ public getAnalysisIndex(id: string) { if (!id) return undefined; @@ -219,10 +221,11 @@ export class AnalysesManager { /** * Checks if the ID of an analysis exists in the AnalysesManager + * @param id */ public includes(id: string) { const index = this.getAnalysisIndex(id); - return index === undefined ? false : !isNaN(index); + return index === undefined ? false : !Number.isNaN(index); } } @@ -233,8 +236,8 @@ function normalizeLabelUnits( if (!originalLabel) { return { units: '', label: '' }; } - if (originalLabel.search(/[[(]]/) >= 0) { - const [units, label] = originalLabel.split(/\s*[[(]/); + if (originalLabel.search(/[([]]/) >= 0) { + const [units, label] = originalLabel.split(/\s*[([]/); return { units: originalUnits || units, label }; } return { label: originalLabel, units: originalUnits }; diff --git a/src/Analysis.ts b/src/Analysis.ts index 3a79d9d..14200da 100644 --- a/src/Analysis.ts +++ b/src/Analysis.ts @@ -41,7 +41,7 @@ export class Analysis { }; public constructor(options: AnalysisOptions = {}) { - this.id = options.id || Math.random().toString(36).substring(2, 10); + this.id = options.id || Math.random().toString(36).slice(2, 10); this.label = options.label || this.id; this.spectrumCallback = options.spectrumCallback; this.spectra = []; @@ -81,6 +81,8 @@ export class Analysis { /** * Add a spectrum in the internal spectra variable + * @param variables + * @param options */ public pushSpectrum( variables: SpectrumVariables, @@ -96,6 +98,7 @@ export class Analysis { /** * Retrieve a Spectrum based on x/y units + * @param selector */ public getXYSpectrum(selector: SpectrumSelector = {}) { const id = JSON.stringify(selector); @@ -107,6 +110,7 @@ export class Analysis { /** * Retrieve spectra matching selector + * @param selector */ public getXYSpectra(selector: SpectrumSelector = {}) { const id = JSON.stringify(selector); @@ -118,9 +122,10 @@ export class Analysis { /** * Retrieve a xy object - * @param selector.units Units separated by vs like for example "g vs °C" - * @param selector.xUnits if undefined takes the first variable - * @param selector.yUnits if undefined takes the second variable + * @param selector.units - Units separated by vs like for example "g vs °C" + * @param selector.xUnits - if undefined takes the first variable + * @param selector.yUnits - if undefined takes the second variable + * @param selector */ public getXY(selector: SpectrumSelector = {}) { const spectrum = this.getXYSpectrum(selector); @@ -134,8 +139,9 @@ export class Analysis { /** * Return the data object for specific x/y units with possibly some * normalization options - * @param options.selector.xUnits // if undefined takes the first variable - * @param options.selector.yUnits // if undefined takes the second variable + * @param options.selector.xUnits - // if undefined takes the first variable + * @param options.selector.yUnits - // if undefined takes the second variable + * @param options */ public getNormalizedSpectrum(options: NormalizedOptions = {}) { const { normalization, selector } = options; @@ -145,6 +151,7 @@ export class Analysis { } /** + * @param options */ public getNormalizedSpectra(options: NormalizedOptions = {}): Spectrum[] { const { normalization, selector } = options; @@ -167,8 +174,9 @@ export class Analysis { /** * Returns the xLabel - * @param selector.xUnits // if undefined takes the first variable - * @param selector.yUnits // if undefined takes the second variable + * @param selector.xUnits - // if undefined takes the first variable + * @param selector.yUnits - // if undefined takes the second variable + * @param selector */ public getXLabel(selector: SpectrumSelector) { return this.getXYSpectrum(selector)?.variables.x.label; @@ -176,8 +184,9 @@ export class Analysis { /** * Returns the yLabel - * @param selector.xUnits // if undefined takes the first variable - * @param selector.yUnits // if undefined takes the second variable + * @param selector.xUnits - // if undefined takes the first variable + * @param selector.yUnits - // if undefined takes the second variable + * @param selector */ public getYLabel(selector: SpectrumSelector) { return this.getXYSpectrum(selector)?.variables.y.label; @@ -186,6 +195,9 @@ export class Analysis { /** * Internal function that ensure the order of x / y array + * @param variables + * @param options + * @param analysisOptions */ function standardizeData( variables: SpectrumVariables, @@ -207,14 +219,14 @@ function standardizeData( const xVariable = variables.x; const yVariable = variables.y; if (!xVariable || !yVariable) { - throw Error('A spectrum must contain at least x and y variables'); + throw new Error('A spectrum must contain at least x and y variables'); } if (!isAnyArray(xVariable.data) || !isAnyArray(yVariable.data)) { - throw Error('x and y variables must contain an array data'); + throw new Error('x and y variables must contain an array data'); } const x = xVariable.data; - const reverse = x && x.length > 1 && x[0] > x[x.length - 1]; + const reverse = x && x.length > 1 && x[0] > x.at(-1); for (const [key, variable] of Object.entries(variables)) { if (reverse) variable.data = variable.data.slice().reverse(); diff --git a/src/__tests__/AnalysesManager.test.ts b/src/__tests__/AnalysesManager.test.ts index b6fb61c..e630ccb 100644 --- a/src/__tests__/AnalysesManager.test.ts +++ b/src/__tests__/AnalysesManager.test.ts @@ -57,7 +57,7 @@ describe('AnalysisManager', () => { const analyses = analysesManager.getAnalyses(); expect(analyses).toHaveLength(3); // we expect to have a total of 3 spectra without filtereing - expect(analyses.map((analysis) => analysis.spectra).flat()).toHaveLength(3); + expect(analyses.flatMap((analysis) => analysis.spectra)).toHaveLength(3); // we select the first analysis, we expect to have 2 spectra const filteredAnalyses = analysesManager.getAnalyses({ ids: ['abc'] }); @@ -83,7 +83,7 @@ describe('AnalysisManager', () => { const analysis2 = new Analysis({ id: 'def' }); analysesManager.addAnalysis(analysis2); - const json = JSON.parse(JSON.stringify(analysesManager)); + const json = structuredClone(analysesManager); const data = json.analyses[0].spectra[0].variables.x.data; expect(Array.isArray(data)).toBe(true); const spectraManager2 = AnalysesManager.fromJSON(json); diff --git a/src/__tests__/Analysis.test.ts b/src/__tests__/Analysis.test.ts index 505263c..8d90501 100644 --- a/src/__tests__/Analysis.test.ts +++ b/src/__tests__/Analysis.test.ts @@ -1,5 +1,5 @@ -import { readFileSync } from 'fs'; -import { join } from 'path'; +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; import { describe, it, expect } from 'vitest'; @@ -9,7 +9,7 @@ describe('Analysis', () => { it('getXY', () => { const text = readFileSync( join(__dirname, '../../testFiles/xps.jdx'), - 'utf-8', + 'utf8', ); const analysis = fromJcamp(text); diff --git a/src/__tests__/AnalysisManager.distinct.test.ts b/src/__tests__/AnalysisManager.distinct.test.ts index c2a34fc..c48bd74 100644 --- a/src/__tests__/AnalysisManager.distinct.test.ts +++ b/src/__tests__/AnalysisManager.distinct.test.ts @@ -1,5 +1,5 @@ -import { readFileSync } from 'fs'; -import { join } from 'path'; +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; import { describe, it, expect } from 'vitest'; diff --git a/src/from/__tests__/fromJcamp.callback.test.ts b/src/from/__tests__/fromJcamp.callback.test.ts index 94ad2c1..ef7f84f 100644 --- a/src/from/__tests__/fromJcamp.callback.test.ts +++ b/src/from/__tests__/fromJcamp.callback.test.ts @@ -1,5 +1,5 @@ -import { readFileSync } from 'fs'; -import { join } from 'path'; +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; import { describe, it, expect } from 'vitest'; diff --git a/src/from/__tests__/fromJcamp.link.test.ts b/src/from/__tests__/fromJcamp.link.test.ts index 89387ab..3e79578 100644 --- a/src/from/__tests__/fromJcamp.link.test.ts +++ b/src/from/__tests__/fromJcamp.link.test.ts @@ -1,5 +1,5 @@ -import { readFileSync } from 'fs'; -import { join } from 'path'; +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; import { test, expect } from 'vitest'; diff --git a/src/from/__tests__/fromJcamp.test.ts b/src/from/__tests__/fromJcamp.test.ts index fd0630d..9be17fb 100644 --- a/src/from/__tests__/fromJcamp.test.ts +++ b/src/from/__tests__/fromJcamp.test.ts @@ -1,5 +1,5 @@ -import { readFileSync } from 'fs'; -import { join } from 'path'; +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; import { describe, it, expect } from 'vitest'; diff --git a/src/from/__tests__/fromText.test.ts b/src/from/__tests__/fromText.test.ts index 209c183..8ab3ff7 100644 --- a/src/from/__tests__/fromText.test.ts +++ b/src/from/__tests__/fromText.test.ts @@ -1,5 +1,5 @@ -import { readFileSync } from 'fs'; -import { join } from 'path'; +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; import { test, expect } from 'vitest'; diff --git a/src/from/fromJcamp.ts b/src/from/fromJcamp.ts index a388c61..9ae9ed7 100644 --- a/src/from/fromJcamp.ts +++ b/src/from/fromJcamp.ts @@ -5,12 +5,12 @@ import { SpectrumVariable } from '../types/Cheminfo'; /** * Creates a new Analysis from a JCAMP string - * @param {string} jcamp - String containing the JCAMP data - * @param {object} [options={}] - * @param {object} [options.id=Math.random()] - * @param {string} [options.label=options.id] human redeable label - * @param {string} [options.spectrumCallback] a callback to apply on variables when creating spectrum - * @return {Analysis} - New class element with the given data + * @param jcamp - String containing the JCAMP data + * @param [options={}] + * @param [options.id=Math.random()] + * @param [options.label=options.id] - human redeable label + * @param [options.spectrumCallback] - a callback to apply on variables when creating spectrum + * @returns - New class element with the given data */ export function fromJcamp(jcamp: string | ArrayBuffer, options = {}): Analysis { const analysis = new Analysis(options); diff --git a/src/from/fromText.ts b/src/from/fromText.ts index 94956f8..6958e36 100644 --- a/src/from/fromText.ts +++ b/src/from/fromText.ts @@ -34,7 +34,8 @@ interface FromTextOptions { /** * Convert strings into JCAMP and add extra information - * @param {string} data - values to add to the file, usually a csv or tsv values + * @param data - values to add to the file, usually a csv or tsv values + * @param options */ export function fromText( diff --git a/src/jsgraph/__tests__/getJSGraph.test.ts b/src/jsgraph/__tests__/getJSGraph.test.ts index 11ce9fd..37bd92b 100644 --- a/src/jsgraph/__tests__/getJSGraph.test.ts +++ b/src/jsgraph/__tests__/getJSGraph.test.ts @@ -1,5 +1,5 @@ -import { readFileSync } from 'fs'; -import { join } from 'path'; +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; import { test, expect, describe, it } from 'vitest'; diff --git a/src/jsgraph/addStyle.ts b/src/jsgraph/addStyle.ts index 56b2c48..3e460a5 100644 --- a/src/jsgraph/addStyle.ts +++ b/src/jsgraph/addStyle.ts @@ -13,7 +13,7 @@ export function addStyle( let { color = '#A9A9A9' } = options; const { opacity = 1, lineWidth = 1 } = options; - if (color.match(/#[0-9A-F]{6}$/i)) { + if (color.match(/#[\da-f]{6}$/i)) { color = (color + ((opacity * 255) >> 0).toString(16)).toUpperCase(); } else { color = color.replace(/rgb ?\((.*)\)/, `rgba($1,${opacity})`); diff --git a/src/jsgraph/getJSGraph.ts b/src/jsgraph/getJSGraph.ts index d9d9037..a8fc271 100644 --- a/src/jsgraph/getJSGraph.ts +++ b/src/jsgraph/getJSGraph.ts @@ -9,6 +9,8 @@ import { COLORS } from './colors'; /** * Generate a jsgraph chart format from an array of Analysis + * @param analyses + * @param options */ export function getJSGraph(analyses: Analysis[], options: JSGraphOptions = {}) { const { diff --git a/src/jsgraph/getNormalizationAnnotations.ts b/src/jsgraph/getNormalizationAnnotations.ts index 1ce6f54..c5c8a78 100644 --- a/src/jsgraph/getNormalizationAnnotations.ts +++ b/src/jsgraph/getNormalizationAnnotations.ts @@ -1,17 +1,20 @@ /** * Returns a JSGraph annotation that represents the normalization * @param {object} [filter={}] - * @param {object} [filter.exclusions=[]] Array of exclusions zones - * @param {object} [boundary={y: {min:'0px', max:'2000px'}}] Height of the annotation + * @param {object} [filter.exclusions=[]] - Array of exclusions zones + * @param {object} [boundary={y: {min:'0px', max:'2000px'}}] - Height of the annotation */ interface AnnotationsFilter { exclusions?: Array<{ ignore?: boolean; from: number; to: number }>; from?: number; to?: number; } + +interface Boundary { y: { min: string; max: string } } + export function getNormalizationAnnotations( filter: AnnotationsFilter = {}, - boundary = { y: { min: '0px', max: '2000px' } }, + boundary: Boundary = { y: { min: '0px', max: '2000px' } }, ) { let { exclusions = [] } = filter; diff --git a/src/reactPlot/getReactPlotJSON.ts b/src/reactPlot/getReactPlotJSON.ts index e30dd16..cae2d9a 100644 --- a/src/reactPlot/getReactPlotJSON.ts +++ b/src/reactPlot/getReactPlotJSON.ts @@ -29,6 +29,9 @@ function getData(x: ListNumber, y: ListNumber) { /** * Generate a jsgraph chart format from an array of Analysis + * @param analyses + * @param query + * @param options */ export function getReactPlotJSON( analyses: Analysis[], diff --git a/src/types/SpectrumSelector.ts b/src/types/SpectrumSelector.ts index 9e5e6b1..6602686 100644 --- a/src/types/SpectrumSelector.ts +++ b/src/types/SpectrumSelector.ts @@ -15,11 +15,13 @@ export interface SpectrumSelector { yLabel?: string | RegExp; /** Allows to specify X and Y variables using a string like 'c vs d' */ variables?: string; - /** Select a specific X variable by one letter name + /** + * Select a specific X variable by one letter name * @default 'x' */ xVariable?: OneLowerCase; - /** Select a specific Y variable by one letter name + /** + * Select a specific Y variable by one letter name * @default 'y' */ yVariable?: OneLowerCase; diff --git a/src/util/autoPeakPicking.ts b/src/util/autoPeakPicking.ts index 363da65..0d41048 100644 --- a/src/util/autoPeakPicking.ts +++ b/src/util/autoPeakPicking.ts @@ -6,7 +6,11 @@ import type { Spectrum } from '../types/Cheminfo'; import { getNormalizedSpectrum } from './getNormalizedSpectrum'; -/** Based on a x value we will return a peak*/ +/** + * Based on a x value we will return a peak + * @param spectrum + * @param options + */ export function autoPeakPicking( spectrum: Spectrum, options: AutoPeakPickingOptions = {}, diff --git a/src/util/convertUnit.ts b/src/util/convertUnit.ts index 4a749c6..689b5f6 100644 --- a/src/util/convertUnit.ts +++ b/src/util/convertUnit.ts @@ -29,8 +29,8 @@ export function convertUnit( } function normalize(unit: string) { - unit = unit.replace(/°C/g, 'tempC'); - unit = unit.replace(/°F/g, 'tempF'); - unit = unit.replace(/(^|\W)K(\W|$)/g, '$1tempK$2'); + unit = unit.replaceAll('°C', 'tempC'); + unit = unit.replaceAll('°F', 'tempF'); + unit = unit.replaceAll(/(^|\W)K(\W|$)/g, '$1tempK$2'); return unit; } diff --git a/src/util/ensureRegexp.ts b/src/util/ensureRegexp.ts index 85bdd4e..dac7d2f 100644 --- a/src/util/ensureRegexp.ts +++ b/src/util/ensureRegexp.ts @@ -1,4 +1,4 @@ -const testRegExp = /^\/((?:\\\/|[^/])+)\/([migyu]{0,5})?$/; +const testRegExp = /^\/((?:\\\/|[^/])+)\/([gimuy]{0,5})?$/; export function ensureRegexp(string: string | RegExp): RegExp { if (typeof string !== 'string') return string; @@ -6,7 +6,7 @@ export function ensureRegexp(string: string | RegExp): RegExp { if (parts) { try { return new RegExp(parts[1], parts[2]); - } catch (err) { + } catch { return stringToRegexp(string); } } else { @@ -16,7 +16,7 @@ export function ensureRegexp(string: string | RegExp): RegExp { function stringToRegexp(string: string, flags = 'i') { return new RegExp( - string.replace(/[[\]\\{}()+*?.$^|]/g, (match: string) => `\\${match}`), + string.replaceAll(/[$()*+.?[\\\]^{|}]/g, (match: string) => `\\${match}`), flags, ); } diff --git a/src/util/getNormalizedSpectrum.ts b/src/util/getNormalizedSpectrum.ts index 892d425..266ab2f 100644 --- a/src/util/getNormalizedSpectrum.ts +++ b/src/util/getNormalizedSpectrum.ts @@ -40,7 +40,7 @@ export function getNormalizedSpectrum( } = options; let { filters = [] } = options; - filters = JSON.parse(JSON.stringify(filters)); + filters = structuredClone(filters); if (numberOfPoints) { filters.push({ name: 'equallySpaced', @@ -60,7 +60,7 @@ export function getNormalizedSpectrum( if (filters.length > 1) { newSpectrum.variables.y.units = ''; newSpectrum.variables.y.label = newSpectrum.variables.y.label?.replace( - /\s*\[.*\]/, + /\s*\[.*]/, '', ); } diff --git a/src/util/getXYSpectra.ts b/src/util/getXYSpectra.ts index 9d062ef..4a88683 100644 --- a/src/util/getXYSpectra.ts +++ b/src/util/getXYSpectra.ts @@ -15,6 +15,8 @@ import { getConvertedVariable } from './getConvertedVariable'; * Retrieve the spectrum with only X/Y data that match all the selectors * If more than one variable match the selector the 'x' or 'y' variable will be * taken + * @param spectra + * @param selector */ export function getXYSpectra( spectra: Spectrum[] = [], @@ -22,7 +24,7 @@ export function getXYSpectra( ): Spectrum[] { const selectedSpectra: Spectrum[] = []; - if (spectra.length < 1) return selectedSpectra; + if (spectra.length === 0) return selectedSpectra; const { variables, units, labels, meta, index } = selector; @@ -69,17 +71,13 @@ export function getXYSpectra( if (!(variableNames.length > 1)) continue; // we filter on general spectrum information - if (dataType) { - if (!spectrum.dataType || !(dataType as RegExp).exec(spectrum.dataType)) { + if (dataType && (!spectrum.dataType || !(dataType as RegExp).exec(spectrum.dataType))) { continue; } - } - if (title) { - if (!spectrum.title || !(title as RegExp).exec(spectrum.title)) { + if (title && (!spectrum.title || !(title as RegExp).exec(spectrum.title))) { continue; } - } if (meta && typeof meta === 'object') { if (!spectrum.meta) continue; @@ -103,7 +101,7 @@ export function getXYSpectra( if (x && y) { // should we reverse the x axis? - if (x.data[0] > x.data[x.data.length - 1]) { + if (x.data[0] > x.data.at(-1)) { x.data = x.data.slice().reverse(); y.data = y.data.slice().reverse(); } @@ -137,7 +135,7 @@ function getPossibleVariable( let convertibleUnits = true; try { convertUnit(1, variable?.units || '', units); - } catch (e) { + } catch { convertibleUnits = false; } if (convertibleUnits && variable) { diff --git a/src/util/getXYSpectrum.ts b/src/util/getXYSpectrum.ts index cdb9b0d..6a827ba 100644 --- a/src/util/getXYSpectrum.ts +++ b/src/util/getXYSpectrum.ts @@ -7,6 +7,8 @@ import { getXYSpectra } from './getXYSpectra'; * Retrieve the spectrum with only X/Y data that match all the selectors * If more than one variable match the selector the 'x' or 'y' variable will be * taken + * @param spectra + * @param selector */ export function getXYSpectrum( spectra: Spectrum[] = [], diff --git a/src/util/peakPicking.ts b/src/util/peakPicking.ts index cc35936..0b41c6f 100644 --- a/src/util/peakPicking.ts +++ b/src/util/peakPicking.ts @@ -4,10 +4,14 @@ import { xFindClosestIndex, xMaxValue } from 'ml-spectra-processing'; import type { Spectrum } from '../types/Cheminfo'; import { PeakPickingOptions } from '../types/PeakPickingOptions'; -/** Based on a x value we will return a peak +/** + * Based on a x value we will return a peak * if you set optimize=True the returned positions will be * the closest actual datapoints to the fitted peak location. * the x/y of the fitted peak will be in xOptimized and yOptimized + * @param spectrum + * @param target + * @param options */ export function peakPicking( spectrum: Spectrum,