@sstorsveen/maths
v2.0.1
Published
Maths library for JS/TS
Maintainers
Readme
maths-js
A small TypeScript/JavaScript library of mathematical functions, mainly vector and matrix utilities.
Documentation
Installation
As an npm package:
$ npm install @sstorsveen/mathsSample usage
Create a file sample.ts:
// import a module
import * as vec2 from '@sstorsveen/maths/vec2';
// initialize a new vector object
const v = vec2.of(1.0, 1.0);
// normalise the vector
vec2.norm(v);
// output the result
console.log(`v = [ ${v.x} ${v.y} ]`);Compile to JavaScript using the TypeScript compiler:
$ tsc sample.tsBundle with e.g. Google Closure Compiler:
$ google-closure-compiler \
--process_common_js_modules=true \
--module_resolution=NODE \
--js=node_modules/@sstorsveen/maths/*.js \
--js=sample.js \
--js_output_file=out.jsRun the bundled code to see the result:
$ node out.js
v = [ 0.7071067811865475 0.7071067811865475 ]