Socket
Socket
Sign inDemoInstall

yahoo-weather

Package Overview
Dependencies
7
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 2.0.0

Gruntfile.js

42

dist/index.js

@@ -8,35 +8,17 @@ 'use strict';

var _http = require('http');
require('isomorphic-fetch');
var _http2 = _interopRequireDefault(_http);
function getWeather(query) {
var unit = arguments.length <= 1 || arguments[1] === undefined ? 'c' : arguments[1];
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function promisedGet(uri) {
return new Promise(function (res, rej) {
_http2.default.get(uri, function (response) {
var body = '';
response.on('data', function (data) {
body += data;
});
response.on('end', function () {
res(JSON.parse(body).query.results.channel);
});
}).on('error', function (e) {
rej(e);
});
var queryUri = 'http://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where u=\'' + unit + '\' AND woeid in (select woeid from geo.places(1) where text="' + query + '")&format=json';
return fetch(queryUri).then(function (response) {
if (response.status >= 400) {
throw new Error('Bad response from server');
}
return response.json();
}).then(function (json) {
return json.query.results.channel;
});
}
function getQueryUri(q) {
var queryUri = 'http://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where u=\'c\' AND woeid in (select woeid from geo.places(1) where text="' + q + '")&format=json';
return queryUri;
}
function getWeather(_ref) {
var q = _ref.q;
var queryUri = getQueryUri(q);
return promisedGet(queryUri);
}
module.exports = exports['default'];
module.exports = exports['default'];
{
"name": "yahoo-weather",
"version": "1.0.0",
"version": "2.0.0",
"description": "A simple yahoo weather API wrapper",
"main": "index.js",
"scripts": {
"build": "babel src -o dist",
"test": "mocha --compilers js:babel-core/register test/index.js",

@@ -27,10 +28,17 @@ "lint": "eslint src test"

"devDependencies": {
"babel-core": "^6.2.1",
"babel-plugin-add-module-exports": "^0.1.1",
"babel-preset-es2015": "^6.1.18",
"chai": "^3.4.1",
"eslint": "^1.10.2",
"eslint-config-airbnb": "^1.0.2",
"mocha": "^2.3.4"
"babel-core": "^6.7.6",
"babel-plugin-add-module-exports": "^0.1.2",
"babel-preset-es2015": "^6.6.0",
"chai": "^3.5.0",
"eslint": "^2.7.0",
"eslint-config-airbnb": "^6.2.0",
"grunt": "^1.0.1",
"grunt-babel": "^6.0.0",
"grunt-contrib-clean": "^1.0.0",
"grunt-eslint": "^18.0.0",
"mocha": "^2.4.5"
},
"dependencies": {
"isomorphic-fetch": "^2.2.1"
}
}
# node-yahoo-weather
**node-yahoo-weather** is a dead simple node module with **zero** dependencies.
**node-yahoo-weather** is a dead simple isomorphic JavaScript weather module in 10 lines of code.
The code is written using [ES2015](https://babeljs.io/docs/learn-es2015/) and simply transformed back using [babel](https://babeljs.io) to the `dist` directory.
The code is written using [ES2015](https://babeljs.io/docs/learn-es2015/) and simply transformed back using [babel](https://babeljs.io) to the `dist` directory using a [Grunt](http://gruntjs.com/) task.

@@ -16,8 +16,9 @@ I made this module cause I need it and I feel it may be used by someone, someday. Let's get started! :grin:

## Usage
Dead simple, as I said! Check it:
Dead simple, as I said! Just one required param. Check it:
```js
import weather from 'yahoo-weather';
weather({ q: 'Tehran' }).then(info => {
import weather from 'yahoo-weather'; // or require it
weather('tehran').then(info => {
// Do what you want with `info`!

@@ -27,6 +28,15 @@ }).catch(err => {

});
weather('tehran', 'f').then(info => { // second arg is the weather unit. you can pass 'c' or 'f'. defaults to 'c'.
// Do what you want with `info`!
}).catch(err => {
// Oops! Errors! :(
});
```
## Tests
Run the tests with following script:
Run the tests with following command:
```bash

@@ -47,4 +57,5 @@ npm test

Remember to lint your code before sending pull requests. Execute the linter script by running the following command and fix the errors if you get any.
```bash
npm run lint
```

@@ -1,27 +0,10 @@

import http from 'http';
function promisedGet(uri) {
return new Promise((res, rej) => {
http.get(uri, response => {
let body = '';
response.on('data', data => {
body += data;
});
response.on('end', () => {
res(JSON.parse(body).query.results.channel);
});
}).on('error', e => {
rej(e);
});
});
import 'isomorphic-fetch';
export default function getWeather(query, unit = 'c') {
const queryUri = `http://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where u='${unit}' AND woeid in (select woeid from geo.places(1) where text="${query}")&format=json`;
return fetch(queryUri).then(response => {
if (response.status >= 400) {
throw new Error('Bad response from server');
}
return response.json();
}).then(json => json.query.results.channel);
}
function getQueryUri(q) {
const queryUri = `http://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where u='c' AND woeid in (select woeid from geo.places(1) where text="${q}")&format=json`;
return queryUri;
}
export default function getWeather({ q }) {
const queryUri = getQueryUri(q);
return promisedGet(queryUri);
}

@@ -11,3 +11,3 @@ /* eslint-env mocha */

before(done => {
yahooWeather({q: 'mashhad'}).then(res => {
yahooWeather('mashhad').then(res => {
response = res;

@@ -14,0 +14,0 @@ done();

Sorry, the diff of this file is not supported yet

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