Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/modernize'
Browse files Browse the repository at this point in the history
  • Loading branch information
pirxpilot committed Feb 27, 2024
2 parents 4979d7a + e33dfb8 commit 7385c76
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 42 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

# Tab indentation in Makefiles
[Makefile]
indent_style = tab

12 changes: 12 additions & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: check
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- uses: actions/setup-node@main
with:
node-version: 'lts/*'
- run: yarn install
- run: make check
1 change: 0 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"eqnull": true,
"immed": true,
"latedef": "nofunc",
"mocha" : true,
"newcap": true,
"noarg": true,
"sub": true,
Expand Down
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

12 changes: 7 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ lint:
./node_modules/.bin/jshint *.js lib test

test:
./node_modules/.bin/mocha --recursive \
node --test \
--require jsdom-global/register \
--require should

build/index.js: $(SRC)
./node_modules/.bin/browserify \
--debug \
--require ./index.js:$(PROJECT) \
--outfile $@
./node_modules/.bin/esbuild \
--bundle \
--sourcemap \
--global-name=$(PROJECT) \
--outfile=$@ \
index.js

clean:
rm -rf build
Expand Down
15 changes: 6 additions & 9 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[![NPM version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Build Status][build-image]][build-url]
[![Dependency Status][deps-image]][deps-url]
[![Dev Dependency Status][deps-dev-image]][deps-dev-url]

# kompas

Expand Down Expand Up @@ -44,14 +43,12 @@ MIT © [Damian Krzeminski](https://pirxpilot.me)

[chrome]: https://developers.google.com/web/updates/2016/03/device-orientation-changes

[npm-image]: https://img.shields.io/npm/v/kompas.svg
[npm-image]: https://img.shields.io/npm/v/kompas
[npm-url]: https://npmjs.org/package/kompas

[travis-url]: https://travis-ci.org/pirxpilot/kompas
[travis-image]: https://img.shields.io/travis/pirxpilot/kompas.svg
[build-url]: https://github.com/pirxpilot/kompas/actions/workflows/check.yaml
[build-image]: https://img.shields.io/github/actions/workflow/status/pirxpilot/kompas/check.yaml?branch=main

[deps-image]: https://img.shields.io/david/pirxpilot/kompas.svg
[deps-url]: https://david-dm.org/pirxpilot/kompas
[deps-image]: https://img.shields.io/librariesio/release/npm/kompas
[deps-url]: https://libraries.io/npm/kompas

[deps-dev-image]: https://img.shields.io/david/dev/pirxpilot/kompas.svg
[deps-dev-url]: https://david-dm.org/pirxpilot/kompas?type=dev
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
<label>beta<input name='beta' value='?' readonly></label>
<label>gamma<input name='gamma' value='?' readonly></label>
<label>absolute<input name='absolute' value='?' readonly></label>
<label>webkitCompassHeading<input name='webkitCompassHeading' value='?' readnly></label>
<label>compassHeading<input name='compassHeading' value='?' readonly></label>
<label>webkitCompassHeading<input name='webkitCompassHeading' value='?' readonly></label>
</form>
<script type="text/javascript">
const kompas = require('kompas');
const form = document.querySelector('.heading-form');
const debugForm = document.querySelector('.debug-form');

Expand Down
6 changes: 3 additions & 3 deletions lib/kompas.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ function compassHeading({ alpha, beta, gamma }) {
const cY = Math.cos(_y);
const cZ = Math.cos(_z);

const Vx = - cZ * sY - sZ * sX * cY;
const Vy = - sZ * sY + cZ * sX * cY;
const Vx = -cZ * sY - sZ * sX * cY;
const Vy = -sZ * sY + cZ * sX * cY;

// Calculate compass heading
let heading = Math.atan( Vx / Vy );
let heading = Math.atan(Vx / Vy);

// Convert from half unit circle to whole unit circle
if (Vy < 0) {
Expand Down
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"email": "pirxpilot@furkot.com",
"url": "https://pirxpilot.me"
},
"repository": "pirxpilot/kompas",
"repository": "github:pirxpilot/kompas",
"license": "MIT",
"keywords": [
"kompas",
Expand All @@ -18,15 +18,14 @@
"geo"
],
"dependencies": {
"component-emitter": "^1.2.1"
"component-emitter": "^1.2.1||~2"
},
"devDependencies": {
"browserify": "^16.2.2",
"jsdom": "^11.11.0",
"jsdom-global": "^3.0.2",
"jshint": "2.9.5",
"mocha": "^5.2.0",
"should": "^13.2.3"
"@pirxpilot/jshint": "~3",
"esbuild": "^0.20.1",
"jsdom": "~24",
"jsdom-global": "~3",
"should": "~13"
},
"scripts": {
"test": "make check"
Expand All @@ -35,4 +34,4 @@
"index.js",
"lib"
]
}
}
18 changes: 10 additions & 8 deletions test/kompas.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { describe, it, beforeEach, afterEach } = require('node:test');

const kompas = require('../');

function dispatch(options) {
Expand All @@ -7,27 +9,27 @@ function dispatch(options) {
}

describe('kompas', function () {
beforeEach(function() {
beforeEach(function () {
this.k = kompas().watch();
});

afterEach(function() {
afterEach(function () {
this.k.clear();
});

it('must display heading if provided', function (done) {
this.k.on('heading', function(heading) {
setTimeout(function() {
it('must display heading if provided', function (_, done) {
this.k.on('heading', function (heading) {
setTimeout(function () {
heading.should.equal(270);
done();
}, 0);
});
dispatch({ webkitCompassHeading: 270 });
});

it('must calculate heading if not provided', function (done) {
this.k.on('heading', function(heading) {
setTimeout(function() {
it('must calculate heading if not provided', function (_, done) {
this.k.on('heading', function (heading) {
setTimeout(function () {
heading.should.be.within(-360, 360);
done();
}, 0);
Expand Down

0 comments on commit 7385c76

Please sign in to comment.