Socket
Socket
Sign inDemoInstall

weathered

Package Overview
Dependencies
8
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.3 to 0.1.0

docs/assets/css/main.css

33

dist/client.d.ts
import { ClientOptions, ForecastResponse, AlertsResponse, ForecastType, AlertOptions } from './types';
/**
* The main client
*
* ```typescript
* const client = new Client();
* ```
*/
declare class Client {
options: ClientOptions;
private options;
constructor(options?: ClientOptions);
private getPath;
private getUrl;
private getPoint;
getOptions(): ClientOptions;
setOptions(newOptions: ClientOptions): void;
/**
* Get weather alerts for a given area
*
* ```typescript
* const active = true;
* const latitude = 35.6175667;
* const longitude = -80.7709911;
* const alerts = await client.getAlerts(active, { latitude, longitude });
* ```
*/
getAlerts(active: boolean, options: AlertOptions): Promise<AlertsResponse>;
private getPoint;
/**
* Get a weather forecast for a given latitude and longitude
*
* ```typescript
* const latitude = 35.6175667;
* const longitude = -80.7709911;
* const forecast = await client.getForecast(latitude, longitude, 'baseline');
* ```
*
*/
getForecast(latitude: number, longitude: number, forecastType: ForecastType): Promise<ForecastResponse>;
}
export { Client };

@@ -26,5 +26,12 @@ "use strict";

};
/**
* The main client
*
* ```typescript
* const client = new Client();
* ```
*/
class Client {
constructor(options) {
this.options = Object.assign(defaultOptions, options);
this.options = { ...defaultOptions, ...options };
}

@@ -38,2 +45,22 @@ getPath(path) {

}
getPoint(latitude, longitude) {
const path = `points/${latitude},${longitude}`;
return this.getPath(path);
}
getOptions() {
return { ...this.options };
}
setOptions(newOptions) {
this.options = { ...this.options, ...newOptions };
}
/**
* Get weather alerts for a given area
*
* ```typescript
* const active = true;
* const latitude = 35.6175667;
* const longitude = -80.7709911;
* const alerts = await client.getAlerts(active, { latitude, longitude });
* ```
*/
getAlerts(active, options) {

@@ -44,6 +71,12 @@ const params = processOptions(options);

}
getPoint(latitude, longitude) {
const path = `points/${latitude},${longitude}`;
return this.getPath(path);
}
/**
* Get a weather forecast for a given latitude and longitude
*
* ```typescript
* const latitude = 35.6175667;
* const longitude = -80.7709911;
* const forecast = await client.getForecast(latitude, longitude, 'baseline');
* ```
*
*/
async getForecast(latitude, longitude, forecastType) {

@@ -50,0 +83,0 @@ const pointResp = await this.getPoint(latitude, longitude);

9

dist/client.test.js

@@ -7,8 +7,13 @@ "use strict";

const client = new _1.Client();
expect(client.options.userAgent).toBe('weathered module version 0.0.0');
expect(client.getOptions().userAgent).toBe('weathered package');
});
it('uses a custom userAgent', () => {
const client = new _1.Client({ userAgent: 'secret agent' });
expect(client.options.userAgent).toBe('secret agent');
expect(client.getOptions().userAgent).toBe('secret agent');
});
it('can change userAgent', () => {
const client = new _1.Client();
client.setOptions({ userAgent: 'a new userAgent' });
expect(client.getOptions().userAgent).toBe('a new userAgent');
});
});
export { Client } from './client';
export { ForecastType, Area, Region, RegionType, Urgency, AlertOptions, ClientOptions, PointResponse, ForecastResponse } from './types';
export { ForecastType, Area, Region, RegionType, Urgency, AlertOptions, ClientOptions, PointResponse, ForecastResponse, AlertsResponse, AlertsFeature } from './types';

@@ -10,23 +10,23 @@ declare type ForecastType = 'hourly' | 'baseline';

