@wlearn/libsvm 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,15 +1,19 @@
1
1
  {
2
2
  "name": "@wlearn/libsvm",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "LIBSVM v3.37 compiled to WebAssembly -- SVM classification, regression, and novelty detection in browsers and Node.js",
5
- "type": "module",
5
+ "type": "commonjs",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
- ".": "./src/index.js"
8
+ ".": {
9
+ "require": "./src/index.js",
10
+ "default": "./src/index.js"
11
+ }
9
12
  },
10
13
  "files": [
11
14
  "src/",
12
15
  "wasm/",
16
+ "dist/",
13
17
  "LICENSE",
14
18
  "README.md",
15
19
  "CHANGELOG.md"
@@ -19,9 +23,12 @@
19
23
  "access": "public"
20
24
  },
21
25
  "scripts": {
22
- "test": "node --experimental-vm-modules test/test.js",
26
+ "test": "node test/test.js",
23
27
  "build": "bash scripts/build-wasm.sh",
24
- "verify": "bash scripts/verify-exports.sh"
28
+ "verify": "bash scripts/verify-exports.sh",
29
+ "build:browser": "bash scripts/build-browser.sh",
30
+ "prepack": "node scripts/prepack.js",
31
+ "prepublishOnly": "node scripts/prepublish.js"
25
32
  },
26
33
  "keywords": [
27
34
  "libsvm",
@@ -33,9 +40,20 @@
33
40
  "wlearn"
34
41
  ],
35
42
  "author": "Anton Zemlyansky",
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "https://github.com/wlearn-org/libsvm-wasm.git"
46
+ },
36
47
  "license": "BSD-3-Clause",
37
48
  "dependencies": {
38
- "@wlearn/types": "0.1.0",
39
- "@wlearn/core": "0.1.0"
40
- }
49
+ "@wlearn/core": "0.2.0"
50
+ },
51
+ "devDependencies": {
52
+ "esbuild": "^0.27.3",
53
+ "playwright": "^1.58.2"
54
+ },
55
+ "bugs": {
56
+ "url": "https://github.com/wlearn-org/libsvm-wasm/issues"
57
+ },
58
+ "homepage": "https://wlearn.org"
41
59
  }
package/src/index.js CHANGED
@@ -1,17 +1,22 @@
1
- export { loadSVM, getWasm } from './wasm.js'
2
- export { SVMModel, SVMType, Kernel } from './model.js'
1
+ const { loadSVM, getWasm } = require('./wasm.js')
2
+ const { SVMModel: SVMModelImpl, SVMType, Kernel } = require('./model.js')
3
+ const { createModelClass } = require('@wlearn/core')
4
+
5
+ const SVMModel = createModelClass(SVMModelImpl, SVMModelImpl, { name: 'SVMModel', load: loadSVM })
3
6
 
4
7
  // Convenience: create, fit, return fitted model
