[node] begin the great typescript rewrite
This commit is contained in:
parent
3b61a9694d
commit
d668eac4a6
31 changed files with 879 additions and 666 deletions
25
nodejs/lib/utils.ts
Normal file
25
nodejs/lib/utils.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import { Cargo, CargoManifest } from '../model/cargo.ts';
|
||||
|
||||
export type CategorizedCargo = {
|
||||
wanted: CargoManifest;
|
||||
goods: CargoManifest;
|
||||
};
|
||||
|
||||
// cargo is a ship.cargo object, want is an optional symbol
|
||||
export function categorizeCargo(cargo: Cargo, want?: string): CategorizedCargo {
|
||||
const wanted = cargo.inventory.filter(i => i.symbol === want || i.symbol === 'ANTIMATTER');
|
||||
const goods = cargo.inventory.filter(i => i.symbol !== want && i.symbol !== 'ANTIMATTER');
|
||||
const wobj = wanted.reduce(function(acc: CargoManifest, e) {
|
||||
acc[e.symbol] = e.units;
|
||||
return acc;
|
||||
}, {});
|
||||
const gobj = goods.reduce(function(acc: CargoManifest, e) {
|
||||
acc[e.symbol] = e.units;
|
||||
return acc;
|
||||
}, {});
|
||||
return {wanted: wobj, goods: gobj};
|
||||
}
|
||||
|
||||
export function systemFromWaypoint(waypoint: string): string {
|
||||
return waypoint.split('-').slice(0,2).join('-');
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue