Skip to content

Commit

Permalink
turn Delaunator into a ES module
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner committed Mar 23, 2018
1 parent 9163638 commit 380c888
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 23 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,22 @@ console.log(delaunay.triangles);

## Install

Install with NPM (`npm install delaunator`), or use the following builds in the browser:
Install with NPM (`npm install delaunator`) or Yarn (`yarn add delaunator`), then:

- [development build](https://unpkg.com/[email protected]/delaunator.js)
- [minified build](https://unpkg.com/[email protected]/delaunator.min.js)
```js
// import as an ES module
import Delaunator from 'delaunator';

// or require in Node / Browserify
const Delaunator = require('delaunator');
```

Or use a browser build directly:

```html
<script src="https://unpkg.com/[email protected]/delaunator.min.js"></script> <!-- minified build -->
<script src="https://unpkg.com/[email protected]/delaunator.js"></script> <!-- dev build -->
```

## API Reference

Expand Down
4 changes: 2 additions & 2 deletions bench.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'; /* eslint no-new: 0, no-unused-vars: 0 */
/* eslint no-unused-vars: 0 */

var Delaunator = require('./');
var Delaunator = require('./index.js').default;
// var fasterDelaunay = require('faster-delaunay');
// var incrementalDelaunay = require('incremental-delaunay');
// var delaunayFast = require('delaunay-fast');
Expand Down
6 changes: 1 addition & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
'use strict';

module.exports = Delaunator;
module.exports.default = Delaunator;

Delaunator.from = function (points, getX, getY) {
if (!getX) getX = defaultGetX;
Expand All @@ -19,7 +15,7 @@ Delaunator.from = function (points, getX, getY) {
return new Delaunator(coords);
};

function Delaunator(coords) {
export default function Delaunator(coords) {
if (!ArrayBuffer.isView(coords)) throw new Error('Expected coords to be a typed array.');

var minX = Infinity;
Expand Down
30 changes: 18 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,41 @@
"name": "delaunator",
"version": "1.0.5",
"description": "A really fast JavaScript library for Delaunay triangulation of 2D points",
"main": "index.js",
"jsdelivr": "delaunator.js",
"unpkg": "delaunator.js",
"main": "delaunator.js",
"module": "index.js",
"jsdelivr": "delaunator.min.js",
"unpkg": "delaunator.min.js",
"dependencies": {},
"devDependencies": {
"browserify": "^14.5.0",
"eslint": "^4.0.0",
"eslint-config-mourner": "^2.0.1",
"tape": "^4.6.3",
"uglify-js": "^3.2.0"
"esm": "^3.0.8",
"rollup": "^0.57.1",
"rollup-plugin-uglify": "^3.0.0",
"tape": "^4.6.3"
},
"repository": {
"type": "git",
"url": "https://github.com/mapbox/delaunator.git"
},
"scripts": {
"lint": "eslint index.js test.js bench.js",
"pretest": "npm run lint",
"test": "tape test.js",
"build": "browserify index.js -s Delaunator -o delaunator.js",
"build-min": "browserify index.js -s Delaunator | uglifyjs -c -m > delaunator.min.js",
"prepare": "npm run build && npm run build-min"
"pretest": "npm run lint && npm run build",
"test": "node test.js",
"bench": "node -r esm bench.js",
"build": "rollup -c",
"prepublishOnly": "npm test && npm run build"
},
"files": [
"index.js",
"delaunator.js",
"delaunator.min.js"
],
"eslintConfig": {
"extends": "mourner"
"extends": "mourner",
"parserOptions": {
"sourceType": "module"
}
},
"keywords": [
"delaunay triangulation",
Expand Down
16 changes: 16 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import uglify from 'rollup-plugin-uglify'

const config = (file, plugins) => ({
input: 'index.js',
output: {
name: 'Delaunator',
format: 'umd',
file
},
plugins
});

export default [
config('delaunator.js', []),
config('delaunator.min.js', [uglify()])
];
1 change: 0 additions & 1 deletion test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 380c888

Please sign in to comment.