Skip to content

Commit d197546

Browse files
committed
refactor!: migrate to TypeScript and ESM
1 parent ce24d49 commit d197546

15 files changed

+108
-79
lines changed

.babelrc.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

.github/workflows/documentationjs.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

.github/workflows/nodejs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ jobs:
1010
nodejs:
1111
# Documentation: https://github.com/zakodium/workflows#nodejs-ci
1212
uses: zakodium/workflows/.github/workflows/nodejs.yml@nodejs-v1
13+
with:
14+
lint-check-types: true

.github/workflows/typedoc.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Deploy TypeDoc on GitHub pages
2+
3+
on:
4+
workflow_dispatch:
5+
release:
6+
types: [published]
7+
8+
env:
9+
NODE_VERSION: 22.x
10+
ENTRY_FILE: 'src/index.js'
11+
12+
jobs:
13+
deploy:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-node@v4
18+
with:
19+
node-version: ${{ env.NODE_VERSION }}
20+
- name: Install dependencies
21+
run: npm install
22+
- name: Build documentation
23+
uses: zakodium/typedoc-action@v2
24+
with:
25+
entry: ${{ env.ENTRY_FILE }}
26+
- name: Deploy to GitHub pages
27+
uses: JamesIves/github-pages-deploy-action@releases/v4
28+
with:
29+
token: ${{ secrets.BOT_TOKEN }}
30+
branch: gh-pages
31+
folder: docs
32+
clean: true

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CHANGELOG.md

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# sparse-matrix
1+
# ml-sparse-matrix
22

33
[![NPM version][npm-image]][npm-url]
44
[![coverage status][codecov-image]][codecov-url]
@@ -13,7 +13,7 @@ Sparse matrix library.
1313
## Usage
1414

1515
```js
16-
import { SparseMatrix } from "ml-sparse-matrix";
16+
import { SparseMatrix } from 'ml-sparse-matrix';
1717

1818
const matrix1 = new SparseMatrix([
1919
[1, 2],

benchmark/denseMatrix.mjs renamed to benchmark/denseMatrix.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,5 @@ for (let i = 0; i < size; i++) {
1414
sum += product.get(i, j);
1515
}
1616
}
17-
console.log(sum)
17+
console.log(sum);
1818
console.timeEnd('dense');
19-
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
2-
31
import { SparseMatrix } from '../lib/index.js';
42

53
let size = 200;
64

7-
8-
95
console.time('dense');
106

117
const matrix1 = new SparseMatrix(size, size);
12-
fillSparseMatrix(matrix1)
8+
fillSparseMatrix(matrix1);
139

1410
const matrix2 = new SparseMatrix(size, size);
15-
fillSparseMatrix(matrix2)
11+
fillSparseMatrix(matrix2);
1612

1713
const product = new SparseMatrix(size, size);
1814
for (let i = 0; i < size; i++) {
1915
for (let j = 0; j < size; j++) {
2016
for (let k = 0; k < size; k++) {
21-
product.set(i, j, product.get(i, j) + matrix1.get(i, k) * matrix2.get(k, j));
17+
product.set(
18+
i,
19+
j,
20+
product.get(i, j) + matrix1.get(i, k) * matrix2.get(k, j),
21+
);
2222
}
2323
}
2424
}
@@ -30,12 +30,12 @@ for (let i = 0; i < size; i++) {
3030
}
3131
}
3232
console.timeEnd('dense');
33-
console.log(sum)
33+
console.log(sum);
3434

3535
function fillSparseMatrix(matrix) {
3636
for (let row = 0; row < matrix.rows; row++) {
3737
for (let column = 0; column < matrix.columns; column++) {
3838
matrix.set(row, column, 1);
3939
}
4040
}
41-
}
41+
}

benchmark/sparseMatrix.mjs renamed to benchmark/sparseMatrix.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ let size = 200;
55
console.time('dense');
66

77
const matrix = new SparseMatrix(size, size);
8-
fillSparseMatrix(matrix)
8+
fillSparseMatrix(matrix);
99

1010
const matrix2 = new SparseMatrix(size, size);
11-
fillSparseMatrix(matrix2)
11+
fillSparseMatrix(matrix2);
1212

1313
const product = matrix.mmul(matrix2);
1414
// sum of all the elements
@@ -19,12 +19,12 @@ for (let i = 0; i < size; i++) {
1919
}
2020
}
2121
console.timeEnd('dense');
22-
console.log(sum)
22+
console.log(sum);
2323

2424
function fillSparseMatrix(matrix) {
2525
for (let row = 0; row < matrix.rows; row++) {
2626
for (let column = 0; column < matrix.columns; column++) {
2727
matrix.set(row, column, 1);
2828
}
2929
}
30-
}
30+
}

eslint.config.mjs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import cheminfo from 'eslint-config-cheminfo';
1+
import { defineConfig, globalIgnores } from 'eslint/config';
2+
import ts from 'eslint-config-cheminfo-typescript/base';
23

3-
export default [
4-
...cheminfo,
5-
{
6-
languageOptions: {
7-
},
8-
rules: {
9-
}
10-
}
11-
]
4+
export default defineConfig(globalIgnores(['lib']), ts, {
5+
files: ['benchmark/**'],
6+
rules: {
7+
'no-console': 'off',
8+
},
9+
});

package.json

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,24 @@
22
"name": "ml-sparse-matrix",
33
"version": "2.1.0",
44
"description": "Sparse matrix library",
5-
"main": "lib/index.js",
6-
"module": "src/index.js",
5+
"type": "module",
6+
"exports": "./lib/index.js",
77
"files": [
88
"lib",
99
"src"
1010
],
1111
"scripts": {
12-
"compile": "rollup -c",
13-
"eslint": "eslint src",
12+
"check-types": "tsc --noEmit",
13+
"clean": "rimraf lib",
14+
"eslint": "eslint .",
1415
"eslint-fix": "npm run eslint -- --fix",
15-
"prepack": "npm run compile",
16-
"prettier": "prettier --check src",
17-
"prettier-write": "prettier --write src",
18-
"test": "npm run test-only && npm run eslint && npm run prettier",
19-
"test-only": "vitest run --coverage"
16+
"prepack": "npm run tsc",
17+
"prettier": "prettier --check .",
18+
"prettier-write": "prettier --write .",
19+
"test": "npm run test-only && npm run check-types && npm run eslint && npm run prettier",
20+
"test-only": "vitest run --coverage",
21+
"tsc": "npm run clean && npm run tsc-build",
22+
"tsc-build": "tsc --project tsconfig.build.json"
2023
},
2124
"repository": {
2225
"type": "git",
@@ -33,13 +36,14 @@
3336
"ml-hash-table": "^1.0.0"
3437
},
3538
"devDependencies": {
36-
"@babel/plugin-transform-modules-commonjs": "^7.24.8",
37-
"@vitest/coverage-v8": "^2.0.5",
38-
"eslint": "^8.10.0",
39-
"eslint-config-cheminfo": "^11.1.1",
40-
"ml-matrix": "^6.11.1",
41-
"prettier": "^3.3.3",
42-
"rollup": "^4.21.0",
43-
"vitest": "^2.0.5"
39+
"@types/node": "^22.15.21",
40+
"@vitest/coverage-v8": "^3.1.4",
41+
"eslint": "^9.27.0",
42+
"eslint-config-cheminfo-typescript": "^18.0.1",
43+
"ml-matrix": "^6.12.1",
44+
"prettier": "^3.5.3",
45+
"rimraf": "^6.0.1",
46+
"typescript": "^5.8.3",
47+
"vitest": "^3.1.4"
4448
}
4549
}

rollup.config.mjs

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/__tests__/index.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { describe, it, expect } from 'vitest';
1+
import { describe, expect, it } from 'vitest';
22

3-
import { SparseMatrix } from '..';
3+
import { SparseMatrix } from '../index.js';
44

55
describe('Sparse Matrix', () => {
66
it('mmul', () => {

tsconfig.build.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"exclude": ["**/__tests__", "**/*.test.ts"]
4+
}

tsconfig.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"compilerOptions": {
3+
"lib": ["ES2022", "WebWorker"],
4+
"types": [],
5+
"target": "ES2022",
6+
"outDir": "lib",
7+
"module": "NodeNext",
8+
"strict": true,
9+
"skipLibCheck": false,
10+
"resolveJsonModule": false,
11+
"forceConsistentCasingInFileNames": true,
12+
"allowJs": true,
13+
"checkJs": true,
14+
"noImplicitAny": false,
15+
"isolatedModules": true,
16+
"verbatimModuleSyntax": true,
17+
"sourceMap": true,
18+
"declaration": true,
19+
"declarationMap": true
20+
},
21+
"include": ["src"]
22+
}

0 commit comments

Comments
 (0)