Skip to content

Commit

Permalink
fix: ✨ implement both commonjs and modules
Browse files Browse the repository at this point in the history
  • Loading branch information
thkruz committed Jan 13, 2024
1 parent d4ddcf3 commit 732a270
Show file tree
Hide file tree
Showing 29 changed files with 141 additions and 97 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea
.vscode
coverage
commonjs
lib
node_modules
*.log
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ console.log(sat.meanMoDev1); // Mean Motion Deviation 1
console.log(sat.meanMoDev2); // Mean Motion Deviation 2
console.log(sat.bstar); // Bstar (Drag Coefficient)
console.log(sat.inclination); // inclination in degrees
console.log(sat.raan); // right ascension of the ascending node in degrees
console.log(sat.rightAscension); // right ascension of the ascending node in degrees
console.log(sat.eccentricity); // eccentricity
console.log(sat.argOfPerigee); // argument of perigee in degrees
console.log(sat.meanAnomaly); // mean anomaly in degrees
Expand Down
4 changes: 2 additions & 2 deletions examples/typescript/tle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const tle = Tle.parse(tle1, tle2);
// meanMoDev2: 0,
// bstar: 0.000059442,
// inclination: 51.6433,
// raan: 59.2583,
// rightAscension: 59.2583,
// eccentricity: 0.0008217,
// argOfPerigee: 16.4489,
// meanAnomaly: 347.6017,
Expand Down Expand Up @@ -76,7 +76,7 @@ const tleAll = Tle.parseAll(tle1, tle2);
// checksum1: 2,
// lineNumber2: 2,
// inclination: 51.6433,
// raan: 59.2583,
// rightAscension: 59.2583,
// eccentricity: 0.0008217,
// argOfPerigee: 16.4489,
// meanAnomaly: 347.6017,
Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "1.0.0-0",
"description": "Orbital Object Toolkit Core including SGP4 Propagator and Coordinate Transforms",
"scripts": {
"mjs": "ttsc -p tsconfig.build.json && node ./scripts/moveMjs.mjs",
"cjs": "ttsc -p tsconfig.build.json -m commonjs",
"mjs": "ttsc -p tsconfig.build.json -m esnext",
"cjs": "ttsc -p tsconfig.c.json -m commonjs",
"build": "node ./scripts/cleanup.mjs && npm run mjs && npm run cjs",
"lint": "eslint src",
"lint:fix": "eslint src --fix",
Expand All @@ -13,11 +13,12 @@
"test:coverage": "jest --coverage",
"version": "auto-changelog -p && git add CHANGELOG.md"
},
"main": "./lib/ootk-core.js",
"main": "./lib/index.js",
"exports": {
"import": "./lib/ootk-core.js",
"require": "./lib/ootk-core.js"
"import": "./lib/index.js",
"require": "./commonjs/index.js"
},
"typings": "./lib/index.d.ts",
"repository": {
"type": "git",
"url": "git://github.com/thkruz/ootk-core"
Expand Down Expand Up @@ -56,4 +57,4 @@
"typescript-transform-paths": "^3.4.6"
},
"homepage": "https://github.com/thkruz/ootk"
}
}
7 changes: 4 additions & 3 deletions scripts/moveMjs.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { renameSync } from 'fs';
import { cpSync, renameSync } from 'fs';

renameSync('./lib/ootk-core.js', './lib/ootk-core.mjs');
renameSync('./lib/ootk-core.js.map', './lib/ootk-core.mjs.map');
renameSync('./lib/index.js', './lib/index.mjs');
renameSync('./lib/index.js.map', './lib/index.mjs.map');
cpSync('./lib/index.d.ts', './lib/index.d.mts');
2 changes: 1 addition & 1 deletion src/body/Celestial.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AzEl, Degrees, RaDec, Radians } from '../ootk-core';
import { AzEl, Degrees, RaDec, Radians } from '..';
import { RAD2DEG } from '../utils/constants';
import { Sun } from './Sun';

Expand Down
2 changes: 1 addition & 1 deletion src/body/Earth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AngularDiameterMethod, Kilometers, Radians } from '..';
import { DataHandler } from '../data/DataHandler';
import { AngularDiameterMethod, Kilometers, Radians } from '../ootk-core';
import { Vector3D } from '../operations/Vector3D';
import { EpochUTC } from '../time/EpochUTC';
import { asec2rad, DEG2RAD, RAD2DEG, secondsPerDay, secondsPerSiderealDay, TAU, ttasec2rad } from '../utils/constants';
Expand Down
2 changes: 1 addition & 1 deletion src/body/Moon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* DEALINGS IN THE SOFTWARE.
*/