declare type XOR<T, U> = (T | U) extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
interface AreaOption {
declare type AreaOption = {
area?: Area | Area[];
}
interface PointOption {
};
declare type PointOption = {
latitude?: number;
longitude?: number;
}
interface RegionOption {
};
declare type RegionOption = {
region?: Region | Region[];
}
interface RegionTypeOption {
};
declare type RegionTypeOption = {
regionType?: RegionType;
}
interface UrgencyOption {
};
declare type UrgencyOption = {
urgency?: Urgency;
}
};
declare type AlertOptions = UrgencyOption & XOR<AreaOption, XOR<PointOption, XOR<RegionOption, RegionTypeOption>>>;
interface ClientOptions {
declare type ClientOptions = {
userAgent?: string;
}
interface PointResponse {
};
declare type PointResponse = {
properties: {

@@ -36,4 +36,4 @@ forecast: string;

};
}
interface ForecastPeriod {
};
declare type ForecastPeriod = {
number: number;

@@ -52,4 +52,4 @@ name: string;

detailedForecast: string;
}
interface ForecastProperties {
};
declare type ForecastProperties = {
updated: string;

@@ -66,7 +66,7 @@ units: string;

periods: ForecastPeriod[];
}
interface ForecastResponse {
};
declare type ForecastResponse = {
properties: ForecastProperties;
}
interface AlertsFeature {
};
declare type AlertsFeature = {
id: string;

@@ -84,6 +84,6 @@ geometry: {

};
}
interface AlertsResponse {
};
declare type AlertsResponse = {
features: AlertsFeature[];
}
export { ForecastType, Area, Region, RegionType, Urgency, AlertOptions, ClientOptions, PointResponse, ForecastResponse, AlertsResponse };
};
export { ForecastType, Area, Region, RegionType, Urgency, AlertOptions, ClientOptions, PointResponse, ForecastResponse, AlertsResponse, AlertsFeature };
{
"name": "weathered",
"version": "0.0.3",
"version": "0.1.0",
"description": "A JavaScript wrapper for the National Weather Service API",

@@ -9,3 +9,4 @@ "main": "dist/index.js",

"watch": "tsc --watch",
"test": "jest"
"test": "jest",
"docs": "typedoc --out docs --theme minimal --excludePrivate src/index.ts"
},

@@ -23,14 +24,15 @@ "keywords": [

"devDependencies": {
"@babel/core": "^7.14.5",
"@babel/preset-env": "^7.14.5",
"@babel/preset-typescript": "^7.14.5",
"@types/jest": "^26.0.23",
"@typescript-eslint/eslint-plugin": "^4.25.0",
"@typescript-eslint/parser": "^4.25.0",
"babel-jest": "^27.0.2",
"eslint": "^7.27.0",
"jest": "^27.0.1",
"typedoc": "^0.20.36",
"typescript": "^4.2.3"
},
"dependencies": {
"@babel/core": "^7.14.3",
"@babel/preset-env": "^7.14.2",
"@babel/preset-typescript": "^7.13.0",
"@types/jest": "^26.0.23",
"babel-jest": "^27.0.1",
"cross-fetch": "^3.1.4"

@@ -37,0 +39,0 @@ },

@@ -1,3 +0,70 @@

## weathered
## weathered 🌤⛈☀️🌨
A JavaScript wrapper for the National Weather Service API - built with TypeScript.
A JavaScript wrapper for the [National Weather Service API](https://www.weather.gov/documentation/services-web-api) - built with TypeScript.
## Documentation
Extensive typedoc generated documentation here - [documentation](https://jasonsanford.github.io/weathered/)
## Getting Started
### Import and instantiate a client
```javascript
import { Client } from 'weathered';
const client = new Client();
```
### Get active weather alerts for a location (latitude and longitude)
```javascript
const active = true;
const latitude = 35.6175667;
const longitude = -80.7709911;
const alerts = await client.getAlerts(active, { latitude, longitude });
alerts.features.forEach(feature => {
console.log(feature.properties.description);
console.log(feature.geometry);
});
// At 744 PM EDT, Doppler radar indicated strong thunderstorms along a
// line extending from 11 miles southeast of Yadkinville to 6 miles
// south of Mocksville to 7 miles northwest of Huntersville, and moving
// east at 20 mph.
// {
// type: 'Polygon',
// coordinates: [
// [ [Array], [Array] ]
// ]
// }
```
### Get all weather alerts (active or inactive) for a region
```javascript
const alerts = await client.getAlerts(active, { region: 'AL' });
alerts.features.forEach(feature => {
console.log(feature.properties.description);
console.log(feature.geometry);
});
// The Flood Warning continues for
// the Pearl River Above Philadelphia ...
// {
// type: 'Polygon',
// coordinates: [
// [ [Array], [Array] ]
// ]
// }
```
### Get weather forecast for a location (latitude and longitude)
```javascript
const forecast = await client.getForecast(latitude, longitude, 'baseline');
forecast.properties.periods.forEach(period => {
console.log(`${period.name}: ${period.detailedForecast}`);
});
// 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.
```

@@ -6,3 +6,3 @@ import { Client } from './';

const client = new Client();
expect(client.options.userAgent).toBe('weathered module version 0.0.0');
expect(client.getOptions().userAgent).toBe('weathered package');
});

@@ -12,4 +12,10 @@

const client = new Client({ userAgent: 'secret agent' });
expect(client.options.userAgent).toBe('secret agent');
expect(client.getOptions().userAgent).toBe('secret agent');
});
it('can change userAgent', () => {
const client = new Client();
client.setOptions({ userAgent: 'a new userAgent' });
expect(client.getOptions().userAgent).toBe('a new userAgent');
});
});

@@ -30,7 +30,14 @@ import fetch from 'cross-fetch';

/**
* The main client
*
* ```typescript
* const client = new Client();
* ```
*/
class Client {
options: ClientOptions;
private options: ClientOptions;
constructor(options?: ClientOptions) {
this.options = Object.assign(defaultOptions, options);
this.options = {...defaultOptions, ...options};
}

@@ -47,2 +54,25 @@

private getPoint(latitude: number, longitude: number) : Promise<PointResponse> {
const path = `points/${latitude},${longitude}`;
return this.getPath(path);
}
getOptions() : ClientOptions {
return {...this.options};
}
setOptions(newOptions: ClientOptions) : void {
this.options = {...this.options, ...newOptions};
}
/**
* Get weather alerts for a given area
*
* ```typescript
* const active = true;
* const latitude = 35.6175667;
* const longitude = -80.7709911;
* const alerts = await client.getAlerts(active, { latitude, longitude });
* ```
*/
getAlerts(active: boolean, options: AlertOptions) : Promise<AlertsResponse> {

@@ -54,7 +84,12 @@ const params = processOptions(options);

private getPoint(latitude: number, longitude: number) : Promise<PointResponse> {
const path = `points/${latitude},${longitude}`;
return this.getPath(path);
}
/**
* Get a weather forecast for a given latitude and longitude
*
* ```typescript
* const latitude = 35.6175667;
* const longitude = -80.7709911;
* const forecast = await client.getForecast(latitude, longitude, 'baseline');
* ```
*
*/
async getForecast(latitude: number, longitude: number, forecastType: ForecastType) : Promise<ForecastResponse> {

@@ -61,0 +96,0 @@ const pointResp = await this.getPoint(latitude, longitude);

export { Client } from './client';
export { ForecastType, Area, Region, RegionType, Urgency, AlertOptions, ClientOptions, PointResponse, ForecastResponse } from './types';
export { ForecastType, Area, Region, RegionType, Urgency, AlertOptions, ClientOptions, PointResponse, ForecastResponse, AlertsResponse, AlertsFeature } from './types';

@@ -24,7 +24,7 @@ type ForecastType = 'hourly' | 'baseline';

interface AreaOption {
type AreaOption = {
area?: Area | Area[];
}
interface PointOption {
type PointOption = {
latitude?: number;

@@ -34,11 +34,11 @@ longitude?: number;

interface RegionOption {
type RegionOption = {
region?: Region | Region[];
}
interface RegionTypeOption {
type RegionTypeOption = {
regionType?: RegionType;
}
interface UrgencyOption {
type UrgencyOption = {
urgency?: Urgency;

@@ -49,7 +49,7 @@ }

interface ClientOptions {
type ClientOptions = {
userAgent?: string;
}
interface PointResponse {
type PointResponse = {
properties: {

@@ -61,3 +61,3 @@ forecast: string;

interface ForecastPeriod {
type ForecastPeriod = {
number: number;

@@ -77,3 +77,3 @@ name: string;

}
interface ForecastProperties {
type ForecastProperties = {
updated: string;

@@ -89,7 +89,7 @@ units: string;

interface ForecastResponse {
type ForecastResponse = {
properties: ForecastProperties;
}
interface AlertsFeature {
type AlertsFeature = {
id: string;

@@ -109,6 +109,6 @@ geometry: {

interface AlertsResponse {
type AlertsResponse = {
features: AlertsFeature[];
}
export { ForecastType, Area, Region, RegionType, Urgency, AlertOptions, ClientOptions, PointResponse, ForecastResponse, AlertsResponse };
export { ForecastType, Area, Region, RegionType, Urgency, AlertOptions, ClientOptions, PointResponse, ForecastResponse, AlertsResponse, AlertsFeature };
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc