Skip to content

Commit

Permalink
v1.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
oceanroleplay committed Sep 6, 2021
1 parent 499b73c commit ffed2de
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aviationweather",
"version": "1.1.4",
"version": "1.1.5",
"description": "Node.js wrapper for aviation weather, written in TypeScript",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand Down
10 changes: 10 additions & 0 deletions src/Identifiers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const skyConditions: { code: string; meaning: string }[] = [
{ code: "BKN", meaning: "Broken cloud layer 5/8ths to 7/8ths" },
{ code: "CB", meaning: "Cumulonimbus" },
{ code: "CLR", meaning: "Sky clear at or below 12,000AGL" },
{ code: "FEW", meaning: "Few cloud layer 0/8ths to 2/8ths" },
{ code: "OVC", meaning: "Overcast cloud layer 8/8ths coverage" },
{ code: "SCT", meaning: "Scattered cloud layer 3/8ths to 4/8ths" },
{ code: "SKC", meaning: "Sky Clear" },
{ code: "TCU", meaning: "Towering Cumulus" },
];
16 changes: 16 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from ".";
import axios from "axios";
import { parse } from "fast-xml-parser";
import { skyConditions } from "./Identifiers";

export class Client {
private options?: IClientOptions;
Expand All @@ -30,6 +31,12 @@ export class Client {
this.options = options;
}

private getDef(identifier: string) {
const search = skyConditions.find((s) => s.code === identifier);
if (!search) return { code: identifier, meaning: "unknown" };
return search;
}

private selectField = (type: IDatasourceType) => {
switch (type) {
case "AIRCRAFTREPORTS":
Expand Down Expand Up @@ -61,6 +68,15 @@ export class Client {
});
}

case "TAFS": {
return data.map((item) => {
if (item?.sky_condition && !(item?.sky_condition instanceof Array)) {
item.sky_condition = [item?.sky_condition];
}
return item;
});
}

case "STATIONS": {
return data.map((item) => {
// combination of station type
Expand Down
6 changes: 3 additions & 3 deletions src/types/responses/AW/ITAF.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ export interface Forecast {
/**
* Sky condition
*/
sky_condition?: {
sky_condition: {
/**
* Sky coverage
*/
sky_cover?: "NSC" | "SKC" | "CLR" | "SKT" | "BKN" | "FEW" | "OVC" | "OVCX";
sky_cover: "NSC" | "SKC" | "CLR" | "SKT" | "BKN" | "FEW" | "OVC" | "OVCX";

/**
* Cloud base (ft AGL)
Expand All @@ -139,7 +139,7 @@ export interface Forecast {
* Cloud type
*/
cloud_type?: "CB" | "TCU" | "CU";
};
}[];

/**
* Forecast change indicator: TEMPO|BECMG|FM|PROB
Expand Down
4 changes: 2 additions & 2 deletions tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Client } from "../src";
const myc = new Client({ debug: true });
myc
.AW({
datasource: "METARS",
stationString: "KBCB",
datasource: "TAFS",
stationString: "YMML",
hoursBeforeNow: 1,
})
.then((res) => {
Expand Down

0 comments on commit ffed2de

Please sign in to comment.