import { AngularDiameterMethod, Celestial, Degrees, Kilometers, RaDec, Radians } from '../ootk-core';
import { AngularDiameterMethod, Celestial, Degrees, Kilometers, RaDec, Radians } from '..';
import { Vector3D } from '../operations/Vector3D';
import { EpochUTC } from '../time/EpochUTC';
import { DEG2RAD, MS_PER_DAY } from '../utils/constants';
Expand Down
2 changes: 1 addition & 1 deletion src/body/NutationAngles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Radians } from '../ootk-core';
import { Radians } from '..';

// / Earth nutation angles _(rad)_.
export type NutationAngles = {
Expand Down
2 changes: 1 addition & 1 deletion src/body/PrecessionAngles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Radians } from '../ootk-core';
import { Radians } from '..';

// / Earth precession angles _(rad)_.
export type PrecessionAngles = {
Expand Down
2 changes: 1 addition & 1 deletion src/body/Sun.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AngularDiameterMethod, AzEl, Degrees, Kilometers, Meters, RaDec, Radians, SunTime } from '../ootk-core';
import { AngularDiameterMethod, AzEl, Degrees, Kilometers, Meters, RaDec, Radians, SunTime } from '..';
import { Vector3D } from '../operations/Vector3D';
import { EpochUTC } from '../time/EpochUTC';
import { astronomicalUnit, cKmPerSec, DEG2RAD, MS_PER_DAY, RAD2DEG, TAU } from '../utils/constants';
Expand Down
2 changes: 1 addition & 1 deletion src/coordinate/Geodetic.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AngularDistanceMethod } from '..';
import { Earth } from '../body/Earth';
import { AngularDistanceMethod } from '../ootk-core';
import { Vector3D } from '../operations/Vector3D';
import { EpochUTC } from '../time/EpochUTC';
import { DEG2RAD, RAD2DEG } from '../utils/constants';
Expand Down
46 changes: 24 additions & 22 deletions src/coordinate/TLE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@
* DEALINGS IN THE SOFTWARE.
*/

