Skip to content

Commit 97b76e9

Browse files
committed
Use ES modules, add types and github action checks
1 parent 8aa025b commit 97b76e9

File tree

9 files changed

+73
-46
lines changed

9 files changed

+73
-46
lines changed

.circleci/config.yml

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

.github/workflows/pullrequest.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Node.js CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: Setup Node.js
16+
uses: actions/setup-node@v3
17+
with:
18+
node-version: '20.x'
19+
- run: npm ci
20+
- run: npm run build --if-present
21+
- run: npm test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
**/*.d.ts

index.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ var italicRE = /(italic|oblique)$/i;
2929

3030
var fontCache = {};
3131

32-
module.exports = function(fonts, size, lineHeight) {
32+
/**
33+
* @param {string|Array<string>} fonts Mapbox GL Style fontstack or single font, e.g. `['Open Sans Regular', 'Arial Unicode MS Regular']` or `'Open Sans Regular'`.
34+
* @param {number} size Font size in pixels.
35+
* @param {string|number} [lineHeight] Line height as css line-height.
36+
* @returns {string} CSS font definition, e.g. `'normal 400 16px/1.2 "Open Sans"'`.
37+
*/
38+
export default function(fonts, size, lineHeight) {
3339
var cssData = fontCache[fonts];
3440
if (!cssData) {
3541
if (!Array.isArray(fonts)) {
@@ -79,4 +85,4 @@ module.exports = function(fonts, size, lineHeight) {
7985
cssData = fontCache[fonts] = [style, weight, fontFamilies];
8086
}
8187
return cssData[0] + sp + cssData[1] + sp + size + 'px' + (lineHeight ? '/' + lineHeight : '') + sp + cssData[2];
82-
};
88+
}

package-lock.json

Lines changed: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
"name": "mapbox-to-css-font",
3-
"version": "2.4.5",
3+
"version": "3.0.0",
44
"description": "Utility to convert Mapbox GL Style font names to CSS font definitions",
5-
"main": "index.js",
5+
"type": "module",
6+
"module": "index.js",
7+
"types": "index.d.ts",
68
"repository": {
79
"type": "git",
810
"url": "git://github.com/openlayers/mapbox-to-css-font.git"
@@ -16,14 +18,16 @@
1618
"scripts": {
1719
"lint": "eslint *.js test",
1820
"pretest": "npm run lint",
19-
"test": "mocha test/index.test.js"
21+
"test": "mocha test/index.test.js && tsc -p tsconfig.build.json --noEmit",
22+
"prepare": "tsc --emitDeclarationOnly -p tsconfig.build.json"
2023
},
2124
"devDependencies": {
2225
"eslint": "^5.15.0",
2326
"eslint-config-openlayers": "^11.0.0",
2427
"karma-mocha": "^2.0.1",
2528
"mocha": "^10.2.0",
2629
"should": "^13.2.3",
27-
"sinon": "^7.2.7"
30+
"sinon": "^7.2.7",
31+
"typescript": "^5.5.3"
2832
}
2933
}

test/index.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-env mocha */
2-
const should = require('should');
3-
const parseFont = require('../index.js');
2+
import should from 'should';
3+
import parseFont from '../index.js';
44

55
describe('mapbox-to-css-font', function() {
66

tsconfig.build.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"allowJs": true,
4+
"checkJs": true,
5+
"lib": ["es2015"],
6+
"declaration": true,
7+
"declarationMap": true
8+
},
9+
"include": ["**/*.js"],
10+
"exclude": ["node_modules", "test"]
11+
}

0 commit comments

Comments
 (0)