diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 00000000..4ded9cdd --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,28 @@ +import cheminfo from 'eslint-config-cheminfo-typescript'; +import globals from 'globals'; + +export default [ + ...cheminfo, + { + languageOptions: { + globals: { + ...globals.node, + }, + }, + rules: { + "jsdoc/require-jsdoc": "off", // this would add automatically an empty bloc of JsDoc + "jsdoc/no-defaults": "off", // this would remove our default values https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/no-defaults.md#readme + "no-loss-of-precision": "off", + '@typescript-eslint/prefer-for-of': 'off', + "unicorn/import-style": [ + "error", + { + "styles": { + "node:path": false + } + } + ] + } + } +] + diff --git a/package.json b/package.json index 3f498e19..23111fb3 100644 --- a/package.json +++ b/package.json @@ -88,22 +88,22 @@ }, "homepage": "https://github.com/mljs/spectra-processing#readme", "devDependencies": { - "@vitest/coverage-v8": "^2.0.4", + "@vitest/coverage-v8": "^2.0.5", "cheminfo-build": "^1.2.0", "eslint": "^8.57.0", - "eslint-config-cheminfo-typescript": "^12.4.0", + "eslint-config-cheminfo-typescript": "^15.0.0", "jest-matcher-deep-close-to": "^3.0.2", - "jscpd": "^3.5.10", + "jscpd": "^4.0.5", "ml-spectra-fitting": "^4.2.3", "prettier": "^3.3.3", - "rimraf": "^5.0.5", + "rimraf": "^6.0.1", "spectrum-generator": "^8.0.11", "typescript": "^5.5.4", - "vitest": "^2.0.4" + "vitest": "^2.0.5" }, "dependencies": { "binary-search": "^1.3.6", - "cheminfo-types": "^1.7.3", + "cheminfo-types": "^1.8.0", "fft.js": "^4.0.4", "is-any-array": "^2.0.1", "ml-matrix": "^6.11.1", diff --git a/src/matrix/__tests__/matrixApplyNumericalDecoding.test.ts b/src/matrix/__tests__/matrixApplyNumericalDecoding.test.ts index 5159ae3e..48010861 100644 --- a/src/matrix/__tests__/matrixApplyNumericalDecoding.test.ts +++ b/src/matrix/__tests__/matrixApplyNumericalDecoding.test.ts @@ -25,8 +25,6 @@ test('should return an array of numbers', () => { dictCategoricalToNumerical, ); - const nonNumbers = matrix - .flat(2) - .filter((value) => typeof value !== 'number'); + const nonNumbers = matrix.flat().filter((value) => typeof value !== 'number'); expect(nonNumbers).toHaveLength(0); }); diff --git a/src/matrix/__tests__/matrixNumericalEncoding.test.ts b/src/matrix/__tests__/matrixNumericalEncoding.test.ts index 69b395e8..726e3f86 100644 --- a/src/matrix/__tests__/matrixNumericalEncoding.test.ts +++ b/src/matrix/__tests__/matrixNumericalEncoding.test.ts @@ -6,8 +6,6 @@ import { datasetForEncoding } from './fixtures/encoding'; test('should return a matrix of numbers', () => { const { matrix } = matrixNumericalEncoding(datasetForEncoding); - const nonNumbers = matrix - .flat(2) - .filter((value) => typeof value !== 'number'); + const nonNumbers = matrix.flat().filter((value) => typeof value !== 'number'); expect(nonNumbers).toHaveLength(0); }); diff --git a/src/matrix/matrixAbsoluteMedian.ts b/src/matrix/matrixAbsoluteMedian.ts index 4d4e29ad..b329d743 100644 --- a/src/matrix/matrixAbsoluteMedian.ts +++ b/src/matrix/matrixAbsoluteMedian.ts @@ -3,6 +3,7 @@ import { xMedian } from '../x'; /** * Returns the median of the absolute matrix. + * @param matrix */ export function matrixAbsoluteMedian(matrix: DoubleMatrix): number { const nbColumns = matrix[0].length; diff --git a/src/matrix/matrixBoxPlot.ts b/src/matrix/matrixBoxPlot.ts index 7a8f8efe..2be4bc1b 100644 --- a/src/matrix/matrixBoxPlot.ts +++ b/src/matrix/matrixBoxPlot.ts @@ -1,3 +1,5 @@ +import { DoubleArray } from 'cheminfo-types'; + import { DoubleMatrix } from '../types'; export interface MatrixBoxPlot { @@ -22,7 +24,7 @@ export function matrixBoxPlot(matrix: DoubleMatrix): MatrixBoxPlot { median: new Float64Array(nbColumns), q3: new Float64Array(nbColumns), min: Float64Array.from(matrix[0]), - max: Float64Array.from(matrix[matrix.length - 1]), + max: Float64Array.from(matrix.at(-1) as DoubleArray), }; const columnArray = new Float64Array(matrix.length); diff --git a/src/matrix/matrixCenterZMean.ts b/src/matrix/matrixCenterZMean.ts index b6d64ff8..88ba59a1 100644 --- a/src/matrix/matrixCenterZMean.ts +++ b/src/matrix/matrixCenterZMean.ts @@ -4,7 +4,6 @@ import { matrixCreateEmpty } from './matrixCreateEmpty'; /** * Center mean of matrix columns. - * * @param matrix - matrix [rows][cols] */ export function matrixCenterZMean(matrix: DoubleMatrix): Float64Array[] { diff --git a/src/matrix/matrixClone.ts b/src/matrix/matrixClone.ts index f79ac2c1..b8feae64 100644 --- a/src/matrix/matrixClone.ts +++ b/src/matrix/matrixClone.ts @@ -1,5 +1,6 @@ /** * Clone a matrix. + * @param matrix */ export function matrixClone(matrix: ValueType[][]): ValueType[][] { return matrix.map((row) => row.slice(0)); diff --git a/src/matrix/matrixColumnsCorrelation.ts b/src/matrix/matrixColumnsCorrelation.ts index f2989d07..afb12075 100644 --- a/src/matrix/matrixColumnsCorrelation.ts +++ b/src/matrix/matrixColumnsCorrelation.ts @@ -5,7 +5,6 @@ import { xCorrelation } from '../x'; /** * Calculates a correlation matrix based on the columns of the initial matrix. - * * @param A - matrix [rows][cols] */ export function matrixColumnsCorrelation(A: DoubleMatrix): Float64Array[] { diff --git a/src/matrix/matrixCreateEmpty.ts b/src/matrix/matrixCreateEmpty.ts index 2c1b27b4..9f309e1d 100644 --- a/src/matrix/matrixCreateEmpty.ts +++ b/src/matrix/matrixCreateEmpty.ts @@ -12,16 +12,19 @@ export interface MatrixCreateEmptyOptions< * Matrix from which to extract nbRows and nbColumns */ matrix?: DoubleMatrix; + /** * Matrix from which to extract nbRows and nbColumns * @default matrix.length || 1 */ nbRows?: number; + /** * Matrix from which to extract nbRows and nbColumns * @default matrix[0].length || 1 */ nbColumns?: number; + /** * Allows to specify the type of array to use * @default Float64Array @@ -31,6 +34,7 @@ export interface MatrixCreateEmptyOptions< /** * Create a new matrix based on the size of the current one or by using specific dimensions. + * @param options */ export function matrixCreateEmpty< ArrayConstructorType extends NumberArrayConstructor = Float64ArrayConstructor, diff --git a/src/matrix/matrixHistogram.ts b/src/matrix/matrixHistogram.ts index bb99daf3..ed21bb6f 100644 --- a/src/matrix/matrixHistogram.ts +++ b/src/matrix/matrixHistogram.ts @@ -10,44 +10,50 @@ export interface MatrixHistogramOptions { /** * Center the X value. We will enlarge the first and * @default true - * */ + */ centerX?: boolean; + /** * histogram - * */ + */ histogram?: DataXY; + /** * Number of slots * @default 256 - * */ + */ nbSlots?: number; + /** * We can first apply a log on the x-axis. - * */ + */ logBaseX?: number; + /** * We can apply a log on the resulting histogram */ logBaseY?: number; + /** * Take the absolute value */ absolute?: boolean; + /** * Maximal value to calculate used to calculate slot size * @default maxValue - * */ + */ max?: number; + /** * Minimum value to calculate used to calculate slot size * @default minValue - * */ + */ min?: number; } /** * Calculates a histogram of defined number of slots. - * * @param matrix - matrix [rows][cols]. * @param options - options * @returns - Result of the histogram. @@ -63,17 +69,17 @@ export function matrixHistogram( throw new Error('matrix must have at least one column and one row'); } - if (typeof min === 'undefined' || typeof max === 'undefined') { + if (min === undefined || max === undefined) { const minMax = absolute ? matrixMinMaxAbsoluteZ(matrix) : matrixMinMaxZ(matrix); - if (typeof min === 'undefined') { + if (min === undefined) { min = logBaseX && minMax.min ? Math.log(minMax.min) / Math.log(logBaseX) : minMax.min; } - if (typeof max === 'undefined') { + if (max === undefined) { max = logBaseX && minMax.max ? Math.log(minMax.max) / Math.log(logBaseX) diff --git a/src/matrix/matrixMaxAbsoluteZ.ts b/src/matrix/matrixMaxAbsoluteZ.ts index f633aa2e..7b324cad 100644 --- a/src/matrix/matrixMaxAbsoluteZ.ts +++ b/src/matrix/matrixMaxAbsoluteZ.ts @@ -2,7 +2,6 @@ import { NumberArray } from 'cheminfo-types'; /** * Returns the max absolute values of Z. - * * @param matrix - matrix [rows][cols]. */ export function matrixMaxAbsoluteZ(matrix: NumberArray[]): number { diff --git a/src/matrix/matrixMedian.ts b/src/matrix/matrixMedian.ts index f4001535..b6945757 100644 --- a/src/matrix/matrixMedian.ts +++ b/src/matrix/matrixMedian.ts @@ -5,6 +5,7 @@ import { matrixToArray } from './matrixToArray'; /** * Returns the median of the matrix. + * @param matrix */ export function matrixMedian(matrix: DoubleMatrix): number { return xMedian(matrixToArray(matrix)); diff --git a/src/matrix/matrixMinMaxAbsoluteZ.ts b/src/matrix/matrixMinMaxAbsoluteZ.ts index dc23e958..f150e77b 100644 --- a/src/matrix/matrixMinMaxAbsoluteZ.ts +++ b/src/matrix/matrixMinMaxAbsoluteZ.ts @@ -2,7 +2,6 @@ import { DoubleMatrix } from '../types'; /** * Get min and max of the absolute values of Z. - * * @param matrix - matrix [rows][cols]. */ export function matrixMinMaxAbsoluteZ(matrix: DoubleMatrix): { diff --git a/src/matrix/matrixMinMaxZ.ts b/src/matrix/matrixMinMaxZ.ts index f21d78fc..813d9524 100644 --- a/src/matrix/matrixMinMaxZ.ts +++ b/src/matrix/matrixMinMaxZ.ts @@ -4,7 +4,6 @@ import { matrixCheck } from './matrixCheck'; /** * Get min and max Z. - * * @param matrix - matrix [rows][cols]. */ export function matrixMinMaxZ(matrix: DoubleMatrix): { diff --git a/src/matrix/matrixPQN.ts b/src/matrix/matrixPQN.ts index 88e641b1..313d9487 100644 --- a/src/matrix/matrixPQN.ts +++ b/src/matrix/matrixPQN.ts @@ -7,8 +7,9 @@ export interface MatrixPQNOptions { /** * Normalization integral constant. * @default 100 - * */ + */ max?: number; + /** * min */ @@ -19,7 +20,6 @@ export interface MatrixPQNOptions { * Performs a Probabilistic quotient normalization (PQN) over the dataset to account dilution based in median spectrum. * Dieterle, F., Ross, A., Schlotterbeck, G., & Senn, H. (2006). Probabilistic quotient normalization as robust method to account for dilution of complex biological mixtures. Application in 1H NMR metabonomics. Analytical chemistry, 78(13), 4281-4290. * DOI: 10.1021/ac051632c - * * @param matrix - matrix [rows][cols]. * @param options - options * @returns - {data: Normalized dataset, medianOfQuotients: The median of quotients of each variables} diff --git a/src/matrix/matrixZPivotRescale.ts b/src/matrix/matrixZPivotRescale.ts index f48d1cfb..7fc00d15 100644 --- a/src/matrix/matrixZPivotRescale.ts +++ b/src/matrix/matrixZPivotRescale.ts @@ -11,8 +11,9 @@ export interface MatrixZPivotRescaleOptions< /** * max * @default 1 - * */ + */ max?: number; + /** * Allows to specify the type of array to use * @default Float64Array @@ -22,7 +23,6 @@ export interface MatrixZPivotRescaleOptions< /** * Rescale a matrix around 0 taking into account the absolute max value. - * * @param matrix - matrix [rows][cols]. * @param options - Options. */ diff --git a/src/matrix/matrixZRescale.ts b/src/matrix/matrixZRescale.ts index 3dc37909..452b0d06 100644 --- a/src/matrix/matrixZRescale.ts +++ b/src/matrix/matrixZRescale.ts @@ -10,13 +10,15 @@ export interface MatrixZRescaleOptions< /** * min * @default 0 - * */ + */ min?: number; + /** * max * @default 1 - * */ + */ max?: number; + /** * Allows to specify the type of array to use. * @default Float64Array @@ -26,7 +28,6 @@ export interface MatrixZRescaleOptions< /** * Rescale a matrix between min and max values. - * * @param matrix - matrix [rows][cols]. * @param options - Options. */ diff --git a/src/matrix/matrixZRescalePerColumn.ts b/src/matrix/matrixZRescalePerColumn.ts index c37c8569..11921247 100644 --- a/src/matrix/matrixZRescalePerColumn.ts +++ b/src/matrix/matrixZRescalePerColumn.ts @@ -6,18 +6,18 @@ export interface MatrixZRescalePerColumnOptions { /** * min * @default 0 - * */ + */ min?: number; + /** * max * @default 1 - * */ + */ max?: number; } /** * Rescale the matrix per column for which we get the min and max values. - * * @param matrix - matrix [rows][cols]. * @param options - Options. */ diff --git a/src/reim/__tests__/reimAutoPhaseCorrection.test.ts b/src/reim/__tests__/reimAutoPhaseCorrection.test.ts index c75630e1..fd7c1e49 100644 --- a/src/reim/__tests__/reimAutoPhaseCorrection.test.ts +++ b/src/reim/__tests__/reimAutoPhaseCorrection.test.ts @@ -1,5 +1,5 @@ import { readFileSync } from 'node:fs'; -import { join } from 'path'; +import { join } from 'node:path'; import { expect, test } from 'vitest'; diff --git a/src/reim/reimAbsolute.ts b/src/reim/reimAbsolute.ts index 0bf335fc..eeb10238 100644 --- a/src/reim/reimAbsolute.ts +++ b/src/reim/reimAbsolute.ts @@ -2,7 +2,6 @@ import { DataReIm } from '../types'; /** * Calculates reimAbsolute value of a complex spectrum. - * * @param data - complex spectrum * @returns - reimAbsolute value */ @@ -12,7 +11,7 @@ export function reimAbsolute(data: DataReIm): Float64Array { const im = data.im; const newArray = new Float64Array(length); for (let i = 0; i < length; i++) { - newArray[i] = Math.sqrt(re[i] ** 2 + im[i] ** 2); + newArray[i] = Math.hypot(re[i], im[i]); } return newArray; diff --git a/src/reim/reimAutoPhaseCorrection.ts b/src/reim/reimAutoPhaseCorrection.ts index 58e922d1..a5ab8df6 100644 --- a/src/reim/reimAutoPhaseCorrection.ts +++ b/src/reim/reimAutoPhaseCorrection.ts @@ -12,21 +12,25 @@ export interface AutoPhaseCorrectionOptions { * @default true */ magnitudeMode?: boolean; + /** * min number of points to auto phase a region * @default 30 */ minRegSize?: number; + /** * max distance between regions (in number of points) to join two regions * @default 256 */ maxDistanceToJoin?: number; + /** * scale the cutoff like factorStd * noiseLevel * @default 3 */ factorNoise?: number; + /** * Apply the phase correction from the last element of the array * @default false @@ -37,7 +41,6 @@ export interface AutoPhaseCorrectionOptions { /** * Implementation of the algorithm for automatic phase correction: A robust, general automatic phase * correction algorithm for high-resolution NMR data. 10.1002/mrc.4586 - * * @param data - complex spectrum * @param options - options */ @@ -151,7 +154,6 @@ interface AutoPhaseRegionResult { /** * AutoPhaseRegion. - * * @param re - Array of Number. * @param im - Array of Number. * @param x0 - Number. @@ -197,7 +199,6 @@ function autoPhaseRegion( /** * Holoborodko. - * * @param s - Array of float. * @returns Array of float. */ @@ -224,7 +225,6 @@ function holoborodko(s: DoubleArray): Float64Array { /** * RobustBaseLineRegionsDetection. - * * @param s * @param options * @param options.magnitudeMode @@ -281,7 +281,6 @@ function robustBaseLineRegionsDetection( /** * WeightedLinearRegression. - * * @param x * @param y * @param w diff --git a/src/reim/reimFFT.ts b/src/reim/reimFFT.ts index 535972f9..9e2a3630 100644 --- a/src/reim/reimFFT.ts +++ b/src/reim/reimFFT.ts @@ -10,7 +10,6 @@ export interface ReimFFTOptions { /** * ReimFFT. - * * @param data - complex spectrum * @param options - options. * @returns FFT of complex spectrum. diff --git a/src/reim/reimPhaseCorrection.ts b/src/reim/reimPhaseCorrection.ts index 7455957f..564dcc3c 100644 --- a/src/reim/reimPhaseCorrection.ts +++ b/src/reim/reimPhaseCorrection.ts @@ -6,7 +6,6 @@ export interface ReimPhaseCorrectionOptions { /** * Phase correction filter. - * * @param data - complex spectrum * @param phi0 - Angle in radians for zero order phase correction * @param phi1 - Angle in radians for first order phase correction diff --git a/src/types/DataReIm.ts b/src/types/DataReIm.ts index d453c7c3..2254d750 100644 --- a/src/types/DataReIm.ts +++ b/src/types/DataReIm.ts @@ -3,6 +3,7 @@ import { DoubleArray } from 'cheminfo-types'; export interface DataReIm { /** Array of re values */ re: ArrayType; + /** Array of im values */ im: ArrayType; } diff --git a/src/types/DataXReIm.ts b/src/types/DataXReIm.ts index fa1558f0..89febe42 100644 --- a/src/types/DataXReIm.ts +++ b/src/types/DataXReIm.ts @@ -3,8 +3,10 @@ import { DoubleArray } from 'cheminfo-types'; export interface DataXReIm { /** Array of x values */ x: ArrayType; + /** Array of re values */ re: ArrayType; + /** Array of im values */ im: ArrayType; } diff --git a/src/types/Point.ts b/src/types/Point.ts index 3d74e292..ac5313b7 100644 --- a/src/types/Point.ts +++ b/src/types/Point.ts @@ -1,8 +1,10 @@ export interface Point { /** x value */ x: number; + /** y value */ y: number; + /** point index */ index?: number; } @@ -10,3 +12,7 @@ export interface Point { export interface PointWithIndex extends Point { index: number; } + +export interface PointWithClose extends Point { + close: boolean; +} diff --git a/src/utils/createFromToArray.ts b/src/utils/createFromToArray.ts index 6a4e4fea..b146a690 100644 --- a/src/utils/createFromToArray.ts +++ b/src/utils/createFromToArray.ts @@ -1,35 +1,45 @@ export interface CreateFromToArrayOptions { /** * start value of range - * @default 0 */ + * @default 0 + */ from?: number; + /** * end value of range - * @default 1 */ + * @default 1 + */ to?: number; + /** * number of points in range - * @default 1000 */ + * @default 1000 + */ length?: number; + /** * include from - * @default true */ + * @default true + */ includeFrom?: boolean; + /** * include to - * @default true */ + * @default true + */ includeTo?: boolean; + /** * distribution used - * @default uniform */ + * @default uniform + */ distribution?: 'uniform' | 'log'; } /** * Create an array with numbers between "from" and "to" of length "length" - * * @param options - options - * @return - array of distributed numbers between "from" and "to" + * @returns - array of distributed numbers between "from" and "to" */ export function createFromToArray( options: CreateFromToArrayOptions = {}, diff --git a/src/utils/createRandomArray.ts b/src/utils/createRandomArray.ts index 1904a501..a62baded 100644 --- a/src/utils/createRandomArray.ts +++ b/src/utils/createRandomArray.ts @@ -7,33 +7,42 @@ export interface CreateRandomArrayOptions { * @default 'normal' */ distribution?: 'uniform' | 'normal'; + /** * Seed for a deterministic sequence of random numbers. * @default Date.now() */ seed?: number; + /** * mean - * @default 0 */ + * @default 0 + */ mean?: number; + /** * standardDeviation, used in case of normal distribution - * @default 1 */ + * @default 1 + */ standardDeviation?: number; + /** *range, used in case of uniform distribution - * @default 1 */ + * @default 1 + */ range?: number; + /** * number of points - * @default 1000 */ + * @default 1000 + */ length?: number; } /** * Create a random array of numbers of a specific length. - * - * @return - array of random floats normally distributed + * @param options + * @returns - array of random floats normally distributed */ export function createRandomArray( options: CreateRandomArrayOptions = {}, diff --git a/src/utils/createStepArray.ts b/src/utils/createStepArray.ts index e5c6be2e..2d6dd443 100644 --- a/src/utils/createStepArray.ts +++ b/src/utils/createStepArray.ts @@ -1,24 +1,27 @@ export interface CreateStepArrayOptions { /** * start value of range - * @default 0 */ + * @default 0 + */ from?: number; + /** * step value between points * @default 1 */ step?: number; + /** * number of points in range - * @default 1000 */ + * @default 1000 + */ length?: number; } /** * Create an array with numbers starting from "from" with step "step" of length "length". - * * @param options - options - * @return - array of distributed numbers with step "step" from "from" + * @returns - array of distributed numbers with step "step" from "from" */ export function createStepArray( options: CreateStepArrayOptions = {}, diff --git a/src/utils/getRescaler.ts b/src/utils/getRescaler.ts index 11cb296e..1dd4a2b8 100644 --- a/src/utils/getRescaler.ts +++ b/src/utils/getRescaler.ts @@ -6,31 +6,37 @@ export interface GetRescalerOptions { * @default 0 */ originalMin?: number; + /** * The maximum value of the original range * @default 1 */ originalMax?: number; + /** * The new minimum value of the target range * @default 0 */ targetMin?: number; + /** * The new maximum value of the target range * @default 1 */ targetMax?: number; + /** * If true, the value will be clamp to the target range * @default true */ clamp?: boolean; + /** * The algorithm to use for the rescaling * @default 'linear' */ algorithm?: RescalerAlgorithm; + /** * Options for the algorithm * @default {} diff --git a/src/utils/isPowerOfTwo.ts b/src/utils/isPowerOfTwo.ts index b81f3a94..bb149c4c 100644 --- a/src/utils/isPowerOfTwo.ts +++ b/src/utils/isPowerOfTwo.ts @@ -1,5 +1,6 @@ /** * Check if a number is a power of two. + * @param n */ export function isPowerOfTwo(n: number): boolean { return n !== 0 && (n & (n - 1)) === 0; diff --git a/src/utils/nextPowerOfTwo.ts b/src/utils/nextPowerOfTwo.ts index db619397..e9b2b1e6 100644 --- a/src/utils/nextPowerOfTwo.ts +++ b/src/utils/nextPowerOfTwo.ts @@ -1,5 +1,6 @@ /** * Get the size of the next power of two. + * @param n */ export function nextPowerOfTwo(n: number): number { if (n === 0) return 1; diff --git a/src/x/getOutputArray.ts b/src/x/getOutputArray.ts index b10f864a..9215c8b6 100644 --- a/src/x/getOutputArray.ts +++ b/src/x/getOutputArray.ts @@ -12,6 +12,7 @@ export function getOutputArray( output: T | undefined, length: number, ): T; + /** * This function * @param output - undefined or a new array @@ -22,7 +23,7 @@ export function getOutputArray( output: NumberArray | undefined, length: number, ): NumberArray { - if (typeof output !== 'undefined') { + if (output !== undefined) { if (!isAnyArray(output)) { throw new TypeError('output option must be an array if specified'); } diff --git a/src/x/utils/erfcinv.ts b/src/x/utils/erfcinv.ts index 5778f62b..d058ac03 100644 --- a/src/x/utils/erfcinv.ts +++ b/src/x/utils/erfcinv.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-loss-of-precision */ /* Adapted from: https://github.com/compute-io/erfcinv/blob/aa116e23883839359e310ad41a7c42f72815fc1e/lib/number.js @@ -109,7 +108,6 @@ const Q5 = [ /** * Polyval. - * * @param c - Array of Number. * @param x - Number. * @returns Number. @@ -124,7 +122,6 @@ function polyval(c: number[], x: number): number { /** * Calculates a rational approximation. - * * @private * @param x - Number. * @param v - Number. @@ -147,7 +144,6 @@ function calc( /** * Evaluates the complementary inverse error function for an input value. - * * @private * @param x - Input value. * @returns Evaluated complementary inverse error function. diff --git a/src/x/utils/rayleighCdf.ts b/src/x/utils/rayleighCdf.ts index f94e11bd..939c2f1d 100644 --- a/src/x/utils/rayleighCdf.ts +++ b/src/x/utils/rayleighCdf.ts @@ -1,6 +1,5 @@ /** * RayleighCdf. - * * @param x - data * @param sigma - standard deviation * @returns - rayleigh cdf diff --git a/src/x/xAbsolute.ts b/src/x/xAbsolute.ts index 31399208..ba61bedb 100644 --- a/src/x/xAbsolute.ts +++ b/src/x/xAbsolute.ts @@ -2,7 +2,6 @@ import { NumberArray } from 'cheminfo-types'; /** * This function returns an array with absolute values. - * * @param array - array of data * @returns - array with absolute values */ diff --git a/src/x/xAbsoluteMedian.ts b/src/x/xAbsoluteMedian.ts index 73213489..f368a935 100644 --- a/src/x/xAbsoluteMedian.ts +++ b/src/x/xAbsoluteMedian.ts @@ -5,7 +5,6 @@ import { xMedian } from './xMedian'; /** * This function calculates the median after taking the xAbsolute values of the points. - * * @param array - the array for which we want to calculate the absolute value * @returns - median */ diff --git a/src/x/xAdd.ts b/src/x/xAdd.ts index 2b4edc20..80a1d9c4 100644 --- a/src/x/xAdd.ts +++ b/src/x/xAdd.ts @@ -3,7 +3,6 @@ import { isAnyArray } from 'is-any-array'; /** * This function xAdd the first array by the second array or a constant value to each element of the first array - * * @param array1 - the first array * @param array2 - the second array or number */ diff --git a/src/x/xApplyFunctionStr.ts b/src/x/xApplyFunctionStr.ts index c8591e64..e4f415ff 100644 --- a/src/x/xApplyFunctionStr.ts +++ b/src/x/xApplyFunctionStr.ts @@ -8,6 +8,7 @@ export interface XApplyFunctionStrOptions { * The function to apply on the array as a string */ fctString?: string; + /** * The variable to use in the fctString (one lower case letter) * @default 'x' @@ -32,11 +33,11 @@ export function xApplyFunctionStr( const fct = new Function( variableLabel, `return Number(${fctString - .replace( + .replaceAll( /(?^|\W)(?[\da-z]{2,}\()/g, '$Math.$', ) - .replace(/Math\.Math/g, 'Math')})`, + .replaceAll('Math.Math', 'Math')})`, ); const toReturn = Float64Array.from(array); for (let i = 0; i < array.length; i++) { diff --git a/src/x/xAutoCorrelation.ts b/src/x/xAutoCorrelation.ts index 623b94ed..af88319f 100644 --- a/src/x/xAutoCorrelation.ts +++ b/src/x/xAutoCorrelation.ts @@ -8,6 +8,7 @@ export interface XAutoCorrelationOptions { * @default 1 */ tau?: number; + /** * scalar lag parameter * @default A.length-1 @@ -17,7 +18,6 @@ export interface XAutoCorrelationOptions { /** * Calculates the auto-correlation of an array - * * @param A - the array for which to calculate the auto-correlation * @param options - Options */ diff --git a/src/x/xBoxPlot.ts b/src/x/xBoxPlot.ts index 4454d472..2d0248f7 100644 --- a/src/x/xBoxPlot.ts +++ b/src/x/xBoxPlot.ts @@ -18,7 +18,6 @@ export interface XBoxPlot { /** * Calculating the box plot of the array - * * @param array - data * @param options */ @@ -29,7 +28,7 @@ export function xBoxPlot( const { allowSmallArray = false } = options; if (array.length < 5) { if (allowSmallArray) { - if (array.length < 1) { + if (array.length === 0) { throw new Error('can not calculate info if array is empty'); } } else { @@ -46,7 +45,7 @@ export function xBoxPlot( median: 0, q3: 0, min: array[0], - max: array[array.length - 1], + max: array.at(-1) as number, }; let q1max, q3min; if (array.length % 2 === 1) { diff --git a/src/x/xCheck.ts b/src/x/xCheck.ts index 005f06c0..f69fc1c0 100644 --- a/src/x/xCheck.ts +++ b/src/x/xCheck.ts @@ -8,7 +8,6 @@ export interface XCheckOptions { /** * Checks if input is of type array. - * * @param input - input * @param options */ diff --git a/src/x/xCheckLengths.ts b/src/x/xCheckLengths.ts index 42f19722..d6003a4d 100644 --- a/src/x/xCheckLengths.ts +++ b/src/x/xCheckLengths.ts @@ -2,7 +2,6 @@ import { NumberArray } from 'cheminfo-types'; /** * Check that two arrays have the same length. - * * @param array1 - First array. * @param array2 - Second array. */ diff --git a/src/x/xCorrelation.ts b/src/x/xCorrelation.ts index 517e4fff..28f29e25 100644 --- a/src/x/xCorrelation.ts +++ b/src/x/xCorrelation.ts @@ -3,7 +3,6 @@ import { NumberArray } from 'cheminfo-types'; /** * Calculates the correlation between 2 vectors * https://en.wikipedia.org/wiki/Correlation_and_dependence - * * @param A - first array * @param B - sencond array */ diff --git a/src/x/xCrossCorrelation.ts b/src/x/xCrossCorrelation.ts index 00ebe331..1f3eceff 100644 --- a/src/x/xCrossCorrelation.ts +++ b/src/x/xCrossCorrelation.ts @@ -6,18 +6,18 @@ export interface XCrossCorrelationOptions { /** * sweep increment size (in number of points, min=1, max=A.length) * @default 1 - * */ + */ tau?: number; + /** * scalar lag parameter * @default A.length-1 - * */ + */ lag?: number; } /** * Calculates the cross-correlation between 2 arrays - * * @param A - fixed array * @param B - sweeping array * @param options - Options diff --git a/src/x/xCumulative.ts b/src/x/xCumulative.ts index 0535a20d..058d6b6a 100644 --- a/src/x/xCumulative.ts +++ b/src/x/xCumulative.ts @@ -3,7 +3,6 @@ import { isAnyArray } from 'is-any-array'; /** * Calculate an array of the same size that is the cumulative values - * * @param array - initial array */ export function xCumulative(array: NumberArray): Float64Array { diff --git a/src/x/xDivide.ts b/src/x/xDivide.ts index 110e0ce0..76a19555 100644 --- a/src/x/xDivide.ts +++ b/src/x/xDivide.ts @@ -10,7 +10,6 @@ export interface XDivideOptions { /** * This function divide the first array by the second array or a constant value to each element of the first array - * * @param array1 - first array * @param array2 - second array or number * @param options - options diff --git a/src/x/xDotProduct.ts b/src/x/xDotProduct.ts index 9ed161aa..5153bbd9 100644 --- a/src/x/xDotProduct.ts +++ b/src/x/xDotProduct.ts @@ -4,7 +4,6 @@ import { xMultiply } from './xMultiply'; /** * Dot product between two arrays. - * * @param A - First array. * @param B - Second array. */ diff --git a/src/x/xEnsureFloat64.ts b/src/x/xEnsureFloat64.ts index 2603702a..64c28e4c 100644 --- a/src/x/xEnsureFloat64.ts +++ b/src/x/xEnsureFloat64.ts @@ -4,7 +4,6 @@ import { xCheck } from './xCheck'; /** * Returns a copy of the data as a Float64Array. - * * @param array - array of numbers */ export function xEnsureFloat64(array: NumberArray): Float64Array { diff --git a/src/x/xFindClosestIndex.ts b/src/x/xFindClosestIndex.ts index 562d8723..774fe89c 100644 --- a/src/x/xFindClosestIndex.ts +++ b/src/x/xFindClosestIndex.ts @@ -10,7 +10,6 @@ export interface XFindClosestIndexOptions { /** * Returns the closest index of a `target` - * * @param array - array of numbers * @param target - target * @param options diff --git a/src/x/xGetFromToIndex.ts b/src/x/xGetFromToIndex.ts index 261e1e43..6d4c92f1 100644 --- a/src/x/xGetFromToIndex.ts +++ b/src/x/xGetFromToIndex.ts @@ -6,26 +6,28 @@ export interface XGetFromToIndexOptions { /** * First point for xyIntegration * @default 0 - * */ + */ fromIndex?: number; + /** * Last point for xyIntegration * @default x.length-1 - * */ + */ toIndex?: number; + /** * First value for xyIntegration in the X scale - * */ + */ from?: number; + /** * Last value for xyIntegration in the X scale - * */ + */ to?: number; } /** * Returns an object with {fromIndex, toIndex} for a specific from / to - * * @param x - array of numbers * @param options - Options */ @@ -36,15 +38,15 @@ export function xGetFromToIndex( let { fromIndex, toIndex } = options; const { from, to } = options; - if (typeof fromIndex === 'undefined') { - if (typeof from !== 'undefined') { + if (fromIndex === undefined) { + if (from !== undefined) { fromIndex = xFindClosestIndex(x, from); } else { fromIndex = 0; } } - if (typeof toIndex === 'undefined') { - if (typeof to !== 'undefined') { + if (toIndex === undefined) { + if (to !== undefined) { toIndex = xFindClosestIndex(x, to); } else { toIndex = x.length - 1; diff --git a/src/x/xGetTargetIndex.ts b/src/x/xGetTargetIndex.ts index 65437f4c..c2ca0b9b 100644 --- a/src/x/xGetTargetIndex.ts +++ b/src/x/xGetTargetIndex.ts @@ -4,6 +4,7 @@ import { xFindClosestIndex } from './xFindClosestIndex'; export interface XGetTargetIndexOptions { target?: number; + /** * @default 0 */ @@ -12,7 +13,6 @@ export interface XGetTargetIndexOptions { /** * Returns the targetIndex - * * @param x - array of numbers * @param options - options */ @@ -21,8 +21,8 @@ export function xGetTargetIndex( options: XGetTargetIndexOptions = {}, ): number { const { target, targetIndex } = options; - if (typeof targetIndex === 'undefined') { - if (typeof target !== 'undefined') { + if (targetIndex === undefined) { + if (target !== undefined) { return xFindClosestIndex(x, target); } else { return 0; diff --git a/src/x/xHilbertTransform.ts b/src/x/xHilbertTransform.ts index f9d6e372..a6ff9015 100644 --- a/src/x/xHilbertTransform.ts +++ b/src/x/xHilbertTransform.ts @@ -72,6 +72,7 @@ function hilbertTransformWithFFT(array: NumberArray): Float64Array { * Performs the discrete Hilbert transform * @param array - Array containing values * @param options + * @param options.inClockwise * @returns A new vector with 90 degree shift regarding the phase of the original function */ function hilbertTransform( diff --git a/src/x/xHistogram.ts b/src/x/xHistogram.ts index e0ec8db6..d47c62c8 100644 --- a/src/x/xHistogram.ts +++ b/src/x/xHistogram.ts @@ -11,45 +11,51 @@ export interface XHistogramOptions { /** * Center the X value. We will enlarge the first and * @default true - * */ + */ centerX?: boolean; + /** * Previously existing histogram to continue to fill * @default {x:[],y:[]} - * */ + */ histogram?: DataXY; + /** * Number of slots * @default 256 - * */ + */ nbSlots?: number; + /** * We can first apply a log on x axis - * */ + */ logBaseX?: number; + /** * We can apply a log on the resulting histogram */ logBaseY?: number; + /** * Take the absolute value */ absolute?: boolean; + /** * Maximal value to calculate used to calculate slot size * @default maxValue - * */ + */ max?: number; + /** * Minimum value to calculate used to calculate slot size * @default minValue - * */ + */ min?: number; } /** * Calculates a histogram of defined number of slots - * * @param array - Array containing values * @param options - options * @returns - result of the histogram @@ -62,7 +68,7 @@ export function xHistogram( const histogram = options.histogram; const { centerX = true, - nbSlots = typeof histogram === 'undefined' ? 256 : histogram.x.length, + nbSlots = histogram === undefined ? 256 : histogram.x.length, logBaseX, logBaseY, absolute = false, @@ -81,10 +87,9 @@ export function xHistogram( const { min = xMinValue(array), max = xMaxValue(array) } = options; const slotSize = (max - min) / (nbSlots + Number.EPSILON); - const y = - typeof histogram === 'undefined' ? new Float64Array(nbSlots) : histogram.y; + const y = histogram === undefined ? new Float64Array(nbSlots) : histogram.y; const x = - typeof histogram === 'undefined' + histogram === undefined ? Array.from( createFromToArray({ from: min + (centerX ? slotSize / 2 : 0), diff --git a/src/x/xIsEquallySpaced.ts b/src/x/xIsEquallySpaced.ts index 104b80db..656962e3 100644 --- a/src/x/xIsEquallySpaced.ts +++ b/src/x/xIsEquallySpaced.ts @@ -10,7 +10,6 @@ export interface XIsEquallySpacedOptions { /** * Check if the values are separated always by the same difference - * * @param array - Monotone growing array of number * @param options */ diff --git a/src/x/xIsMonotonic.ts b/src/x/xIsMonotonic.ts index e56f5a14..e2366558 100644 --- a/src/x/xIsMonotonic.ts +++ b/src/x/xIsMonotonic.ts @@ -2,7 +2,6 @@ import { NumberArray } from 'cheminfo-types'; /** * Returns true if x is monotonic. - * * @param array - array of numbers. * @returns 1 if monotonic increasing, -1 if monotonic decreasing, 0 if not monotonic. */ @@ -18,7 +17,7 @@ export function xIsMonotonic(array: NumberArray): -1 | 0 | 1 { return 1; } - if (array[0] < array[array.length - 1]) { + if (array[0] < (array.at(-1) as number)) { for (let i = 0; i < array.length - 1; i++) { if (array[i] >= array[i + 1]) return 0; } diff --git a/src/x/xMassCenterVectorSimilarity.ts b/src/x/xMassCenterVectorSimilarity.ts index ce20384b..e07a4c76 100644 --- a/src/x/xMassCenterVectorSimilarity.ts +++ b/src/x/xMassCenterVectorSimilarity.ts @@ -6,6 +6,7 @@ interface XMassCenterVectorSimilarityOptions { * @default (a, b) => (a === b ? 1 : 0) */ similarityFct?: (a: number, b: number) => number; + /** * Should we recenter the tree ? * @default: true diff --git a/src/x/xMaxAbsoluteValue.ts b/src/x/xMaxAbsoluteValue.ts index 0897063e..7955ed99 100644 --- a/src/x/xMaxAbsoluteValue.ts +++ b/src/x/xMaxAbsoluteValue.ts @@ -5,7 +5,6 @@ import { xGetFromToIndex, XGetFromToIndexOptions } from './xGetFromToIndex'; /** * Computes the maximal value of an array of values - * * @param array - array of numbers * @param options - options */ diff --git a/src/x/xMaxIndex.ts b/src/x/xMaxIndex.ts index 611f2442..44609650 100644 --- a/src/x/xMaxIndex.ts +++ b/src/x/xMaxIndex.ts @@ -5,7 +5,6 @@ import { xGetFromToIndex, XGetFromToIndexOptions } from './xGetFromToIndex'; /** * Computes the index of the maximum of the given values - * * @param array - array of numbers * @param options - options * @returns - index diff --git a/src/x/xMaxValue.ts b/src/x/xMaxValue.ts index 69b3e0e4..e8c64a15 100644 --- a/src/x/xMaxValue.ts +++ b/src/x/xMaxValue.ts @@ -5,7 +5,6 @@ import { xGetFromToIndex, XGetFromToIndexOptions } from './xGetFromToIndex'; /** * Computes the maximal value of an array of values - * * @param array - array of numbers * @param options - options */ diff --git a/src/x/xMean.ts b/src/x/xMean.ts index 8c33e3ea..8dcc3c69 100644 --- a/src/x/xMean.ts +++ b/src/x/xMean.ts @@ -5,7 +5,6 @@ import { xGetFromToIndex, XGetFromToIndexOptions } from './xGetFromToIndex'; /** * Computes the mean value of an array of values. - * * @param array - array of numbers * @param options - options */ diff --git a/src/x/xMeanAbsoluteError.ts b/src/x/xMeanAbsoluteError.ts index d0428ef9..c24a456a 100644 --- a/src/x/xMeanAbsoluteError.ts +++ b/src/x/xMeanAbsoluteError.ts @@ -4,7 +4,6 @@ import { xCheckLengths } from './xCheckLengths'; /** * This function calculates the mean absolute error. - * * @param array1 - first array * @param array2 - second array */ diff --git a/src/x/xMeanSquaredError.ts b/src/x/xMeanSquaredError.ts index ed67d04b..51d8c108 100644 --- a/src/x/xMeanSquaredError.ts +++ b/src/x/xMeanSquaredError.ts @@ -4,7 +4,6 @@ import { xCheckLengths } from './xCheckLengths'; /** * This function calculates the mean squared error. - * * @param array1 -first array * @param array2 - second array */ diff --git a/src/x/xMeanWeighted.ts b/src/x/xMeanWeighted.ts index c66f40bc..17fe8d71 100644 --- a/src/x/xMeanWeighted.ts +++ b/src/x/xMeanWeighted.ts @@ -5,7 +5,6 @@ import { xGetFromToIndex, XGetFromToIndexOptions } from './xGetFromToIndex'; /** * Computes the weighted mean value of an array of values. - * * @deprecated please use xyMassCenter * @param array - array of numbers * @param weights - array of weights diff --git a/src/x/xMedian.ts b/src/x/xMedian.ts index f08eae41..f6f3cbc2 100644 --- a/src/x/xMedian.ts +++ b/src/x/xMedian.ts @@ -3,7 +3,6 @@ import { isAnyArray } from 'is-any-array'; /** * Calculates the median of an array. - * * @param input - Array containing values * @returns - median */ diff --git a/src/x/xMedianAbsoluteDeviation.ts b/src/x/xMedianAbsoluteDeviation.ts index a5327be2..af1c8d11 100644 --- a/src/x/xMedianAbsoluteDeviation.ts +++ b/src/x/xMedianAbsoluteDeviation.ts @@ -7,6 +7,7 @@ export interface XMedianAbsoluteDeviationResult { * Median of the data */ median: number; + /** * Median absolute devication */ diff --git a/src/x/xMinIndex.ts b/src/x/xMinIndex.ts index b81523fd..84c80dec 100644 --- a/src/x/xMinIndex.ts +++ b/src/x/xMinIndex.ts @@ -5,7 +5,6 @@ import { xGetFromToIndex, XGetFromToIndexOptions } from './xGetFromToIndex'; /** * Computes the index of the minimum of the given values. - * * @param array - array of numbers * @param options - options * @returns - index diff --git a/src/x/xMinMaxDelta.ts b/src/x/xMinMaxDelta.ts index e2cbe18c..965c721b 100644 --- a/src/x/xMinMaxDelta.ts +++ b/src/x/xMinMaxDelta.ts @@ -4,7 +4,6 @@ import { xCheck } from './xCheck'; /** * Return min and max values of an array. - * * @param array - array of number * @returns - Object with 2 properties, min and max */ diff --git a/src/x/xMinMaxValues.ts b/src/x/xMinMaxValues.ts index 99759729..b150a1ad 100644 --- a/src/x/xMinMaxValues.ts +++ b/src/x/xMinMaxValues.ts @@ -4,7 +4,6 @@ import { xCheck } from './xCheck'; /** * Return min and max values of an array. - * * @param array - array of number * @returns - Object with 2 properties, min and max */ diff --git a/src/x/xMinValue.ts b/src/x/xMinValue.ts index 2b07ca7b..5256ae9e 100644 --- a/src/x/xMinValue.ts +++ b/src/x/xMinValue.ts @@ -5,7 +5,6 @@ import { xGetFromToIndex, XGetFromToIndexOptions } from './xGetFromToIndex'; /** * Computes the minimal value of an array of values. - * * @param array - array of numbers * @param options - options */ diff --git a/src/x/xMode.ts b/src/x/xMode.ts index 284470b2..c3f28a19 100644 --- a/src/x/xMode.ts +++ b/src/x/xMode.ts @@ -2,7 +2,6 @@ import { NumberArray } from 'cheminfo-types'; /** * Calculates the mode of an array - * * @param input - Array containing values * @returns - mode */ diff --git a/src/x/xMultiply.ts b/src/x/xMultiply.ts index 1b7f990b..e51f76fc 100644 --- a/src/x/xMultiply.ts +++ b/src/x/xMultiply.ts @@ -12,7 +12,6 @@ export interface XMultiplyOptions< /** * This function xMultiply the first array by the second array or a constant value to each element of the first array - * * @param array1 - first array * @param array2 - second array * @param options - options diff --git a/src/x/xNoiseSanPlot.ts b/src/x/xNoiseSanPlot.ts index 7e47301b..9433fb96 100644 --- a/src/x/xNoiseSanPlot.ts +++ b/src/x/xNoiseSanPlot.ts @@ -1,5 +1,3 @@ -/* eslint-disable max-lines-per-function */ - import { DataXY, FromTo, NumberArray } from 'cheminfo-types'; // @ts-expect-error Missing types. import SplineInterpolator from 'spline-interpolator'; @@ -8,37 +6,44 @@ import { createFromToArray } from '../utils'; import erfcinv from './utils/erfcinv'; import rayleighCdf from './utils/rayleighCdf'; +import { xCheck } from './xCheck'; export interface XNoiseSanPlotOptions { /** * boolean array to filter data, if the i-th element is true then the i-th element of the distribution will be ignored. */ mask?: NumberArray; + /** * percent of positive signal distribution where the noise level will be determined, if it is not defined the program calculate it. */ cutOff?: number; + /** * true the noise level will be recalculated get out the signals using factorStd. * @default true */ refine?: boolean; magnitudeMode?: boolean; + /** * factor to scale the data input[i]*=scaleFactor. * @default 1 */ scaleFactor?: number; + /** * factor times std to determine what will be marked as signals. * @default 5 */ factorStd?: number; + /** * If the baseline is correct, the midpoint of distribution should be zero. if true, the distribution will be centered. * @default true */ fixOffset?: boolean; + /** * log scale to apply in the intensity axis in order to avoid big numbers. * @default 2 @@ -58,7 +63,6 @@ export interface XNoiseSanPlotResult { /** * Determine noise level by san plot methodology (https://doi.org/10.1002/mrc.4882) - * * @param array - real or magnitude spectra data. * @param options - options * @returns noise level @@ -84,6 +88,8 @@ export function xNoiseSanPlot( input = new Float64Array(array); } + xCheck(input); + if (scaleFactor > 1) { for (let i = 0; i < input.length; i++) { input[i] *= scaleFactor; @@ -100,7 +106,9 @@ export function xNoiseSanPlot( } const firstNegativeValueIndex = - input[input.length - 1] >= 0 ? input.length : input.findIndex((e) => e < 0); + (input.at(-1) as number) >= 0 + ? input.length + : input.findIndex((e) => e < 0); let lastPositiveValueIndex = firstNegativeValueIndex - 1; for (let i = lastPositiveValueIndex; i >= 0; i--) { if (input[i] > 0) { @@ -199,7 +207,6 @@ export function xNoiseSanPlot( /** * DetermineCutOff. - * * @param signPositive - Array of numbers. * @param [options = {}] - Options. * @param [options.mask] - Boolean array to filter data, if the i-th element is true then the i-th element of the distribution will be ignored. @@ -278,31 +285,37 @@ interface SimpleNormInvOptions { * Boolean array to filter data, if the i-th element is true then the i-th element of the distribution will be ignored. */ mask?: NumberArray; + /** * Percent of positive signal distribution where the noise level will be determined, if it is not defined the program calculate it. */ cutOff?: number; + /** * If true the noise level will be recalculated get out the signals using factorStd. * @default true */ refine?: boolean; magnitudeMode?: boolean; + /** * Factor to scale the data input[i]*=scaleFactor. * @default 1 */ scaleFactor?: number; + /** * Factor times std to determine what will be marked as signals. * @default 5 */ factorStd?: number; + /** * If the baseline is correct, the midpoint of distribution should be zero. If true, the distribution will be centered. * @default true */ fixOffset?: boolean; + /** * Log scale to apply in the intensity axis in order to avoid big numbers. * @default 2 @@ -321,7 +334,6 @@ function simpleNormInvNumber( /** * SimpleNormInvs. - * * @param data - Data array. * @param options */ @@ -359,7 +371,6 @@ function simpleNormInv( /** * CreateArray. - * * @param from - From. * @param to - To. * @param step - Step. @@ -376,7 +387,6 @@ function createArray(from: number, to: number, step: number): number[] { /** * GenerateSanPlot. - * * @param array - Array. * @param [options = {}] - Options. * @param [options.mask] - Boolean array to filter data, if the i-th element is true then the i-th element of the distribution will be ignored. @@ -430,7 +440,6 @@ function generateSanPlot( /** * Scale. - * * @param array - Array. * @param [options = {}] - Options. * @param [options.mask] - Boolean array to filter data, if the i-th element is true then the i-th element of the distribution will be ignored. diff --git a/src/x/xNoiseStandardDeviation.ts b/src/x/xNoiseStandardDeviation.ts index 44e3a493..365a6870 100644 --- a/src/x/xNoiseStandardDeviation.ts +++ b/src/x/xNoiseStandardDeviation.ts @@ -7,10 +7,12 @@ export interface XNoiseStandardDeviationResult { * Median of the data */ median: number; + /** * Median absolute deviation */ mad: number; + /** * standard deviation of the noise */ diff --git a/src/x/xNorm.ts b/src/x/xNorm.ts index 02b9eb0f..349c6e5b 100644 --- a/src/x/xNorm.ts +++ b/src/x/xNorm.ts @@ -2,7 +2,6 @@ import { NumberArray } from 'cheminfo-types'; /** * This function calculate the norm of a vector. - * * @example xNorm([3, 4]) -> 5 * @param array - array * @returns - calculated norm diff --git a/src/x/xNormed.ts b/src/x/xNormed.ts index bd4afb55..655b0d0e 100644 --- a/src/x/xNormed.ts +++ b/src/x/xNormed.ts @@ -6,14 +6,18 @@ import { xMaxValue } from './xMaxValue'; import { xSum } from './xSum'; export interface XNormedOptions { - /** algorithm can be 'sum' 'max' or 'absolute' + /** + * algorithm can be 'sum' 'max' or 'absolute' * @default 'absolute' */ algorithm?: 'absolute' | 'max' | 'sum'; - /** max or sum value + + /** + * max or sum value * @default 1 */ value?: number; + /** output into which the result should be placed if needed */ output?: ArrayType; } diff --git a/src/x/xPadding.ts b/src/x/xPadding.ts index 62ad7bf1..ce9fd5e2 100644 --- a/src/x/xPadding.ts +++ b/src/x/xPadding.ts @@ -9,6 +9,7 @@ export interface XPaddingOptions { * @default 0 */ size?: number; + /** * value to use for padding (if algorithm='value') * @default 0 @@ -29,7 +30,6 @@ export function xPadding( ): Float64Array { const { size = 0, value = 0, algorithm } = options; xCheck(array); - if (!algorithm) { return xEnsureFloat64(array); } @@ -57,7 +57,7 @@ export function xPadding( result[i] = array[0]; } for (let i = fromEnd; i < toEnd; i++) { - result[i] = array[array.length - 1]; + result[i] = array.at(-1) as number; } break; case 'circular': diff --git a/src/x/xParetoNormalization.ts b/src/x/xParetoNormalization.ts index d2c1a8fd..5517c7c8 100644 --- a/src/x/xParetoNormalization.ts +++ b/src/x/xParetoNormalization.ts @@ -7,7 +7,6 @@ import { xStandardDeviation } from './xStandardDeviation'; * Pareto scaling, which uses the square root of standard deviation as the scaling factor, circumvents the amplification of noise by retaining a small portion of magnitude information. * Noda, I. (2008). Scaling techniques to enhance two-dimensional correlation spectra. Journal of Molecular Structure, 883, 216-227. * DOI: 10.1016/j.molstruc.2007.12.026 - * * @param array - array of number */ export function xParetoNormalization(array: NumberArray): Float64Array { diff --git a/src/x/xRescale.ts b/src/x/xRescale.ts index 23b8917b..49646867 100644 --- a/src/x/xRescale.ts +++ b/src/x/xRescale.ts @@ -8,11 +8,13 @@ import { xMinValue } from './xMinValue'; export interface XRescaleOptions { /** output into which to placed the data */ output?: ArrayType; + /** * min used for the scaling * @default 0 */ min?: number; + /** * max used for the scaling * @default 1 @@ -22,7 +24,6 @@ export interface XRescaleOptions { /** * Function used to rescale data - * * @param input - input for the rescale * @param options - options * @returns rescaled data diff --git a/src/x/xRolling.ts b/src/x/xRolling.ts index fdd4d046..8dbc06e6 100644 --- a/src/x/xRolling.ts +++ b/src/x/xRolling.ts @@ -9,6 +9,7 @@ export interface XRollingOptions { * @default 5 */ window?: number; + /** * padding */ @@ -17,7 +18,6 @@ export interface XRollingOptions { /** * This function calculates a rolling average - * * @param array - array * @param fct - callback function that from an array returns a value * @param options - options diff --git a/src/x/xRollingAverage.ts b/src/x/xRollingAverage.ts index 47f980ea..8d39db4f 100644 --- a/src/x/xRollingAverage.ts +++ b/src/x/xRollingAverage.ts @@ -5,7 +5,6 @@ import { xRolling, XRollingOptions } from './xRolling'; /** * This function calculates a rolling average - * * @param array - array * @param options - option */ diff --git a/src/x/xRollingMax.ts b/src/x/xRollingMax.ts index d2e09a8b..b1718f67 100644 --- a/src/x/xRollingMax.ts +++ b/src/x/xRollingMax.ts @@ -5,7 +5,6 @@ import { xRolling, XRollingOptions } from './xRolling'; /** * This function calculates a maximum within a rolling window - * * @param array - array * @param options - options */ diff --git a/src/x/xRollingMedian.ts b/src/x/xRollingMedian.ts index 83d15e43..e95404c4 100644 --- a/src/x/xRollingMedian.ts +++ b/src/x/xRollingMedian.ts @@ -5,7 +5,6 @@ import { xRolling, XRollingOptions } from './xRolling'; /** * This function calculates a rolling average - * * @param array - array * @param options - options */ diff --git a/src/x/xRollingMin.ts b/src/x/xRollingMin.ts index 1b80b731..4886cc63 100644 --- a/src/x/xRollingMin.ts +++ b/src/x/xRollingMin.ts @@ -5,7 +5,6 @@ import { xRolling, XRollingOptions } from './xRolling'; /** * This function calculates a minimum within a rolling window - * * @param array - array * @param options - options */ diff --git a/src/x/xRotate.ts b/src/x/xRotate.ts index 194c1c26..09f603c0 100644 --- a/src/x/xRotate.ts +++ b/src/x/xRotate.ts @@ -3,7 +3,6 @@ import { NumberArray } from 'cheminfo-types'; /** * This function performs a circular shift to an array. * Positive values of shifts will shift to the right and negative values will do to the left. - * * @example xRotate([1,2,3,4],1) -> [4,1,2,3] * @example xRotate([1,2,3,4],-1) -> [2,3,4,1] * @param array - array diff --git a/src/x/xSampling.ts b/src/x/xSampling.ts index eb17640a..4a706ad7 100644 --- a/src/x/xSampling.ts +++ b/src/x/xSampling.ts @@ -5,7 +5,8 @@ import { xCheck } from './xCheck'; export interface XSamplingOptions { /** * number of points to sample within the array - * @default 10 */ + * @default 10 + */ length?: number; } @@ -13,7 +14,7 @@ export interface XSamplingOptions { * Sample within the array * @param array - array from which to sample * @param options - options - * @return - array with evenly spaced elements + * @returns - array with evenly spaced elements * @link https://en.wikipedia.org/wiki/Sampling_(signal_processing) */ export function xSampling( @@ -35,7 +36,7 @@ export function xSampling( * Downsample within the array * @param array - array from which to sample * @param length - * @return - array with evenly spaced elements + * @returns - array with evenly spaced elements * @link https://en.wikipedia.org/wiki/Downsampling_(signal_processing) */ function downSampling(array: NumberArray, length: number): Float64Array { diff --git a/src/x/xSortAscending.ts b/src/x/xSortAscending.ts index 8f8087e1..4fe1b66d 100644 --- a/src/x/xSortAscending.ts +++ b/src/x/xSortAscending.ts @@ -3,7 +3,6 @@ import { NumberArray } from 'cheminfo-types'; /** * Function that sorts arrays or Float64Arrays in ascending order in place ! * This method is optimized for typed arrays. - * * @param array - array to sort * @returns sorted array */ diff --git a/src/x/xSortDescending.ts b/src/x/xSortDescending.ts index 54d769f9..efecc627 100644 --- a/src/x/xSortDescending.ts +++ b/src/x/xSortDescending.ts @@ -1,7 +1,7 @@ import { NumberArray } from 'cheminfo-types'; -/** Function that sorts arrays or Float64Arrays in descending order - * +/** + * Function that sorts arrays or Float64Arrays in descending order * @param array - array to sort * @returns sorted array */ diff --git a/src/x/xStandardDeviation.ts b/src/x/xStandardDeviation.ts index 6c034f53..59786c3c 100644 --- a/src/x/xStandardDeviation.ts +++ b/src/x/xStandardDeviation.ts @@ -2,8 +2,8 @@ import { NumberArray } from 'cheminfo-types'; import { xVariance, XVarianceOptions } from './xVariance'; -/** Finds the standard deviation for the data at hand - * +/** + * Finds the standard deviation for the data at hand * @param values - values in the data * @param options - options * @returns standard deviation diff --git a/src/x/xSubtract.ts b/src/x/xSubtract.ts index fa0c9cdd..339a5145 100644 --- a/src/x/xSubtract.ts +++ b/src/x/xSubtract.ts @@ -3,7 +3,6 @@ import { isAnyArray } from 'is-any-array'; /** * This function xSubtract the first array by the second array or a constant value from each element of the first array - * * @param array1 - the array that will be rotated * @param array2 - second array or number * @returns array after subtraction diff --git a/src/x/xSum.ts b/src/x/xSum.ts index 7584ada0..4c541a91 100644 --- a/src/x/xSum.ts +++ b/src/x/xSum.ts @@ -5,7 +5,6 @@ import { xGetFromToIndex, XGetFromToIndexOptions } from './xGetFromToIndex'; /** * Calculate the sum of the values - * * @param array - Object that contains property x (an ordered increasing array) and y (an array). * @param options - Options. * @returns XSum value on the specified range. diff --git a/src/x/xUniqueSorted.ts b/src/x/xUniqueSorted.ts index e1ef3e98..eca6ad64 100644 --- a/src/x/xUniqueSorted.ts +++ b/src/x/xUniqueSorted.ts @@ -2,7 +2,6 @@ import { NumberArray } from 'cheminfo-types'; /** * XUniqueSorted. - * * @param array - array of numbers * @returns - sorted array */ diff --git a/src/x/xVariance.ts b/src/x/xVariance.ts index a92c275e..164ba196 100644 --- a/src/x/xVariance.ts +++ b/src/x/xVariance.ts @@ -4,18 +4,21 @@ import { isAnyArray } from 'is-any-array'; import { xMean } from './xMean'; export interface XVarianceOptions { - /** Unbiased option + /** + * Unbiased option * @default true */ unbiased?: boolean; - /** Mean of the data + + /** + * Mean of the data * @default mean calculated */ mean?: number; } -/** Finds the variance of the data - * +/** + * Finds the variance of the data * @param values - the values of the array * @param options - options * @returns variance diff --git a/src/xreim/xreimSortX.ts b/src/xreim/xreimSortX.ts index 6e7141e3..0a0c85ea 100644 --- a/src/xreim/xreimSortX.ts +++ b/src/xreim/xreimSortX.ts @@ -4,7 +4,6 @@ import { DataXReIm } from '../types'; /** * Sort object of array, x has to be monotone. - * * @param data - object of kind {x:[], re:[], im:[]} * @returns - sorted array */ diff --git a/src/xreim/xreimZeroFilling.ts b/src/xreim/xreimZeroFilling.ts index ea83bd91..7dc1e7f1 100644 --- a/src/xreim/xreimZeroFilling.ts +++ b/src/xreim/xreimZeroFilling.ts @@ -2,7 +2,6 @@ import { DataXReIm } from '../types'; /** * This function make a zero filling to re and im part. - * * @param data - object of kind {x:[], re:[], im:[]} * @param totalLength - final number of points * @returns - data. @@ -35,7 +34,7 @@ export function xreimZeroFilling( newRE[i] = re[i]; newIM[i] = im[i]; } - const deltaX = (x[x.length - 1] - x[0]) / (length - 1); + const deltaX = ((x.at(-1) as number) - x[0]) / (length - 1); for (let i = length; i < totalLength; i++) { newX[i] = newX[i - 1] + deltaX; } diff --git a/src/xy/__tests__/xyEquallySpaced.test.ts b/src/xy/__tests__/xyEquallySpaced.test.ts index 610a29c3..99385574 100644 --- a/src/xy/__tests__/xyEquallySpaced.test.ts +++ b/src/xy/__tests__/xyEquallySpaced.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 { expect, test } from 'vitest'; diff --git a/src/xy/__tests__/xyMedian.test.ts b/src/xy/__tests__/xyMedian.test.ts index 49893714..e28aedea 100644 --- a/src/xy/__tests__/xyMedian.test.ts +++ b/src/xy/__tests__/xyMedian.test.ts @@ -55,5 +55,5 @@ test('empty property x, should return NaN', () => { x: [], y: [], }; - expect(xyMedian(data)).toBe(NaN); + expect(xyMedian(data)).toBe(Number.NaN); }); diff --git a/src/xy/utils/equallySpacedSlot.ts b/src/xy/utils/equallySpacedSlot.ts index ec801970..58c47627 100644 --- a/src/xy/utils/equallySpacedSlot.ts +++ b/src/xy/utils/equallySpacedSlot.ts @@ -1,32 +1,37 @@ -/* eslint-disable max-lines-per-function */ - /** * Function that retrieves the getEquallySpacedData with the variant "slot". - * * @param x * @param y * @param from * @param to * @param numberOfPoints - * @return Array of y's equally spaced with the variant "slot" + * @returns Array of y's equally spaced with the variant "slot" */ export default function equallySpacedSlot( /** x coordinates */ x: number[], + /** y coordinates */ y: number[], + /** from value */ from: number, + /** to value */ to: number, + /** number of points */ numberOfPoints: number, ): Float64Array { const xLength = x.length; + if (xLength < 2) { + return Float64Array.from(x); + } + const step = (to - from) / (numberOfPoints > 1 ? numberOfPoints - 1 : 1); const halfStep = step / 2; - const lastStep = x[x.length - 1] - x[x.length - 2]; + const lastStep = (x.at(-1) as number) - (x.at(-2) as number); const start = from - halfStep; // Changed Array to Float64Array diff --git a/src/xy/utils/equallySpacedSmooth.ts b/src/xy/utils/equallySpacedSmooth.ts index 660ced29..c8794589 100644 --- a/src/xy/utils/equallySpacedSmooth.ts +++ b/src/xy/utils/equallySpacedSmooth.ts @@ -2,23 +2,26 @@ import integral from './integral'; /** * Function that retrieves the getEquallySpacedData with the variant "smooth". - * * @param x * @param y * @param from * @param to * @param numberOfPoints - * @return - Array of y's equally spaced with the variant "smooth" + * @returns - Array of y's equally spaced with the variant "smooth" */ export default function equallySpacedSmooth( /** x coordinates */ x: number[], + /** y coordinates */ y: number[], + /** from value */ from: number, + /** to value */ to: number, + /** number of points */ numberOfPoints: number, ): Float64Array { diff --git a/src/xy/utils/integral.ts b/src/xy/utils/integral.ts index 7fd42175..538583a4 100644 --- a/src/xy/utils/integral.ts +++ b/src/xy/utils/integral.ts @@ -5,15 +5,18 @@ * @param x1 * @param slope * @param intercept - * @return integral value. + * @returns integral value. */ export default function integral( /** first coordinate of point */ x0: number, + /** second coordinate of point */ x1: number, + /** slope of the line */ slope: number, + /** intercept of the line on the y axis */ intercept: number, ): number { diff --git a/src/xy/xyAlign.ts b/src/xy/xyAlign.ts index 3be9c04f..250306e7 100644 --- a/src/xy/xyAlign.ts +++ b/src/xy/xyAlign.ts @@ -1,5 +1,3 @@ -/* eslint-disable max-lines-per-function */ - import { DataXY } from 'cheminfo-types'; export interface XYAlignOptions { @@ -8,15 +6,17 @@ export interface XYAlignOptions { * @default 1 */ delta?: ((arg: number) => number) | number; + /** * If `true`, only the data considered as common to both spectra is kept. If `false`, the data y arrays are completed with zeroes where no common values are found * @default true */ common?: boolean; + /** * Defines what x values should be kept (`x1` : spectrum 1 x values, `x2` spectrum 2 x values, `weighted`: weighted average of both spectra x values) * @default "x1" - * */ + */ x?: 'x1' | 'x2' | 'weighted'; } @@ -30,7 +30,6 @@ export interface XYAlignResult { * Align data of two spectra by verifying wether x values are in a certain range (`delta`). * The two spectra should not have two consecutive x values which difference is * smaller than `delta` to achieve good results! - * * @param data1 - First spectrum data * @param data2 - Second spectrum data * @param options - Options diff --git a/src/xy/xyCheck.ts b/src/xy/xyCheck.ts index 089ee2ea..3bf34dc8 100644 --- a/src/xy/xyCheck.ts +++ b/src/xy/xyCheck.ts @@ -3,9 +3,9 @@ import { isAnyArray, AnyArray } from 'is-any-array'; /** * Verify that `data` is an object of x,y arrays. * Throws an error if it's not. - * * @param data * @param options + * @param options.minLength */ export function xyCheck( data: unknown, diff --git a/src/xy/xyCovariance.ts b/src/xy/xyCovariance.ts index 4683bf7d..97d85a7d 100644 --- a/src/xy/xyCovariance.ts +++ b/src/xy/xyCovariance.ts @@ -3,7 +3,8 @@ import { DataXY } from 'cheminfo-types'; import { xMean } from '../x'; export interface XYCovarianceOptions { - /** if true, divide by (n-1); if false, divide by n + /** + * if true, divide by (n-1); if false, divide by n * @default true */ unbiased?: boolean; @@ -11,10 +12,9 @@ export interface XYCovarianceOptions { /** * Finds the covariance of the points. - * * @param data * @param options - * @return the covariance + * @returns the covariance */ export function xyCovariance( data: DataXY, diff --git a/src/xy/xyCumulativeDistributionStatistics.ts b/src/xy/xyCumulativeDistributionStatistics.ts index 551a098d..34664d44 100644 --- a/src/xy/xyCumulativeDistributionStatistics.ts +++ b/src/xy/xyCumulativeDistributionStatistics.ts @@ -17,19 +17,16 @@ export interface XYCumulativeDistributionStatisticsResult { xMean: number; } -/** Cumulative Distribution Statistics - * +/** + * Cumulative Distribution Statistics * @param data - array of points {x,y} * @returns x0, x25, x50, x75, x100, xMode, xMean (x for maxY) */ export function xyCumulativeDistributionStatistics( data: DataXY, ): XYCumulativeDistributionStatisticsResult { - xyCheck(data); + xyCheck(data, { minLength: 1 }); const { x, y } = data; - if (x.length === 0) { - throw new Error('array length must be greater than 0'); - } const cumulativeSum = xCumulative(y); const maxY = xMaxValue(cumulativeSum); for (let i = 0; i < cumulativeSum.length; i++) { @@ -48,7 +45,7 @@ export function xyCumulativeDistributionStatistics( // need to find the x values closest to STEPS/100 result.x0 = x[0]; - result.x100 = x[x.length - 1]; + result.x100 = x.at(-1) as number; let currentStep = 0; breakPoint: for (let i = 1; i < cumulativeSum.length; i++) { diff --git a/src/xy/xyEnsureGrowingX.ts b/src/xy/xyEnsureGrowingX.ts index fb5bab4f..4bbbb777 100644 --- a/src/xy/xyEnsureGrowingX.ts +++ b/src/xy/xyEnsureGrowingX.ts @@ -6,7 +6,6 @@ import { xyCheck } from './xyCheck'; /** * Filters x,y values to allow strictly growing values in x-axis. - * * @param data - Object that contains property x (an ordered increasing array) and y (an array). */ export function xyEnsureGrowingX(data: DataXY): DataXY { diff --git a/src/xy/xyEquallySpaced.ts b/src/xy/xyEquallySpaced.ts index 6da4ace9..e64e76bd 100644 --- a/src/xy/xyEquallySpaced.ts +++ b/src/xy/xyEquallySpaced.ts @@ -8,27 +8,38 @@ import equallySpacedSmooth from './utils/equallySpacedSmooth'; import { xyCheck } from './xyCheck'; export interface XYEquallySpacedOptions { - /** from + /** + * from * @default x[0] */ from?: number; - /** to + + /** + * to * @default x[x.length-1] */ to?: number; - /** variant + + /** + * variant * @default 'smooth' */ variant?: 'slot' | 'smooth'; - /** number of points + + /** + * number of points * @default 100 */ numberOfPoints?: number; - /** array of from / to that should be skipped for the generation of the points + + /** + * array of from / to that should be skipped for the generation of the points * @default [] */ exclusions?: FromTo[]; - /** array of from / to that should be kept + + /** + * array of from / to that should be kept * @default [] */ zones?: FromTo[]; @@ -51,10 +62,9 @@ export interface XYEquallySpacedOptions { * of the slot and divide by the step size between two points in an array. * * If exclusions zone are present, zones are ignored ! - * * @param data - object containing 2 properties x and y * @param options - options - * @return new object with x / y array with the equally spaced data. + * @returns new object with x / y array with the equally spaced data. */ export function xyEquallySpaced( diff --git a/src/xy/xyExtract.ts b/src/xy/xyExtract.ts index ac7da488..a35da9e6 100644 --- a/src/xy/xyExtract.ts +++ b/src/xy/xyExtract.ts @@ -10,7 +10,6 @@ export interface XYExtractOptions { /** * Extract zones from a XY data. - * * @param data - Object that contains property x (an ordered increasing array) and y (an array) * @param options - options * @returns - Array of points @@ -26,8 +25,8 @@ export function xyExtract( zones = zonesNormalize(zones); if ( - typeof x === 'undefined' || - typeof y === 'undefined' || + x === undefined || + y === undefined || !Array.isArray(zones) || zones.length === 0 ) { diff --git a/src/xy/xyFilter.ts b/src/xy/xyFilter.ts index 81388f7d..ed218aca 100644 --- a/src/xy/xyFilter.ts +++ b/src/xy/xyFilter.ts @@ -1,17 +1,18 @@ import { DataXY } from 'cheminfo-types'; export interface XYFilterOptions { - /** callback + /** + * callback * @default ()=>true */ filter?: (x: number, y: number) => boolean; } -/** Filter an array x/y based on various criteria x points are expected to be sorted - * +/** + * Filter an array x/y based on various criteria x points are expected to be sorted * @param data - object containing 2 properties x and y * @param options - options - * @return filtered array + * @returns filtered array */ export function xyFilter( data: DataXY, diff --git a/src/xy/xyFilterMinYValue.ts b/src/xy/xyFilterMinYValue.ts index 8de4b9e9..51c2eccf 100644 --- a/src/xy/xyFilterMinYValue.ts +++ b/src/xy/xyFilterMinYValue.ts @@ -2,14 +2,14 @@ import { DataXY } from 'cheminfo-types'; import { xMinMaxValues } from '../x'; -/** Filter an array x/y based on various criteria x points are expected to be sorted - * +/** + * Filter an array x/y based on various criteria x points are expected to be sorted * @param data - object containing 2 properties x and y * @param minRelativeYValue - the minimum relative value compare to the Y max value - * @return filtered data + * @returns filtered data */ export function xyFilterMinYValue(data: DataXY, minRelativeYValue?: number) { - if (typeof minRelativeYValue === 'undefined') return data; + if (minRelativeYValue === undefined) return data; const { x, y } = data; diff --git a/src/xy/xyFilterTopYValues.ts b/src/xy/xyFilterTopYValues.ts index 5e6cc545..12c8a511 100644 --- a/src/xy/xyFilterTopYValues.ts +++ b/src/xy/xyFilterTopYValues.ts @@ -4,13 +4,12 @@ import { xSortDescending } from '../x'; /** * Filter an array x/y based on various criteria x points are expected to be sorted - * * @param data - object containing 2 properties x and y * @param nbPeaks - * @return filtered data + * @returns filtered data */ export function xyFilterTopYValues(data: DataXY, nbPeaks?: number) { - if (typeof nbPeaks === 'undefined') return data; + if (nbPeaks === undefined) return data; if (nbPeaks > data.x.length) return data; const { x, y } = data; diff --git a/src/xy/xyFilterX.ts b/src/xy/xyFilterX.ts index a3641fc6..6e690ad2 100644 --- a/src/xy/xyFilterX.ts +++ b/src/xy/xyFilterX.ts @@ -3,38 +3,51 @@ import { DataXY, FromTo } from 'cheminfo-types'; import { zonesNormalize } from '../zones'; export interface XYFilterXOptions { - /** filter from + /** + * filter from * @default x[0] */ from?: number; - /** filter to + + /** + * filter to * @default x[x.length - 1] */ to?: number; - /** zones to exclude, contains {from, to} pairs + + /** + * zones to exclude, contains {from, to} pairs * @default [] */ exclusions?: FromTo[]; - /** zones to keep + + /** + * zones to keep * @default [{from,to}] */ zones?: FromTo[]; } -/** Filter an array x/y based on various criteria x points are expected to be sorted - * +/** + * Filter an array x/y based on various criteria x points are expected to be sorted * @param data - object containing 2 properties x and y * @param options - options - * @return filtered array + * @returns filtered array */ export function xyFilterX( data: DataXY, options: XYFilterXOptions = {}, ): DataXY { const { x, y } = data; + if (x.length === 0) { + return { + x: Array.from(x), + y: Array.from(y), + }; + } const { from = x[0], - to = x[x.length - 1], + to = x.at(-1) as number, zones = [{ from, to }], exclusions = [], } = options; diff --git a/src/xy/xyFilterXPositive.ts b/src/xy/xyFilterXPositive.ts index 6d9292c9..d80ce0b0 100644 --- a/src/xy/xyFilterXPositive.ts +++ b/src/xy/xyFilterXPositive.ts @@ -1,9 +1,9 @@ import { DataXY } from 'cheminfo-types'; import { xyCheck } from './xyCheck'; + /** * Filter out all the points for which x <= 0. Useful to display log scale data - * * @param data - data * @returns - An object with the filtered data */ @@ -12,7 +12,7 @@ export function xyFilterXPositive(data: DataXY): DataXY { const { x, y } = data; const newX: number[] = []; const newY: number[] = []; - if (typeof x === 'undefined' || typeof y === 'undefined') { + if (x === undefined || y === undefined) { return { x: newX, y: newY }; } for (let i = 0; i < x.length; i++) { diff --git a/src/xy/xyFindClosestPoint.ts b/src/xy/xyFindClosestPoint.ts index ebc807b3..1d596992 100644 --- a/src/xy/xyFindClosestPoint.ts +++ b/src/xy/xyFindClosestPoint.ts @@ -4,7 +4,6 @@ import { xFindClosestIndex } from '../x'; /** * Finds the closest point - * * @param data - x array should be sorted and ascending * @param target - target to search * @returns - closest point diff --git a/src/xy/xyGetNMaxY.ts b/src/xy/xyGetNMaxY.ts index 08b3b440..bced6514 100644 --- a/src/xy/xyGetNMaxY.ts +++ b/src/xy/xyGetNMaxY.ts @@ -4,7 +4,6 @@ import { xyCheck } from './xyCheck'; /** * Returns the numberMaxPoints points with the bigger y. - * * @param data - Object that contains property x (an ordered increasing array) and y (an array) * @param numberMaxPoints - Number of points to keep * @returns - The points filtered to keep the `numberMaxPoints` most intense points of the input. diff --git a/src/xy/xyGrowingX.ts b/src/xy/xyGrowingX.ts index acb6a4c3..4dd35ecf 100644 --- a/src/xy/xyGrowingX.ts +++ b/src/xy/xyGrowingX.ts @@ -2,7 +2,6 @@ import { DataXY } from 'cheminfo-types'; /** * Order object of array, x has to be monotone. Ensure x is growing - * * @param data - Object of kind {x:[], y:[]}. */ export function xyGrowingX(data: DataXY): DataXY { diff --git a/src/xy/xyIntegral.ts b/src/xy/xyIntegral.ts index 1cfeb9e5..4520fb21 100644 --- a/src/xy/xyIntegral.ts +++ b/src/xy/xyIntegral.ts @@ -9,13 +9,12 @@ export interface XYIntegralOptions extends XYIntegrationOptions { /** * Integrate from the larger value to the smallest value * @default false - * */ + */ reverse?: boolean; } /** * Generate a X / Y of the xyIntegral - * * @param data - Object that contains property x (an ordered increasing array) and y (an array) * @param options - Options * @returns - An object with the xyIntegration function diff --git a/src/xy/xyIntegration.ts b/src/xy/xyIntegration.ts index aa8e2ef3..448cf59c 100644 --- a/src/xy/xyIntegration.ts +++ b/src/xy/xyIntegration.ts @@ -9,16 +9,19 @@ export interface XYIntegrationOptions { * First value for xyIntegration in the X scale */ from?: number; + /** * First point for xyIntegration * @default 0 - * */ + */ fromIndex?: number; + /** * Last point for xyIntegration * @default x.length-1 - * */ + */ toIndex?: number; + /** * Last value for xyIntegration in the X scale */ @@ -27,7 +30,6 @@ export interface XYIntegrationOptions { /** * Calculate integration - * * @param data - Object that contains property x (an ordered increasing array) and y (an array) * @param options - Options * @returns - xyIntegration value on the specified range diff --git a/src/xy/xyJoinX.ts b/src/xy/xyJoinX.ts index 16e21a31..b0c9ebbe 100644 --- a/src/xy/xyJoinX.ts +++ b/src/xy/xyJoinX.ts @@ -13,7 +13,6 @@ export interface XYJoinXOptions { /** * Join x / y values when difference in X is closer than delta. * When joining, y values are summed and x values are weighted average - * * @param data - Object that contains property x (an ordered increasing array) and y (an array) * @param options - Options * @returns - An object with the xyIntegration function diff --git a/src/xy/xyMassCenter.ts b/src/xy/xyMassCenter.ts index 7d56b701..e4a0dee4 100644 --- a/src/xy/xyMassCenter.ts +++ b/src/xy/xyMassCenter.ts @@ -6,7 +6,6 @@ import { xyCheck } from '.'; /** * Computes the weighted mean value of an array of values. - * * @param data - array of DataXY * @param options - options */ diff --git a/src/xy/xyMassCenterVector.ts b/src/xy/xyMassCenterVector.ts index 455b8009..575f7d3b 100644 --- a/src/xy/xyMassCenterVector.ts +++ b/src/xy/xyMassCenterVector.ts @@ -12,7 +12,6 @@ export interface XYMassCenterVectorOptions { * We will calculate a vector containing center of mass of DataXY as well as center of mass of both parts, etc. * This approach allows to efficiently represent spectra like XPS, NMR, etc. It should provide an extremely efficient * way to store and search similar spectra. - * * @param data - Object that contains property x (an ordered increasing array) and y (an array) * @param options * @returns - Array of centers of mass @@ -95,10 +94,11 @@ function getWeightedIntegral(data: DataXY) { weightedIntegral[i] = totalWeightedIntegral; } // the last point, no points after - const lastIntegration = (x[x.length - 1] - x[x.length - 2]) * y[y.length - 1]; + const lastIntegration = + ((x.at(-1) as number) - (x.at(-2) as number)) * (y.at(-1) as number); totalIntegration += lastIntegration; integral[x.length - 1] = totalIntegration; - totalWeightedIntegral += lastIntegration * x[x.length - 1]; + totalWeightedIntegral += lastIntegration * (x.at(-1) as number); weightedIntegral[x.length - 1] = totalWeightedIntegral; return { integral, weightedIntegral }; } diff --git a/src/xy/xyMaxClosestYPoint.ts b/src/xy/xyMaxClosestYPoint.ts index 93498900..fcd7c774 100644 --- a/src/xy/xyMaxClosestYPoint.ts +++ b/src/xy/xyMaxClosestYPoint.ts @@ -13,7 +13,6 @@ export interface XYMaxClosestYPointOptions { /** * Find the closest maximum going up hill - * * @param data - Object that contains property x (an ordered increasing array) and y (an array) * @param options - options * @returns - An object with the x/y value @@ -28,8 +27,8 @@ export function xyMaxClosestYPoint( const { target } = options; let { targetIndex } = options; - if (typeof targetIndex === 'undefined') { - if (typeof target !== 'undefined') { + if (targetIndex === undefined) { + if (target !== undefined) { targetIndex = xFindClosestIndex(x, target); } else { targetIndex = 0; diff --git a/src/xy/xyMaxMerge.ts b/src/xy/xyMaxMerge.ts index a58a9822..f7729172 100644 --- a/src/xy/xyMaxMerge.ts +++ b/src/xy/xyMaxMerge.ts @@ -10,10 +10,9 @@ interface XYMaxMergeOptions { /** * Merge abscissas values on similar ordinates and weight the group of abscissas - * * @param data - object containing 2 properties x and y * @param options - options - * @return array of merged and weighted points + * @returns array of merged and weighted points */ export function xyMaxMerge( data: DataXY, diff --git a/src/xy/xyMaxY.ts b/src/xy/xyMaxY.ts index bc4be692..7c0a680d 100644 --- a/src/xy/xyMaxY.ts +++ b/src/xy/xyMaxY.ts @@ -9,16 +9,19 @@ export interface XYMaxYOptions { * First value for xyMaxY in the X scale */ from?: number; + /** * First point for xyMaxY * @default 0 - * */ + */ fromIndex?: number; + /** * Last point for xyMaxY * @default x.length-1 - * */ + */ toIndex?: number; + /** * Last value for xyMaxY in the X scale */ @@ -27,7 +30,6 @@ export interface XYMaxYOptions { /** * Finds the max value in a zone - * * @param data - Object that contains property x (an ordered increasing array) and y (an array) * @param options - Options * @returns - Max y on the specified range diff --git a/src/xy/xyMaxYPoint.ts b/src/xy/xyMaxYPoint.ts index 3f71cc77..b744ae4a 100644 --- a/src/xy/xyMaxYPoint.ts +++ b/src/xy/xyMaxYPoint.ts @@ -10,16 +10,19 @@ export interface XYMaxYPointOptions { * First value for xyMaxYPoint in the X scale */ from?: number; + /** * First point for xyMaxYPoint * @default 0 - * */ + */ fromIndex?: number; + /** * Last point for xyMaxYPoint * @default x.length-1 - * */ + */ toIndex?: number; + /** * Last value for xyMaxYPoint in the X scale */ @@ -28,9 +31,8 @@ export interface XYMaxYPointOptions { /** * Finds the max y value in a range and return a {x,y} point - * * @param data - Object that contains property x (an ordered increasing array) and y (an array) - * @param options Options + * @param options - Options */ export function xyMaxYPoint( data: DataXY, diff --git a/src/xy/xyMaximaY.ts b/src/xy/xyMaximaY.ts index 8e19d5ef..99255f73 100644 --- a/src/xy/xyMaximaY.ts +++ b/src/xy/xyMaximaY.ts @@ -9,7 +9,6 @@ import { xyCheck } from './xyCheck'; * Finds all the max values * If the values are equal the middle * of the equal part will be the position of the signal! - * * @param data - Object that contains property x (an ordered increasing array) and y (an array) * @param options - Object with from and to properties * @returns - Array of points diff --git a/src/xy/xyMedian.ts b/src/xy/xyMedian.ts index 836b2c91..b6eb9e60 100644 --- a/src/xy/xyMedian.ts +++ b/src/xy/xyMedian.ts @@ -2,7 +2,6 @@ import { DataXY } from 'cheminfo-types'; /** * Finds the median x value for an object with properties x and y (arrays of the same length) - * * @param data - x should be sorted in increasing order * @returns - the median of x values */ diff --git a/src/xy/xyMergeByCentroids.ts b/src/xy/xyMergeByCentroids.ts index b54dcccb..fe2c4e96 100644 --- a/src/xy/xyMergeByCentroids.ts +++ b/src/xy/xyMergeByCentroids.ts @@ -1,7 +1,8 @@ import { DataXY } from 'cheminfo-types'; export interface XYMergeByCentroidsOptions { - /** window size, has to be a positive number + /** + * window size, has to be a positive number * @default 0.01 */ window?: number; @@ -9,11 +10,10 @@ export interface XYMergeByCentroidsOptions { /** * Merge abscissa values if the ordinate value is in a list of centroids - * * @param data - object containing 2 properties x and y * @param centroids - centroids * @param options - options - * @return merged points + * @returns merged points */ export function xyMergeByCentroids( data: DataXY, diff --git a/src/xy/xyMinClosestYPoint.ts b/src/xy/xyMinClosestYPoint.ts index 4d1df8a8..631e7999 100644 --- a/src/xy/xyMinClosestYPoint.ts +++ b/src/xy/xyMinClosestYPoint.ts @@ -13,7 +13,6 @@ export interface XYMinClosestYPointOptions { /** * Find the closest minimum going down hill - * * @param data - Object that contains property x (an ordered increasing array) and y (an array) * @param options - Options * @returns - An object with the x/y value @@ -28,8 +27,8 @@ export function xyMinClosestYPoint( const { target } = options; let { targetIndex } = options; - if (typeof targetIndex === 'undefined') { - if (typeof target !== 'undefined') { + if (targetIndex === undefined) { + if (target !== undefined) { targetIndex = xFindClosestIndex(x, target); } else { targetIndex = 0; diff --git a/src/xy/xyMinYPoint.ts b/src/xy/xyMinYPoint.ts index c6a3c9b4..cba1803f 100644 --- a/src/xy/xyMinYPoint.ts +++ b/src/xy/xyMinYPoint.ts @@ -10,16 +10,19 @@ export interface XYMinYPointOptions { * First value for xyMinYPoint in the X scale */ from?: number; + /** * First point for xyMinYPoint * @default 0 - * */ + */ fromIndex?: number; + /** * Last point for xyMinYPoint * @default x.length-1 - * */ + */ toIndex?: number; + /** * Last value for xyMinYPoint in the X scale */ @@ -28,7 +31,6 @@ export interface XYMinYPointOptions { /** * Finds the min y value in a range and return a {x,y} point - * * @param data - Object that contains property x (an ordered increasing array) and y (an array) * @param options - Options */ diff --git a/src/xy/xyMinimaY.ts b/src/xy/xyMinimaY.ts index cdebc446..598fdda9 100644 --- a/src/xy/xyMinimaY.ts +++ b/src/xy/xyMinimaY.ts @@ -9,7 +9,6 @@ import { xyCheck } from './xyCheck'; * Finds all the min values * If the values are equal the middle * of the equal part will be the position of the signal! - * * @param data - Object that contains property X (an ordered increasing array) and y (an arraY) * @param options - Object with from and to properties * @returns - Array of points. diff --git a/src/xy/xyPeakInfo.ts b/src/xy/xyPeakInfo.ts index 067be3a4..137713e0 100644 --- a/src/xy/xyPeakInfo.ts +++ b/src/xy/xyPeakInfo.ts @@ -26,7 +26,6 @@ export interface XYPeakInfo { * ML.ArrayPoints.uniqueX * ML.ArrayPoints.sortX * ML.ArrayPoints.equallySpaced - * * @param data - Object that contains property x (an ordered increasing array) and y (an array) * @param options - options * @returns - Information about signal @@ -37,16 +36,16 @@ export function xyPeakInfo( ): XYPeakInfo | undefined { xyCheck(data); const { x, y } = data; - if (typeof x === 'undefined' || typeof y === 'undefined' || x.length < 3) { + if (x === undefined || y === undefined || x.length < 3) { return; } const { target } = options; let { targetIndex } = options; - if (typeof targetIndex === 'undefined' && typeof target !== 'undefined') { + if (targetIndex === undefined && target !== undefined) { targetIndex = xFindClosestIndex(x, target); } - if (typeof targetIndex === 'undefined') { + if (targetIndex === undefined) { throw new Error('must specify target or targetIndex'); } diff --git a/src/xy/xyRealMaxYPoint.ts b/src/xy/xyRealMaxYPoint.ts index edaa9d02..76d3832d 100644 --- a/src/xy/xyRealMaxYPoint.ts +++ b/src/xy/xyRealMaxYPoint.ts @@ -7,7 +7,6 @@ import { xyCheck } from './xyCheck'; /** * Find the closest minimum going down hill - * * @param data - Object that contains property x (an ordered increasing array) and y (an array) * @param options - options * @returns - An object with the x/y value diff --git a/src/xy/xyRealMinYPoint.ts b/src/xy/xyRealMinYPoint.ts index d872a04a..1e0a78af 100644 --- a/src/xy/xyRealMinYPoint.ts +++ b/src/xy/xyRealMinYPoint.ts @@ -7,7 +7,6 @@ import { xyCheck } from './xyCheck'; /** * xyRealMinYPoint. - * * @param data - Data. * @param options - Options. */ diff --git a/src/xy/xyReduce.ts b/src/xy/xyReduce.ts index f58ceb46..98f1c433 100644 --- a/src/xy/xyReduce.ts +++ b/src/xy/xyReduce.ts @@ -1,4 +1,3 @@ -/* eslint-disable max-lines-per-function */ import { DataXY, DoubleArray, FromTo, NumberArray } from 'cheminfo-types'; import { xFindClosestIndex } from '../x'; @@ -19,24 +18,28 @@ export interface XYReduceOptions { * @default x[0] */ from?: number; + /** * @default x[x.length-1] */ to?: number; + /** * Number of points * @default 4001 - * */ + */ nbPoints?: number; + /** * If optimize we may have less than nbPoints at the end. It should not have visible effects * @default false - * */ + */ optimize?: boolean; + /** * Array of zones to keep (from/to object) * @default [] - * */ + */ zones?: FromTo[]; } @@ -47,7 +50,6 @@ export interface XYReduceOptions { * * SHOULD NOT BE USED FOR DATA PROCESSING !!! * You should rather use ml-xy-equally-spaced to make further processing - * * @param data - Object that contains property x (an ordered increasing array) and y (an array) * @param options - options */ @@ -56,10 +58,16 @@ export function xyReduce( options: XYReduceOptions = {}, ): DataXY { xyCheck(data); + if (data.x.length < 2) { + return { + x: Float64Array.from(data.x), + y: Float64Array.from(data.y), + }; + } const { x, y } = data; const { from = x[0], - to = x[x.length - 1], + to = x.at(-1) as number, nbPoints = 4001, optimize = false, } = options; @@ -96,7 +104,7 @@ export function xyReduce( zone.nbPoints = Math.round((zone.nbPoints as number) * ratio); currentTotal += zone.nbPoints; } - internalZones[internalZones.length - 1].nbPoints = nbPoints - currentTotal; + (internalZones.at(-1) as InternalZone).nbPoints = nbPoints - currentTotal; const newX: number[] = []; const newY: number[] = []; @@ -112,7 +120,6 @@ export function xyReduce( /** * AppendFromTo. - * * @param fromIndex - From. * @param toIndex - To. * @param zoneNbPoints - NbPoints. diff --git a/src/xy/xyRolling.ts b/src/xy/xyRolling.ts index 8e369c69..4b589e67 100644 --- a/src/xy/xyRolling.ts +++ b/src/xy/xyRolling.ts @@ -5,7 +5,6 @@ import { xRolling, xRollingAverage, XRollingOptions } from '../x'; /** * This function calculates a rolling average. * This methods will recalculate the x values by using xRollingAverage - * * @param data - array of points {x,y} * @param fct - callback function that from an array returns a value. * @param options - options diff --git a/src/xy/xySetYValue.ts b/src/xy/xySetYValue.ts index 6e1189fc..867d76c9 100644 --- a/src/xy/xySetYValue.ts +++ b/src/xy/xySetYValue.ts @@ -6,13 +6,13 @@ import { xyCheck } from './xyCheck'; export interface XYSetYValueOptions { zones?: FromTo[]; + /** data contains x and y values */ value?: number; } /** * Set a value (default 0) to specific zones. - * * @param data - Object that contains property x (an ordered increasing array) and y (an array) * @param options - options * @returns - Array of points diff --git a/src/xy/xySortX.ts b/src/xy/xySortX.ts index 1766a425..16531bf3 100644 --- a/src/xy/xySortX.ts +++ b/src/xy/xySortX.ts @@ -4,7 +4,6 @@ import { xIsMonotonic } from '../x'; /** * This function performs a quick sort of the x array while transforming the y array to preserve the coordinates. - * * @param data - Object that contains property x (Array) and y (Array) */ export function xySortX(data: DataXY): DataXY { diff --git a/src/xy/xyToXYArray.ts b/src/xy/xyToXYArray.ts index b2cf4799..3ecbf2ca 100644 --- a/src/xy/xyToXYArray.ts +++ b/src/xy/xyToXYArray.ts @@ -4,7 +4,6 @@ import { xyCheck } from './xyCheck'; /** * Convert a DataXY to an array of array containing x,y. - * * @param data - array of points {x,y} */ export function xyToXYArray(data: DataXY): Array<[number, number]> { diff --git a/src/xy/xyToXYObject.ts b/src/xy/xyToXYObject.ts index fb2c00a6..39f91d6d 100644 --- a/src/xy/xyToXYObject.ts +++ b/src/xy/xyToXYObject.ts @@ -6,7 +6,6 @@ import { xyCheck } from './xyCheck'; /** * xyToXYObject. - * * @param data - Array of points {x,y}. */ export function xyToXYObject(data: DataXY): Point[] { diff --git a/src/xy/xyUniqueX.ts b/src/xy/xyUniqueX.ts index b626f105..27b7d6a8 100644 --- a/src/xy/xyUniqueX.ts +++ b/src/xy/xyUniqueX.ts @@ -7,18 +7,18 @@ export interface XYUniqueXOptions { /** * either 'average' or 'sum' * @default 'average' - * */ + */ algorithm?: 'average' | 'sum'; + /** * if false the DataXY has to be sorted first * @default true - * */ + */ isSorted?: boolean; } /** * Ensure x values are unique - * * @param data - Object that contains property x (Array) and y (Array) * @param options - Object containing a property algorithm (can be 'sum' or 'average', the latter being the default value), and a property isSorted (boolean indicating if the x-array is sorted). */ @@ -28,6 +28,10 @@ export function xyUniqueX( ): DataXY { xyCheck(data); + if (data.x.length === 0) { + return { x: [], y: [] }; + } + const { algorithm = 'average', isSorted = true } = options; if (!isSorted) { @@ -46,7 +50,6 @@ export function xyUniqueX( /** * Average. - * * @param data - Input. * @returns Result. */ @@ -65,14 +68,13 @@ function average(data: DataXY): DataXY { cumulativeY += data.y[i]; divider++; } - x.push(data.x[data.x.length - 1]); + x.push(data.x.at(-1) as number); y.push(cumulativeY / divider); return { x, y }; } /** * Sum. - * * @param data - Input. * @returns Result. */ @@ -88,7 +90,7 @@ function sum(data: DataXY): DataXY { } cumulativeY += data.y[i]; } - x.push(data.x[data.x.length - 1]); + x.push(data.x.at(-1) as number); y.push(cumulativeY); return { x, y }; } diff --git a/src/xy/xyWeightedMerge.ts b/src/xy/xyWeightedMerge.ts index 22f0430c..d3a79d75 100644 --- a/src/xy/xyWeightedMerge.ts +++ b/src/xy/xyWeightedMerge.ts @@ -1,7 +1,8 @@ import { DataXY } from 'cheminfo-types'; interface XYWeightedMergeOptions { - /** window for abscissas to merge + /** + * window for abscissas to merge * @default 0.001 */ groupWidth?: number; @@ -9,10 +10,9 @@ interface XYWeightedMergeOptions { /** * Merge abscissas values on similar ordinates and weight the group of abscissas - * * @param data - object containing 2 properties x and y * @param options - options - * @return array of merged and weighted points + * @returns array of merged and weighted points */ export function xyWeightedMerge( data: DataXY, diff --git a/src/xy2/xy2ToXY.ts b/src/xy2/xy2ToXY.ts index 99f4f80e..e183fbe9 100644 --- a/src/xy2/xy2ToXY.ts +++ b/src/xy2/xy2ToXY.ts @@ -2,7 +2,6 @@ import { DataXY } from 'cheminfo-types'; /** * Convert an array of XY arrays to a DataXY object containing x,y arrays - * * @param data - array of arrays [[x,y],[x,y],...] */ export function xy2ToXY(data: Array<[number, number]>): DataXY { diff --git a/src/xyArray/utils/getSlots.ts b/src/xyArray/utils/getSlots.ts index 51a3e828..dc9021cc 100644 --- a/src/xyArray/utils/getSlots.ts +++ b/src/xyArray/utils/getSlots.ts @@ -18,7 +18,6 @@ export interface Slot { /** * GetSlots. - * * @param data - data. * @param options - Options. */ @@ -30,7 +29,7 @@ export function getSlots( const deltaIsFunction = typeof delta === 'function'; const possibleXs = Float64Array.from( - data.map((spectrum) => spectrum.x as number[]).flat(), + data.flatMap((spectrum) => spectrum.x as number[]), ).sort(); if (possibleXs.length === 0) { diff --git a/src/xyArray/utils/getSlotsToFirst.ts b/src/xyArray/utils/getSlotsToFirst.ts index c009b706..22f8c7e7 100644 --- a/src/xyArray/utils/getSlotsToFirst.ts +++ b/src/xyArray/utils/getSlotsToFirst.ts @@ -18,7 +18,6 @@ export interface Slot { /** * GetSlotsToFirst. - * * @param data - data. * @param options - Options. */ diff --git a/src/xyArray/xyArrayAlign.ts b/src/xyArray/xyArrayAlign.ts index 78ceedf8..7e9b1617 100644 --- a/src/xyArray/xyArrayAlign.ts +++ b/src/xyArray/xyArrayAlign.ts @@ -10,6 +10,7 @@ export interface XYArrayAlignOptions { * @default 1 */ delta?: ((arg: number) => number) | number; + /** * If true, the y values must be present everywhere * @default false @@ -19,7 +20,6 @@ export interface XYArrayAlignOptions { /** * Aligns data, can be used for spectra - * * @param data - data * @param options - Options */ diff --git a/src/xyArray/xyArrayAlignToFirst.ts b/src/xyArray/xyArrayAlignToFirst.ts index 3399589e..f6dad795 100644 --- a/src/xyArray/xyArrayAlignToFirst.ts +++ b/src/xyArray/xyArrayAlignToFirst.ts @@ -14,9 +14,8 @@ export interface XYArrayAlignToFirstOptions { * We align all the data/spectra to the first array of X. * The alignment is based on the X values of the first spectrum and the `delta` error allowed. * If some x values are missing in the first spectrum we will add them - * - * @param data data - * @param options options + * @param data - data + * @param options - options */ export function xyArrayAlignToFirst( data: DataXY[], diff --git a/src/xyArray/xyArrayMerge.ts b/src/xyArray/xyArrayMerge.ts index 597e34c6..0057308d 100644 --- a/src/xyArray/xyArrayMerge.ts +++ b/src/xyArray/xyArrayMerge.ts @@ -15,7 +15,6 @@ export interface XYArrayMergeOptions { /** * Merge DataXY * We have an array of DataXY and the goal is to merge all the values that are the closest possible - * * @param data - data * @param options - Options */ diff --git a/src/xyArray/xyArrayWeightedMerge.ts b/src/xyArray/xyArrayWeightedMerge.ts index 88e967c6..eef3e378 100644 --- a/src/xyArray/xyArrayWeightedMerge.ts +++ b/src/xyArray/xyArrayWeightedMerge.ts @@ -14,7 +14,6 @@ export interface XYArrayWeightedMergeOptions { * Merge DataXY * We have an array of DataXY and the goal is to merge all the values for which the deltaX is small or equal to delta. * X values are weighted average - * * @param data - data * @param options - Options */ @@ -70,7 +69,6 @@ export function xyArrayWeightedMerge( /** * NextValue. - * * @param data - data. * @param positions - Positions array. * @param point - Point. diff --git a/src/xyObject/xyObjectBestPoints.ts b/src/xyObject/xyObjectBestPoints.ts index 66ad31e8..e23f0c70 100644 --- a/src/xyObject/xyObjectBestPoints.ts +++ b/src/xyObject/xyObjectBestPoints.ts @@ -1,4 +1,4 @@ -import { Point } from '../types'; +import { Point, PointWithClose } from '../types'; import { xyObjectMaxXPoint } from './xyObjectMaxXPoint'; import { xyObjectMinXPoint } from './xyObjectMinXPoint'; @@ -8,28 +8,34 @@ export interface XYObjectBestPointsOptions { * min X value of the window to consider */ from?: number; + /** * max X value of the window to consider */ to?: number; + /** * max number of points * @default 20 - * */ + */ limit?: number; + /** * minimal intensity compare to more intense * @default 0.01 - * */ + */ threshold?: number; + /** * number of slots - * @default 50 */ + * @default 50 + */ numberCloseSlots?: number; + /** * define the number of slots and indirectly the slot width * @default 10 - * */ + */ numberSlots?: number; } @@ -37,7 +43,6 @@ export interface XYObjectBestPointsOptions { * Filter the array by taking the higher points (max y value) and only. * Keep one per slot. There are 2 different slots, the smallest one will have the * new property `close` to true - * * @param points - array of all the points * @param options - Options * @returns - copy of points with 'close' property @@ -71,7 +76,7 @@ export function xyObjectBestPoints( return b.point.y - a.point.y; }); - const toReturn: Point[] = []; + const toReturn: PointWithClose[] = []; if (selected.length === 0) return []; const minY = selected[0].point.y * threshold; peakLoop: for (const item of selected) { @@ -91,8 +96,7 @@ export function xyObjectBestPoints( close = true; } } - const newPeak = JSON.parse(JSON.stringify(item.point)); - newPeak.close = close; + const newPeak = { ...item.point, close }; toReturn.push(newPeak); if (toReturn.length === limit) break; } diff --git a/src/xyObject/xyObjectCheck.ts b/src/xyObject/xyObjectCheck.ts index 5809fa28..8d5e0ccc 100644 --- a/src/xyObject/xyObjectCheck.ts +++ b/src/xyObject/xyObjectCheck.ts @@ -2,7 +2,6 @@ import { Point } from '../types'; /** * Throws an error in not an array of x,y objects. - * * @param points - List of points. */ export function xyObjectCheck(points?: Point[]): asserts points is Point[] { diff --git a/src/xyObject/xyObjectJoinX.ts b/src/xyObject/xyObjectJoinX.ts index 5fc9fea8..4479115f 100644 --- a/src/xyObject/xyObjectJoinX.ts +++ b/src/xyObject/xyObjectJoinX.ts @@ -4,13 +4,12 @@ export interface XYObjectJoinXOptions { /** * Limit to join the data. * @default Number.EPSILON - * */ + */ xError?: number; } /** * xyObjectJoinX. - * * @param points - Array of growing points {x,y}. * @param options - Options. */ diff --git a/src/xyObject/xyObjectMaxXPoint.ts b/src/xyObject/xyObjectMaxXPoint.ts index 5f759ce6..d7e3e828 100644 --- a/src/xyObject/xyObjectMaxXPoint.ts +++ b/src/xyObject/xyObjectMaxXPoint.ts @@ -1,9 +1,9 @@ import { Point } from '../types'; import { xyObjectCheck } from './xyObjectCheck'; + /** * Finds the max x value and return a {x,y,index} point - * * @param points - Object that contains property x (an ordered increasing array) and y (an array) */ export function xyObjectMaxXPoint(points: Point[] = []): Point { diff --git a/src/xyObject/xyObjectMaxYPoint.ts b/src/xyObject/xyObjectMaxYPoint.ts index d517a33d..3ca77f19 100644 --- a/src/xyObject/xyObjectMaxYPoint.ts +++ b/src/xyObject/xyObjectMaxYPoint.ts @@ -1,9 +1,9 @@ import { Point } from '../types'; import { xyObjectCheck } from './xyObjectCheck'; + /** * Finds the max y value and return a {x,y,index} point - * * @param points - Object that contains property x (an ordered increasing array) and y (an array) */ export function xyObjectMaxYPoint(points: Point[] = []): Point { diff --git a/src/xyObject/xyObjectMinXPoint.ts b/src/xyObject/xyObjectMinXPoint.ts index d8846973..3d46690d 100644 --- a/src/xyObject/xyObjectMinXPoint.ts +++ b/src/xyObject/xyObjectMinXPoint.ts @@ -4,7 +4,6 @@ import { xyObjectCheck } from './xyObjectCheck'; /** * Finds the min x value and return a {x,y,index} point - * * @param points - Object that contains property x (an ordered increasing array) and y (an array) */ export function xyObjectMinXPoint(points: Point[] = []): Point { diff --git a/src/xyObject/xyObjectMinYPoint.ts b/src/xyObject/xyObjectMinYPoint.ts index ee7db5b3..8f7f0be3 100644 --- a/src/xyObject/xyObjectMinYPoint.ts +++ b/src/xyObject/xyObjectMinYPoint.ts @@ -4,7 +4,6 @@ import { xyObjectCheck } from './xyObjectCheck'; /** * Finds the min y value and return a {x,y,index} point - * * @param points - Object that contains property x (an ordered increasing array) and y (an array) */ export function xyObjectMinYPoint(points: Point[] = []): Point { diff --git a/src/xyObject/xyObjectSlotX.ts b/src/xyObject/xyObjectSlotX.ts index f372ba99..168074ae 100644 --- a/src/xyObject/xyObjectSlotX.ts +++ b/src/xyObject/xyObjectSlotX.ts @@ -4,13 +4,12 @@ export interface XYObjectSlotXOptions { /** * Limit to join the dataPoints[]. * @default 1 - * */ + */ slotWidth?: number; } /** * xyObjectSlotX - * * @param points - Array of growing points {x,y}. * @param options - Options. */ diff --git a/src/xyObject/xyObjectSortX.ts b/src/xyObject/xyObjectSortX.ts index 8dd27800..0a46a75e 100644 --- a/src/xyObject/xyObjectSortX.ts +++ b/src/xyObject/xyObjectSortX.ts @@ -2,7 +2,6 @@ import { Point } from '../types'; /** * Sorts an array of points in-place. - * * @param points - array of points {x,y} * @returns - sorted array of points {x,y} */ diff --git a/src/xyObject/xyObjectSumY.ts b/src/xyObject/xyObjectSumY.ts index c81c06cb..59926416 100644 --- a/src/xyObject/xyObjectSumY.ts +++ b/src/xyObject/xyObjectSumY.ts @@ -4,7 +4,6 @@ import { xyObjectCheck } from './xyObjectCheck'; /** * Calculate the sum of Y values. - * * @param points - Object that contains property x and y (an array) */ export function xyObjectSumY(points: Point[] = []): number { diff --git a/src/xyObject/xyObjectToXY.ts b/src/xyObject/xyObjectToXY.ts index 78c2327f..50fc545b 100644 --- a/src/xyObject/xyObjectToXY.ts +++ b/src/xyObject/xyObjectToXY.ts @@ -4,7 +4,6 @@ import { Point } from '../types'; /** * xyObjectToXY. - * * @param points - Array of points {x,y}. */ export function xyObjectToXY(points: Point[]): DataXY { diff --git a/src/zones/zonesNormalize.ts b/src/zones/zonesNormalize.ts index 58382506..d85f1b5b 100644 --- a/src/zones/zonesNormalize.ts +++ b/src/zones/zonesNormalize.ts @@ -1,16 +1,18 @@ -/* eslint-disable max-lines-per-function */ - import { FromTo } from 'cheminfo-types'; export interface ZonesNormalizeOptions { - /** specify min value of zones + /** + * specify min value of zones * @default Number.NEGATIVE_INFINITY */ from?: number; - /** specify max value of zones + + /** + * specify max value of zones * @default Number.POSITIVE_INFINITY */ to?: number; + /** * List of exclusion zones */ diff --git a/src/zones/zonesWithPoints.ts b/src/zones/zonesWithPoints.ts index 8a75fe1e..e36092f8 100644 --- a/src/zones/zonesWithPoints.ts +++ b/src/zones/zonesWithPoints.ts @@ -3,11 +3,14 @@ import { FromTo } from 'cheminfo-types'; import { zonesNormalize } from './zonesNormalize'; export interface ZonesWithPointsOptions { - /** specify min value of zones + /** + * specify min value of zones * @default Number.NEGATIVE_INFINITY */ from?: number; - /** specify max value of zones + + /** + * specify max value of zones * @default Number.POSITIVE_INFINITY */ to?: number; @@ -19,7 +22,6 @@ export interface FromToWithNumberOfPoints extends FromTo { /** * Add the number of points per zone to reach a specified total - * * @param zones - array of zones * @param numberOfPoints - total number of points to distribute between zones * @param options - options @@ -27,6 +29,7 @@ export interface FromToWithNumberOfPoints extends FromTo { */ export function zonesWithPoints( zones: FromTo[] = [], + /** * total number of points to distribute between zones * @default 10 @@ -59,7 +62,7 @@ export function zonesWithPoints( } zonesWithNumberOfPoints.push({ - ...normalizedZones[normalizedZones.length - 1], + ...(normalizedZones.at(-1) as FromTo), numberOfPoints: numberOfPoints - currentTotal, }); diff --git a/tsconfig.json b/tsconfig.json index 576c1104..5c287c22 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,7 @@ "outDir": "lib", "sourceMap": true, "strict": true, - "target": "es2020", + "target": "es2022", "skipLibCheck": true }, "include": ["./src/**/*", "vitest.setup.ts"]