diff --git a/package.json b/package.json index 4b37409..4e41d80 100644 --- a/package.json +++ b/package.json @@ -55,32 +55,32 @@ "trailingComma": "all" }, "devDependencies": { - "@babel/plugin-transform-modules-commonjs": "^7.21.2", - "@babel/preset-typescript": "^7.21.0", - "@types/jest": "^29.5.0", + "@babel/plugin-transform-modules-commonjs": "^7.23.3", + "@babel/preset-typescript": "^7.23.3", + "@types/jest": "^29.5.12", "chemcalc": "^3.4.1", "cheminfo-build": "^1.2.0", - "eslint": "^8.36.0", - "eslint-config-cheminfo-typescript": "^11.3.1", - "eslint-plugin-jest": "^27.2.1", + "eslint": "^8.57.0", + "eslint-config-cheminfo-typescript": "^12.2.0", + "eslint-plugin-jest": "^27.9.0", "esm": "^3.2.25", - "jest": "^29.5.0", + "jest": "^29.7.0", "jest-matcher-deep-close-to": "^3.0.2", - "mf-global": "^2.1.2", + "mf-global": "^3.0.16", "ml-stat": "^1.3.3", - "nodemon": "^2.0.22", - "prettier": "^2.8.7", - "rimraf": "^4.4.1", - "spectrum-generator": "^8.0.6", - "typescript": "^5.0.2", - "xy-parser": "^5.0.4" + "nodemon": "^3.1.0", + "prettier": "^3.2.5", + "rimraf": "^5.0.5", + "spectrum-generator": "^8.0.11", + "typescript": "^5.4.2", + "xy-parser": "^5.0.5" }, "dependencies": { - "@lukeed/uuid": "^2.0.0", - "cheminfo-types": "^1.4.0", + "@lukeed/uuid": "^2.0.1", + "cheminfo-types": "^1.7.2", "ml-peak-shape-generator": "^4.1.2", "ml-savitzky-golay-generalized": "^4.0.1", - "ml-spectra-fitting": "^4.2.1", - "ml-spectra-processing": "^14.0.0" + "ml-spectra-fitting": "^4.2.3", + "ml-spectra-processing": "^14.2.0" } } diff --git a/src/__tests__/ethylvinylether.test.ts b/src/__tests__/ethylvinylether.test.ts index 6e60187..be553b5 100644 --- a/src/__tests__/ethylvinylether.test.ts +++ b/src/__tests__/ethylvinylether.test.ts @@ -5,10 +5,10 @@ import { gsd } from '../gsd'; describe('Global spectra deconvolution NMR spectra', () => { // Test case obtained from Pag 443, Chap 8. it('Ethylvinylether should have 21 peaks', () => { - let spectrum: number[][] = JSON.parse( + const spectrum: number[][] = JSON.parse( readFileSync(`${__dirname}/data/ethylvinylether.json`, 'utf-8'), ); - let result = gsd( + const result = gsd( { x: spectrum[0].reverse(), y: spectrum[1].reverse() }, { minMaxRatio: 0.03, diff --git a/src/__tests__/gaussian-noise.test.ts b/src/__tests__/gaussian-noise.test.ts index 2795353..667f40b 100644 --- a/src/__tests__/gaussian-noise.test.ts +++ b/src/__tests__/gaussian-noise.test.ts @@ -29,7 +29,7 @@ describe('smooth:false option', () => { }); it('positive maxima peaks', () => { - let peakList = gsd(data); + const peakList = gsd(data); expect(peakList).toMatchCloseTo([ { x: -0.5, y: 1.131 }, { x: 0.5, y: 1.05 }, @@ -37,7 +37,10 @@ describe('smooth:false option', () => { }); it('negative maxima peaks', () => { - let peakList = gsd({ x: data.x, y: data.y.map((value) => value - 2) }, {}); + const peakList = gsd( + { x: data.x, y: data.y.map((value) => value - 2) }, + {}, + ); expect(peakList).toMatchCloseTo([ { x: -0.5, y: -0.868 }, { x: 0.5, y: -0.95 }, @@ -46,7 +49,7 @@ describe('smooth:false option', () => { it('Negative peaks', () => { // we check negative peaks - let peakList = gsd( + const peakList = gsd( { x: data.x, y: data.y.map((value) => -value) }, { maxCriteria: false }, ); @@ -58,7 +61,7 @@ describe('smooth:false option', () => { it('minima peaks', () => { // we check negative peaks - let peakList = gsd( + const peakList = gsd( { x: data.x, y: data.y.map((value) => 1 - value) }, { maxCriteria: false }, ); diff --git a/src/__tests__/gaussian-noiseParam.test.ts b/src/__tests__/gaussian-noiseParam.test.ts index a71cbc4..cef8b43 100644 --- a/src/__tests__/gaussian-noiseParam.test.ts +++ b/src/__tests__/gaussian-noiseParam.test.ts @@ -29,12 +29,12 @@ describe('smooth:false option', () => { }); it('positive maxima peaks but noiseLevel over the peaks', () => { - let peakList = gsd(data, { noiseLevel: 1.2 }); + const peakList = gsd(data, { noiseLevel: 1.2 }); expect(peakList).toStrictEqual([]); }); it('positive maxima peaks', () => { - let peakList = gsd(data, { noiseLevel: 0.5 }); + const peakList = gsd(data, { noiseLevel: 0.5 }); expect(peakList).toMatchCloseTo([ { x: -0.5, y: 1.131 }, { x: 0.5, y: 1.05 }, @@ -42,7 +42,7 @@ describe('smooth:false option', () => { }); it('negative maxima peaks', () => { - let peakList = gsd( + const peakList = gsd( { x: data.x, y: data.y.map((value) => value - 2) }, { noiseLevel: -1.5 }, ); @@ -54,7 +54,7 @@ describe('smooth:false option', () => { it('Negative peaks', () => { // we check negative peaks - let peakList = gsd( + const peakList = gsd( { x: data.x, y: data.y.map((value) => -value) }, { maxCriteria: false, noiseLevel: -0.5 }, ); @@ -66,7 +66,7 @@ describe('smooth:false option', () => { it('Negative peaks with noiseLevel too low', () => { // we check negative peaks - let peakList = gsd( + const peakList = gsd( { x: data.x, y: data.y.map((value) => -value) }, { maxCriteria: false, noiseLevel: -1.2 }, ); @@ -75,7 +75,7 @@ describe('smooth:false option', () => { it('minima peaks', () => { // we check negative peaks - let peakList = gsd( + const peakList = gsd( { x: data.x, y: data.y.map((value) => 1 - value) }, { maxCriteria: false, noiseLevel: 0.5 }, ); diff --git a/src/__tests__/gaussian-overlapping.test.ts b/src/__tests__/gaussian-overlapping.test.ts index 796756a..0f30445 100644 --- a/src/__tests__/gaussian-overlapping.test.ts +++ b/src/__tests__/gaussian-overlapping.test.ts @@ -27,7 +27,7 @@ describe('gaussian overlapping', () => { }, }); - let peaks = gsd(data, {}); + const peaks = gsd(data, {}); expect(peaks).toMatchCloseTo([ { x: -0.1, @@ -43,7 +43,7 @@ describe('gaussian overlapping', () => { }, ]); - let optimizedPeaks = optimizePeaks(data, peaks, { groupingFactor: 3 }); + const optimizedPeaks = optimizePeaks(data, peaks, { groupingFactor: 3 }); expect(optimizedPeaks).toMatchCloseTo([ { x: -0.1, diff --git a/src/__tests__/gaussian-smooth.test.ts b/src/__tests__/gaussian-smooth.test.ts index 21901ff..c5e3a29 100644 --- a/src/__tests__/gaussian-smooth.test.ts +++ b/src/__tests__/gaussian-smooth.test.ts @@ -28,7 +28,7 @@ describe('gaussian simulated peaks', () => { }, }); - let peakList = gsd(data, { + const peakList = gsd(data, { smoothY: true, }); expect(peakList).toBeDeepCloseTo([ diff --git a/src/__tests__/gaussian.test.ts b/src/__tests__/gaussian.test.ts index 4a0e1fa..bc6326c 100644 --- a/src/__tests__/gaussian.test.ts +++ b/src/__tests__/gaussian.test.ts @@ -29,9 +29,9 @@ describe('smooth:false option', () => { // we have here a low resolution spectrum so the impact is big it('positive maxima peaks', () => { - let peakList = gsd(data); + const peakList = gsd(data); - let expected = [ + const expected = [ { x: -0.5, y: 1, @@ -59,9 +59,12 @@ describe('smooth:false option', () => { }); it('negative maxima peaks', () => { - let peakList = gsd({ x: data.x, y: data.y.map((value) => value - 2) }, {}); + const peakList = gsd( + { x: data.x, y: data.y.map((value) => value - 2) }, + {}, + ); - let expected = [ + const expected = [ { x: -0.5, y: -1, @@ -90,11 +93,11 @@ describe('smooth:false option', () => { it('Negative peaks', () => { // we check negative peaks - let peakList = gsd( + const peakList = gsd( { x: data.x, y: data.y.map((value) => -value) }, { maxCriteria: false }, ); - let expected = [ + const expected = [ { x: -0.5, y: -1, @@ -124,11 +127,11 @@ describe('smooth:false option', () => { it('minima peaks', () => { // we check negative peaks - let peakList = gsd( + const peakList = gsd( { x: data.x, y: data.y.map((value) => 1 - value) }, { maxCriteria: false }, ); - let expected = [ + const expected = [ { x: -0.5, y: 0, @@ -157,7 +160,7 @@ describe('smooth:false option', () => { }); it('negative peaks with maxCriteria true', () => { - let peakList = gsd( + const peakList = gsd( { x: data.x, y: data.y.map((value) => -value) }, { maxCriteria: true }, ); diff --git a/src/__tests__/power.test.ts b/src/__tests__/power.test.ts index f426dc2..f220997 100644 --- a/src/__tests__/power.test.ts +++ b/src/__tests__/power.test.ts @@ -48,8 +48,8 @@ describe('power', () => { // we have here a low resolution spectrum so the impact is big it('default options', () => { - let peakList = gsd(data); - let expected = [ + const peakList = gsd(data); + const expected = [ { id: peakList[0].id, x: 5, @@ -66,7 +66,7 @@ describe('power', () => { expect(peakList).toBeDeepCloseTo(expected); }); it('custom options', () => { - let peakList = gsd(data, { + const peakList = gsd(data, { smoothY: false, sgOptions: { windowSize: 7, polynomial: 3 }, }); diff --git a/src/__tests__/ubiquitin.test.ts b/src/__tests__/ubiquitin.test.ts index f2c3707..610191f 100644 --- a/src/__tests__/ubiquitin.test.ts +++ b/src/__tests__/ubiquitin.test.ts @@ -12,11 +12,11 @@ expect.extend({ toBeDeepCloseTo, toMatchCloseTo }); describe('Global spectra deconvolution ubiquitin', () => { it('HR mass spectra', () => { - let spectrum = parseXY( + const spectrum = parseXY( readFileSync(`${__dirname}/data/ubiquitin.txt`, 'utf-8'), ); - let peaks = gsd(spectrum, { + const peaks = gsd(spectrum, { minMaxRatio: 0.0, smoothY: false, realTopDetection: true, diff --git a/src/__tests__/zero.test.ts b/src/__tests__/zero.test.ts index 69bcfaa..64b763f 100644 --- a/src/__tests__/zero.test.ts +++ b/src/__tests__/zero.test.ts @@ -2,25 +2,25 @@ import { gsd } from '../gsd'; describe('Simple test cases', () => { it('length = 0', () => { - let x = []; - let y = []; + const x = []; + const y = []; expect(() => { gsd({ x, y }); }).toThrow('input must not be empty'); }); it('length = 2', () => { - let x = [1, 2]; - let y = [2, 3]; + const x = [1, 2]; + const y = [2, 3]; expect(() => { gsd({ x, y }); }).toThrow('Window size is higher than the data length 9>2'); }); it('no peaks', () => { - let x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; - let y = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]; - let peaks = gsd({ x, y }); + const x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; + const y = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]; + const peaks = gsd({ x, y }); expect(peaks[0].x).toBe(8); }); }); diff --git a/src/gsd.ts b/src/gsd.ts index c8a1ab1..a4053a7 100644 --- a/src/gsd.ts +++ b/src/gsd.ts @@ -57,19 +57,19 @@ export type GSDPeakID = MakeMandatory; */ export function gsd(data: DataXY, options: GSDOptions = {}): GSDPeakID[] { - let { + let { noiseLevel } = options; + const { sgOptions = { windowSize: 9, polynomial: 3, }, - noiseLevel, smoothY = false, maxCriteria = true, minMaxRatio = 0.00025, realTopDetection = false, } = options; - - let { x, y } = data; + const { x } = data; + let { y } = data; if (xIsMonotonic(x) !== 1) { throw new Error('GSD only accepts monotone increasing x values'); } @@ -141,9 +141,9 @@ export function gsd(data: DataXY, options: GSDOptions = {}): GSDPeakID[] { let lastMax: XIndex | null = null; let lastMin: XIndex | null = null; - let minddY: number[] = []; - let intervalL: XIndex[] = []; - let intervalR: XIndex[] = []; + const minddY: number[] = []; + const intervalL: XIndex[] = []; + const intervalR: XIndex[] = []; // By the intermediate value theorem We cannot find 2 consecutive maximum or minimum for (let i = 1; i < yData.length - 1; ++i) { @@ -186,7 +186,7 @@ export function gsd(data: DataXY, options: GSDOptions = {}): GSDPeakID[] { const peaks: GSDPeakID[] = []; for (const minddYIndex of minddY) { - let deltaX = x[minddYIndex]; + const deltaX = x[minddYIndex]; let possible = -1; let k = lastK + 1; let minDistance = Number.POSITIVE_INFINITY; @@ -210,7 +210,7 @@ export function gsd(data: DataXY, options: GSDOptions = {}): GSDPeakID[] { if (possible !== -1) { if (yData[minddYIndex] > yThreshold) { - let width = Math.abs(intervalR[possible].x - intervalL[possible].x); + const width = Math.abs(intervalR[possible].x - intervalL[possible].x); peaks.push({ id: generateID(), x: deltaX, diff --git a/src/post/__tests__/broadenPeaks.test.ts b/src/post/__tests__/broadenPeaks.test.ts index c99174a..ba4f214 100644 --- a/src/post/__tests__/broadenPeaks.test.ts +++ b/src/post/__tests__/broadenPeaks.test.ts @@ -6,12 +6,12 @@ expect.extend({ toBeDeepCloseTo, toMatchCloseTo }); describe('broadenPeaks', () => { it('empty', () => { - let result = broadenPeaks([]); + const result = broadenPeaks([]); expect(result).toStrictEqual([]); }); it('Default value, factor:2, overlap:false', () => { - let result = broadenPeaks([ + const result = broadenPeaks([ { x: -0.5, y: 1, @@ -57,7 +57,7 @@ describe('broadenPeaks', () => { }); it('no change, factor:1, overlap:false', () => { - let result = broadenPeaks( + const result = broadenPeaks( [ { x: -0.5, @@ -105,7 +105,7 @@ describe('broadenPeaks', () => { }); it('factor=10', () => { - let result = broadenPeaks( + const result = broadenPeaks( [ { x: -0.5, @@ -153,7 +153,7 @@ describe('broadenPeaks', () => { }); it('factor=20', () => { - let result = broadenPeaks( + const result = broadenPeaks( [ { x: -0.5, @@ -201,7 +201,7 @@ describe('broadenPeaks', () => { }); it('factor=20 not same width', () => { - let result = broadenPeaks( + const result = broadenPeaks( [ { x: -0.5, @@ -249,7 +249,7 @@ describe('broadenPeaks', () => { }); it('factor=20 overlap=true', () => { - let result = broadenPeaks( + const result = broadenPeaks( [ { x: -0.5, @@ -297,7 +297,7 @@ describe('broadenPeaks', () => { }); it('3 peaks factor=20', () => { - let result = broadenPeaks( + const result = broadenPeaks( [ { id: '1', diff --git a/src/post/__tests__/optimizePeaks.test.ts b/src/post/__tests__/optimizePeaks.test.ts index dafd9c4..f05ca58 100644 --- a/src/post/__tests__/optimizePeaks.test.ts +++ b/src/post/__tests__/optimizePeaks.test.ts @@ -20,7 +20,7 @@ describe('optimizePeaks', () => { }, }); - let result = optimizePeaks(data, [ + const result = optimizePeaks(data, [ { x: 0.01, y: 0.9, diff --git a/src/post/__tests__/optimizePeaksWithLogs.test.ts b/src/post/__tests__/optimizePeaksWithLogs.test.ts index a178a93..e5d8852 100644 --- a/src/post/__tests__/optimizePeaksWithLogs.test.ts +++ b/src/post/__tests__/optimizePeaksWithLogs.test.ts @@ -20,7 +20,7 @@ describe('optimizePeaksWithLogs', () => { }, }); - let result = optimizePeaksWithLogs(data, [ + const result = optimizePeaksWithLogs(data, [ { x: 0.01, y: 0.9, diff --git a/src/post/broadenPeaks.ts b/src/post/broadenPeaks.ts index fce6c63..c03205d 100644 --- a/src/post/broadenPeaks.ts +++ b/src/post/broadenPeaks.ts @@ -44,8 +44,8 @@ export function broadenPeaks( if (!overlap) { for (let i = 0; i < peaks.length - 1; i++) { - let peak = peaks[i]; - let nextPeak = peaks[i + 1]; + const peak = peaks[i]; + const nextPeak = peaks[i + 1]; if (peak.to.x > nextPeak.from.x) { // we do it proportional to the width of the peaks peak.to.x = @@ -73,7 +73,7 @@ export function broadenPeaks( function mapPeaks( peaks: T[], factor: number, -): WithIDOrShape[] { +): Array> { return peaks.map((peak) => { const { id, shape } = peak; const xFrom = peak.x - (peak.x - peak.inflectionPoints.from.x) * factor; diff --git a/src/post/joinBroadPeaks.ts b/src/post/joinBroadPeaks.ts index fe0aa80..935c229 100644 --- a/src/post/joinBroadPeaks.ts +++ b/src/post/joinBroadPeaks.ts @@ -41,7 +41,7 @@ export function joinBroadPeaks( peakList: T[], options: JoinBroadPeaksOptions = {}, ): GSDPeakOptimizedID[] { - let { + const { shape = { kind: 'gaussian' }, optimization = { kind: 'lm', options: { timeout: 10 } }, broadWidth = 0.25, @@ -93,7 +93,7 @@ export function joinBroadPeaks( count++; } else { if (count > 2) { - let fitted = optimizePeaks( + const fitted = optimizePeaks( candidates, [ { @@ -132,7 +132,7 @@ export function joinBroadPeaks( function getGSDPeakOptimizedStructure(peak: T) { const { id, shape, x, y, width } = peak; - let newPeak = { + const newPeak = { x, y, width, diff --git a/src/post/optimizePeaksWithLogs.ts b/src/post/optimizePeaksWithLogs.ts index 8f12211..6e356d6 100644 --- a/src/post/optimizePeaksWithLogs.ts +++ b/src/post/optimizePeaksWithLogs.ts @@ -32,7 +32,7 @@ export function optimizePeaksWithLogs( data: DataXY, peakList: T[], options: OptimizePeaksOptions = {}, -): { logs: any[]; optimizedPeaks: GSDPeakOptimizedIDOrNot[] } { +): { logs: any[]; optimizedPeaks: Array> } { const { fromTo = {}, baseline, @@ -52,9 +52,9 @@ export function optimizePeaksWithLogs( We can not simply optimize everything because there would be too many variables to optimize and it would be too time consuming. */ - let groups = groupPeaks(peakList, { factor: groupingFactor }); - let logs: any[] = []; - let results: GSDPeakOptimizedIDOrNot[] = []; + const groups = groupPeaks(peakList, { factor: groupingFactor }); + const logs: any[] = []; + const results: Array> = []; groups.forEach((peakGroup) => { const start = Date.now(); // In order to make optimization we will add fwhm and shape on all the peaks @@ -112,7 +112,7 @@ export function optimizePeaksWithLogs( message: 'optimization successful', }); } else { - results.push(...(peaks as GSDPeakOptimizedIDOrNot[])); + results.push(...(peaks as Array>)); logs.push({ ...log, iterations: 0, diff --git a/src/utils/__tests__/addMissingShape.test.ts b/src/utils/__tests__/addMissingShape.test.ts index 19989ba..6897b43 100644 --- a/src/utils/__tests__/addMissingShape.test.ts +++ b/src/utils/__tests__/addMissingShape.test.ts @@ -7,7 +7,7 @@ expect.extend({ toMatchCloseTo }); describe('addMissingShape', () => { it('gaussian shape', () => { - let result = addMissingShape([ + const result = addMissingShape([ { x: 5, y: 10, @@ -53,7 +53,7 @@ describe('addMissingShape', () => { ]); }); it('lorentzian shape', () => { - let result = addMissingShape( + const result = addMissingShape( [ { x: 5, @@ -117,7 +117,7 @@ describe('addMissingShape', () => { ]); }); it('pseudovoigt shape', () => { - let result = addMissingShape( + const result = addMissingShape( [ { x: 5, diff --git a/src/utils/__tests__/groupPeaks.test.ts b/src/utils/__tests__/groupPeaks.test.ts index efc57fc..9299390 100644 --- a/src/utils/__tests__/groupPeaks.test.ts +++ b/src/utils/__tests__/groupPeaks.test.ts @@ -2,7 +2,7 @@ import { groupPeaks } from '../groupPeaks'; describe('groupPeaks', () => { it('default factor value', () => { - let result = groupPeaks([ + const result = groupPeaks([ { x: 5, y: 10, width: 5 }, { x: 10, y: 10, width: 5 }, { x: 30, y: 10, width: 5 }, @@ -17,7 +17,7 @@ describe('groupPeaks', () => { }); it('factor = 0.1', () => { - let result = groupPeaks( + const result = groupPeaks( [ { x: 5, y: 10, width: 5 }, { x: 10, y: 10, width: 5 }, @@ -33,7 +33,7 @@ describe('groupPeaks', () => { }); it('factor=3', () => { - let result = groupPeaks( + const result = groupPeaks( [ { x: 5, y: 10, width: 5 }, { x: 10, y: 10, width: 5 }, @@ -51,7 +51,7 @@ describe('groupPeaks', () => { }); it('factor=5', () => { - let result = groupPeaks( + const result = groupPeaks( [ { x: 5, y: 10, width: 5 }, { x: 10, y: 10, width: 5 }, diff --git a/src/utils/__tests__/optimizeTop.test.ts b/src/utils/__tests__/optimizeTop.test.ts index 99b68a1..5bba21b 100644 --- a/src/utils/__tests__/optimizeTop.test.ts +++ b/src/utils/__tests__/optimizeTop.test.ts @@ -6,12 +6,12 @@ expect.extend({ toBeDeepCloseTo }); describe('optimizeTop', () => { it('no change', () => { - let peaks = [{ index: 2, x: 2, y: 5 }]; + const peaks = [{ index: 2, x: 2, y: 5 }]; optimizeTop({ x: [0, 1, 2, 3, 4], y: [1, 3, 5, 3, 1] }, peaks); expect(peaks).toBeDeepCloseTo([{ index: 2, x: 2, y: 5 }]); }); it('should optimize', () => { - let peaks = [{ index: 2, x: 2, y: 5 }]; + const peaks = [{ index: 2, x: 2, y: 5 }]; optimizeTop({ x: [0, 1, 2, 3, 4], y: [1, 3, 5, 4, 1] }, peaks); expect(peaks).toBeDeepCloseTo([ { index: 2, x: 2.195976944413467, y: 5.048994236103367 }, diff --git a/src/utils/__tests__/setShape.test.ts b/src/utils/__tests__/setShape.test.ts index 76be629..21cb70a 100644 --- a/src/utils/__tests__/setShape.test.ts +++ b/src/utils/__tests__/setShape.test.ts @@ -6,7 +6,7 @@ expect.extend({ toMatchCloseTo }); describe('setShape', () => { it('gaussian shape', () => { - let result = setShape([ + const result = setShape([ { x: 5, y: 10, @@ -51,7 +51,7 @@ describe('setShape', () => { ]); }); it('lorentzian shape', () => { - let result = setShape( + const result = setShape( [ { x: 5, @@ -114,7 +114,7 @@ describe('setShape', () => { ]); }); it('pseudovoigt shape', () => { - let result = setShape( + const result = setShape( [ { x: 5, diff --git a/src/utils/addMissingIDs.ts b/src/utils/addMissingIDs.ts index 00a14e5..a09e828 100644 --- a/src/utils/addMissingIDs.ts +++ b/src/utils/addMissingIDs.ts @@ -13,5 +13,5 @@ export function addMissingIDs( } } - return output as (T & { id: string })[]; + return output as Array; } diff --git a/src/utils/addMissingShape.ts b/src/utils/addMissingShape.ts index 0ad6c09..8919950 100644 --- a/src/utils/addMissingShape.ts +++ b/src/utils/addMissingShape.ts @@ -9,10 +9,10 @@ const { parse, stringify } = JSON; export function addMissingShape( peaks: T[], options: { shape?: Shape1D; output?: T[] } = {}, -): (T & { shape: Shape1D })[] { +): Array { const { shape = { kind: 'gaussian' }, output = parse(stringify(peaks)) } = options; - let shapeInstance = getShape1D(shape); + const shapeInstance = getShape1D(shape); return output.map((peak) => { if (hasShape(peak)) { if (!('fwhm' in peak.shape)) { diff --git a/src/utils/groupPeaks.ts b/src/utils/groupPeaks.ts index 3b0615f..494bae0 100644 --- a/src/utils/groupPeaks.ts +++ b/src/utils/groupPeaks.ts @@ -23,7 +23,7 @@ export function groupPeaks( let previousPeak = peaks[0]; let currentGroup: T[] = [previousPeak]; - let groups: T[][] = [currentGroup]; + const groups: T[][] = [currentGroup]; for (let i = 1; i < peaks.length; i++) { const peak = peaks[i]; diff --git a/src/utils/optimizeTop.ts b/src/utils/optimizeTop.ts index 9a67c17..34e4205 100644 --- a/src/utils/optimizeTop.ts +++ b/src/utils/optimizeTop.ts @@ -45,10 +45,10 @@ export function optimizeTop( (y[currentIndex] !== y[currentIndex - 1] || y[currentIndex] !== y[currentIndex + 1]) ) { - let alpha = 20 * Math.log10(y[currentIndex - 1]); - let beta = 20 * Math.log10(y[currentIndex]); - let gamma = 20 * Math.log10(y[currentIndex + 1]); - let p = (0.5 * (alpha - gamma)) / (alpha - 2 * beta + gamma); + const alpha = 20 * Math.log10(y[currentIndex - 1]); + const beta = 20 * Math.log10(y[currentIndex]); + const gamma = 20 * Math.log10(y[currentIndex + 1]); + const p = (0.5 * (alpha - gamma)) / (alpha - 2 * beta + gamma); peak.x = x[currentIndex] + (x[currentIndex] - x[currentIndex - 1]) * p; peak.y = y[currentIndex] - diff --git a/src/utils/setShape.ts b/src/utils/setShape.ts index 43b038c..1798466 100644 --- a/src/utils/setShape.ts +++ b/src/utils/setShape.ts @@ -16,12 +16,12 @@ export function setShape( shape?: Shape1D; output?: T[]; } = {}, -): (T & { shape: Shape1D })[] { - let { +): Array { + const { shape = { kind: 'gaussian' }, output = parse(stringify(peaks)) as T[], } = options; - let shapeInstance = getShape1D(shape); + const shapeInstance = getShape1D(shape); return output.map((peak) => ({ ...peak, shape: { fwhm: shapeInstance.widthToFWHM(peak.width), ...shape },