diff --git a/README.md b/README.md index 389c9b5..0a00cda 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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... ``` diff --git a/index.js b/index.js index 9a0f76b..b6b1bdc 100644 --- a/index.js +++ b/index.js @@ -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. diff --git a/package.json b/package.json index 2a9dfde..2ec232d 100644 --- a/package.json +++ b/package.json @@ -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", @@ -15,11 +16,6 @@ "keywords": [ "point" ], - "exports": { - "types": "./index.d.ts", - "require": "./index.js", - "import": "./wrapper.mjs" - }, "author": "Andrew Kelley", "license": "BSD", "devDependencies": { @@ -27,7 +23,6 @@ "standard": "^17.0.0", "tsd": "^0.25.0" }, - "dependencies": {}, "tsd": { "directory": "test" }, @@ -35,4 +30,4 @@ "type": "git", "url": "https://github.com/PrismarineJS/node-vec3.git" } -} +} \ No newline at end of file diff --git a/test/index.test-d.ts b/test/index.test-d.ts index 896d491..04508f9 100644 --- a/test/index.test-d.ts +++ b/test/index.test-d.ts @@ -1,5 +1,5 @@ import { expectType } from "tsd"; -import vec3, { Vec3 } from ".."; +import vec3, { Vec3 } from "../"; const vec = vec3([1, 2, 3]); expectType(vec); diff --git a/test/test.js b/test/test.js index 1c24eec..c69159d 100644 --- a/test/test.js +++ b/test/test.js @@ -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) @@ -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) diff --git a/wrapper.mjs b/wrapper.mjs deleted file mode 100644 index e6ef4fb..0000000 --- a/wrapper.mjs +++ /dev/null @@ -1,4 +0,0 @@ -import mod from './index.js' - -export default mod -export const Vec3 = mod.Vec3