Socket
Socket
Sign inDemoInstall

dark-sky-api

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dark-sky-api - npm Package Compare versions

Comparing version 0.5.291 to 0.6.0

821

dist/dark-sky-api.js

@@ -1,24 +0,6 @@

'use strict';
import darkSkySkeleton from 'dark-sky-skeleton';
import moment from 'moment';
import { getNavigatorCoords, degreeToCardinal } from 'geo-loc-utils';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _darkSkySkeleton = require('dark-sky-skeleton');
var _darkSkySkeleton2 = _interopRequireDefault(_darkSkySkeleton);
var _moment = require('moment');
var _moment2 = _interopRequireDefault(_moment);
var _geoLocUtils = require('geo-loc-utils');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var config = {
const config = {
storageKeyCurrent: 'weather-data-current',

@@ -41,3 +23,3 @@ storageKeyForecast: 'weather-data-forecast',

var DarkSkyApi = function () {
class DarkSkyApi {
// darkSkyApi; instance of dark sky skeleton

@@ -58,19 +40,4 @@ // initialized; weather the instance of dark sky api has lat and long set

*/
function DarkSkyApi(apiKey, proxyUrl, units, language, processor) {
var _this = this;
_classCallCheck(this, DarkSkyApi);
this.position = function (_ref) {
var latitude = _ref.latitude,
longitude = _ref.longitude;
_this.darkSkyApi.latitude(latitude).longitude(longitude);
_this.initialized = true;
return _this;
};
this.loadPosition = DarkSkyApi.loadPosition;
this.darkSkyApi = new _darkSkySkeleton2.default(apiKey, proxyUrl);
constructor(apiKey, proxyUrl, units, language, processor) {
this.darkSkyApi = new darkSkySkeleton(apiKey, proxyUrl);
this._units = units || 'us';

@@ -86,505 +53,389 @@ this._language = language || 'en';

*/
initialize(position) {
this.position(position);
this.initialized = true;
return this;
}
/**
* Set dark sky api position data - Chainable
* @param {object} position - containing geo latitude and longitude
*/
position({ latitude, longitude }) {
this.darkSkyApi.latitude(latitude).longitude(longitude);
this.initialized = true;
return this;
}
_createClass(DarkSkyApi, [{
key: 'initialize',
value: function initialize(position) {
this.position(position);
this.initialized = true;
return this;
/**
* Set unit type for response formatting - Chainable
* @param {String} value - unit token
*/
units(value) {
if (config.acceptedUnits.indexOf(value) === -1) {
console.warn(`${value} ${config.warningMessage.invalidUnit}`); // eslint-disable-line no-console
} else {
!value ? null : this._units = value;
}
return this;
}
/**
* Set dark sky api position data - Chainable
* @param {object} position - containing geo latitude and longitude
*/
}, {
key: 'units',
/**
* Set unit type for response formatting - Chainable
* @param {String} value - unit token
*/
value: function units(value) {
if (config.acceptedUnits.indexOf(value) === -1) {
console.warn(value + ' ' + config.warningMessage.invalidUnit); // eslint-disable-line no-console
} else {
!value ? null : this._units = value;
}
return this;
/**
* Set language for response summaries
* @param {String} value - language token
*/
language(value) {
if (config.acceptedLanguage.indexOf(value) === -1) {
console.warn(`${value} ${config.warningMessage.invalidLanguage}`); // eslint-disable-line no-console
} else {
!value ? null : this._language = value;
}
return this;
}
/**
* Set language for response summaries
* @param {String} value - language token
*/
time() {
console.warn('dark-sky-api: The \'time\' method is deprecated. Pass your time to loadTime');
}
}, {
key: 'language',
value: function language(value) {
if (config.acceptedLanguage.indexOf(value) === -1) {
console.warn(value + ' ' + config.warningMessage.invalidLanguage); // eslint-disable-line no-console
} else {
!value ? null : this._language = value;
}
return this;
}
/**
* Add a post processor for weather items - accepts a weather data object as single parameter - must return object
* @param {function} func
*/
postProcessor(func) {
this._postProcessor = func;
return this;
}
/**
* Add a post processor for weather items - accepts a weather data object as single parameter - must return object
* @param {function} func
*/
/**
* Set whether to extend forecast with additional hours
* @param {bool} extend
*/
extendHourly(extend) {
this._extendHourly = extend;
}
}, {
key: 'postProcessor',
value: function postProcessor(func) {
this._postProcessor = func;
return this;
/**
* Get forecasted week of weather
*/
loadCurrent() {
if (!this.initialized) {
return this.loadPosition().then(position => this.initialize(position).loadCurrent());
}
return this.darkSkyApi.units(this._units).language(this._language).exclude(config.excludes.filter(val => val != 'currently').join(',')).time(false).get().then(({ currently }) => this.processWeatherItem(currently));
}
/**
* Set whether to extend forecast with additional hours
* @param {bool} extend
*/
}, {
key: 'extendHourly',
value: function extendHourly(extend) {
this._extendHourly = extend;
/**
* Get forecasted week of weather
*/
loadForecast() {
if (!this.initialized) {
return this.loadPosition().then(position => this.initialize(position).loadForecast());
}
return this.darkSkyApi.units(this._units).language(this._language).exclude(config.excludes.filter(val => val != 'daily').join(',')).extendHourly(this._extendHourly).time(false).get().then(data => {
!data.daily.data ? null : data.daily.data = data.daily.data.map(item => this.processWeatherItem(item));
!data.daily ? null : data.daily.updatedDateTime = moment();
return data;
});
}
/**
* Set time for timemachine request (loadTime)
* @param {*} time moment or formatted date time string in format: 'YYYY-MM-DDTHH:mm:ss' i.e. 2000-04-06T12:20:05
*/
}, {
key: 'time',
value: function time(_time) {
this._time = _moment2.default.isMoment(_time) ? _time.format(config.dateFormat) : _time;
/**
* Get the whole kit and kaboodle - contains currently, minutely, hourly, daily, alerts, and flags unless excluded
* daily and durrently are processed if returned
* @param {string} excludesBlock - pass comma separated excludes
*/
loadItAll(excludesBlock) {
if (!this.initialized) {
return this.loadPosition().then(position => this.initialize(position).loadItAll(excludesBlock));
}
return this.darkSkyApi.units(this._units).language(this._language).exclude(excludesBlock).extendHourly(this._extendHourly).time(false).get().then(data => {
// process current block
!data.currently ? null : data.currently = this.processWeatherItem(data.currently);
/**
* Get forecasted week of weather
*/
}, {
key: 'loadCurrent',
value: function loadCurrent() {
var _this2 = this;
if (!this.initialized) {
return this.loadPosition().then(function (position) {
return _this2.initialize(position).loadCurrent();
});
// process daily block
if (data.daily) {
!data.daily.data ? null : data.daily.data = data.daily.data.map(item => this.processWeatherItem(item));
}
return this.darkSkyApi.units(this._units).language(this._language).exclude(config.excludes.filter(function (val) {
return val != 'currently';
}).join(',')).get().then(function (_ref2) {
var currently = _ref2.currently;
return _this2.processWeatherItem(currently);
});
}
/**
* Get forecasted week of weather
*/
data.updatedDateTime = moment();
return data;
});
}
}, {
key: 'loadForecast',
value: function loadForecast() {
var _this3 = this;
if (!this.initialized) {
return this.loadPosition().then(function (position) {
return _this3.initialize(position).loadForecast();
});
}
return this.darkSkyApi.units(this._units).language(this._language).exclude(config.excludes.filter(function (val) {
return val != 'daily';
}).join(',')).extendHourly(this._extendHourly).get().then(function (data) {
!data.daily.data ? null : data.daily.data = data.daily.data.map(function (item) {
return _this3.processWeatherItem(item);
});
!data.daily ? null : data.daily.updatedDateTime = (0, _moment2.default)();
return data;
});
/**
* Time machine request
* @ref https://darksky.net/dev/docs/time-machine
* @param {*} [time] formatted date time string in format: 'YYYY-MM-DDTHH:mm:ss' i.e. 2000-04-06T12:20:05
*/
loadTime(time) {
if (!this.initialized) {
return this.loadPosition().then(position => this.initialize(position).loadTime(time));
}
/**
* Get the whole kit and kaboodle - contains currently, minutely, hourly, daily, alerts, and flags unless excluded
* daily and durrently are processed if returned
* @param {string} excludesBlock - pass comma separated excludes
*/
}, {
key: 'loadItAll',
value: function loadItAll(excludesBlock) {
var _this4 = this;
if (!this.initialized) {
return this.loadPosition().then(function (position) {
return _this4.initialize(position).loadItAll(excludesBlock);
});
}
return this.darkSkyApi.units(this._units).language(this._language).exclude(excludesBlock).extendHourly(this._extendHourly).get().then(function (data) {
// process current block
!data.currently ? null : data.currently = _this4.processWeatherItem(data.currently);
// process daily block
if (data.daily) {
!data.daily.data ? null : data.daily.data = data.daily.data.map(function (item) {
return _this4.processWeatherItem(item);
});
}
data.updatedDateTime = (0, _moment2.default)();
return data;
});
if (!time) {
throw new Error(config.errorMessage.noTimeSupplied);
}
time = moment.isMoment(time) ? time.format(config.dateFormat) : time;
return this.darkSkyApi.units(this._units).language(this._language).extendHourly(this._extendHourly).time(time).get().then(data => {
!data.currently ? null : data.currently = this.processWeatherItem(data.currently);
!data.daily.data ? null : data.daily.data = data.daily.data.map(item => this.processWeatherItem(item));
return data;
});
}
/**
* Time machine request
* @ref https://darksky.net/dev/docs/time-machine
* @param {*} [time] formatted date time string in format: 'YYYY-MM-DDTHH:mm:ss' i.e. 2000-04-06T12:20:05
*/
/**
* Make response a bit more friendly
* @param {object} item - item to process
*/
processWeatherItem(item) {
item.windDirection = degreeToCardinal(item.windBearing);
!item.nearestStormBearing ? null : item.nearestStormDirection = degreeToCardinal(item.nearestStormBearing);
}, {
key: 'loadTime',
value: function loadTime(time) {
var _this5 = this;
item.dateTime = moment.unix(item.time);
!item.sunriseTime ? null : item.sunriseDateTime = moment.unix(item.sunriseTime);
!item.sunsetTime ? null : item.sunsetDateTime = moment.unix(item.sunsetTime);
!item.temperatureMinTime ? null : item.temperatureMinDateTime = moment.unix(item.temperatureMinTime);
!item.temperatureMaxTime ? null : item.temperatureMaxDateTime = moment.unix(item.temperatureMaxTime);
!item.apparentTemperatureMinTime ? null : item.apparentTemperatureMinDateTime = moment.unix(item.apparentTemperatureMinTime);
!item.apparentTemperatureMaxTime ? null : item.apparentTemperatureMaxDateTime = moment.unix(item.apparentTemperatureMaxTime);
if (!this.initialized) {
return this.loadPosition().then(function (position) {
return _this5.initialize(position).loadTime(time);
});
}
this.time(time);
return this.darkSkyApi.units(this._units).language(this._language).extendHourly(this._extendHourly).time(this._time).get().then(function (data) {
!data.currently ? null : data.currently = _this5.processWeatherItem(data.currently);
!data.daily.data ? null : data.daily.data = data.daily.data.map(function (item) {
return _this5.processWeatherItem(item);
});
return data;
});
}
!this._postProcessor ? null : item = this._postProcessor(item);
return item;
}
/**
* Make response a bit more friendly
* @param {object} item - item to process
*/
/**
* Get units object showing units returned based on configured units
* @returns {object} units
*/
getResponseUnits() {
let unitsObject, unitsId;
}, {
key: 'processWeatherItem',
value: function processWeatherItem(item) {
item.windDirection = (0, _geoLocUtils.degreeToCardinal)(item.windBearing);
!item.nearestStormBearing ? null : item.nearestStormDirection = (0, _geoLocUtils.degreeToCardinal)(item.nearestStormBearing);
item.dateTime = _moment2.default.unix(item.time);
!item.sunriseTime ? null : item.sunriseDateTime = _moment2.default.unix(item.sunriseTime);
!item.sunsetTime ? null : item.sunsetDateTime = _moment2.default.unix(item.sunsetTime);
!item.temperatureMinTime ? null : item.temperatureMinDateTime = _moment2.default.unix(item.temperatureMinTime);
!item.temperatureMaxTime ? null : item.temperatureMaxDateTime = _moment2.default.unix(item.temperatureMaxTime);
!item.apparentTemperatureMinTime ? null : item.apparentTemperatureMinDateTime = _moment2.default.unix(item.apparentTemperatureMinTime);
!item.apparentTemperatureMaxTime ? null : item.apparentTemperatureMaxDateTime = _moment2.default.unix(item.apparentTemperatureMaxTime);
!this._postProcessor ? null : item = this._postProcessor(item);
return item;
if (this._units === 'auto') {
console.warn(config.warningMessage.cantGuessUnits); // eslint-disable-line no-console
unitsId = 'us';
} else {
unitsId = this._units;
}
/**
* Get units object showing units returned based on configured units
* @returns {object} units
*/
}, {
key: 'getResponseUnits',
value: function getResponseUnits() {
var unitsObject = void 0,
unitsId = void 0;
if (this._units === 'auto') {
console.warn(config.warningMessage.cantGuessUnits); // eslint-disable-line no-console
unitsId = 'us';
} else {
unitsId = this._units;
}
// get units object by id
switch (unitsId) {
case 'us':
unitsObject = DarkSkyApi.getUsUnits();
break;
case 'ca':
unitsObject = DarkSkyApi.getCaUnits();
break;
case 'uk2':
unitsObject = DarkSkyApi.getUk2Units();
break;
case 'si':
unitsObject = DarkSkyApi.getSiUnits();
break;
}
return unitsObject;
// get units object by id
switch (unitsId) {
case 'us':
unitsObject = DarkSkyApi.getUsUnits();
break;
case 'ca':
unitsObject = DarkSkyApi.getCaUnits();
break;
case 'uk2':
unitsObject = DarkSkyApi.getUk2Units();
break;
case 'si':
unitsObject = DarkSkyApi.getSiUnits();
break;
}
return unitsObject;
}
/**
* Get browser navigator coords - Promise
*/
/**
* Get browser navigator coords - Promise
*/
loadPosition() {
return DarkSkyApi.loadPosition();
}
// allow config and deferring of initialization
// allow config and deferring of initialization
/**
* Get browser navigator coords - Promise
*/
/**
* Get browser navigator coords - Promise
*/
}], [{
key: 'initialize',
/**
* Initialize a static instance of weather api with dark sky api key
* @param {string} apiKey
* @param {string} proxyUrl
*/
value: function initialize(apiKey, proxyUrl, units, language, postProcessor) {
if (this._api) {
return;
}
if (!this.apiKey && !this.proxyUrl && !apiKey && !proxyUrl) {
throw new Error(config.errorMessage.noApiKeyOrProxyUrl);
}
var key = apiKey || this.apiKey || '';
var proxy = proxyUrl || this.proxyUrl || '';
var unit = units || this.units || '';
var lang = language || this.language || '';
var processor = postProcessor || this.postProcessor || null;
this._api = new DarkSkyApi(key, proxy, unit, lang, processor);
/**
* Initialize a static instance of weather api with dark sky api key
* @param {string} apiKey
* @param {string} proxyUrl
*/
static initialize(apiKey, proxyUrl, units, language, postProcessor) {
if (this._api) {
return;
}
/**
* Get units object showing units returned based on configured units - initialize or configure with api key or proxy first
* @returns {object} units
*/
}, {
key: 'getResponseUnits',
value: function getResponseUnits() {
this.initialize();
return this._api.getResponseUnits();
if (!this.apiKey && !this.proxyUrl && !apiKey && !proxyUrl) {
throw new Error(config.errorMessage.noApiKeyOrProxyUrl);
}
/**
* Set unit type for response formatting - initialize or configure with api key or proxy first
* @param {String} value - unit token
*/
const key = apiKey || this.apiKey || '';
const proxy = proxyUrl || this.proxyUrl || '';
const unit = units || this.units || '';
const lang = language || this.language || '';
const processor = postProcessor || this.postProcessor || null;
this._api = new DarkSkyApi(key, proxy, unit, lang, processor);
}
}, {
key: 'setUnits',
value: function setUnits(units) {
this.initialize();
this._api.units(units);
}
/**
* Get units object showing units returned based on configured units - initialize or configure with api key or proxy first
* @returns {object} units
*/
static getResponseUnits() {
this.initialize();
return this._api.getResponseUnits();
}
/**
* Set language for response summaries - initialize or configure with api key or proxy first
* @param {String} value - language token
*/
/**
* Set unit type for response formatting - initialize or configure with api key or proxy first
* @param {String} value - unit token
*/
static setUnits(units) {
this.initialize();
this._api.units(units);
}
}, {
key: 'setLanguage',
value: function setLanguage(language) {
this.initialize();
this._api.language(language);
}
/**
* Set language for response summaries - initialize or configure with api key or proxy first
* @param {String} value - language token
*/
static setLanguage(language) {
this.initialize();
this._api.language(language);
}
/**
* Set date time string for time machine requests
* @ref https://darksky.net/dev/docs/time-machine
* @param {string} time in format: 'YYYY-MM-DDTHH:mm:ss' i.e. 2000-04-06T12:20:05
*/
/**
* Return hour-by-hour data for the next 168 hours, instead of the next 48.
* @param {bool} extend whether to extend the request hours
*/
static extendHourly(extend) {
this.initialize();
this._api.extendHourly(extend);
}
}, {
key: 'setTime',
value: function setTime(time) {
this.initialize();
this._api.time(time);
}
/**
* Set post processor for weather items - accepts a weather data object as single parameter - initialize or configure with api key or proxy first - must return object
* @param {function} func
*/
static setPostProcessor(func) {
this.initialize();
this._api.postProcessor(func);
}
/**
* Return hour-by-hour data for the next 168 hours, instead of the next 48.
* @param {bool} extend whether to extend the request hours
*/
}, {
key: 'extendHourly',
value: function extendHourly(extend) {
this.initialize();
this._api.extendHourly(extend);
/**
* Get today's weather - Promise
* @param {object} [position] - if omitted will use loadPosition
*/
static loadCurrent(position) {
this.initialize();
if (position) {
return this._api.position(position).loadCurrent();
} else {
return this._api.loadCurrent();
}
}
/**
* Set post processor for weather items - accepts a weather data object as single parameter - initialize or configure with api key or proxy first - must return object
* @param {function} func
*/
}, {
key: 'setPostProcessor',
value: function setPostProcessor(func) {
this.initialize();
this._api.postProcessor(func);
/**
* Get forecasted week of weather - Promise
* @param {object} [position] - if omitted api will use loadPosition
*/
static loadForecast(position) {
this.initialize();
if (position) {
return this._api.position(position).loadForecast();
} else {
return this._api.loadForecast();
}
}
/**
* Get today's weather - Promise
* @param {object} [position] - if omitted will use loadPosition
*/
static setTime() {
console.warn('dark-sky-api: The \'setTime\' method is deprecated. Pass your time to loadTime');
}
}, {
key: 'loadCurrent',
value: function loadCurrent(position) {
this.initialize();
if (position) {
return this._api.position(position).loadCurrent();
} else {
return this._api.loadCurrent();
}
/**
* Get the whole kit and kaboodle - contains currently, minutely, hourly, daily, alerts, and flags unless excluded
* daily and currently are processed if returned
* @param {string} excludesBlock - pass comma separated excludes
* @param {object} [position] - if omitted api will use loadPosition
*/
static loadItAll(excludesBlock, position) {
this.initialize();
if (position) {
return this._api.position(position).loadItAll(excludesBlock);
} else {
return this._api.loadItAll(excludesBlock);
}
}
/**
* Get forecasted week of weather - Promise
* @param {object} [position] - if omitted api will use loadPosition
*/
}, {
key: 'loadForecast',
value: function loadForecast(position) {
this.initialize();
if (position) {
return this._api.position(position).loadForecast();
} else {
return this._api.loadForecast();
}
static loadTime(time, position) {
this.initialize();
if (!time) {
throw new Error(config.errorMessage.noTimeSupplied);
}
/**
* Get the whole kit and kaboodle - contains currently, minutely, hourly, daily, alerts, and flags unless excluded
* daily and currently are processed if returned
* @param {string} excludesBlock - pass comma separated excludes
* @param {object} [position] - if omitted api will use loadPosition
*/
}, {
key: 'loadItAll',
value: function loadItAll(excludesBlock, position) {
this.initialize();
if (position) {
return this._api.position(position).loadItAll(excludesBlock);
} else {
return this._api.loadItAll(excludesBlock);
}
if (position) {
return this._api.position(position).loadTime(time);
} else {
return this._api.loadTime(time);
}
}, {
key: 'loadTime',
value: function loadTime(time, position) {
this.initialize();
if (!time && !this._api._time) {
throw new Error(config.errorMessage.noTimeSupplied);
}
if (position) {
return this._api.position(position).loadTime(time);
} else {
return this._api.loadTime(time);
}
}
}
/**
* Return the us response units
* @return {object} units
*/
/**
* Return the us response units
* @return {object} units
*/
static getUsUnits() {
return {
nearestStormDistance: 'mi',
precipIntensity: 'in/h',
precipIntensityMax: 'in/h',
precipAccumulation: 'in',
temperature: 'f',
temperatureMin: 'f',
temperatureMax: 'f',
apparentTemperature: 'f',
dewPoint: 'f',
windSpeed: 'mph',
pressure: 'mbar',
visibility: 'mi'
};
}
}, {
key: 'getUsUnits',
value: function getUsUnits() {
return {
nearestStormDistance: 'mi',
precipIntensity: 'in/h',
precipIntensityMax: 'in/h',
precipAccumulation: 'in',
temperature: 'f',
temperatureMin: 'f',
temperatureMax: 'f',
apparentTemperature: 'f',
dewPoint: 'f',
windSpeed: 'mph',
pressure: 'mbar',
visibility: 'mi'
};
}
/**
* Return the si response units
* @return {object} units
*/
static getSiUnits() {
return {
nearestStormDistance: 'km',
precipIntensity: 'mm/h',
precipIntensityMax: 'mm/h',
precipAccumulation: 'cm',
temperature: 'c',
temperatureMin: 'c',
temperatureMax: 'c',
apparentTemperature: 'c',
dewPoint: 'c',
windSpeed: 'mps',
pressure: 'hPa',
visibility: 'km'
};
}
/**
* Return the si response units
* @return {object} units
*/
/**
* Return ca response units
* @return {object} units
*/
static getCaUnits() {
let unitsObject = this.getUsUnits();
unitsObject.windSpeed = 'km/h';
return unitsObject;
}
}, {
key: 'getSiUnits',
value: function getSiUnits() {
return {
nearestStormDistance: 'km',
precipIntensity: 'mm/h',
precipIntensityMax: 'mm/h',
precipAccumulation: 'cm',
temperature: 'c',
temperatureMin: 'c',
temperatureMax: 'c',
apparentTemperature: 'c',
dewPoint: 'c',
windSpeed: 'mps',
pressure: 'hPa',
visibility: 'km'
};
}
/**
* Return uk2 response units
* @return {object} units
*/
static getUk2Units() {
let unitsObject = this.getSiUnits();
unitsObject.nearestStormDistance = unitsObject.visibility = 'mi';
unitsObject.windSpeed = 'mph';
return unitsObject;
}
}
/**
* Return ca response units
* @return {object} units
*/
DarkSkyApi.loadPosition = () => getNavigatorCoords();
}, {
key: 'getCaUnits',
value: function getCaUnits() {
var unitsObject = this.getUsUnits();
unitsObject.windSpeed = 'km/h';
return unitsObject;
}
/**
* Return uk2 response units
* @return {object} units
*/
}, {
key: 'getUk2Units',
value: function getUk2Units() {
var unitsObject = this.getSiUnits();
unitsObject.nearestStormDistance = unitsObject.visibility = 'mi';
unitsObject.windSpeed = 'mph';
return unitsObject;
}
}]);
return DarkSkyApi;
}();
DarkSkyApi.loadPosition = function () {
return (0, _geoLocUtils.getNavigatorCoords)();
};
exports.default = DarkSkyApi;
export default DarkSkyApi;
{
"name": "dark-sky-api",
"version": "0.5.291",
"version": "0.6.0",
"description": "a simple and robust dark sky api service for client-side js",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -166,14 +166,6 @@ # dark-sky-api

const time = moment().year(2000);
DarkSkyApi.loadTime(time)
DarkSkyApi.loadTime(time) // or '2000-04-06T12:20:05' aka moment.format()
.then(result => console.log(result));
```
use `setTime` and call without time parameter
```javascript
DarkSkyApi.setTime('2000-04-06T12:20:05'); // moment().year(2000).format('YYYY-MM-DDTHH:mm:ss')
DarkSkyApi.loadTime()
.then(result => console.log(result));
```
### Hourly, Minutely, Alerts, and Flags

@@ -242,3 +234,2 @@

// can only be set after initialization
DarkSkyApi.setTime('2000-04-06T12:20:05');
DarkSkyApi.extendHourly(true);

@@ -292,7 +283,2 @@ ```

// time machine request
api.time('2000-04-06T12:20:05')
.loadTime()
.then(console.log);
// or
api.loadTime('2000-04-06T12:20:05')

@@ -299,0 +285,0 @@ .then(console.log)

@@ -63,3 +63,3 @@ import darkSkySkeleton from 'dark-sky-skeleton';

*/
position = ({ latitude, longitude }) => {
position({ latitude, longitude }) {
this.darkSkyApi

@@ -98,2 +98,6 @@ .latitude(latitude)

time() {
console.warn('dark-sky-api: The \'time\' method is deprecated. Pass your time to loadTime');
}
/**

@@ -117,10 +121,2 @@ * Add a post processor for weather items - accepts a weather data object as single parameter - must return object

/**
* Set time for timemachine request (loadTime)
* @param {*} time moment or formatted date time string in format: 'YYYY-MM-DDTHH:mm:ss' i.e. 2000-04-06T12:20:05
*/
time(time) {
this._time = moment.isMoment(time) ? time.format(config.dateFormat) : time;
}
/**
* Get forecasted week of weather

@@ -137,2 +133,3 @@ */

.exclude(config.excludes.filter(val => val != 'currently').join(','))
.time(false)
.get()

@@ -155,2 +152,3 @@ .then(({ currently }) => this.processWeatherItem(currently));

.extendHourly(this._extendHourly)
.time(false)
.get()

@@ -179,2 +177,3 @@ .then((data) => {

.extendHourly(this._extendHourly)
.time(false)
.get()

@@ -205,3 +204,6 @@ .then((data) => {

}
this.time(time);
if (!time) {
throw new Error(config.errorMessage.noTimeSupplied);
}
time = moment.isMoment(time) ? time.format(config.dateFormat) : time;
return this.darkSkyApi

@@ -211,3 +213,3 @@ .units(this._units)

.extendHourly(this._extendHourly)
.time(this._time)
.time(time)
.get()

@@ -276,3 +278,5 @@ .then((data) => {

*/
loadPosition = DarkSkyApi.loadPosition;
loadPosition() {
return DarkSkyApi.loadPosition();
}

@@ -343,12 +347,2 @@ static _api;

/**
* Set date time string for time machine requests
* @ref https://darksky.net/dev/docs/time-machine
* @param {string} time in format: 'YYYY-MM-DDTHH:mm:ss' i.e. 2000-04-06T12:20:05
*/
static setTime(time) {
this.initialize();
this._api.time(time);
}
/**
* Return hour-by-hour data for the next 168 hours, instead of the next 48.

@@ -401,2 +395,6 @@ * @param {bool} extend whether to extend the request hours

static setTime() {
console.warn('dark-sky-api: The \'setTime\' method is deprecated. Pass your time to loadTime');
}
/**

@@ -421,3 +419,3 @@ * Get the whole kit and kaboodle - contains currently, minutely, hourly, daily, alerts, and flags unless excluded

this.initialize();
if (!time && !this._api._time) {
if (!time) {
throw new Error(config.errorMessage.noTimeSupplied);

@@ -424,0 +422,0 @@ }

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc