Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ES modules, add types and github action checks #20

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

15 changes: 10 additions & 5 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 @@ -15,15 +17,18 @@
"license": "BSD-2-Clause",
"scripts": {
"lint": "eslint *.js test",
"pretest": "npm run lint",
"test": "mocha test/index.test.js"
"typecheck": "tsc --noEmit -p tsconfig.build.json",
"pretest": "npm run lint && npm run typecheck",
"test": "mocha test/index.test.js",
"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"]
}
Loading