Skip to content

Commit

Permalink
Make rbush an ES6 library (mourner#89)
Browse files Browse the repository at this point in the history
* Make rbush an ES6 library.

* Update package.json and rollup config

* Fix gitignore and travis config
  • Loading branch information
rowanwins authored and mourner committed May 10, 2019
1 parent 175cb6a commit 7c16ca1
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
npm-debug.log
coverage
.nyc_output
rbush.js
rbush.min.js
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: node_js
node_js:
- "4"
- "8"
- "stable"
4 changes: 1 addition & 3 deletions bench/perf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
import rbush from '..';

var N = 1000000,
maxFill = 16;
Expand Down Expand Up @@ -31,8 +31,6 @@ var bboxes100 = genData(1000, 100 * Math.sqrt(0.1));
var bboxes10 = genData(1000, 10);
var bboxes1 = genData(1000, 1);

var rbush = typeof require !== 'undefined' ? require('..') : rbush;

var tree = rbush(maxFill);

console.time('insert one by one');
Expand Down
9 changes: 2 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
'use strict';
import quickselect from 'quickselect';

module.exports = rbush;
module.exports.default = rbush;

var quickselect = require('quickselect');

function rbush(maxEntries, format) {
export default function rbush(maxEntries, format) {
if (!(this instanceof rbush)) return new rbush(maxEntries, format);

// max entries in a node is 9 by default; min node fill is 40% for best performance
Expand Down
37 changes: 23 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,48 @@
],
"author": "Vladimir Agafonkin",
"license": "MIT",
"main": "index.js",
"jsdelivr": "rbush.js",
"unpkg": "rbush.js",
"main": "rbush.js",
"module": "index.js",
"browser": "rbush.min.js",
"jsdelivr": "rbush.min.js",
"unpkg": "rbush.min.js",
"devDependencies": {
"benchmark": "^2.1.4",
"browserify": "^14.5.0",
"eslint": "^4.13.1",
"eslint-config-mourner": "^2.0.3",
"esm": "^3.0.84",
"faucet": "0.0.1",
"istanbul": "~0.4.5",
"tape": "^4.8.0",
"uglify-js": "^3.2.2"
"nyc": "^13.1.0",
"rollup": "^0.67.3",
"rollup-plugin-node-resolve": "^3.4.0",
"rollup-plugin-terser": "^3.0.0",
"tape": "^4.8.0"
},
"scripts": {
"test": "eslint index.js test/test.js && node test/test.js | faucet",
"perf": "node ./bench/perf.js",
"cov": "istanbul cover test/test.js -x test/test.js",
"build": "browserify index.js -s rbush -o rbush.js",
"build-min": "browserify index.js -s rbush | uglifyjs -c warnings=false -m > rbush.min.js",
"prepare": "npm run build && npm run build-min"
"pretest": "eslint index.js test/test.js ",
"test": "node -r esm test/test.js | faucet",
"perf": "node -r esm ./bench/perf.js",
"cov": "nyc --check-coverage --require esm npm test",
"build": "rollup -c",
"prepare": "npm run build",
"prepublishOnly": "npm run build"
},
"files": [
"index.js",
"rbush.js",
"rbush.min.js"
],
"eslintConfig": {
"extends": "mourner",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"new-cap": 0,
"consistent-return": 0
}
},
"dependencies": {
"quickselect": "^1.0.1"
"quickselect": "^2.0.0"
}
}
17 changes: 17 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {terser} from 'rollup-plugin-terser';
import resolve from 'rollup-plugin-node-resolve';

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

export default [
output('rbush.js', [resolve()]),
output('rbush.min.js', [resolve(), terser()])
];
5 changes: 2 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
'use strict';

/*eslint key-spacing: 0, comma-spacing: 0 */

var rbush = require('..'),
t = require('tape');
import rbush from '..';
import t from 'tape';

function sortedEqual(t, a, b, compare) {
compare = compare || defaultCompare;
Expand Down

0 comments on commit 7c16ca1

Please sign in to comment.