Skip to content

Commit 246e1cc

Browse files
chore!: migrate project to TypeScript (#18)
close: #17 close: #19
1 parent d0ea5f9 commit 246e1cc

14 files changed

Lines changed: 67 additions & 21 deletions

.eslintrc.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
extends: cheminfo
1+
extends: cheminfo-typescript
2+
root: true
23
parserOptions:
34
sourceType: module
5+
env:
6+
jest: true

.github/workflows/nodejs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ jobs:
1111
# Documentation: https://github.com/zakodium/workflows#nodejs-ci
1212
uses: zakodium/workflows/.github/workflows/nodejs.yml@nodejs-v1
1313
with:
14-
node-version-matrix: '[12, 14, 16]'
14+
lint-check-types: true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ jspm_packages
4040
.node_repl_history
4141

4242
lib
43+
lib-esm

babel.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
module.exports = {
2-
"plugins": ["@babel/plugin-transform-modules-commonjs"]
2+
presets: ['@babel/preset-typescript'],
3+
plugins: ['@babel/plugin-transform-modules-commonjs'],
34
};

package.json

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,27 @@
22
"name": "ml-rolling-ball-baseline",
33
"version": "1.1.0",
44
"description": "Rolling ball baseline correction",
5-
"main": "lib/index.js",
6-
"module": "src/index.js",
5+
"main": "./lib/index.js",
6+
"module": "./lib-esm/index.js",
7+
"types": "./lib/index.d.ts",
78
"files": [
89
"lib",
9-
"src"
10+
"src",
11+
"lib-esm"
1012
],
1113
"scripts": {
14+
"check-types": "tsc --noEmit",
15+
"clean": "rimraf lib lib-esm",
1216
"eslint": "eslint src",
1317
"eslint-fix": "npm run eslint -- --fix",
14-
"prepack": "rollup -c",
18+
"prepack": "npm run tsc",
1519
"prettier": "prettier --check src",
1620
"prettier-write": "prettier --write src",
17-
"test": "npm run test-only && npm run eslint && npm run prettier",
18-
"test-only": "jest --coverage"
21+
"test": "npm run test-only && npm run eslint && npm run prettier && npm run check-types",
22+
"test-only": "jest --coverage",
23+
"tsc": "npm run clean && npm run tsc-cjs && npm run tsc-esm",
24+
"tsc-cjs": "tsc --project tsconfig.cjs.json",
25+
"tsc-esm": "tsc --project tsconfig.esm.json"
1926
},
2027
"repository": {
2128
"type": "git",
@@ -29,13 +36,15 @@
2936
},
3037
"homepage": "https://github.com/mljs/rolling-ball-baseline#readme",
3138
"devDependencies": {
32-
"@babel/plugin-transform-modules-commonjs": "^7.17.7",
33-
"@types/jest": "^27.4.1",
39+
"@babel/plugin-transform-modules-commonjs": "^7.19.6",
40+
"@babel/preset-typescript": "^7.18.6",
41+
"@types/jest": "^27.5.2",
42+
"cheminfo-types": "^1.4.0",
3443
"eslint": "^8.12.0",
35-
"eslint-config-cheminfo": "^7.3.0",
44+
"eslint-config-cheminfo-typescript": "^11.2.2",
3645
"jest": "^27.5.1",
3746
"prettier": "^2.6.1",
38-
"rollup": "^2.70.1"
47+
"rimraf": "^3.0.2"
3948
},
4049
"dependencies": {
4150
"is-any-array": "^2.0.0",

rollup.config.js

Lines changed: 0 additions & 7 deletions
This file was deleted.
File renamed without changes.
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { NumberArray } from 'cheminfo-types';
12
import { isAnyArray } from 'is-any-array';
23
import { xMean, xMaxValue, xMinValue } from 'ml-spectra-processing';
34

@@ -23,7 +24,15 @@ import { xMean, xMaxValue, xMinValue } from 'ml-spectra-processing';
2324
* @param {Number} [options.windowM] - width of local window for minimization/maximization, defaults to 4% of the spectrum length
2425
* @param {Number} [options.windowS] - width of local window for smoothing, defaults to 8% of the spectrum length
2526
*/
26-
export function rollingBall(spectrum, options = {}) {
27+
28+
interface Options {
29+
windowM: number;
30+
windowS: number;
31+
}
32+
export function rollingBall(
33+
spectrum: NumberArray,
34+
options: Partial<Options> = {},
35+
): NumberArray {
2736
if (!isAnyArray(spectrum)) {
2837
throw new Error('Spectrum must be an array');
2938
}

0 commit comments

Comments
 (0)