Skip to content

Commit 1f70a88

Browse files
authored
Convert to Typescript (#2)
* Update package.json, add typescript, vitest * Convert to typescript * Fix lints * Prefer function over lambdas, type instead of class, preserve original ordering * Update tests * Add rollup * Get eslint running * Add CI * Prepare for onboarding * Remove old example, add coverage reporting * fix lint: Use `interface` instead of `type` * Fix coverage reporting * Fix comparison, remove comment types
1 parent a112362 commit 1f70a88

24 files changed

+11885
-4195
lines changed

.circleci/config.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

.eslintrc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
"extends": "standard"
3-
};
2+
extends: 'standard'
3+
}

.github/FUNDING.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github: [maplibre]
2+
open_collective: maplibre

.github/workflows/unit-tests.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Unit Tests
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
8+
jobs:
9+
build:
10+
name: Build and Test
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
node-version: [20.x, 22.x]
15+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
submodules: 'recursive'
20+
- name: Use Node.js ${{ matrix.node-version }}
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: ${{ matrix.node-version }}
24+
cache: 'npm'
25+
- run: npm ci
26+
- run: npm run lint
27+
- run: npm run build
28+
- run: npm run test-unit
29+
30+
run-tests:
31+
name: Generate Coverage
32+
runs-on: ubuntu-latest
33+
strategy:
34+
matrix:
35+
node-version: [22.x]
36+
steps:
37+
- uses: actions/checkout@v4
38+
with:
39+
submodules: 'recursive'
40+
- name: Use Node.js ${{ matrix.node-version }}
41+
uses: actions/setup-node@v4
42+
with:
43+
node-version: ${{ matrix.node-version }}
44+
cache: 'npm'
45+
- run: npm ci
46+
- run: npm run test-unit-ci
47+
- name: Upload test results to Codecov
48+
if: '!cancelled()'
49+
uses: codecov/test-results-action@v1
50+
with:
51+
token: ${{ secrets.CODECOV_TOKEN }}
52+
- name: Upload coverage reports to Codecov
53+
uses: codecov/codecov-action@v5
54+
with:
55+
files: ${{ github.workspace }}/coverage/vitest/unit/coverage-final.json
56+
verbose: true
57+
token: ${{ secrets.CODECOV_TOKEN }}
58+
disable_search: true

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules
1+
node_modules
2+
dist

CODE_OF_CONDUCT.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Contributor Covenant
2+
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](https://github.com/maplibre/maplibre/blob/main/CODE_OF_CONDUCT.md)

CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Contributing
2+
3+
Thanks for getting involved and contributing to vt-pbf. Below are a few things to keep in mind when submitting a PR.
4+
5+
* If adding new functionality, consider adding tests for it! Run the unit tests locally: `npm run test-unit`.
6+
* Make sure you run the linter and address any issues: `npm run lint`.
7+
* We're using rollup to bundle releases, run `npm run build` to create a new release inside `dist/`.

LICENSE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
The MIT License (MIT)
22

3+
Copyright (c) 2025 MapLibre contributors
4+
35
Copyright (c) 2015 Anand Thakker
46

57
Permission is hereby granted, free of charge, to any person obtaining a copy

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# vt-pbf [![CircleCI](https://circleci.com/gh/mapbox/vt-pbf.svg?style=svg)](https://circleci.com/gh/mapbox/vt-pbf)
1+
[![MapLibre Logo](https://maplibre.org/img/maplibre-logo-big.svg)](https://maplibre.org/)
2+
3+
# vt-pbf
24

35
Serialize [Mapbox vector tiles](https://github.com/mapbox/vector-tile-spec) to binary protobufs in javascript.
46

@@ -13,34 +15,34 @@ different:
1315
## From vector-tile-js
1416

1517
```javascript
16-
var vtpbf = require('vt-pbf')
17-
var VectorTile = require('@mapbox/vector-tile').VectorTile
18-
var Protobuf = require('pbf')
18+
import {fromVectorTileJs} from 'vt-pbf'
19+
import {VectorTile} = from '@mapbox/vector-tile'
20+
import Protobuf from 'pbf'
1921

2022
var data = fs.readFileSync(__dirname + '/fixtures/rectangle-1.0.0.pbf')
2123
var tile = new VectorTile(new Protobuf(data))
2224
var orig = tile.layers['geojsonLayer'].feature(0).toGeoJSON(0, 0, 1)
2325

24-
var buff = vtpbf(tile)
26+
var buff = fromVectorTileJs(tile)
2527
fs.writeFileSync('my-tile.pbf', buff)
2628
```
2729

2830
## From geojson-vt
2931

3032
```javascript
31-
var vtpbf = require('vt-pbf')
32-
var geojsonVt = require('geojson-vt')
33+
import {fromGeojsonVt} from 'vt-pbf'
34+
import geojsonVt from 'geojson-vt'
3335

3436
var orig = JSON.parse(fs.readFileSync(__dirname + '/fixtures/rectangle.geojson'))
3537
var tileindex = geojsonVt(orig)
3638
var tile = tileindex.getTile(1, 0, 0)
3739

3840
// pass in an object mapping layername -> tile object
39-
var buff = vtpbf.fromGeojsonVt({ 'geojsonLayer': tile })
41+
var buff = fromGeojsonVt({ 'geojsonLayer': tile })
4042
fs.writeFileSync('my-tile.pbf', buff)
4143
```
4244

43-
`vtpbf.fromGeojsonVt` takes two arguments:
45+
`fromGeojsonVt` takes two arguments:
4446
- `layerMap` is an object where keys are layer names and values are a geojson-vt tile,
4547
- `options` is an object (optional argument). There are 2 supported keys: `version` to define the version of the mvt spec used and `extent` to define the extent of the tile. `version` defaults to 1 and `extent` to 4096.
4648

SECURITY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
For an up-to-date policy refer to
2+
https://github.com/maplibre/maplibre/blob/main/SECURITY.md

0 commit comments

Comments
 (0)