metar-taf-parser 3.1.2 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/README.md +1 -1
  2. package/{dist/locale → locale}/de.d.ts +0 -0
  3. package/{dist/locale → locale}/de.js +3 -3
  4. package/{dist/locale → locale}/en.d.ts +0 -0
  5. package/{dist/locale → locale}/en.js +3 -3
  6. package/{dist/locale → locale}/fr.d.ts +0 -0
  7. package/{dist/locale → locale}/fr.js +3 -3
  8. package/{dist/locale → locale}/it.d.ts +0 -0
  9. package/{dist/locale → locale}/it.js +3 -3
  10. package/{dist/locale → locale}/pl.d.ts +0 -0
  11. package/{dist/locale → locale}/pl.js +3 -3
  12. package/{dist/locale → locale}/zh-CN.d.ts +0 -0
  13. package/{dist/locale → locale}/zh-CN.js +3 -3
  14. package/metar-taf-parser.d.ts +1325 -0
  15. package/metar-taf-parser.js +2703 -0
  16. package/package.json +23 -16
  17. package/dist/command/common.d.ts +0 -54
  18. package/dist/command/common.js +0 -243
  19. package/dist/command/metar/AltimeterCommand.d.ts +0 -7
  20. package/dist/command/metar/AltimeterCommand.js +0 -26
  21. package/dist/command/metar/AltimeterMercuryCommand.d.ts +0 -7
  22. package/dist/command/metar/AltimeterMercuryCommand.js +0 -51
  23. package/dist/command/metar/RunwayCommand.d.ts +0 -7
  24. package/dist/command/metar/RunwayCommand.js +0 -60
  25. package/dist/command/metar/TemperatureCommand.d.ts +0 -7
  26. package/dist/command/metar/TemperatureCommand.js +0 -51
  27. package/dist/command/metar.d.ts +0 -9
  28. package/dist/command/metar.js +0 -31
  29. package/dist/command/remark/CeilingHeightCommand.d.ts +0 -18
  30. package/dist/command/remark/CeilingHeightCommand.js +0 -40
  31. package/dist/command/remark/CeilingSecondLocationCommand.d.ts +0 -12
  32. package/dist/command/remark/CeilingSecondLocationCommand.js +0 -40
  33. package/dist/command/remark/Command.d.ts +0 -8
  34. package/dist/command/remark/Command.js +0 -9
  35. package/dist/command/remark/DefaultCommand.d.ts +0 -11
  36. package/dist/command/remark/DefaultCommand.js +0 -38
  37. package/dist/command/remark/HailSizeCommand.d.ts +0 -11
  38. package/dist/command/remark/HailSizeCommand.js +0 -38
  39. package/dist/command/remark/HourlyMaximumMinimumTemperatureCommand.d.ts +0 -18
  40. package/dist/command/remark/HourlyMaximumMinimumTemperatureCommand.js +0 -39
  41. package/dist/command/remark/HourlyMaximumTemperatureCommand.d.ts +0 -14
  42. package/dist/command/remark/HourlyMaximumTemperatureCommand.js +0 -38
  43. package/dist/command/remark/HourlyMinimumTemperatureCommand.d.ts +0 -14
  44. package/dist/command/remark/HourlyMinimumTemperatureCommand.js +0 -38
  45. package/dist/command/remark/HourlyPrecipitationAmountCommand.d.ts +0 -14
  46. package/dist/command/remark/HourlyPrecipitationAmountCommand.js +0 -38
  47. package/dist/command/remark/HourlyPressureCommand.d.ts +0 -32
  48. package/dist/command/remark/HourlyPressureCommand.js +0 -40
  49. package/dist/command/remark/HourlyTemperatureDewPointCommand.d.ts +0 -18
  50. package/dist/command/remark/HourlyTemperatureDewPointCommand.js +0 -52
  51. package/dist/command/remark/IceAccretionCommand.d.ts +0 -15
  52. package/dist/command/remark/IceAccretionCommand.js +0 -38
  53. package/dist/command/remark/ObscurationCommand.d.ts +0 -14
  54. package/dist/command/remark/ObscurationCommand.js +0 -44
  55. package/dist/command/remark/PrecipitationAmount24HourCommand.d.ts +0 -14
  56. package/dist/command/remark/PrecipitationAmount24HourCommand.js +0 -39
  57. package/dist/command/remark/PrecipitationAmount36HourCommand.d.ts +0 -15
  58. package/dist/command/remark/PrecipitationAmount36HourCommand.js +0 -41
  59. package/dist/command/remark/PrecipitationBegCommand.d.ts +0 -15
  60. package/dist/command/remark/PrecipitationBegCommand.js +0 -45
  61. package/dist/command/remark/PrecipitationBegEndCommand.d.ts +0 -17
  62. package/dist/command/remark/PrecipitationBegEndCommand.js +0 -46
  63. package/dist/command/remark/PrecipitationEndCommand.d.ts +0 -15
  64. package/dist/command/remark/PrecipitationEndCommand.js +0 -45
  65. package/dist/command/remark/PrevailingVisibilityCommand.d.ts +0 -12
  66. package/dist/command/remark/PrevailingVisibilityCommand.js +0 -41
  67. package/dist/command/remark/SeaLevelPressureCommand.d.ts +0 -11
  68. package/dist/command/remark/SeaLevelPressureCommand.js +0 -39
  69. package/dist/command/remark/SecondLocationVisibilityCommand.d.ts +0 -12
  70. package/dist/command/remark/SecondLocationVisibilityCommand.js +0 -41
  71. package/dist/command/remark/SectorVisibilityCommand.d.ts +0 -13
  72. package/dist/command/remark/SectorVisibilityCommand.js +0 -42
  73. package/dist/command/remark/SmallHailSizeCommand.d.ts +0 -11
  74. package/dist/command/remark/SmallHailSizeCommand.js +0 -38
  75. package/dist/command/remark/SnowDepthCommand.d.ts +0 -11
  76. package/dist/command/remark/SnowDepthCommand.js +0 -38
  77. package/dist/command/remark/SnowIncreaseCommand.d.ts +0 -12
  78. package/dist/command/remark/SnowIncreaseCommand.js +0 -40
  79. package/dist/command/remark/SnowPelletsCommand.d.ts +0 -11
  80. package/dist/command/remark/SnowPelletsCommand.js +0 -37
  81. package/dist/command/remark/SunshineDurationCommand.d.ts +0 -11
  82. package/dist/command/remark/SunshineDurationCommand.js +0 -38
  83. package/dist/command/remark/SurfaceVisibilityCommand.d.ts +0 -11
  84. package/dist/command/remark/SurfaceVisibilityCommand.js +0 -39
  85. package/dist/command/remark/ThunderStormLocationCommand.d.ts +0 -12
  86. package/dist/command/remark/ThunderStormLocationCommand.js +0 -40
  87. package/dist/command/remark/ThunderStormLocationMovingCommand.d.ts +0 -19
  88. package/dist/command/remark/ThunderStormLocationMovingCommand.js +0 -42
  89. package/dist/command/remark/TornadicActivityBegCommand.d.ts +0 -16
  90. package/dist/command/remark/TornadicActivityBegCommand.js +0 -44
  91. package/dist/command/remark/TornadicActivityBegEndCommand.d.ts +0 -18
  92. package/dist/command/remark/TornadicActivityBegEndCommand.js +0 -46
  93. package/dist/command/remark/TornadicActivityEndCommand.d.ts +0 -16
  94. package/dist/command/remark/TornadicActivityEndCommand.js +0 -44
  95. package/dist/command/remark/TowerVisibilityCommand.d.ts +0 -11
  96. package/dist/command/remark/TowerVisibilityCommand.js +0 -39
  97. package/dist/command/remark/VariableSkyCommand.d.ts +0 -12
  98. package/dist/command/remark/VariableSkyCommand.js +0 -41
  99. package/dist/command/remark/VariableSkyHeightCommand.d.ts +0 -13
  100. package/dist/command/remark/VariableSkyHeightCommand.js +0 -43
  101. package/dist/command/remark/VirgaDirectionCommand.d.ts +0 -12
  102. package/dist/command/remark/VirgaDirectionCommand.js +0 -40
  103. package/dist/command/remark/WaterEquivalentSnowCommand.d.ts +0 -11
  104. package/dist/command/remark/WaterEquivalentSnowCommand.js +0 -38
  105. package/dist/command/remark/WindPeakCommandCommand.d.ts +0 -17
  106. package/dist/command/remark/WindPeakCommandCommand.js +0 -42
  107. package/dist/command/remark/WindShiftCommand.d.ts +0 -12
  108. package/dist/command/remark/WindShiftCommand.js +0 -38
  109. package/dist/command/remark/WindShiftFropaCommand.d.ts +0 -12
  110. package/dist/command/remark/WindShiftFropaCommand.js +0 -38
  111. package/dist/command/remark.d.ts +0 -109
  112. package/dist/command/remark.js +0 -152
  113. package/dist/commons/converter.d.ts +0 -21
  114. package/dist/commons/converter.js +0 -108
  115. package/dist/commons/errors.d.ts +0 -24
  116. package/dist/commons/errors.js +0 -46
  117. package/dist/commons/i18n.d.ts +0 -12
  118. package/dist/commons/i18n.js +0 -30
  119. package/dist/dates/metar.d.ts +0 -5
  120. package/dist/dates/metar.js +0 -8
  121. package/dist/dates/taf.d.ts +0 -28
  122. package/dist/dates/taf.js +0 -17
  123. package/dist/forecast/forecast.d.ts +0 -36
  124. package/dist/forecast/forecast.js +0 -72
  125. package/dist/helpers/date.d.ts +0 -11
  126. package/dist/helpers/date.js +0 -56
  127. package/dist/helpers/helpers.d.ts +0 -17
  128. package/dist/helpers/helpers.js +0 -46
  129. package/dist/index.d.ts +0 -32
  130. package/dist/index.js +0 -62
  131. package/dist/model/enum.d.ts +0 -265
  132. package/dist/model/enum.js +0 -280
  133. package/dist/model/model.d.ts +0 -188
  134. package/dist/model/model.js +0 -11
  135. package/dist/parser/parser.d.ts +0 -111
  136. package/dist/parser/parser.js +0 -480
