alexbol99 / flatten-js

Javascript library for 2d geometry
MIT License
551 stars 58 forks source link

Errors export #157

Closed edemaine closed 9 months ago

edemaine commented 10 months ago

The Errors class is documented, but doesn't seem to be exported correctly. Instead of being a class, it's an object with default property that is the class. The ESM code looks OK, so it's probably a bundling bug...

Also, the Errors export is missing from the .d.ts file.

Context: I think Errors is useful for detecting that we got a division-by-zero error instead of something else.

alexbol99 commented 10 months ago

Class Error exported in new release v1.4.6, you can check flatten-js errors like this:

import {Errors, vector} from "@flatten-js/core";

try {
    const v = vector(0,0)
    v.normalize()
}
catch (e) {
    console.log(e.message === Errors.ZERO_DIVISION.message)
}
alexbol99 commented 9 months ago

Fixed in v1.4.6