import { Sgp4, Vector3D } from '..';
import { Earth } from '../body';
import { ClassicalElements, FormatTle, TEME } from '../coordinate';
import { Sgp4OpsMode } from '../enums/Sgp4OpsMode';
import { Sgp4, Vector3D } from '../ootk-core';
import { Sgp4GravConstants } from '../sgp4/sgp4';
import { EpochUTC } from '../time/EpochUTC';
import {
Degrees,
EciVec3,
Line1Data,
Line2Data,
Minutes,
SatelliteRecord,
StateVectorSgp4,
TleData,
Expand Down Expand Up @@ -123,7 +125,7 @@ export class Tle {
/** The mean motion field. */
private static readonly meanMo_ = new TleFormatData(53, 63);
/** The right ascension of the ascending node field. */
private static readonly raan_ = new TleFormatData(18, 25);
private static readonly rightAscension_ = new TleFormatData(18, 25);
/** The revolution number field. */
private static readonly revNum_ = new TleFormatData(64, 68);
/** The satellite number field. */
Expand Down Expand Up @@ -274,16 +276,16 @@ export class Tle {
* Example: 69.9862
*
* @param {string} tleLine2 The second line of the Tle to parse.
* @returns {number} The argument of perigee in degrees.
* @returns {Degrees} The argument of perigee in degrees.
*/
static argOfPerigee(tleLine2: TleLine2): number {
static argOfPerigee(tleLine2: TleLine2): Degrees {
const argPe = parseFloat(tleLine2.substring(Tle.argPerigee_.start, Tle.argPerigee_.stop));

if (!(argPe >= 0 && argPe < 360)) {
throw new Error(`Invalid argument of perigee: ${argPe}`);
}

return toPrecision(argPe, 4);
return toPrecision(argPe, 4) as Degrees;
}

/**
Expand Down Expand Up @@ -494,16 +496,16 @@ export class Tle {
* Example: 51.6400
*
* @param {string} tleLine2 The second line of the Tle to parse.
* @returns {number} The inclination of the satellite.
* @returns {Degrees} The inclination of the satellite.
*/
static inclination(tleLine2: TleLine2): number {
static inclination(tleLine2: TleLine2): Degrees {
const inc = parseFloat(tleLine2.substring(Tle.inclination_.start, Tle.inclination_.stop));

if (inc < 0 || inc > 180) {
throw new Error(`Invalid inclination: ${inc}`);
}

return toPrecision(inc, 4);
return toPrecision(inc, 4) as Degrees;
}

/**
Expand Down Expand Up @@ -585,16 +587,16 @@ export class Tle {
* Example: 25.2906
*
* @param {string} tleLine2 The second line of the Tle to parse.
* @returns {number} The mean anomaly of the satellite.
* @returns {Degrees} The mean anomaly of the satellite.
*/
static meanAnomaly(tleLine2: TleLine2): number {
static meanAnomaly(tleLine2: TleLine2): Degrees {
const meanA = parseFloat(tleLine2.substring(Tle.meanAnom_.start, Tle.meanAnom_.stop));

if (!(meanA >= 0 && meanA <= 360)) {
throw new Error(`Invalid mean anomaly: ${meanA}`);
}

return toPrecision(meanA, 4);
return toPrecision(meanA, 4) as Degrees;
}

/**
Expand Down Expand Up @@ -669,10 +671,10 @@ export class Tle {
* @param tleLine2 The Tle line 2.
* @returns The period of the satellite orbit in minutes.
*/
static period(tleLine2: TleLine2): number {
static period(tleLine2: TleLine2): Minutes {
const meanMo = Tle.meanMotion(tleLine2);

return 1440 / meanMo;
return (1440 / meanMo) as Minutes;
}

/**
Expand All @@ -687,16 +689,16 @@ export class Tle {
* Example: 208.9163
*
* @param {string} tleLine2 The second line of the Tle to parse.
* @returns {number} The right ascension of the satellite.
* @returns {Degrees} The right ascension of the satellite.
*/
static rightAscension(tleLine2: TleLine2): number {
const raan = parseFloat(tleLine2.substring(Tle.raan_.start, Tle.raan_.stop));
static rightAscension(tleLine2: TleLine2): Degrees {
const rightAscension = parseFloat(tleLine2.substring(Tle.rightAscension_.start, Tle.rightAscension_.stop));

if (!(raan >= 0 && raan <= 360)) {
throw new Error(`Invalid RAAN: ${raan}`);
if (!(rightAscension >= 0 && rightAscension <= 360)) {
throw new Error(`Invalid Right Ascension: ${rightAscension}`);
}

return toPrecision(raan, 4);
return toPrecision(rightAscension, 4) as Degrees;
}

/**
Expand Down Expand Up @@ -806,7 +808,7 @@ export class Tle {
const satNum = Tle.satNum(tleLine2);
const satNumRaw = Tle.rawSatNum(tleLine2);
const inclination = Tle.inclination(tleLine2);
const raan = Tle.rightAscension(tleLine2);
const rightAscension = Tle.rightAscension(tleLine2);
const eccentricity = Tle.eccentricity(tleLine2);
const argOfPerigee = Tle.argOfPerigee(tleLine2);
const meanAnomaly = Tle.meanAnomaly(tleLine2);
Expand All @@ -820,7 +822,7 @@ export class Tle {
satNum,
satNumRaw,
inclination,
raan,
rightAscension,
eccentricity,
argOfPerigee,
meanAnomaly,
Expand Down Expand Up @@ -868,7 +870,7 @@ export class Tle {
meanMoDev2: line1.meanMoDev2,
bstar: line1.bstar,
inclination: line2.inclination,
raan: line2.raan,
rightAscension: line2.rightAscension,
eccentricity: line2.eccentricity,
argOfPerigee: line2.argOfPerigee,
meanAnomaly: line2.meanAnomaly,
Expand Down
6 changes: 3 additions & 3 deletions src/ootk-core.ts → src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@
* SOFTWARE.
*/

export * from './body';
export { Celestial, Earth, Moon, Sun } from './body';
export * from './coordinate';
export { Tle } from './coordinate/Tle';
export * from './data/DataHandler';
export * from './enums';
export * from './interfaces';
export * from './objects';
export { BaseObject, GroundPosition, Satellite, Sensor, Star } from './objects';
export * from './observation';
export * from './operations/operations';
export { Sgp4 } from './sgp4/sgp4';
export * from './sgp4';
export * from './time/time';
export * from './transforms';
export * from './types/types';
Expand Down
12 changes: 6 additions & 6 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { BaseObjectParams } from './BaseObjectParams';
export { GroundPositionParams } from './GroundPositionParams';
export { OptionsParams } from './OptionsParams';
export { SatelliteParams } from './SatelliteParams';
export { SensorParams } from './SensorParams';
export { StarObjectParams } from './StarObjectParams';
export type { BaseObjectParams } from './BaseObjectParams';
export type { GroundPositionParams } from './GroundPositionParams';
export type { OptionsParams } from './OptionsParams';
export type { SatelliteParams } from './SatelliteParams';
export type { SensorParams } from './SensorParams';
export type { StarObjectParams } from './StarObjectParams';
Loading

0 comments on commit 732a270

Please sign in to comment.