5
- export async function train(params, X, y) {
6
- const model = await (await import('./model.js')).SVMModel.create(params)
7
- model.fit(X, y)
8
+ async function train(params, X, y) {
9
+ const model = await SVMModel.create(params)
10
+ await model.fit(X, y)
8
11
  return model
9
12
  }
10
13
 
11
14
  // Convenience: load WLRN bundle and predict, auto-disposes model
12
- export async function predict(bundleBytes, X) {
13
- const model = await (await import('./model.js')).SVMModel.load(bundleBytes)
15
+ async function predict(bundleBytes, X) {
16
+ const model = await SVMModel.load(bundleBytes)
14
17
  const result = model.predict(X)
15
18
  model.dispose()
16
19
  return result
17
20
  }
21
+
22
+ module.exports = { loadSVM, getWasm, SVMModel, SVMType, Kernel, train, predict }
package/src/model.js CHANGED
@@ -1,10 +1,10 @@
1
- import { getWasm, loadSVM } from './wasm.js'
2
- import {
1
+ const { getWasm, loadSVM } = require('./wasm.js')
2
+ const {
3
3
  normalizeX, normalizeY,
4
4
  encodeBundle, decodeBundle,
5
5
  register,
6
6
  DisposedError, NotFittedError
7
- } from '@wlearn/core'
7
+ } = require('@wlearn/core')
8
8
 
9
9
  // FinalizationRegistry safety net -- warns if dispose() was never called
10
10
  const leakRegistry = typeof FinalizationRegistry !== 'undefined'
@@ -18,7 +18,7 @@ const leakRegistry = typeof FinalizationRegistry !== 'undefined'
18
18
 
19
19
  // --- SVM type and kernel constants ---
20
20
 
21
- export const SVMType = {
21
+ const SVMType = {
22
22
  C_SVC: 0,
23
23
  NU_SVC: 1,
24
24
  ONE_CLASS: 2,
@@ -26,7 +26,7 @@ export const SVMType = {
26
26
  NU_SVR: 4
27
27
  }
28
28
 
29
- export const Kernel = {
29
+ const Kernel = {
30
30
  LINEAR: 0,
31
31
  POLY: 1,
32
32
  RBF: 2,
@@ -59,7 +59,7 @@ const LOAD_SENTINEL = Symbol('load')
59
59
 
60
60
  // --- SVMModel ---
61
61
 
62
- export class SVMModel {
62
+ class SVMModel {
63
63
  #handle = null
64
64
  #freed = false
65
65
  #ptrRef = null
@@ -479,3 +479,5 @@ export class SVMModel {
479
479
 
480
480
  register('wlearn.libsvm.classifier@1', (m, t, b) => SVMModel._fromBundle(m, t, b))
481
481
  register('wlearn.libsvm.regressor@1', (m, t, b) => SVMModel._fromBundle(m, t, b))
482
+
483
+ module.exports = { SVMModel, SVMType, Kernel }
package/src/wasm.js CHANGED
@@ -1,19 +1,15 @@
1
1
  // WASM loader -- loads the LIBSVM WASM module (singleton, lazy init)
2
2
 
3
- import { createRequire } from 'module'
4
-
5
3
  let wasmModule = null
6
4
  let loading = null
7
5
 
8
- export async function loadSVM(options = {}) {
6
+ async function loadSVM(options = {}) {
9
7
  if (wasmModule) return wasmModule
10
8
  if (loading) return loading
11
9
 
12
10
  loading = (async () => {
13
11
  // SINGLE_FILE=1: .wasm is embedded in the .js file, no locateFile needed
14
- // Emscripten output is CJS, use createRequire for ESM compatibility
15
- const require = createRequire(import.meta.url)
16
- const createSVM = require('../wasm/svm.cjs')
12
+ const createSVM = require('../wasm/svm.js')
17
13
  wasmModule = await createSVM(options)
18
14
  return wasmModule
19
15
  })()
@@ -21,7 +17,9 @@ export async function loadSVM(options = {}) {
21
17
  return loading
22
18
  }
23
19
 
24
- export function getWasm() {
20
+ function getWasm() {
25
21
  if (!wasmModule) throw new Error('WASM not loaded -- call loadSVM() first')
26
22
  return wasmModule
27
23
  }
24
+
25
+ module.exports = { loadSVM, getWasm }
package/wasm/BUILD_INFO CHANGED
@@ -1,6 +1,6 @@
1
1
  upstream: libsvm v3.37
2
2
  upstream_commit: 6b907139084abf2da4d6d3cb10dc3b7eaffa2fbb
3
- build_date: 2026-02-27T13:03:12Z
3
+ build_date: 2026-05-25T14:47:52Z
4
4
  emscripten: emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 5.0.2 (dc80f645ee70178c11666de0c3860d9e064d50e4)
5
5
  build_flags: -O2 SINGLE_FILE=1
6
6
  wasm_embedded: true