metar-taf-parser 8.0.1 → 8.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.
- package/metar-taf-parser.d.ts +22 -12
- package/metar-taf-parser.js +35 -4
- package/package.json +1 -1
package/metar-taf-parser.d.ts
CHANGED
|
@@ -754,10 +754,10 @@ declare const _default: {
|
|
|
754
754
|
};
|
|
755
755
|
};
|
|
756
756
|
|
|
757
|
-
|
|
757
|
+
type DeepPartial<T> = T extends object ? {
|
|
758
758
|
[P in keyof T]?: DeepPartial<T[P]>;
|
|
759
759
|
} : T;
|
|
760
|
-
|
|
760
|
+
type Locale = DeepPartial<typeof _default>;
|
|
761
761
|
|
|
762
762
|
interface ICeilingHeightRemark extends IBaseRemark {
|
|
763
763
|
type: RemarkType.CeilingHeight;
|
|
@@ -1051,7 +1051,7 @@ interface IWindShiftFropaRemark extends IBaseRemark {
|
|
|
1051
1051
|
startMinute: number;
|
|
1052
1052
|
}
|
|
1053
1053
|
|
|
1054
|
-
|
|
1054
|
+
type DefaultRemarkTypes = RemarkType.AO1 | RemarkType.AO2 | RemarkType.PRESFR | RemarkType.PRESRR | RemarkType.TORNADO | RemarkType.FUNNELCLOUD | RemarkType.WATERSPOUT | RemarkType.VIRGA;
|
|
1055
1055
|
interface IDefaultCommandRemark extends IBaseRemark {
|
|
1056
1056
|
type: DefaultRemarkTypes;
|
|
1057
1057
|
}
|
|
@@ -1130,7 +1130,7 @@ declare enum RemarkType {
|
|
|
1130
1130
|
SunshineDuration = "SunshineDuration",
|
|
1131
1131
|
WaterEquivalentSnow = "WaterEquivalentSnow"
|
|
1132
1132
|
}
|
|
1133
|
-
|
|
1133
|
+
type Remark = IUnknownRemark | IDefaultCommandRemark | ICeilingHeightRemark | ICeilingSecondLocationRemark | IHailSizeRemark | IHourlyMaximumMinimumTemperatureRemark | IHourlyMaximumTemperatureRemark | IHourlyMinimumTemperatureRemark | IHourlyPrecipitationAmountRemark | IHourlyPressureRemark | IHourlyTemperatureDewPointRemark | IIceAccretionRemark | IObscurationRemark | IPrecipitationAmount24HourRemark | IPrecipitationAmount36HourRemark | IPrecipitationAmount36HourRemark | IPrecipitationBegRemark | IPrecipitationBegEndRemark | IPrecipitationEndRemark | IPrevailingVisibilityRemark | ISeaLevelPressureRemark | ISecondLocationVisibilityRemark | ISectorVisibilityRemark | ISmallHailSizeRemark | ISnowDepthRemark | ISnowIncreaseRemark | ISnowPelletsRemark | ISunshineDurationRemark | ISurfaceVisibilityRemark | IThunderStormLocationRemark | IThunderStormLocationMovingRemark | ITornadicActivityBegRemark | ITornadicActivityBegEndRemark | ITornadicActivityEndRemark | ITowerVisibilityRemark | IVariableSkyRemark | IVariableSkyHeightRemark | IVirgaDirectionRemark | IWaterEquivalentSnowRemark | IWindPeakCommandRemark | IWindShiftRemark | IWindShiftFropaRemark;
|
|
1134
1134
|
|
|
1135
1135
|
interface IWind {
|
|
1136
1136
|
speed: number;
|
|
@@ -1154,7 +1154,7 @@ interface Distance {
|
|
|
1154
1154
|
/** No Directional Visibility */
|
|
1155
1155
|
ndv?: true;
|
|
1156
1156
|
}
|
|
1157
|
-
|
|
1157
|
+
type Visibility = Distance & {
|
|
1158
1158
|
/**
|
|
1159
1159
|
* Never in North American METARs
|
|
1160
1160
|
*/
|
|
@@ -1182,7 +1182,7 @@ interface ITemperature {
|
|
|
1182
1182
|
interface ITemperatureDated extends ITemperature {
|
|
1183
1183
|
date: Date;
|
|
1184
1184
|
}
|
|
1185
|
-
|
|
1185
|
+
type RunwayInfo = IRunwayInfoRange | IRunwayInfoDeposit;
|
|
1186
1186
|
interface IBaseRunwayInfo {
|
|
1187
1187
|
name: string;
|
|
1188
1188
|
}
|
|
@@ -1376,7 +1376,7 @@ interface IBaseTAFTrend extends IAbstractTrend, ITafGroups {
|
|
|
1376
1376
|
*/
|
|
1377
1377
|
validity: IAbstractValidity & Partial<IFMValidity> & Partial<IValidity>;
|
|
1378
1378
|
}
|
|
1379
|
-
|
|
1379
|
+
type TAFTrend = IBaseTAFTrend & ({
|
|
1380
1380
|
type: WeatherChangeType.FM;
|
|
1381
1381
|
validity: IFMValidity;
|
|
1382
1382
|
} | {
|
|
@@ -1431,7 +1431,7 @@ interface IMetarDated extends IMetar {
|
|
|
1431
1431
|
issued: Date;
|
|
1432
1432
|
}
|
|
1433
1433
|
|
|
1434
|
-
|
|
1434
|
+
type TAFTrendDated = IAbstractTrend & IBaseTAFTrend & {
|
|
1435
1435
|
validity: IBaseTAFTrend["validity"] & {
|
|
1436
1436
|
start: Date;
|
|
1437
1437
|
end?: Date;
|
|
@@ -1468,6 +1468,16 @@ declare class InvalidWeatherStatementError extends ParseError {
|
|
|
1468
1468
|
cause?: unknown;
|
|
1469
1469
|
constructor(cause?: unknown);
|
|
1470
1470
|
}
|
|
1471
|
+
/**
|
|
1472
|
+
* Thrown when an input contains data elements that are recognized but
|
|
1473
|
+
* intentionally not supported.
|
|
1474
|
+
*/
|
|
1475
|
+
declare class PartialWeatherStatementError extends InvalidWeatherStatementError {
|
|
1476
|
+
name: string;
|
|
1477
|
+
part: number;
|
|
1478
|
+
total: number;
|
|
1479
|
+
constructor(partialMessage: string, part: number, total: number);
|
|
1480
|
+
}
|
|
1471
1481
|
/**
|
|
1472
1482
|
* Thrown when command marked as canParse, but couldn't parse when
|
|
1473
1483
|
* executing (for example, an invalid CloudQuantity)
|
|
@@ -1488,9 +1498,9 @@ declare class UnexpectedParseError extends ParseError {
|
|
|
1488
1498
|
* The initial forecast, extracted from the first line of the TAF, does not have
|
|
1489
1499
|
* a trend type (FM, BECMG, etc)
|
|
1490
1500
|
*/
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1501
|
+
type ForecastWithoutDates = Omit<TAFTrendDated, "type"> & Partial<Pick<TAFTrendDated, "type">>;
|
|
1502
|
+
type ForecastWithoutValidity = Omit<ForecastWithoutDates, "validity">;
|
|
1503
|
+
type Forecast = Omit<ForecastWithoutValidity, "type"> & {
|
|
1494
1504
|
start: Date;
|
|
1495
1505
|
end: Date;
|
|
1496
1506
|
} & ({
|
|
@@ -1554,4 +1564,4 @@ declare function parseTAF(rawTAF: string, options?: IMetarTAFParserOptions): ITA
|
|
|
1554
1564
|
declare function parseTAF(rawTAF: string, options?: IMetarTAFParserOptionsDated): ITAFDated;
|
|
1555
1565
|
declare function parseTAFAsForecast(rawTAF: string, options: IMetarTAFParserOptionsDated): IForecastContainer;
|
|
1556
1566
|
|
|
1557
|
-
export { AltimeterUnit, CloudQuantity, CloudType, CommandExecutionError, DepositCoverage, DepositType, Descriptive, Direction, Distance, DistanceUnit, Forecast, IAbstractTrend, IAbstractValidity, IAbstractWeatherCode, IAbstractWeatherCodeDated, IAbstractWeatherContainer, IAltimeter, IBaseRemark, IBaseRunwayInfo, IBaseTAFTrend, ICeilingHeightRemark, ICeilingSecondLocationRemark, ICloud, ICompositeForecast, IEndValidity, IFMValidity, IFlags, IForecastContainer, IHourlyMaximumMinimumTemperatureRemark, IHourlyMaximumTemperatureRemark, IHourlyMinimumTemperatureRemark, IHourlyPrecipitationAmountRemark, IHourlyPressureRemark, IHourlyTemperatureDewPointRemark, IIceAccretionRemark, IIcing, IMetar, IMetarDated, IMetarTAFParserOptions, IMetarTAFParserOptionsDated, IMetarTrend, IMetarTrendTime, IObscurationRemark, IPrecipitationAmount24HourRemark, IPrecipitationAmount36HourRemark, IPrecipitationBegEndRemark, IPrevailingVisibilityRemark, IRunwayInfoDeposit, IRunwayInfoRange, ISeaLevelPressureRemark, ISecondLocationVisibilityRemark, ISectorVisibilityRemark, ISmallHailSizeRemark, ISnowIncreaseRemark, ISnowPelletsRemark, ISunshineDurationRemark, ISurfaceVisibilityRemark, ITAF, ITAFDated, ITafGroups, ITemperature, ITemperatureDated, IThunderStormLocationMovingRemark, IThunderStormLocationRemark, ITime, ITornadicActivityBegEndRemark, ITornadicActivityBegRemark, ITornadicActivityEndRemark, ITowerVisibilityRemark, ITurbulence, IUnknownRemark, IValidity, IValidityDated, IVariableSkyHeightRemark, IVariableSkyRemark, IVirgaDirectionRemark, IWaterEquivalentSnowRemark, IWeatherCondition, IWind, IWindPeakCommandRemark, IWindShear, IWindShiftFropaRemark, IcingIntensity, Intensity, InvalidWeatherStatementError, Locale, MetarType, ParseError, Phenomenon, Remark, RemarkType, RunwayInfo, RunwayInfoTrend, RunwayInfoUnit, SpeedUnit, TAFTrend, TAFTrendDated, TimeIndicator, TimestampOutOfBoundsError, TurbulenceIntensity, UnexpectedParseError, ValueIndicator, Visibility, WeatherChangeType, getCompositeForecastForDate, isWeatherConditionValid, parseMetar, parseTAF, parseTAFAsForecast };
|
|
1567
|
+
export { AltimeterUnit, CloudQuantity, CloudType, CommandExecutionError, DepositCoverage, DepositType, Descriptive, Direction, Distance, DistanceUnit, Forecast, IAbstractTrend, IAbstractValidity, IAbstractWeatherCode, IAbstractWeatherCodeDated, IAbstractWeatherContainer, IAltimeter, IBaseRemark, IBaseRunwayInfo, IBaseTAFTrend, ICeilingHeightRemark, ICeilingSecondLocationRemark, ICloud, ICompositeForecast, IEndValidity, IFMValidity, IFlags, IForecastContainer, IHourlyMaximumMinimumTemperatureRemark, IHourlyMaximumTemperatureRemark, IHourlyMinimumTemperatureRemark, IHourlyPrecipitationAmountRemark, IHourlyPressureRemark, IHourlyTemperatureDewPointRemark, IIceAccretionRemark, IIcing, IMetar, IMetarDated, IMetarTAFParserOptions, IMetarTAFParserOptionsDated, IMetarTrend, IMetarTrendTime, IObscurationRemark, IPrecipitationAmount24HourRemark, IPrecipitationAmount36HourRemark, IPrecipitationBegEndRemark, IPrevailingVisibilityRemark, IRunwayInfoDeposit, IRunwayInfoRange, ISeaLevelPressureRemark, ISecondLocationVisibilityRemark, ISectorVisibilityRemark, ISmallHailSizeRemark, ISnowIncreaseRemark, ISnowPelletsRemark, ISunshineDurationRemark, ISurfaceVisibilityRemark, ITAF, ITAFDated, ITafGroups, ITemperature, ITemperatureDated, IThunderStormLocationMovingRemark, IThunderStormLocationRemark, ITime, ITornadicActivityBegEndRemark, ITornadicActivityBegRemark, ITornadicActivityEndRemark, ITowerVisibilityRemark, ITurbulence, IUnknownRemark, IValidity, IValidityDated, IVariableSkyHeightRemark, IVariableSkyRemark, IVirgaDirectionRemark, IWaterEquivalentSnowRemark, IWeatherCondition, IWind, IWindPeakCommandRemark, IWindShear, IWindShiftFropaRemark, IcingIntensity, Intensity, InvalidWeatherStatementError, Locale, MetarType, ParseError, PartialWeatherStatementError, Phenomenon, Remark, RemarkType, RunwayInfo, RunwayInfoTrend, RunwayInfoUnit, SpeedUnit, TAFTrend, TAFTrendDated, TimeIndicator, TimestampOutOfBoundsError, TurbulenceIntensity, UnexpectedParseError, ValueIndicator, Visibility, WeatherChangeType, getCompositeForecastForDate, isWeatherConditionValid, parseMetar, parseTAF, parseTAFAsForecast };
|
package/metar-taf-parser.js
CHANGED
|
@@ -39,6 +39,19 @@ class InvalidWeatherStatementError extends ParseError {
|
|
|
39
39
|
this.cause = cause;
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Thrown when an input contains data elements that are recognized but
|
|
44
|
+
* intentionally not supported.
|
|
45
|
+
*/
|
|
46
|
+
class PartialWeatherStatementError extends InvalidWeatherStatementError {
|
|
47
|
+
constructor(partialMessage, part, total) {
|
|
48
|
+
super(`Input is partial TAF (${partialMessage}), see: https://github.com/aeharding/metar-taf-parser/issues/68`);
|
|
49
|
+
this.name = "PartialWeatherStatementError";
|
|
50
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
51
|
+
this.part = part;
|
|
52
|
+
this.total = total;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
42
55
|
/**
|
|
43
56
|
* Thrown when command marked as canParse, but couldn't parse when
|
|
44
57
|
* executing (for example, an invalid CloudQuantity)
|
|
@@ -2239,7 +2252,7 @@ class CommandSupplier {
|
|
|
2239
2252
|
}
|
|
2240
2253
|
_CommandSupplier_commands = new WeakMap();
|
|
2241
2254
|
|
|
2242
|
-
var _AbstractParser_INTENSITY_REGEX, _AbstractParser_CAVOK, _AbstractParser_commonSupplier, _MetarParser_commandSupplier, _TAFParser_commandSupplier, _TAFParser_validityPattern, _RemarkParser_supplier;
|
|
2255
|
+
var _AbstractParser_INTENSITY_REGEX, _AbstractParser_CAVOK, _AbstractParser_commonSupplier, _MetarParser_commandSupplier, _TAFParser_commandSupplier, _TAFParser_validityPattern, _TAFParser_partialPattern, _RemarkParser_supplier;
|
|
2243
2256
|
function isStation(stationString) {
|
|
2244
2257
|
return stationString.length === 4;
|
|
2245
2258
|
}
|
|
@@ -2576,6 +2589,23 @@ class TAFParser extends AbstractParser {
|
|
|
2576
2589
|
this.TN = "TN";
|
|
2577
2590
|
_TAFParser_commandSupplier.set(this, new CommandSupplier());
|
|
2578
2591
|
_TAFParser_validityPattern.set(this, /^\d{4}\/\d{4}$/);
|
|
2592
|
+
_TAFParser_partialPattern.set(this, /^PART (\d) OF (\d) /);
|
|
2593
|
+
}
|
|
2594
|
+
/**
|
|
2595
|
+
* Check a tokenized TAF against patterns that are explicitly not supported,
|
|
2596
|
+
* throwing a descriptive exception to assist anyone who might want to apply
|
|
2597
|
+
* any necessary custom parsing.
|
|
2598
|
+
*
|
|
2599
|
+
* @param input original input.
|
|
2600
|
+
*/
|
|
2601
|
+
throwIfPartial(input) {
|
|
2602
|
+
// TAFs in NOAA cycle files beginning `PART x OF y`,
|
|
2603
|
+
// implying they are incomplete
|
|
2604
|
+
const matches = input.match(__classPrivateFieldGet(this, _TAFParser_partialPattern, "f"));
|
|
2605
|
+
if (matches) {
|
|
2606
|
+
const [partialMessage, part, total] = matches;
|
|
2607
|
+
throw new PartialWeatherStatementError(partialMessage.trim(), +part, +total);
|
|
2608
|
+
}
|
|
2579
2609
|
}
|
|
2580
2610
|
/**
|
|
2581
2611
|
* TAF messages can be formatted poorly
|
|
@@ -2605,6 +2635,7 @@ class TAFParser extends AbstractParser {
|
|
|
2605
2635
|
* @throws ParseError if the message is invalid
|
|
2606
2636
|
*/
|
|
2607
2637
|
parse(input) {
|
|
2638
|
+
this.throwIfPartial(input);
|
|
2608
2639
|
const lines = this.extractLinesTokens(input);
|
|
2609
2640
|
let [index, flags] = this.parseMessageStart(lines[0]);
|
|
2610
2641
|
const station = lines[0][index];
|
|
@@ -2674,7 +2705,7 @@ class TAFParser extends AbstractParser {
|
|
|
2674
2705
|
const singleLine = tafCode.replace(/\n/g, " ");
|
|
2675
2706
|
const cleanLine = singleLine.replace(/\s{2,}/g, " ");
|
|
2676
2707
|
const lines = joinProbIfNeeded(cleanLine
|
|
2677
|
-
.replace(/\s(?=PROB\d{2}\s(?=TEMPO|INTER)|TEMPO|INTER|BECMG|FM|PROB)/g, "\n")
|
|
2708
|
+
.replace(/\s(?=PROB\d{2}\s(?=TEMPO|INTER)|TEMPO|INTER|BECMG|FM(?![A-Z]{2}\s)|PROB)/g, "\n")
|
|
2678
2709
|
.split(/\n/));
|
|
2679
2710
|
// TODO cleanup
|
|
2680
2711
|
function joinProbIfNeeded(ls) {
|
|
@@ -2785,7 +2816,7 @@ class TAFParser extends AbstractParser {
|
|
|
2785
2816
|
};
|
|
2786
2817
|
}
|
|
2787
2818
|
}
|
|
2788
|
-
_TAFParser_commandSupplier = new WeakMap(), _TAFParser_validityPattern = new WeakMap();
|
|
2819
|
+
_TAFParser_commandSupplier = new WeakMap(), _TAFParser_validityPattern = new WeakMap(), _TAFParser_partialPattern = new WeakMap();
|
|
2789
2820
|
class RemarkParser {
|
|
2790
2821
|
constructor(locale) {
|
|
2791
2822
|
this.locale = locale;
|
|
@@ -3093,4 +3124,4 @@ function parse(rawReport, options, parser, datesHydrator) {
|
|
|
3093
3124
|
}
|
|
3094
3125
|
}
|
|
3095
3126
|
|
|
3096
|
-
export { AltimeterUnit, CloudQuantity, CloudType, CommandExecutionError, DepositCoverage, DepositType, Descriptive, Direction, DistanceUnit, IcingIntensity, Intensity, InvalidWeatherStatementError, MetarType, ParseError, Phenomenon, RemarkType, RunwayInfoTrend, RunwayInfoUnit, SpeedUnit, TimeIndicator, TimestampOutOfBoundsError, TurbulenceIntensity, UnexpectedParseError, ValueIndicator, WeatherChangeType, getCompositeForecastForDate, isWeatherConditionValid, parseMetar, parseTAF, parseTAFAsForecast };
|
|
3127
|
+
export { AltimeterUnit, CloudQuantity, CloudType, CommandExecutionError, DepositCoverage, DepositType, Descriptive, Direction, DistanceUnit, IcingIntensity, Intensity, InvalidWeatherStatementError, MetarType, ParseError, PartialWeatherStatementError, Phenomenon, RemarkType, RunwayInfoTrend, RunwayInfoUnit, SpeedUnit, TimeIndicator, TimestampOutOfBoundsError, TurbulenceIntensity, UnexpectedParseError, ValueIndicator, WeatherChangeType, getCompositeForecastForDate, isWeatherConditionValid, parseMetar, parseTAF, parseTAFAsForecast };
|