Skip to content

Commit 30dbbbb

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

File tree

9 files changed

+75
-47
lines changed

9 files changed

+75
-47
lines changed

Diff for: .circleci/config.yml

-37
This file was deleted.

Diff for: .github/workflows/pullrequest.yml

+21
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

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
**/*.d.ts

Diff for: index.d.ts.map

+1
Original file line numberDiff line numberDiff line change

Diff for: index.js

+8-2
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+
}

Diff for: package-lock.json

+21-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+10-5
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"
@@ -15,15 +17,18 @@
1517
"license": "BSD-2-Clause",
1618
"scripts": {
1719
"lint": "eslint *.js test",
18-
"pretest": "npm run lint",
19-
"test": "mocha test/index.test.js"
20+
"typecheck": "tsc --noEmit -p tsconfig.build.json",
21+
"pretest": "npm run lint && npm run typecheck",
22+
"test": "mocha test/index.test.js",
23+
"prepare": "tsc --emitDeclarationOnly -p tsconfig.build.json"
2024
},
2125
"devDependencies": {
2226
"eslint": "^5.15.0",
2327
"eslint-config-openlayers": "^11.0.0",
2428
"karma-mocha": "^2.0.1",
2529
"mocha": "^10.2.0",
2630
"should": "^13.2.3",
27-
"sinon": "^7.2.7"
31+
"sinon": "^7.2.7",
32+
"typescript": "^5.5.3"
2833
}
2934
}

Diff for: test/index.test.js

+2-2
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

Diff for: tsconfig.build.json

+11
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)