Skip to content

Commit f6a914e

Browse files
committed
feat!: migrate to type:module
1 parent eb164c3 commit f6a914e

22 files changed

+209
-232
lines changed

.eslintcache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"/Users/lpatiny/git/mljs/kmeans/babel.config.js":"1","/Users/lpatiny/git/mljs/kmeans/eslint.config.js":"2","/Users/lpatiny/git/mljs/kmeans/example/iris/iris.js":"3","/Users/lpatiny/git/mljs/kmeans/src/KMeansResult.ts":"4","/Users/lpatiny/git/mljs/kmeans/src/__tests__/initialization.test.ts":"5","/Users/lpatiny/git/mljs/kmeans/src/__tests__/kmeans.test.ts":"6","/Users/lpatiny/git/mljs/kmeans/src/__tests__/utils.test.ts":"7","/Users/lpatiny/git/mljs/kmeans/src/assert.ts":"8","/Users/lpatiny/git/mljs/kmeans/src/initialization.ts":"9","/Users/lpatiny/git/mljs/kmeans/src/kmeans.ts":"10","/Users/lpatiny/git/mljs/kmeans/src/utils.ts":"11","/Users/lpatiny/git/mljs/kmeans/src/index.ts":"12"},{"size":120,"mtime":1729492886985,"results":"13","hashOfConfig":"14"},{"size":195,"mtime":1763041929454,"results":"15","hashOfConfig":"14"},{"size":758,"mtime":1763101159116,"results":"16","hashOfConfig":"17"},{"size":2331,"mtime":1763101057895,"results":"18","hashOfConfig":"19"},{"size":1808,"mtime":1763101330240,"results":"20","hashOfConfig":"21"},{"size":4202,"mtime":1763101294003,"results":"22","hashOfConfig":"21"},{"size":2710,"mtime":1763101096199,"results":"23","hashOfConfig":"21"},{"size":356,"mtime":1729492886987,"results":"24","hashOfConfig":"19"},{"size":5039,"mtime":1763042226049,"results":"25","hashOfConfig":"19"},{"size":6059,"mtime":1763101330241,"results":"26","hashOfConfig":"19"},{"size":3549,"mtime":1763101043999,"results":"27","hashOfConfig":"19"},{"size":29,"mtime":1763101183140,"results":"28","hashOfConfig":"19"},{"filePath":"29","messages":"30","suppressedMessages":"31","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"949zda",{"filePath":"32","messages":"33","suppressedMessages":"34","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"35","messages":"36","suppressedMessages":"37","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"k8r5y1",{"filePath":"38","messages":"39","suppressedMessages":"40","errorCount":0,"fatalErrorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},"eftbd8",{"filePath":"41","messages":"42","suppressedMessages":"43","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"7cox8e",{"filePath":"44","messages":"45","suppressedMessages":"46","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"47","messages":"48","suppressedMessages":"49","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"50","messages":"51","suppressedMessages":"52","errorCount":0,"fatalErrorCount":0,"warningCount":2,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"53","messages":"54","suppressedMessages":"55","errorCount":0,"fatalErrorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"56","messages":"57","suppressedMessages":"58","errorCount":0,"fatalErrorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"59","messages":"60","suppressedMessages":"61","errorCount":0,"fatalErrorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"62","messages":"63","suppressedMessages":"64","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Users/lpatiny/git/mljs/kmeans/babel.config.js",[],[],"/Users/lpatiny/git/mljs/kmeans/eslint.config.js",[],[],"/Users/lpatiny/git/mljs/kmeans/example/iris/iris.js",[],["65","66","67","68","69","70","71"],"/Users/lpatiny/git/mljs/kmeans/src/KMeansResult.ts",["72"],[],"/Users/lpatiny/git/mljs/kmeans/src/__tests__/initialization.test.ts",[],[],"/Users/lpatiny/git/mljs/kmeans/src/__tests__/kmeans.test.ts",[],[],"/Users/lpatiny/git/mljs/kmeans/src/__tests__/utils.test.ts",[],[],"/Users/lpatiny/git/mljs/kmeans/src/assert.ts",["73","74"],[],"/Users/lpatiny/git/mljs/kmeans/src/initialization.ts",["75"],[],"/Users/lpatiny/git/mljs/kmeans/src/kmeans.ts",["76"],[],"/Users/lpatiny/git/mljs/kmeans/src/utils.ts",["77"],[],"/Users/lpatiny/git/mljs/kmeans/src/index.ts",[],[],{"ruleId":"78","severity":2,"message":"79","line":11,"column":1,"nodeType":"80","messageId":"81","endLine":11,"endColumn":12,"suggestions":"82","suppressions":"83"},{"ruleId":"78","severity":2,"message":"79","line":12,"column":1,"nodeType":"80","messageId":"81","endLine":12,"endColumn":12,"suggestions":"84","suppressions":"85"},{"ruleId":"78","severity":2,"message":"79","line":16,"column":1,"nodeType":"80","messageId":"81","endLine":16,"endColumn":12,"suggestions":"86","suppressions":"87"},{"ruleId":"78","severity":2,"message":"79","line":22,"column":1,"nodeType":"80","messageId":"81","endLine":22,"endColumn":12,"suggestions":"88","suppressions":"89"},{"ruleId":"78","severity":2,"message":"79","line":32,"column":1,"nodeType":"80","messageId":"81","endLine":32,"endColumn":12,"suggestions":"90","suppressions":"91"},{"ruleId":"78","severity":2,"message":"79","line":33,"column":1,"nodeType":"80","messageId":"81","endLine":33,"endColumn":12,"suggestions":"92","suppressions":"93"},{"ruleId":"78","severity":2,"message":"79","line":37,"column":1,"nodeType":"80","messageId":"81","endLine":37,"endColumn":12,"suggestions":"94","suppressions":"95"},{"ruleId":"96","severity":1,"message":"97","line":52,"column":1,"nodeType":"98","endLine":52,"endColumn":1},{"ruleId":"99","severity":1,"message":"100","line":1,"column":8,"nodeType":"101","messageId":"102","endLine":2,"endColumn":1},{"ruleId":"99","severity":1,"message":"100","line":5,"column":8,"nodeType":"101","messageId":"102","endLine":6,"endColumn":1},{"ruleId":"99","severity":1,"message":"100","line":87,"column":8,"nodeType":"101","messageId":"102","endLine":88,"endColumn":1},{"ruleId":"103","severity":1,"message":"104","line":80,"column":1,"nodeType":"98","endLine":80,"endColumn":1},{"ruleId":"96","severity":1,"message":"97","line":110,"column":1,"nodeType":"98","endLine":110,"endColumn":1},"no-console","Unexpected console statement.","MemberExpression","unexpected",["105"],["106"],["107"],["108"],["109"],["110"],["111"],["112"],["113"],["114"],["115"],["116"],["117"],["118"],"jsdoc/require-returns-description","Missing JSDoc @returns description.","Block","jsdoc/require-jsdoc","Missing JSDoc comment.","FunctionDeclaration","missingJsDoc","jsdoc/check-param-names","Expected @param names to be \"data, K, options\". Got \"centers, data, clusterID, K, options\".",{"fix":"119","messageId":"120","data":"121","desc":"122"},{"kind":"123","justification":"124"},{"fix":"125","messageId":"120","data":"126","desc":"122"},{"kind":"123","justification":"124"},{"fix":"127","messageId":"120","data":"128","desc":"122"},{"kind":"123","justification":"124"},{"fix":"129","messageId":"120","data":"130","desc":"122"},{"kind":"123","justification":"124"},{"fix":"131","messageId":"120","data":"132","desc":"122"},{"kind":"123","justification":"124"},{"fix":"133","messageId":"120","data":"134","desc":"122"},{"kind":"123","justification":"124"},{"fix":"135","messageId":"120","data":"136","desc":"122"},{"kind":"123","justification":"124"},{"range":"137","text":"124"},"removeConsole",{"propertyName":"138"},"Remove the console.log().","directive","",{"range":"139","text":"124"},{"propertyName":"138"},{"range":"140","text":"124"},{"propertyName":"138"},{"range":"141","text":"124"},{"propertyName":"138"},{"range":"142","text":"124"},{"propertyName":"138"},{"range":"143","text":"124"},{"propertyName":"138"},{"range":"144","text":"124"},{"propertyName":"138"},[248,272],"log",[273,349],[350,380],[459,552],[627,649],[650,726],[727,757]]

