Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# vec3

[![NPM version](https://img.shields.io/npm/v/vec3.svg)](http://npmjs.com/package/vec3)
[![Build Status](https://github.com/PrismarineJS/node-vec3/workflows/CI/badge.svg)](https://github.com/PrismarineJS/node-vec3/actions?query=workflow%3A%22CI%22)

Expand All @@ -7,20 +8,21 @@
## Usage

```js
var v = require('vec3');
import { v, Vec3 } from 'vec3'

var v1 = v(1, 2, 3);
const v1 = v(1, 2, 3);
console.log(v1); // prints "(1, 2, 3)"
var v2 = v1.offset(0, 0, 1);
const v2 = v1.offset(0, 0, 1);
console.log(v2); // prints "(1, 2, 4)"

const v3 = new Vec3(0, 1, 2);
```

Or:
Or _if you prefer_ CommonJS:

```js
var Vec3 = require('vec3').Vec3;

var v1 = new Vec3(1, 2, 3);
const v = require('vec3')
const Vec3 = v.Vec3
// etc...
```

Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,5 +265,7 @@ function euclideanMod (numerator, denominator) {
return result < 0 ? result + denominator : result
}

module.exports = v
v.Vec3 = Vec3
export default v // So that import v from 'vec3' works.
export { v as 'module.exports' } // So that const v = require('vec3') works.
export { Vec3, v } // So that import { Vec3, v } from 'vec3' and const { Vec3, v } = require('vec3') work.
11 changes: 3 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "vec3",
"version": "0.1.10",
"version": "0.1.11",
"description": "3d vector math with good unit tests",
"main": "index.js",
"types": "index.d.ts",
"type": "module",
"scripts": {
"test": "npm run test-js && npm run test-types",
"test-js": "mocha --reporter spec",
Expand All @@ -15,24 +16,18 @@
"keywords": [
"point"
],
"exports": {
"types": "./index.d.ts",
"require": "./index.js",
"import": "./wrapper.mjs"
},
"author": "Andrew Kelley",
"license": "BSD",
"devDependencies": {
"mocha": "^11.0.1",
"standard": "^17.0.0",
"tsd": "^0.25.0"
},
"dependencies": {},
"tsd": {
"directory": "test"
},
"repository": {
"type": "git",
"url": "https://github.com/PrismarineJS/node-vec3.git"
}
}
}
2 changes: 1 addition & 1 deletion test/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expectType } from "tsd";
import vec3, { Vec3 } from "..";
import vec3, { Vec3 } from "../";

const vec = vec3([1, 2, 3]);
expectType<Vec3>(vec);
Expand Down
10 changes: 5 additions & 5 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* eslint-env mocha */

const v = require('../')
const Vec3 = v.Vec3
const assert = require('assert')
import assert from 'node:assert'
import { v, Vec3 } from '../index.js'

describe('v()', function () {
describe('v() esm', function () {
it('no args', function () {
const v1 = v()
assert.strictEqual(v1.x, 0)
Expand Down Expand Up @@ -51,7 +50,8 @@ describe('v()', function () {
}, /cannot parse/)
})
})
describe('vec3', function () {

describe('vec3 esm', function () {
it('isZero', function () {
const v1 = new Vec3(0, 1, 2)
const v2 = new Vec3(0, 0, 0)
Expand Down
4 changes: 0 additions & 4 deletions wrapper.mjs

This file was deleted.