Skip to content

Commit 9270181

Browse files
Refactor code to use ES module syntax
1 parent c6bcc2f commit 9270181

File tree

11 files changed

+33
-55
lines changed

11 files changed

+33
-55
lines changed

eslint.config.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
"use strict";
1+
import globals from "globals";
2+
import js from "@eslint/js";
23

3-
const globals = require("globals");
4-
const js = require("@eslint/js");
5-
6-
module.exports = [
4+
export default [
75
js.configs.recommended,
86
{
97
languageOptions: {
108
globals: {
119
...globals.builtin,
1210
...globals.node
1311
},
14-
sourceType: "commonjs"
12+
sourceType: "module"
1513
},
1614
rules: {
1715
"array-bracket-spacing": "error",

index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
"use strict";
2-
3-
module.exports = require("./lib/quadprog");
1+
export * from "./lib/quadprog.js";

lib/dpofa.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"use strict";
2-
31
function dpofa(a, lda, n) {
42
let info, jm1, t, s;
53

@@ -35,4 +33,4 @@ function dpofa(a, lda, n) {
3533
return info;
3634
}
3735

38-
module.exports = dpofa;
36+
export default dpofa;

lib/dpori.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"use strict";
2-
31
function dpori(a, lda, n) {
42
let kp1, t;
53

@@ -28,4 +26,4 @@ function dpori(a, lda, n) {
2826
}
2927
}
3028

31-
module.exports = dpori;
29+
export default dpori;

lib/dposl.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"use strict";
2-
31
function dposl(a, lda, n, b) {
42
let k, t;
53

@@ -26,4 +24,4 @@ function dposl(a, lda, n, b) {
2624
}
2725
}
2826

29-
module.exports = dposl;
27+
export default dposl;

lib/qpgen2.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
"use strict";
2-
3-
const vsmall = require("./vsmall");
4-
const dpori = require("./dpori");
5-
const dposl = require("./dposl");
6-
const dpofa = require("./dpofa");
1+
import vsmall from "./vsmall.js";
2+
import dpori from "./dpori.js";
3+
import dposl from "./dposl.js";
4+
import dpofa from "./dpofa.js";
75

86
function qpgen2(dmat, dvec, fddmat, n, sol, lagr, crval, amat, bvec, fdamat, q, meq, iact, nnact, iter, work, ierr) {
97
let l1, it1, nvl, nact, temp, sum, t1, tt, gc, gs, nu, t1inf, t2min, go;
@@ -413,4 +411,4 @@ function qpgen2(dmat, dvec, fddmat, n, sol, lagr, crval, amat, bvec, fdamat, q,
413411

414412
}
415413

416-
module.exports = qpgen2;
414+
export default qpgen2;

lib/quadprog.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"use strict";
2-
3-
const qpgen2 = require("./qpgen2");
1+
import qpgen2 from "./qpgen2.js";
42

53
function solveQP(Dmat, dvec, Amat, bvec = [], meq = 0, factorized = [0, 0]) {
64
const crval = [];
@@ -83,4 +81,4 @@ function solveQP(Dmat, dvec, Amat, bvec = [], meq = 0, factorized = [0, 0]) {
8381
};
8482
}
8583

86-
exports.solveQP = solveQP;
84+
export { solveQP };

lib/vsmall.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"use strict";
2-
31
let epsilon = 1.0e-60;
42
let tmpa;
53
let tmpb;
@@ -10,4 +8,4 @@ do {
108
tmpb = 1 + 0.2 * epsilon;
119
} while (tmpa <= 1 || tmpb <= 1);
1210

13-
module.exports = epsilon;
11+
export default epsilon;

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"description": "Module for solving quadratic programming problems",
44
"version": "1.6.1",
55
"main": "index",
6+
"type": "module",
67
"repository": "http://github.com/albertosantini/quadprog",
78
"keywords": [
89
"quadprog",
@@ -15,7 +16,7 @@
1516
"node": ">=18.x"
1617
},
1718
"scripts": {
18-
"test": "npm run lint && node --test test/solution-test.js && npm run benchmark",
19+
"test": "npm run lint && node --test --test-reporter=spec test/solution-test.js && npm run benchmark",
1920
"lint": "eslint .",
2021
"benchmark": "node test/bench.js"
2122
},

test/bench.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
"use strict";
2-
3-
const fs = require("node:fs");
4-
5-
const { performance } = require("node:perf_hooks");
6-
7-
const solve = require("../lib/quadprog").solveQP;
1+
import { readFileSync, readdirSync } from "node:fs";
2+
import { performance } from "node:perf_hooks";
3+
import { solveQP } from "../lib/quadprog.js";
84

95
function wsolve(file) {
106
const {
@@ -14,13 +10,13 @@ function wsolve(file) {
1410
bvec,
1511
meq,
1612
factorized
17-
} = JSON.parse(fs.readFileSync(file).toString());
13+
} = JSON.parse(readFileSync(file).toString());
1814

1915
[Dmat, Amat].forEach(m => m.forEach(r => r.unshift(0)));
2016
[Dmat, dvec, Amat, bvec].forEach(v => v.unshift([]));
2117

2218
function wrapped() {
23-
solve(
19+
solveQP(
2420
Dmat.map(r => r.slice()),
2521
dvec.slice(),
2622
Amat.map(r => r.slice()),
@@ -32,7 +28,7 @@ function wsolve(file) {
3228
return wrapped;
3329
}
3430

35-
fs.readdirSync("test")
31+
readdirSync("test")
3632
.filter(f => f.endsWith("-data.json"))
3733
.forEach(f => {
3834
const testName = f.slice(0, -10);

0 commit comments

Comments
 (0)