Skip to content

Commit

Permalink
Use ES modules, add types and github action checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ahocevar committed Jul 17, 2024
1 parent 8aa025b commit 97b76e9
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 46 deletions.
37 changes: 0 additions & 37 deletions .circleci/config.yml

This file was deleted.

21 changes: 21 additions & 0 deletions .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Node.js CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20.x'
- run: npm ci
- run: npm run build --if-present
- run: npm test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
**/*.d.ts
1 change: 1 addition & 0 deletions index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ var italicRE = /(italic|oblique)$/i;

var fontCache = {};

module.exports = function(fonts, size, lineHeight) {
/**
* @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'`.
* @param {number} size Font size in pixels.
* @param {string|number} [lineHeight] Line height as css line-height.
* @returns {string} CSS font definition, e.g. `'normal 400 16px/1.2 "Open Sans"'`.
*/
export default function(fonts, size, lineHeight) {
var cssData = fontCache[fonts];
if (!cssData) {
if (!Array.isArray(fonts)) {
Expand Down Expand Up @@ -79,4 +85,4 @@ module.exports = function(fonts, size, lineHeight) {
cssData = fontCache[fonts] = [style, weight, fontFamilies];
}
return cssData[0] + sp + cssData[1] + sp + size + 'px' + (lineHeight ? '/' + lineHeight : '') + sp + cssData[2];
};
}
22 changes: 21 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"name": "mapbox-to-css-font",
"version": "2.4.5",
"version": "3.0.0",
"description": "Utility to convert Mapbox GL Style font names to CSS font definitions",
"main": "index.js",
"type": "module",
"module": "index.js",
"types": "index.d.ts",
"repository": {
"type": "git",
"url": "git://github.com/openlayers/mapbox-to-css-font.git"
Expand All @@ -16,14 +18,16 @@
"scripts": {
"lint": "eslint *.js test",
"pretest": "npm run lint",
"test": "mocha test/index.test.js"
"test": "mocha test/index.test.js && tsc -p tsconfig.build.json --noEmit",
"prepare": "tsc --emitDeclarationOnly -p tsconfig.build.json"
},
"devDependencies": {
"eslint": "^5.15.0",
"eslint-config-openlayers": "^11.0.0",
"karma-mocha": "^2.0.1",
"mocha": "^10.2.0",
"should": "^13.2.3",
"sinon": "^7.2.7"
"sinon": "^7.2.7",
"typescript": "^5.5.3"
}
}
4 changes: 2 additions & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-env mocha */
const should = require('should');
const parseFont = require('../index.js');
import should from 'should';
import parseFont from '../index.js';

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

Expand Down
11 changes: 11 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"lib": ["es2015"],
"declaration": true,
"declarationMap": true
},
"include": ["**/*.js"],
"exclude": ["node_modules", "test"]
}

0 comments on commit 97b76e9

Please sign in to comment.