.eslintrc.yml

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

CHANGELOG.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414

1515
## [6.0.0](https://github.com/mljs/kmeans/compare/v5.0.0...v6.0.0) (2023-02-24)
1616

17-
1817
### ⚠ BREAKING CHANGES
1918

20-
* remove withIterations options and instead export generatorKmeans
19+
- remove withIterations options and instead export generatorKmeans
2120

2221
### Miscellaneous Chores
2322

24-
* setup project with TypeScript ([#18](https://github.com/mljs/kmeans/issues/18)) ([878bf1c](https://github.com/mljs/kmeans/commit/878bf1c9accef575ac48a35b71be18ac30adbe4a))
23+
- setup project with TypeScript ([#18](https://github.com/mljs/kmeans/issues/18)) ([878bf1c](https://github.com/mljs/kmeans/commit/878bf1c9accef575ac48a35b71be18ac30adbe4a))
2524

2625
## [4.2.1](https://github.com/mljs/kmeans/compare/v4.2.0...v4.2.1) (2018-08-15)
2726

babel.config.js

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

eslint.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { defineConfig, globalIgnores } from 'eslint/config';
2+
import cheminfo from 'eslint-config-cheminfo-typescript';
3+
4+
export default defineConfig(globalIgnores(['coverage', 'lib']), cheminfo);

example/iris/index.js

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

example/iris/iris.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-console */
22
import { getNumbers } from 'ml-dataset-iris';
33

4-
import { kmeans } from '../../src/kmeans';
4+
import { kmeans } from '../../src/index.ts';
55

66
let values = getNumbers();
77
values = values.map((val) => val.slice(0, 2));

package.json

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,26 @@
22
"name": "ml-kmeans",
33
"version": "6.0.0",
44
"description": "K-Means clustering",
5-
"main": "./lib/kmeans.js",
6-
"module": "./lib-esm/kmeans.js",
7-
"types": "./lib/kmeans.d.ts",
5+
"type": "module",
6+
"exports": {
7+
".": "./lib/index.js"
8+
},
89
"files": [
910
"src",
10-
"lib",
11-
"lib-esm"
11+
"lib"
1212
],
1313
"scripts": {
1414
"check-types": "tsc --noEmit",
15-
"clean": "rimraf lib lib-esm",
16-
"eslint": "eslint src",
17-
"eslint-fix": "npm run eslint -- --fix",
15+
"clean": "rimraf coverage dist lib",
16+
"eslint": "eslint . --cache",
17+
"eslint-fix": "eslint . --cache --fix",
1818
"prepack": "npm run tsc",
19-
"prettier": "prettier --check src example",
20-
"prettier-write": "prettier --write src example",
21-
"test": "npm run test-only && npm run eslint && npm run prettier && npm run check-types",
22-
"test-only": "vitest --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"
19+
"prettier": "prettier --check .",
20+
"prettier-write": "prettier --write .",
21+
"test": "npm run test-only && npm run check-types && npm run eslint && npm run prettier",
22+
"test-only": "vitest run --coverage",
23+
"tsc": "npm run clean && npm run tsc-build",
24+
"tsc-build": "tsc --project tsconfig.build.json"
2625
},
2726
"repository": {
2827
"type": "git",
@@ -44,22 +43,24 @@
4443
},
4544
"homepage": "https://github.com/mljs/kmeans",
4645
"devDependencies": {
47-
"@babel/plugin-transform-modules-commonjs": "^7.20.11",
48-
"@babel/preset-typescript": "^7.18.6",
46+
"@babel/plugin-transform-modules-commonjs": "^7.27.1",
47+
"@babel/preset-typescript": "^7.28.5",
48+
"@types/node": "^24.10.1",
4949
"@vitest/coverage-v8": "^4.0.8",
50-
"eslint": "^8.10.0",
51-
"eslint-config-cheminfo-typescript": "^11.2.2",
50+
"@zakodium/tsconfig": "^1.0.2",
51+
"eslint": "^9.39.1",
52+
"eslint-config-cheminfo-typescript": "^21.0.1",
5253
"esm": "^3.2.25",
5354
"ml-dataset-iris": "^1.2.1",
54-
"prettier": "^2.8.3",
55-
"rimraf": "^3.0.2",
56-
"typescript": "^4.9.4",
55+
"prettier": "^3.6.2",
56+
"rimraf": "^6.1.0",
57+
"typescript": "^5.9.3",
5758
"vitest": "^4.0.8"
5859
},
5960
"dependencies": {
60-
"ml-distance-euclidean": "^2.0.0",
61-
"ml-matrix": "^6.9.0",
62-
"ml-nearest-vector": "^2.0.1",
63-
"ml-random": "^0.5.0"
61+
"ml-distance-euclidean": "^3.0.0",
62+
"ml-matrix": "^6.12.1",
63+
"ml-nearest-vector": "^3.0.0",
64+
"ml-random": "^2.0.0"
6465
}
6566
}

src/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
__tests__
2+
*.test.*
23
.npmignore

src/KMeansResult.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { updateClusterID } from './utils';
1+
import { updateClusterID } from './utils.js';
22

33
export interface CentroidWithInformation {
44
centroid: number[];
@@ -13,7 +13,7 @@ export class KMeansResult {
1313
* @param converged - Converge criteria satisfied
1414
* @param iterations - Current number of iterations
1515
* @param distance - Distance function to use between the points
16-
* @constructor
16+
* @class
1717
*/
1818

1919
public clusters: number[];
@@ -37,8 +37,8 @@ export class KMeansResult {
3737

3838
/**
3939
* Allows to compute for a new array of points their cluster id
40-
* @param {Array<Array<number>>} data - the [x,y,z,...] points to cluster
41-
* @return {Array<number>} - cluster id for each point
40+
* @param data - the [x,y,z,...] points to cluster
41+
* @returns - cluster id for each point
4242
*/
4343
nearest(data: number[][]): number[] {
4444
const clusterID = new Array<number>(data.length);
@@ -48,11 +48,11 @@ export class KMeansResult {
4848
/**
4949
* Returns the error and size of each cluster
5050
* @ignore
51-
* @param {Array<Array<number>>} data - the [x,y,z,...] points to cluster
52-
* @return {KMeansResult}
51+
* @param data - the [x,y,z,...] points to cluster
52+
* @returns
5353
*/
5454
computeInformation(data: number[][]): CentroidWithInformation[] {
55-
let enrichedCentroids = this.centroids.map((centroid) => {
55+
const enrichedCentroids = this.centroids.map((centroid) => {
5656
return {
5757
centroid,
5858
error: 0,
@@ -70,7 +70,7 @@ export class KMeansResult {
7070

7171
for (let j = 0; j < this.centroids.length; j++) {
7272
let error = enrichedCentroids[j].error;
73-
if (enrichedCentroids[j].size && error !== -1) {
73+
if (enrichedCentroids[j].size > 0 && error !== -1) {
7474
error /= enrichedCentroids[j].size;
7575
} else {
7676
enrichedCentroids[j].error = -1;

0 commit comments

Comments
 (0)