@@ -1,21 +0,0 @@
1
- import { Distance } from "../model/model";
2
- export declare function degreesToCardinal(input: number | string): string;
3
- export declare function convertVisibility(input: string): Distance;
4
- /**
5
- * @param input May start with P or M, and must end with SM
6
- * @returns Distance
7
- */
8
- export declare function convertNauticalMilesVisibility(input: string): Distance;
9
- /**
10
- * Converts fractional and/or whole amounts
11
- *
12
- * Example "1/3", "1 1/3" and "1"
13
- */
14
- export declare function convertFractionalAmount(input: string): number;
15
- export declare function convertTemperature(input: string): number;
16
- export declare function convertInchesMercuryToPascal(input: number): number;
17
- /**
18
- * Converts number `.toFixed(1)` before outputting to match python implementation
19
- */
20
- export declare function convertTemperatureRemarks(sign: string, temperature: string): number;
21
- export declare function convertPrecipitationAmount(amount: string): number;
@@ -1,108 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertPrecipitationAmount = exports.convertTemperatureRemarks = exports.convertInchesMercuryToPascal = exports.convertTemperature = exports.convertFractionalAmount = exports.convertNauticalMilesVisibility = exports.convertVisibility = exports.degreesToCardinal = void 0;
4
- const helpers_1 = require("../helpers/helpers");
5
- const enum_1 = require("../model/enum");
6
- function degreesToCardinal(input) {
7
- const degrees = +input;
8
- if (isNaN(degrees))
9
- return "VRB";
10
- const dirs = [
11
- "N",
12
- "NNE",
13
- "NE",
14
- "ENE",
15
- "E",
16
- "ESE",
17
- "SE",
18
- "SSE",
19
- "S",
20
- "SSW",
21
- "SW",
22
- "WSW",
23
- "W",
24
- "WNW",
25
- "NW",
26
- "NNW",
27
- ];
28
- const ix = Math.floor((degrees + 11.25) / 22.5);
29
- return dirs[ix % 16];
30
- }
31
- exports.degreesToCardinal = degreesToCardinal;
32
- function convertVisibility(input) {
33
- if (input === "9999")
34
- return {
35
- indicator: enum_1.ValueIndicator.GreaterThan,
36
- value: +input,
37
- unit: enum_1.DistanceUnit.Meters,
38
- };
39
- return {
40
- value: +input,
41
- unit: enum_1.DistanceUnit.Meters,
42
- };
43
- }
44
- exports.convertVisibility = convertVisibility;
45
- /**
46
- * @param input May start with P or M, and must end with SM
47
- * @returns Distance
48
- */
49
- function convertNauticalMilesVisibility(input) {
50
- let indicator;
51
- let index = 0;
52
- if (input.startsWith("P")) {
53
- indicator = enum_1.ValueIndicator.GreaterThan;
54
- index = 1;
55
- }
56
- else if (input.startsWith("M")) {
57
- indicator = enum_1.ValueIndicator.LessThan;
58
- index = 1;
59
- }
60
- return {
61
- indicator,
62
- value: convertFractionalAmount(input.slice(index, -2)),
63
- unit: enum_1.DistanceUnit.StatuteMiles,
64
- };
65
- }
66
- exports.convertNauticalMilesVisibility = convertNauticalMilesVisibility;
67
- /**
68
- * Converts fractional and/or whole amounts
69
- *
70
- * Example "1/3", "1 1/3" and "1"
71
- */
72
- function convertFractionalAmount(input) {
73
- const [whole, fraction] = input.split(" ");
74
- if (!fraction)
75
- return parseFraction(whole);
76
- return +whole + parseFraction(fraction);
77
- }
78
- exports.convertFractionalAmount = convertFractionalAmount;
79
- function parseFraction(input) {
80
- const [top, bottom] = input.split("/");
81
- if (!bottom)
82
- return +top;
83
- return Math.round((+top / +bottom) * 100) / 100;
84
- }
85
- function convertTemperature(input) {
86
- if (input.startsWith("M"))
87
- return -(0, helpers_1.pySplit)(input, "M")[1];
88
- return +input;
89
- }
90
- exports.convertTemperature = convertTemperature;
91
- function convertInchesMercuryToPascal(input) {
92
- return 33.8639 * input;
93
- }
94
- exports.convertInchesMercuryToPascal = convertInchesMercuryToPascal;
95
- /**
96
- * Converts number `.toFixed(1)` before outputting to match python implementation
97
- */
98
- function convertTemperatureRemarks(sign, temperature) {
99
- const temp = +temperature / 10;
100
- if (sign === "0")
101
- return temp;
102
- return -temp;
103
- }
104
- exports.convertTemperatureRemarks = convertTemperatureRemarks;
105
- function convertPrecipitationAmount(amount) {
106
- return +amount / 100;
107
- }
108
- exports.convertPrecipitationAmount = convertPrecipitationAmount;
@@ -1,24 +0,0 @@
1
- export declare abstract class ParseError extends Error {
2
- name: string;
3
- constructor(message?: string);
4
- }
5
- export declare class InvalidWeatherStatementError extends ParseError {
6
- name: string;
7
- cause?: unknown;
8
- constructor(cause?: unknown);
9
- }
10
- /**
11
- * Thrown when command marked as canParse, but couldn't parse when
12
- * executing (for example, an invalid CloudQuantity)
13
- */
14
- export declare class CommandExecutionError extends ParseError {
15
- name: string;
16
- constructor(message: string);
17
- }
18
- /**
19
- * Should never occur
20
- */
21
- export declare class UnexpectedParseError extends ParseError {
22
- name: string;
23
- constructor(message?: string);
24
- }
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UnexpectedParseError = exports.CommandExecutionError = exports.InvalidWeatherStatementError = exports.ParseError = void 0;
4
- class ParseError extends Error {
5
- constructor(message) {
6
- super(message);
7
- this.name = "ParseError";
8
- Object.setPrototypeOf(this, new.target.prototype);
9
- }
10
- }
11
- exports.ParseError = ParseError;
12
- class InvalidWeatherStatementError extends ParseError {
13
- constructor(cause) {
14
- super(typeof cause === "string"
15
- ? `Invalid weather string: ${cause}`
16
- : "Invalid weather string");
17
- this.name = "InvalidWeatherStatementError";
18
- Object.setPrototypeOf(this, new.target.prototype);
19
- if (typeof cause !== "string")
20
- this.cause = cause;
21
- }
22
- }
23
- exports.InvalidWeatherStatementError = InvalidWeatherStatementError;
24
- /**
25
- * Thrown when command marked as canParse, but couldn't parse when
26
- * executing (for example, an invalid CloudQuantity)
27
- */
28
- class CommandExecutionError extends ParseError {
29
- constructor(message) {
30
- super(message);
31
- this.name = "CommandExecutionError";
32
- Object.setPrototypeOf(this, new.target.prototype);
33
- }
34
- }
35
- exports.CommandExecutionError = CommandExecutionError;
36
- /**
37
- * Should never occur
38
- */
39
- class UnexpectedParseError extends ParseError {
40
- constructor(message) {
41
- super(message);
42
- this.name = "UnexpectedParseError";
43
- Object.setPrototypeOf(this, new.target.prototype);
44
- }
45
- }
46
- exports.UnexpectedParseError = UnexpectedParseError;
@@ -1,12 +0,0 @@
1
- import en from "../locale/en";
2
- export default en;
3
- declare type DeepPartial<T> = T extends object ? {
4
- [P in keyof T]?: DeepPartial<T[P]>;
5
- } : T;
6
- export declare type Locale = DeepPartial<typeof en>;
7
- declare type PathsToStringProps<T> = T extends string ? [] : {
8
- [K in Extract<keyof T, string>]: [K, ...PathsToStringProps<T[K]>];
9
- }[Extract<keyof T, string>];
10
- declare type Join<T extends string[], D extends string> = T extends [] ? never : T extends [infer F] ? F : T extends [infer F, ...infer R] ? F extends string ? `${F}${D}${Join<Extract<R, string[]>, D>}` : never : string;
11
- export declare function _(path: Join<PathsToStringProps<typeof en>, ".">, lang: Locale): string | undefined;
12
- export declare function format(message: string | undefined, ...args: unknown[]): string | undefined;
@@ -1,30 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.format = exports._ = void 0;
7
- const en_1 = __importDefault(require("../locale/en"));
8
- const helpers_1 = require("../helpers/helpers");
9
- exports.default = en_1.default;
10
- function _(path, lang) {
11
- const translation = (0, helpers_1.resolve)(lang, path);
12
- if (!translation || typeof translation !== "string")
13
- return undefined;
14
- return translation;
15
- }
16
- exports._ = _;
17
- function format(message, ...args) {
18
- if (!message)
19
- return;
20
- // All arguments must be defined, otherwise nothing is returned
21
- for (const arg of args) {
22
- if (arg === undefined)
23
- return;
24
- }
25
- return message.replace(/{\d+}/g, (match) => {
26
- const index = +match.slice(1, -1);
27
- return `${args[index]}`;
28
- });
29
- }
30
- exports.format = format;
@@ -1,5 +0,0 @@
1
- import { IMetar } from "../model/model";
2
- export interface IMetarDated extends IMetar {
3
- issued: Date;
4
- }
5
- export declare function metarDatesHydrator(report: IMetar, date: Date): IMetarDated;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.metarDatesHydrator = void 0;
4
- const date_1 = require("../helpers/date");
5
- function metarDatesHydrator(report, date) {
6
- return Object.assign(Object.assign({}, report), { issued: (0, date_1.determineReportIssuedDate)(date, report.day, report.hour, report.minute) });
7
- }
8
- exports.metarDatesHydrator = metarDatesHydrator;
@@ -1,28 +0,0 @@
1
- import { WeatherChangeType } from "../model/enum";
2
- import { IAbstractTrend, IFMValidity, ITAF, IBaseTAFTrend, IValidity } from "../model/model";
3
- export declare type TAFTrendDated = IAbstractTrend & IBaseTAFTrend & {
4
- validity: IBaseTAFTrend["validity"] & {
5
- start: Date;
6
- end?: Date;
7
- };
8
- } & ({
9
- type: WeatherChangeType.FM;
10
- validity: IFMValidity & {
11
- start: Date;
12
- };
13
- } | {
14
- type: WeatherChangeType;
15
- validity: IValidity & {
16
- start: Date;
17
- end: Date;
18
- };
19
- });
20
- export interface ITAFDated extends ITAF {
21
- issued: Date;
22
- validity: ITAF["validity"] & {
23
- start: Date;
24
- end: Date;
25
- };
26
- trends: TAFTrendDated[];
27
- }
28
- export declare function tafDatesHydrator(report: ITAF, date: Date): ITAFDated;
package/dist/dates/taf.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tafDatesHydrator = void 0;
4
- const enum_1 = require("../model/enum");
5
- const date_1 = require("../helpers/date");
6
- function tafDatesHydrator(report, date) {
7
- const issued = (0, date_1.determineReportIssuedDate)(date, report.day, report.hour, report.minute);
8
- return Object.assign(Object.assign({}, report), { issued, validity: Object.assign(Object.assign({}, report.validity), { start: (0, date_1.getReportDate)(issued, report.validity.startDay, report.validity.startHour), end: (0, date_1.getReportDate)(issued, report.validity.endDay, report.validity.endHour) }), trends: report.trends.map((trend) => (Object.assign(Object.assign({}, trend), { validity: (() => {
9
- switch (trend.type) {
10
- case enum_1.WeatherChangeType.FM:
11
- return Object.assign(Object.assign({}, trend.validity), { start: (0, date_1.getReportDate)(issued, trend.validity.startDay, trend.validity.startHour, trend.validity.startMinutes) });
12
- default:
13
- return Object.assign(Object.assign({}, trend.validity), { start: (0, date_1.getReportDate)(issued, trend.validity.startDay, trend.validity.startHour), end: (0, date_1.getReportDate)(issued, trend.validity.endDay, trend.validity.endHour) });
14
- }
15
- })() }))) });
16
- }
17
- exports.tafDatesHydrator = tafDatesHydrator;
@@ -1,36 +0,0 @@
1
- import { TAFTrendDated } from "../dates/taf";
2
- import { ITAFDated } from "../dates/taf";
3
- import { ParseError } from "../commons/errors";
4
- /**
5
- * The initial forecast, extracted from the first line of the TAF, does not have
6
- * a trend type (FM, BECMG, etc)
7
- */
8
- export declare type Forecast = Omit<TAFTrendDated, "type"> & Partial<Pick<TAFTrendDated, "type">>;
9
- export interface IForecastContainer {
10
- station: string;
11
- issued: Date;
12
- start: Date;
13
- end: Date;
14
- message: string;
15
- forecast: Forecast[];
16
- }
17
- export declare function getForecastFromTAF(taf: ITAFDated): IForecastContainer;
18
- export interface ICompositeForecast {
19
- /**
20
- * The base forecast (type is `FM` or initial group)
21
- */
22
- base: Forecast;
23
- /**
24
- * Any forecast here should pre-empt the base forecast. These forecasts may
25
- * have probabilities of occuring, be temporary, or otherwise notable
26
- * precipitation events
27
- *
28
- * `type` is (`BECMG`, `TEMPO` or `PROB`)
29
- */
30
- additional: Forecast[];
31
- }
32
- export declare class TimestampOutOfBoundsError extends ParseError {
33
- name: string;
34
- constructor(message?: string);
35
- }
36
- export declare function getCompositeForecastForDate(date: Date, forecastContainer: IForecastContainer): ICompositeForecast;
@@ -1,72 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCompositeForecastForDate = exports.TimestampOutOfBoundsError = exports.getForecastFromTAF = void 0;
4
- const date_1 = require("../helpers/date");
5
- const errors_1 = require("../commons/errors");
6
- function getForecastFromTAF(taf) {
7
- return {
8
- issued: taf.issued,
9
- station: taf.station,
10
- message: taf.message,
11
- start: (0, date_1.getReportDate)(taf.issued, taf.validity.startDay, taf.validity.startHour),
12
- end: (0, date_1.getReportDate)(taf.issued, taf.validity.endDay, taf.validity.endHour),
13
- forecast: [makeInitialForecast(taf), ...taf.trends],
14
- };
15
- }
16
- exports.getForecastFromTAF = getForecastFromTAF;
17
- /**
18
- * Treat the base of the TAF as a FM
19
- */
20
- function makeInitialForecast(taf) {
21
- return {
22
- wind: taf.wind,
23
- visibility: taf.visibility,
24
- verticalVisibility: taf.verticalVisibility,
25
- windShear: taf.windShear,
26
- cavok: taf.cavok,
27
- remark: taf.remark,
28
- remarks: taf.remarks,
29
- clouds: taf.clouds,
30
- weatherConditions: taf.weatherConditions,
31
- validity: {
32
- // End day/hour are for end of the entire TAF
33
- startDay: taf.validity.startDay,
34
- startHour: taf.validity.startHour,
35
- startMinutes: 0,
36
- start: taf.validity.start,
37
- },
38
- };
39
- }
40
- class TimestampOutOfBoundsError extends errors_1.ParseError {
41
- constructor(message) {
42
- super(message);
43
- this.name = "TimestampOutOfBoundsError";
44
- Object.setPrototypeOf(this, new.target.prototype);
45
- }
46
- }
47
- exports.TimestampOutOfBoundsError = TimestampOutOfBoundsError;
48
- function getCompositeForecastForDate(date, forecastContainer) {
49
- // Validity bounds check
50
- if (date.getTime() > forecastContainer.end.getTime() ||
51
- date.getTime() < forecastContainer.start.getTime())
52
- throw new TimestampOutOfBoundsError("Provided timestamp is outside the report validity period");
53
- let base;
54
- let additional = [];
55
- for (const forecast of forecastContainer.forecast) {
56
- if (!forecast.validity.end &&
57
- forecast.validity.start.getTime() <= date.getTime()) {
58
- // Is FM or initial forecast
59
- base = forecast;
60
- }
61
- if (forecast.validity.end &&
62
- forecast.validity.end.getTime() - date.getTime() > 0 &&
63
- forecast.validity.start.getTime() - date.getTime() <= 0) {
64
- // Is BECMG or TEMPO
65
- additional.push(forecast);
66
- }
67
- }
68
- if (!base)
69
- throw new errors_1.UnexpectedParseError("Unable to find trend for date");
70
- return { base, additional };
71
- }
72
- exports.getCompositeForecastForDate = getCompositeForecastForDate;
@@ -1,11 +0,0 @@
1
- /**
2
- *
3
- * @param date Ideally the date the report was issued. However, any date within
4
- * ~14 days of the report will work.
5
- * @param day Day of the month (from the report)
6
- * @param hour Hour (from the report)
7
- * @param minute Minute (from the report)
8
- * @returns
9
- */
10
- export declare function determineReportIssuedDate(date: Date, day: number, hour: number, minute?: number): Date;
11
- export declare function getReportDate(issued: Date, day: number, hour: number, minute?: number): Date;
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getReportDate = exports.determineReportIssuedDate = void 0;
4
- /**
5
- *
6
- * @param date Ideally the date the report was issued. However, any date within
7
- * ~14 days of the report will work.
8
- * @param day Day of the month (from the report)
9
- * @param hour Hour (from the report)
10
- * @param minute Minute (from the report)
11
- * @returns
12
- */
13
- function determineReportIssuedDate(date, day, hour, minute) {
14
- const months = [
15
- setDateComponents(addMonthsUTC(date, -1), day, hour, minute),
16
- setDateComponents(new Date(date), day, hour, minute),
17
- setDateComponents(addMonthsUTC(date, 1), day, hour, minute),
18
- ];
19
- return months
20
- .map((d) => ({
21
- date: d,
22
- difference: Math.abs(d.getTime() - date.getTime()),
23
- }))
24
- .sort((a, b) => a.difference - b.difference)[0].date;
25
- }
26
- exports.determineReportIssuedDate = determineReportIssuedDate;
27
- function getReportDate(issued, day, hour, minute = 0) {
28
- let date = new Date(issued);
29
- if (day < date.getUTCDate()) {
30
- date = addMonthsUTC(date, 1);
31
- }
32
- date.setUTCDate(day);
33
- date.setUTCHours(hour);
34
- if (minute != null)
35
- date.setUTCMinutes(minute);
36
- return date;
37
- }
38
- exports.getReportDate = getReportDate;
39
- function setDateComponents(date, day, hour, minute) {
40
- date.setUTCDate(day);
41
- date.setUTCHours(hour);
42
- if (minute != null)
43
- date.setUTCMinutes(minute);
44
- return date;
45
- }
46
- function addMonthsUTC(date, count) {
47
- if (date && count) {
48
- let m, d = (date = new Date(+date)).getUTCDate();
49
- date.setUTCMonth(date.getUTCMonth() + count, 1);
50
- m = date.getUTCMonth();
51
- date.setUTCDate(d);
52
- if (date.getUTCMonth() !== m)
53
- date.setUTCDate(0);
54
- }
55
- return date;
56
- }
@@ -1,17 +0,0 @@
1
- /**
2
- * Split behaving similar to Python's implementation
3
- */
4
- export declare function pySplit(string: string, separator: string, n?: number): string[];
5
- /**
6
- * Access nested object properties by string path
7
- *
8
- * https://stackoverflow.com/a/22129960
9
- */
10
- export declare function resolve(obj: any, path: string | string[], separator?: string): unknown;
11
- /**
12
- * For safely casting input values
13
- * @param input String that is expected to be in the snum
14
- * @param enumExpected The enum to cast the input value to
15
- * @throws RemarkExecutionError when input is not a key of enum
16
- */
17
- export declare function as<T extends Record<string, unknown>>(input: string, enumExpected: T): T[keyof T];
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.as = exports.resolve = exports.pySplit = void 0;
4
- const errors_1 = require("../commons/errors");
5
- /**
6
- * Split behaving similar to Python's implementation
7
- */
8
- function pySplit(string, separator, n) {
9
- let split = string.split(separator);
10
- // Note: Python implementation will automatically trim empty values if
11
- // separator is undefined. Since this function is kinda meh, we'll just do it
12
- // for any spaces (pretty close to their implementation, since a space is the
13
- // default character to split on)
14
- //
15
- // https://docs.python.org/3/library/stdtypes.html?highlight=split#str.split
16
- if (separator === " ")
17
- split = split.filter((n) => n);
18
- if (n == null || split.length <= n)
19
- return split;
20
- const out = split.slice(0, n);
21
- out.push(split.slice(n).join(separator));
22
- return out;
23
- }
24
- exports.pySplit = pySplit;
25
- /**
26
- * Access nested object properties by string path
27
- *
28
- * https://stackoverflow.com/a/22129960
29
- */
30
- function resolve(obj, path, separator = ".") {
31
- const properties = Array.isArray(path) ? path : path.split(separator);
32
- return properties.reduce((prev, curr) => prev === null || prev === void 0 ? void 0 : prev[curr], obj);
33
- }
34
- exports.resolve = resolve;
35
- /**
36
- * For safely casting input values
37
- * @param input String that is expected to be in the snum
38
- * @param enumExpected The enum to cast the input value to
39
- * @throws RemarkExecutionError when input is not a key of enum
40
- */
41
- function as(input, enumExpected) {
42
- if (!Object.values(enumExpected).includes(input))
43
- throw new errors_1.CommandExecutionError(`${input} not found in ${Object.values(enumExpected)}`);
44
- return input;
45
- }
46
- exports.as = as;
package/dist/index.d.ts DELETED
@@ -1,32 +0,0 @@
1
- import { IMetar, ITAF } from "./model/model";
2
- import { Locale } from "./commons/i18n";
3
- import { IMetarDated } from "./dates/metar";
4
- import { ITAFDated } from "./dates/taf";
5
- import { IForecastContainer } from "./forecast/forecast";
6
- export { Locale } from "./commons/i18n";
7
- export * from "./commons/errors";
8
- export * from "./model/model";
9
- export * from "./model/enum";
10
- export { RemarkType, IBaseRemark, IUnknownRemark, Remark, ICeilingHeightRemark, ICeilingSecondLocationRemark, IHourlyMaximumMinimumTemperatureRemark, IHourlyMaximumTemperatureRemark, IHourlyMinimumTemperatureRemark, IHourlyPrecipitationAmountRemark, IHourlyPressureRemark, IHourlyTemperatureDewPointRemark, IIceAccretionRemark, IObscurationRemark, IPrecipitationAmount24HourRemark, IPrecipitationAmount36HourRemark, IPrecipitationBegEndRemark, IPrevailingVisibilityRemark, ISeaLevelPressureRemark, ISecondLocationVisibilityRemark, ISectorVisibilityRemark, ISmallHailSizeRemark, ISnowIncreaseRemark, ISnowPelletsRemark, ISunshineDurationRemark, ISurfaceVisibilityRemark, IThunderStormLocationRemark, IThunderStormLocationMovingRemark, ITornadicActivityBegRemark, ITornadicActivityBegEndRemark, ITornadicActivityEndRemark, ITowerVisibilityRemark, IVariableSkyRemark, IVariableSkyHeightRemark, IVirgaDirectionRemark, IWaterEquivalentSnowRemark, IWindPeakCommandRemark, IWindShiftFropaRemark, } from "./command/remark";
11
- export { getCompositeForecastForDate, IForecastContainer, ICompositeForecast, Forecast, TimestampOutOfBoundsError, } from "./forecast/forecast";
12
- export { TAFTrendDated, ITAFDated } from "./dates/taf";
13
- export interface IMetarTAFParserOptions {
14
- locale?: Locale;
15
- }
16
- export interface IMetarTAFParserOptionsDated extends IMetarTAFParserOptions {
17
- /**
18
- * This date should ideally be the date the report was issued. Otherwise, it
19
- * can be be +/- one week of the actual report date and work properly.
20
- *
21
- * So if you know the report was recently issued, you can pass `new Date()`
22
- *
23
- * This date is needed to create actual timestamps since the report only has
24
- * day of month, hour, and minute.
25
- */
26
- date: Date;
27
- }
28
- export declare function parseMetar(rawMetar: string, options?: IMetarTAFParserOptions): IMetar;
29
- export declare function parseMetar(rawMetar: string, options?: IMetarTAFParserOptionsDated): IMetarDated;
30
- export declare function parseTAF(rawTAF: string, options?: IMetarTAFParserOptions): ITAF;
31
- export declare function parseTAF(rawTAF: string, options?: IMetarTAFParserOptionsDated): ITAFDated;
32
- export declare function parseTAFAsForecast(rawTAF: string, options: IMetarTAFParserOptionsDated): IForecastContainer;
package/dist/index.js DELETED
@@ -1,62 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.parseTAFAsForecast = exports.parseTAF = exports.parseMetar = exports.TimestampOutOfBoundsError = exports.getCompositeForecastForDate = exports.RemarkType = void 0;
21
- const parser_1 = require("./parser/parser");
22
- const errors_1 = require("./commons/errors");
23
- const en_1 = __importDefault(require("./locale/en"));
24
- const metar_1 = require("./dates/metar");
25
- const taf_1 = require("./dates/taf");
26
- const forecast_1 = require("./forecast/forecast");
27
- __exportStar(require("./commons/errors"), exports);
28
- __exportStar(require("./model/model"), exports);
29
- __exportStar(require("./model/enum"), exports);
30
- var remark_1 = require("./command/remark");
31
- Object.defineProperty(exports, "RemarkType", { enumerable: true, get: function () { return remark_1.RemarkType; } });
32
- var forecast_2 = require("./forecast/forecast");
33
- Object.defineProperty(exports, "getCompositeForecastForDate", { enumerable: true, get: function () { return forecast_2.getCompositeForecastForDate; } });
34
- Object.defineProperty(exports, "TimestampOutOfBoundsError", { enumerable: true, get: function () { return forecast_2.TimestampOutOfBoundsError; } });
35
- function parseMetar(rawMetar, options) {
36
- return parse(rawMetar, options, parser_1.MetarParser, metar_1.metarDatesHydrator);
37
- }
38
- exports.parseMetar = parseMetar;
39
- function parseTAF(rawTAF, options) {
40
- return parse(rawTAF, options, parser_1.TAFParser, taf_1.tafDatesHydrator);
41
- }
42
- exports.parseTAF = parseTAF;
43
- function parseTAFAsForecast(rawTAF, options) {
44
- const taf = parseTAF(rawTAF, options);
45
- return (0, forecast_1.getForecastFromTAF)(taf);
46
- }
47
- exports.parseTAFAsForecast = parseTAFAsForecast;
48
- function parse(rawReport, options, parser, datesHydrator) {
49
- const lang = (options === null || options === void 0 ? void 0 : options.locale) || en_1.default;
50
- try {
51
- const report = new parser(lang).parse(rawReport);
52
- if (options && "date" in options) {
53
- return datesHydrator(report, options.date);
54
- }
55
- return report;
56
- }
57
- catch (e) {
58
- if (e instanceof errors_1.ParseError)
59
- throw e;
60
- throw new errors_1.InvalidWeatherStatementError(e);
61
- }
62
- }