这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,45 @@ forecast.properties.periods.forEach(period => {
// Today Partly sunny, with a high near 86. Northeast wind 2 to 6 mph.
// Tonight Partly cloudy, with a low around 68. South southeast wind around 3 mph.
```

### Get the closest weather stations for a given latitude and longitude

```javascript
const stations = await client.getStations(latitude, longitude);
stations.features.forEach(station => console.log(station.properties.name));
// San Francisco, San Francisco International Airport
// SAN FRANCISCO DOWNTOWN
// Half Moon Bay Airport
```

### Get the closest weather station for a given latitude and longitude

```javascript
const nearestStation = await client.getNearestStation(latitude, longitude);
if (nearestStation) {
console.log(nearestStation.properties.stationIdentifier);
}
// KSFO
```

### Get weather observations for a given station

```javascript
const nearestStation = await client.getNearestStation(latitude, longitude);
if (nearestStation) {
const { stationIdentifier } = nearestStation.properties;
const observations = await client.getStationObservations(stationIdentifier);
observations.features.forEach(obs => console.log(obs.properties.temperature));
// { value: 16.1, unitCode: 'unit:degC', qualityControl: 'qc:V' }
// { value: 16.7, unitCode: 'unit:degC', qualityControl: 'qc:V' }
// { value: 17.2, unitCode: 'unit:degC', qualityControl: 'qc:V' }
}
```

### Get the latest weather observation for a given station

```javascript
const latestObservation = await client.getLatestStationObservations('KSFO');
console.log(latestObservation.properties.relativeHumidity);
// { value: 64.486025639597, unitCode: 'unit:percent', qualityControl: 'qc:V' }
```
18 changes: 17 additions & 1 deletion dist/client.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ClientOptions, ForecastResponse, AlertsResponse, ForecastType, StationsResponse, Station, AlertOptions } from './types';
import { ClientOptions, ForecastResponse, AlertsResponse, ForecastType, StationsResponse, Station, ObservationResponse, ObservationsResponse, AlertOptions } from './types';
/**
* The main client
*
Expand Down Expand Up @@ -60,5 +60,21 @@ declare class Client {
*
*/
getNearestStation(latitude: number, longitude: number): Promise<Station | null>;
/**
* Get weather observations for a given station.
*
* ```typescript
* const observations = await client.getStationObservations('KSFO');
* ```
*/
getStationObservations(stationId: string): Promise<ObservationsResponse>;
/**
* Get latest weather observation for a given station.
*
* ```typescript
* const latestObservation = await client.getLatestStationObservations('KSFO');
* ```
*/
getLatestStationObservations(stationId: string): Promise<ObservationResponse>;
}
export { Client };
20 changes: 20 additions & 0 deletions dist/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,25 @@ class Client {
}
return null;
}
/**
* Get weather observations for a given station.
*
* ```typescript
* const observations = await client.getStationObservations('KSFO');
* ```
*/
getStationObservations(stationId) {
return this.getPath(`stations/${stationId}/observations`);
}
/**
* Get latest weather observation for a given station.
*
* ```typescript
* const latestObservation = await client.getLatestStationObservations('KSFO');
* ```
*/
getLatestStationObservations(stationId) {
return this.getPath(`stations/${stationId}/observations/latest`);
}
}
exports.Client = Client;
2 changes: 1 addition & 1 deletion dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { Client } from './client';
export { ForecastType, Area, Region, RegionType, Urgency, AlertOptions, ClientOptions, PointResponse, ForecastResponse, ForecastProperties, AlertsResponse, Station, StationsResponse, AlertsFeature } from './types';
export { ForecastType, Area, Region, RegionType, Urgency, AlertOptions, ClientOptions, PointResponse, ForecastResponse, ForecastProperties, AlertsResponse, Station, StationsResponse, AlertsFeature, ObservationResponse, ObservationsResponse, Measure } from './types';
31 changes: 30 additions & 1 deletion dist/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,39 @@ declare type PointResponse = {
};
declare type Station = {
id: string;
properties: {
name: string;
stationIdentifier: string;
};
};
declare type StationsResponse = {
features: Station[];
};
declare type PresentWeather = {
[key: string]: string | null;
};
declare type Measure = {
value: number;
unitCode: string;
};
declare type ObservationResponse = {
properties: {
presentWeather: PresentWeather[];
temperature: Measure;
barometricPressure: Measure;
seaLevelPressure: Measure;
dewpoint: Measure;
windDirection: Measure;
windSpeed: Measure;
windGust: Measure;
visibility: Measure;
relativeHumidity: Measure;
heatIndex: Measure;
};
};
declare type ObservationsResponse = {
features: ObservationResponse[];
};
declare type ForecastPeriod = {
number: number;
name: string;
Expand Down Expand Up @@ -88,4 +117,4 @@ declare type AlertsFeature = {
declare type AlertsResponse = {
features: AlertsFeature[];
};
export { ForecastType, Area, Region, RegionType, Urgency, AlertOptions, ClientOptions, PointResponse, ForecastResponse, ForecastProperties, Station, StationsResponse, AlertsResponse, AlertsFeature };
export { ForecastType, Area, Region, RegionType, Urgency, AlertOptions, ClientOptions, PointResponse, ForecastResponse, ForecastProperties, Station, StationsResponse, AlertsResponse, AlertsFeature, ObservationsResponse, ObservationResponse, Measure };
2 changes: 1 addition & 1 deletion docs/assets/js/search.js

Large diffs are not rendered by default.

91 changes: 84 additions & 7 deletions docs/classes/client.html
Original file line number Diff line number Diff line change
Expand Up @@ -2716,12 +2716,18 @@
<li class=" tsd-kind-method tsd-parent-kind-class">
<a href="client.html#getforecast" class="tsd-kind-icon">get<wbr>Forecast</a>
</li>
<li class=" tsd-kind-method tsd-parent-kind-class">
<a href="client.html#getlateststationobservations" class="tsd-kind-icon">get<wbr>Latest<wbr>Station<wbr>Observations</a>
</li>
<li class=" tsd-kind-method tsd-parent-kind-class">
<a href="client.html#getneareststation" class="tsd-kind-icon">get<wbr>Nearest<wbr>Station</a>
</li>
<li class=" tsd-kind-method tsd-parent-kind-class">
<a href="client.html#getoptions" class="tsd-kind-icon">get<wbr>Options</a>
</li>
<li class=" tsd-kind-method tsd-parent-kind-class">
<a href="client.html#getstationobservations" class="tsd-kind-icon">get<wbr>Station<wbr>Observations</a>
</li>
<li class=" tsd-kind-method tsd-parent-kind-class">
<a href="client.html#getstations" class="tsd-kind-icon">get<wbr>Stations</a>
</li>
Expand Down Expand Up @@ -2754,6 +2760,15 @@
<li class=" tsd-kind-type-alias">
<a href="../modules.html#forecasttype" class="tsd-kind-icon">Forecast<wbr>Type</a>
</li>
<li class=" tsd-kind-type-alias">
<a href="../modules.html#measure" class="tsd-kind-icon">Measure</a>
</li>
<li class=" tsd-kind-type-alias">
<a href="../modules.html#observationresponse" class="tsd-kind-icon">Observation<wbr>Response</a>
</li>
<li class=" tsd-kind-type-alias">
<a href="../modules.html#observationsresponse" class="tsd-kind-icon">Observations<wbr>Response</a>
</li>
<li class=" tsd-kind-type-alias">
<a href="../modules.html#pointresponse" class="tsd-kind-icon">Point<wbr>Response</a>
</li>
Expand Down Expand Up @@ -2808,8 +2823,10 @@ <h3>Methods</h3>
<ul class="tsd-index-list">
<li class="tsd-kind-method tsd-parent-kind-class"><a href="client.html#getalerts" class="tsd-kind-icon">get<wbr>Alerts</a></li>
<li class="tsd-kind-method tsd-parent-kind-class"><a href="client.html#getforecast" class="tsd-kind-icon">get<wbr>Forecast</a></li>
<li class="tsd-kind-method tsd-parent-kind-class"><a href="client.html#getlateststationobservations" class="tsd-kind-icon">get<wbr>Latest<wbr>Station<wbr>Observations</a></li>
<li class="tsd-kind-method tsd-parent-kind-class"><a href="client.html#getneareststation" class="tsd-kind-icon">get<wbr>Nearest<wbr>Station</a></li>
<li class="tsd-kind-method tsd-parent-kind-class"><a href="client.html#getoptions" class="tsd-kind-icon">get<wbr>Options</a></li>
<li class="tsd-kind-method tsd-parent-kind-class"><a href="client.html#getstationobservations" class="tsd-kind-icon">get<wbr>Station<wbr>Observations</a></li>
<li class="tsd-kind-method tsd-parent-kind-class"><a href="client.html#getstations" class="tsd-kind-icon">get<wbr>Stations</a></li>
<li class="tsd-kind-method tsd-parent-kind-class"><a href="client.html#setoptions" class="tsd-kind-icon">set<wbr>Options</a></li>
</ul>
Expand All @@ -2829,7 +2846,7 @@ <h3>constructor</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/JasonSanford/weathered/blob/6eb952d/src/client.ts#L41">client.ts:41</a></li>
<li>Defined in <a href="https://github.com/JasonSanford/weathered/blob/8ef2873/src/client.ts#L41">client.ts:41</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand All @@ -2855,7 +2872,7 @@ <h3>get<wbr>Alerts</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/JasonSanford/weathered/blob/6eb952d/src/client.ts#L91">client.ts:91</a></li>
<li>Defined in <a href="https://github.com/JasonSanford/weathered/blob/8ef2873/src/client.ts#L91">client.ts:91</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -2891,7 +2908,7 @@ <h3>get<wbr>Forecast</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/JasonSanford/weathered/blob/6eb952d/src/client.ts#L107">client.ts:107</a></li>
<li>Defined in <a href="https://github.com/JasonSanford/weathered/blob/8ef2873/src/client.ts#L107">client.ts:107</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -2919,6 +2936,36 @@ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</
</li>
</ul>
</section>
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class">
<a name="getlateststationobservations" class="tsd-anchor"></a>
<h3>get<wbr>Latest<wbr>Station<wbr>Observations</h3>
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class">
<li class="tsd-signature tsd-kind-icon">get<wbr>Latest<wbr>Station<wbr>Observations<span class="tsd-signature-symbol">(</span>stationId<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><a href="../modules.html#observationresponse" class="tsd-signature-type" data-tsd-kind="Type alias">ObservationResponse</a><span class="tsd-signature-symbol">&gt;</span></li>
</ul>
<ul class="tsd-descriptions">
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/JasonSanford/weathered/blob/8ef2873/src/client.ts#L177">client.ts:177</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Get latest weather observation for a given station.</p>
</div>
<pre><code class="language-typescript"><span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">latestObservation</span><span style="color: #000000"> = </span><span style="color: #AF00DB">await</span><span style="color: #000000"> </span><span style="color: #001080">client</span><span style="color: #000000">.</span><span style="color: #795E26">getLatestStationObservations</span><span style="color: #000000">(</span><span style="color: #A31515">&#039;KSFO&#039;</span><span style="color: #000000">);</span>
</code></pre>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>stationId: <span class="tsd-signature-type">string</span></h5>
</li>
</ul>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><a href="../modules.html#observationresponse" class="tsd-signature-type" data-tsd-kind="Type alias">ObservationResponse</a><span class="tsd-signature-symbol">&gt;</span></h4>
</li>
</ul>
</section>
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class">
<a name="getneareststation" class="tsd-anchor"></a>
<h3>get<wbr>Nearest<wbr>Station</h3>
Expand All @@ -2929,7 +2976,7 @@ <h3>get<wbr>Nearest<wbr>Station</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/JasonSanford/weathered/blob/6eb952d/src/client.ts#L150">client.ts:150</a></li>
<li>Defined in <a href="https://github.com/JasonSanford/weathered/blob/8ef2873/src/client.ts#L150">client.ts:150</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -2964,13 +3011,43 @@ <h3>get<wbr>Options</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/JasonSanford/weathered/blob/6eb952d/src/client.ts#L73">client.ts:73</a></li>
<li>Defined in <a href="https://github.com/JasonSanford/weathered/blob/8ef2873/src/client.ts#L73">client.ts:73</a></li>
</ul>
</aside>
<h4 class="tsd-returns-title">Returns <a href="../modules.html#clientoptions" class="tsd-signature-type" data-tsd-kind="Type alias">ClientOptions</a></h4>
</li>
</ul>
</section>
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class">
<a name="getstationobservations" class="tsd-anchor"></a>
<h3>get<wbr>Station<wbr>Observations</h3>
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class">
<li class="tsd-signature tsd-kind-icon">get<wbr>Station<wbr>Observations<span class="tsd-signature-symbol">(</span>stationId<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><a href="../modules.html#observationsresponse" class="tsd-signature-type" data-tsd-kind="Type alias">ObservationsResponse</a><span class="tsd-signature-symbol">&gt;</span></li>
</ul>
<ul class="tsd-descriptions">
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/JasonSanford/weathered/blob/8ef2873/src/client.ts#L166">client.ts:166</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Get weather observations for a given station.</p>
</div>
<pre><code class="language-typescript"><span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">observations</span><span style="color: #000000"> = </span><span style="color: #AF00DB">await</span><span style="color: #000000"> </span><span style="color: #001080">client</span><span style="color: #000000">.</span><span style="color: #795E26">getStationObservations</span><span style="color: #000000">(</span><span style="color: #A31515">&#039;KSFO&#039;</span><span style="color: #000000">);</span>
</code></pre>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>stationId: <span class="tsd-signature-type">string</span></h5>
</li>
</ul>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><a href="../modules.html#observationsresponse" class="tsd-signature-type" data-tsd-kind="Type alias">ObservationsResponse</a><span class="tsd-signature-symbol">&gt;</span></h4>
</li>
</ul>
</section>
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class">
<a name="getstations" class="tsd-anchor"></a>
<h3>get<wbr>Stations</h3>
Expand All @@ -2981,7 +3058,7 @@ <h3>get<wbr>Stations</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/JasonSanford/weathered/blob/6eb952d/src/client.ts#L124">client.ts:124</a></li>
<li>Defined in <a href="https://github.com/JasonSanford/weathered/blob/8ef2873/src/client.ts#L124">client.ts:124</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -3016,7 +3093,7 @@ <h3>set<wbr>Options</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/JasonSanford/weathered/blob/6eb952d/src/client.ts#L77">client.ts:77</a></li>
<li>Defined in <a href="https://github.com/JasonSanford/weathered/blob/8ef2873/src/client.ts#L77">client.ts:77</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand Down
Loading