Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/modernize'
Browse files Browse the repository at this point in the history
  • Loading branch information
pirxpilot committed Feb 22, 2024
2 parents cb2c65d + e461925 commit 90d5776
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 357 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/check.yaml
@@ -0,0 +1,12 @@
name: check
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- uses: actions/setup-node@main
with:
node-version: 'lts/*'
- run: yarn install
- run: make check
3 changes: 1 addition & 2 deletions .jshintrc
Expand Up @@ -4,12 +4,11 @@
"eqnull": true,
"immed": true,
"latedef": "nofunc",
"mocha" : true,
"newcap": true,
"noarg": true,
"node": true,
"sub": true,
"undef": true,
"unused": true,
"esversion": 6
"esversion": 11
}
4 changes: 2 additions & 2 deletions Makefile
@@ -1,9 +1,9 @@
check: lint test

lint:
./node_modules/.bin/jshint *.js lib test
./node_modules/.bin/jshint *.js test

test:
./node_modules/.bin/mocha --recursive --require should
node --test

.PHONY: check lint test
14 changes: 7 additions & 7 deletions Readme.md
@@ -1,6 +1,6 @@
[![NPM version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Dependency Status][gemnasium-image]][gemnasium-url]
[![Build Status][build-image]][build-url]
[![Dependency Status][deps-image]][deps-url]

# dump-tile

Expand All @@ -26,11 +26,11 @@ cat tile.pbf | dump-tile > tile.json

MIT © [Damian Krzeminski](https://furkot.com)

[npm-image]: https://img.shields.io/npm/v/dump-tile.svg
[npm-image]: https://img.shields.io/npm/v/dump-tile
[npm-url]: https://npmjs.org/package/dump-tile

[travis-url]: https://travis-ci.org/pirxpilot/dump-tile
[travis-image]: https://img.shields.io/travis/pirxpilot/dump-tile.svg
[build-url]: https://github.com/pirxpilot/dump-tile/actions/workflows/check.yaml
[build-image]: https://img.shields.io/github/actions/workflow/status/pirxpilot/dump-tile/check.yaml?branch=main

[gemnasium-image]: https://img.shields.io/gemnasium/pirxpilot/dump-tile.svg
[gemnasium-url]: https://gemnasium.com/pirxpilot/dump-tile
[deps-image]: https://img.shields.io/librariesio/release/npm/dump-tile
[deps-url]: https://libraries.io/npm/dump-tile
10 changes: 6 additions & 4 deletions index.js
@@ -1,11 +1,14 @@
#!/usr/bin/env node

const concat = require('concat-stream');
const { buffer } = require('node:stream/consumers');
const Pbf = require('pbf');
const { VectorTile } = require('@mapbox/vector-tile');

module.exports = dump;

function dump(input, output) {
input.pipe(concat(buffer => dumpBuffer(buffer, output)));
return buffer(input)
.then(buffer => dumpBuffer(buffer, output));
}

function dumpBuffer(buffer, output) {
Expand Down Expand Up @@ -38,7 +41,7 @@ function dumpFeature(vf) {

function dumpGeometry(vg) {
function convertRing(ring) {
return ring.reduce(function(r, { x, y }) {
return ring.reduce(function (r, { x, y }) {
r.push(x, y);
return r;
}, []);
Expand All @@ -49,4 +52,3 @@ function dumpGeometry(vg) {
if (!module.parent) {
dump(process.stdin, process.stdout);
}

9 changes: 3 additions & 6 deletions package.json
Expand Up @@ -7,7 +7,7 @@
"email": "pirxpilot@furkot.com",
"url": "https://furkot.com"
},
"repository": "pirxpilot/dump-tile",
"repository": "github:pirxpilot/dump-tile",
"bin": "./index.js",
"license": "MIT",
"keywords": [
Expand All @@ -18,18 +18,15 @@
],
"dependencies": {
"@mapbox/vector-tile": "^1.3.1",
"concat-stream": "^1.6.1",
"pbf": "^3.1.0"
},
"devDependencies": {
"jshint": "^2.9.5",
"mocha": "^5.0.4",
"should": "^13.2.1"
"@pirxpilot/jshint": "~3"
},
"scripts": {
"test": "make check"
},
"files": [
"index.js"
]
}
}
34 changes: 28 additions & 6 deletions test/dump-tile.js
@@ -1,9 +1,31 @@
var should = require('should');
var dumpTile = require('../');
const test = require('node:test');
const assert = require('node:assert/strict');

describe('dump-tile node module', function () {
it('must have at least one test', function () {
dumpTile();
should.fail('Need to write tests.');
const { createReadStream } = require('node:fs');
const { PassThrough } = require('node:stream');
const { buffer } = require('node:stream/consumers');

const dumpTile = require('../');

test('dump tile', async function (t) {

await t.test('empty tile', async function () {
const o = await parseToObject('test/fixtures/empty.pbf');
assert.deepEqual(o, { layers: [] });
});

await t.test('simple tile', async function () {
const o = await parseToObject('test/fixtures/data.pbf');
assert(Array.isArray(o.layers));
assert.equal(o.layers.length, 16);
});

});

async function parseToObject(filename) {
const from = createReadStream(filename);
const to = new PassThrough();
await dumpTile(from, to);
to.end();
return JSON.parse((await buffer(to)));
}
Binary file added test/fixtures/data.pbf
Binary file not shown.
Binary file added test/fixtures/empty.pbf
Binary file not shown.

0 comments on commit 90d5776

Please sign in to comment.