Skip to content

Commit

Permalink
Merge pull request #147 from neaps/kevee/move-mocha
Browse files Browse the repository at this point in the history
Remove babel, change testing infrastructure to mocha
  • Loading branch information
kevee authored Jul 16, 2022
2 parents 6d59924 + 0d8585d commit 7013d92
Show file tree
Hide file tree
Showing 52 changed files with 3,643 additions and 19,231 deletions.
18 changes: 18 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
env: {
browser: true,
es2021: true,
node: true
},
extends: 'eslint:recommended',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module'
},
rules: {
indent: ['error', 2],
'linebreak-style': ['error', 'unix'],
quotes: ['error', 'single'],
semi: ['error', 'never']
}
}
22 changes: 0 additions & 22 deletions .eslintrc.js

This file was deleted.

6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,11 @@ jobs:
- name: Install modules
run: npm install

- name: Install codecov
run: npm install -g codecov

- name: Test
run: npm run ci

- name: Test build
run: npm run build
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules
coverage
junit.xml
.test-cache
.DS_Store
.DS_Store
.nyc_output
87 changes: 0 additions & 87 deletions Gruntfile.js

This file was deleted.

19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![example workflow](https://github.com/neaps/tide-predictor/actions/workflows/test.yml/badge.svg) [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fneaps%2Ftide-predictor.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fneaps%2Ftide-predictor?ref=badge_shield)
![example workflow](https://github.com/neaps/tide-predictor/actions/workflows/test.yml/badge.svg) [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fneaps%2Ftide-predictor.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fneaps%2Ftide-predictor?ref=badge_shield) [![codecov](https://codecov.io/gh/neaps/tide-predictor/branch/main/graph/badge.svg?token=KEJK5NQR5H)](https://codecov.io/gh/neaps/tide-predictor)

# Tide predictor

Expand All @@ -25,6 +25,17 @@ yarn add @neaps/tide-prediction
```

## Importing

You can import the module using Ecmascript, or CommonJS. Note that the CommonJS export is transpiled, so deep debugging the module that way will be difficult.

```js
import TidePrediction from '@neaps/tide-prediction'
const TidePrediction = require('@neaps/tide-prediction')
```

There are also packaged and minified versions for the browser in `dist/web`.

# Usage

Neaps requires that you [provide your own tidal harmonics information](#constituent-object) to generate a prediction.
Expand All @@ -35,6 +46,7 @@ Note that, for now, Neaps **will not** do any timezone corrections. This means y

```javascript
import TidePrediction from '@neaps/tide-prediction'

const constituents = [
{
phase_GMT: 98.7,
Expand All @@ -48,7 +60,10 @@ const constituents = [

const highLowTides = tidePrediction(constituents, {
phaseKey: 'phase_GMT'
}).getExtremesPrediction(new Date('2019-01-01'), new Date('2019-01-10'))
}).getExtremesPrediction({
start: new Date('2019-01-01'),
end: new Date('2019-01-10')
})
```

## Tide prediction object
Expand Down
9 changes: 0 additions & 9 deletions babel.config.js

This file was deleted.

50 changes: 26 additions & 24 deletions lib/index.es6.js → dist/commonjs/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

const d2r = Math.PI / 180.0;
const r2d = 180.0 / Math.PI;

Expand Down Expand Up @@ -208,7 +210,7 @@ const astro = (time) => {
pp: coefficients.solarPerigee,
90: [90.0],
omega: coefficients.terrestrialObliquity,
i: coefficients.lunarInclination,
i: coefficients.lunarInclination
};

// Polynomials are in T, that is Julian Centuries; we want our speeds to be
Expand All @@ -217,7 +219,7 @@ const astro = (time) => {
Object.keys(polynomials).forEach((name) => {
result[name] = {
value: modulus$1(polynomial(polynomials[name], T(time)), 360.0),
speed: derivativePolynomial(polynomials[name], T(time)) * dTdHour,
speed: derivativePolynomial(polynomials[name], T(time)) * dTdHour
};
});

Expand All @@ -229,7 +231,7 @@ const astro = (time) => {
xi: _xi,
nu: _nu,
nup: _nup,
nupp: _nupp,
nupp: _nupp
};
Object.keys(functions).forEach((name) => {
const functionCall = functions[name];
Expand All @@ -238,7 +240,7 @@ const astro = (time) => {
functionCall(result.N.value, result.i.value, result.omega.value),
360.0
),
speed: null,
speed: null
};
});

Expand All @@ -247,20 +249,20 @@ const astro = (time) => {
// This is in line with convention.
const hour = {
value: (JD(time) - Math.floor(JD(time))) * 360.0,
speed: 15.0,
speed: 15.0
};

result['T+h-s'] = {
value: hour.value + result.h.value - result.s.value,
speed: hour.speed + result.h.speed - result.s.speed,
speed: hour.speed + result.h.speed - result.s.speed
};

// It is convenient to calculate Schureman's P here since several node
// factors need it, although it could be argued that these
// (along with I, xi, nu etc) belong somewhere else.
result.P = {
value: result.p.value - (result.xi.value % 360.0),
speed: null,
speed: null
};

return result
Expand Down Expand Up @@ -582,7 +584,7 @@ const corrections = {

// Node factors u, see Table 2 of Schureman.

uZero(a) {
uZero() {
return 0.0
},

Expand Down Expand Up @@ -814,67 +816,67 @@ constituents.M3 = constituentFactory(
// Compound
constituents.MSF = compoundConstituentFactory('MSF', [
{ constituent: constituents.S2, factor: 1 },
{ constituent: constituents.M2, factor: -1 },
{ constituent: constituents.M2, factor: -1 }
]);

// Diurnal
constituents['2Q1'] = compoundConstituentFactory('2Q1', [
{ constituent: constituents.N2, factor: 1 },
{ constituent: constituents.J1, factor: -1 },
{ constituent: constituents.J1, factor: -1 }
]);
constituents.RHO = compoundConstituentFactory('RHO', [
{ constituent: constituents.NU2, factor: 1 },
{ constituent: constituents.K1, factor: -1 },
{ constituent: constituents.K1, factor: -1 }
]);

// Semi-Diurnal

constituents.MU2 = compoundConstituentFactory('MU2', [
{ constituent: constituents.M2, factor: 2 },
{ constituent: constituents.S2, factor: -1 },
{ constituent: constituents.S2, factor: -1 }
]);
constituents['2SM2'] = compoundConstituentFactory('2SM2', [
{ constituent: constituents.S2, factor: 2 },
{ constituent: constituents.M2, factor: -1 },
{ constituent: constituents.M2, factor: -1 }
]);

// Third-Diurnal
constituents['2MK3'] = compoundConstituentFactory('2MK3', [
{ constituent: constituents.M2, factor: 1 },
{ constituent: constituents.O1, factor: 1 },
{ constituent: constituents.O1, factor: 1 }
]);
constituents.MK3 = compoundConstituentFactory('MK3', [
{ constituent: constituents.M2, factor: 1 },
{ constituent: constituents.K1, factor: 1 },
{ constituent: constituents.K1, factor: 1 }
]);

// Quarter-Diurnal
constituents.MN4 = compoundConstituentFactory('MN4', [
{ constituent: constituents.M2, factor: 1 },
{ constituent: constituents.N2, factor: 1 },
{ constituent: constituents.N2, factor: 1 }
]);
constituents.M4 = compoundConstituentFactory('M4', [
{ constituent: constituents.M2, factor: 2 },
{ constituent: constituents.M2, factor: 2 }
]);
constituents.MS4 = compoundConstituentFactory('MS4', [
{ constituent: constituents.M2, factor: 1 },
{ constituent: constituents.S2, factor: 1 },
{ constituent: constituents.S2, factor: 1 }
]);
constituents.S4 = compoundConstituentFactory('S4', [
{ constituent: constituents.S2, factor: 2 },
{ constituent: constituents.S2, factor: 2 }
]);

// Sixth-Diurnal
constituents.M6 = compoundConstituentFactory('M6', [
{ constituent: constituents.M2, factor: 3 },
{ constituent: constituents.M2, factor: 3 }
]);
constituents.S6 = compoundConstituentFactory('S6', [
{ constituent: constituents.S2, factor: 3 },
{ constituent: constituents.S2, factor: 3 }
]);

// Eighth-Diurnals
constituents.M8 = compoundConstituentFactory('M8', [
{ constituent: constituents.M2, factor: 4 },
{ constituent: constituents.M2, factor: 4 }
]);

const getDate = (time) => {
Expand Down Expand Up @@ -911,7 +913,7 @@ const harmonicsFactory = ({ harmonicConstituents, phaseKey, offset }) => {
throw new Error('Harmonic constituents are not an array')
}
const constituents$1 = [];
harmonicConstituents.forEach((constituent, index) => {
harmonicConstituents.forEach((constituent) => {
if (typeof constituent.name === 'undefined') {
throw new Error('Harmonic constituents must have a name property')
}
Expand Down Expand Up @@ -1000,4 +1002,4 @@ const tidePredictionFactory = (constituents, options) => {
return tidePrediction
};

export { tidePredictionFactory as default };
module.exports = tidePredictionFactory;
1 change: 1 addition & 0 deletions dist/commonjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"commonjs"}
Loading

0 comments on commit 7013d92

Please sign in to comment.