Comparing version 1.3.5 to 1.3.6
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("miniOwm",[],e):"object"==typeof exports?exports.miniOwm=e():t.miniOwm=e()}(window,(function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=3)}([function(t,e){},function(t,e){},function(t,e){},function(t,e,n){"use strict";n.r(e),n.d(e,"coords",(function(){return i.a})),n.d(e,"getAtts",(function(){return o.a})),n.d(e,"IMiniOwm",(function(){return c.a})),n.d(e,"default",(function(){return f})),n.d(e,"Units",(function(){return s}));var r=n(0),i=n.n(r),u=n(1),o=n.n(u),a=n(2),c=n.n(a),s={Standard:"",Metric:"metric",Imperial:"imperial"};function l(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}var f=function(){function t(e,n,r,i,u,o){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this._apiKey=e||"",this._latitude=n||0,this._longitude=r||0,this._exclude=i||"",this._units=u&&u.trim()?u.trim().toLowerCase():s.Metric,this._units===s.Standard&&(this._units=""),this._language=o&&o.trim()?o.trim().toLowerCase():""}var e,n,r;return e=t,(n=[{key:"apiKey",value:function(t){return this._apiKey=t,this}},{key:"latitude",value:function(t){return this._latitude=t,this}},{key:"longitude",value:function(t){return this._longitude=t,this}},{key:"exclude",value:function(t){return this._exclude=t,this}},{key:"standard",value:function(){return this._units=s.Standard,this}},{key:"metric",value:function(){return this._units=s.Metric,this}},{key:"imperial",value:function(){return this._units=s.Imperial,this}},{key:"language",value:function(t){return this._language=t&&t.trim()?t.trim().toLowerCase():"",this}},{key:"get",value:function(t){var e=this,n=this._latitude,r=this._longitude,i=this._exclude,u=this._apiKey,o=this._units,a=this._language,c=t||{},l=c.apiKey||u,f=c.coords?c.coords.latitude:n,d=c.coords?c.coords.longitude:r,p=c.language&&c.language.trim()?c.language.trim().toLowerCase():a,h=c.units&&c.units.trim()?c.units.trim().toLowerCase():o,y=c.exclude||i;if(!l||!f||!d)throw new Error("Missing required parameters for Open Weather Map api call.");var m="https://api.openweathermap.org/data/2.5/onecall?lat=".concat(f,"&lon=").concat(d,"&exclude=").concat(y,"&appid=").concat(l);return h&&h!==s.Standard&&(m="".concat(m,"&units=").concat(h)),p&&(m="".concat(m,"&lang=").concat(p)),fetch(m).then((function(t){return t.json()})).then((function(t){return t.current&&(t.current.rain=e.getPrecipitation(t.current.rain),t.current.snow=e.getPrecipitation(t.current.snow)),t.daily&&(t.daily=t.daily.map((function(t){return t.rain=t.rain||0,t.snow=t.snow||0,t}))),t.hourly&&(t.hourly=t.hourly.map((function(t){return t.rain=e.getPrecipitation(t.rain),t.snow=e.getPrecipitation(t.snow),t}))),t}))}},{key:"getPrecipitation",value:function(t){return t&&t["1h"]?t["1h"]:0}}])&&l(e.prototype,n),r&&l(e,r),t}()}]).default})); | ||
!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define("miniOwm",[],n):"object"==typeof exports?exports.miniOwm=n():t.miniOwm=n()}(window,(function(){return function(t){var n={};function e(i){if(n[i])return n[i].exports;var r=n[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,e),r.l=!0,r.exports}return e.m=t,e.c=n,e.d=function(t,n,i){e.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:i})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,n){if(1&n&&(t=e(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(e.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var r in t)e.d(i,r,function(n){return t[n]}.bind(null,r));return i},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},e.p="",e(e.s=3)}([function(t,n){},function(t,n){},function(t,n){},function(t,n,e){"use strict";e.r(n),e.d(n,"coords",(function(){return r.a})),e.d(n,"getAtts",(function(){return u.a})),e.d(n,"IMiniOwm",(function(){return c.a})),e.d(n,"default",(function(){return l})),e.d(n,"Units",(function(){return s}));var i=e(0),r=e.n(i),o=e(1),u=e.n(o),a=e(2),c=e.n(a),s={Standard:"",Metric:"metric",Imperial:"imperial"};function d(t,n,e){return n in t?Object.defineProperty(t,n,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[n]=e,t}var l=function t(n,e,i,r,o,u){var a=this;!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),d(this,"_apiKey",void 0),d(this,"_longitude",void 0),d(this,"_latitude",void 0),d(this,"_exclude",void 0),d(this,"_units",void 0),d(this,"_language",void 0),d(this,"apiKey",(function(t){return a._apiKey=t,a})),d(this,"latitude",(function(t){return a._latitude=t,a})),d(this,"longitude",(function(t){return a._longitude=t,a})),d(this,"exclude",(function(t){return a._exclude=t,a})),d(this,"standard",(function(){return a._units=s.Standard,a})),d(this,"metric",(function(){return a._units=s.Metric,a})),d(this,"imperial",(function(){return a._units=s.Imperial,a})),d(this,"language",(function(t){return a._language=t&&t.trim()?t.trim().toLowerCase():"",a})),d(this,"get",(function(t){var n=a._latitude,e=a._longitude,i=a._exclude,r=a._apiKey,o=a._units,u=a._language,c=t||{},d=c.apiKey||r,l=c.coords&&c.coords.latitude?c.coords.latitude:n,f=c.coords&&c.coords.longitude?c.coords.longitude:e,p=c.language&&c.language.trim()?c.language.trim().toLowerCase():u,g=c.units&&c.units.trim()?c.units.trim().toLowerCase():o,h=c.exclude||i;if(!d||!l&&0!==l||!f&&0!==f)throw new Error("Missing required parameters for Open Weather Map api call.");var m="https://api.openweathermap.org/data/2.5/onecall?lat=".concat(l,"&lon=").concat(f,"&exclude=").concat(h,"&appid=").concat(d);return g&&g!==s.Standard&&(m="".concat(m,"&units=").concat(g)),p&&(m="".concat(m,"&lang=").concat(p)),fetch(m).then((function(t){return t.json()})).then((function(t){return t.current&&(t.current.rain=a.getPrecipitation(t.current.rain),t.current.snow=a.getPrecipitation(t.current.snow)),t.daily&&(t.daily=t.daily.map((function(t){return t.rain=t.rain||0,t.snow=t.snow||0,t}))),t.hourly&&(t.hourly=t.hourly.map((function(t){return t.rain=a.getPrecipitation(t.rain),t.snow=a.getPrecipitation(t.snow),t}))),t}))})),d(this,"getPrecipitation",(function(t){return t&&t["1h"]?t["1h"]:0})),this._apiKey=n||"",this._latitude=e||0,this._longitude=i||0,this._exclude=r||"",this._units=o&&o.trim()?o.trim().toLowerCase():s.Metric,this._units===s.Standard&&(this._units=""),this._language=u&&u.trim()?u.trim().toLowerCase():""}}]).default})); | ||
//# sourceMappingURL=index.js.map |
@@ -11,13 +11,13 @@ import getAtts from "./getAtts"; | ||
constructor(apiKey?: string, latitude?: number, longitude?: number, exclude?: string, units?: string, language?: string); | ||
apiKey(value: string): this; | ||
latitude(value: number): this; | ||
longitude(value: number): this; | ||
exclude(value: string): this; | ||
standard(): this; | ||
metric(): this; | ||
imperial(): this; | ||
language(value: string): this; | ||
get(attributes?: getAtts): Promise<any>; | ||
apiKey: (value: string) => this; | ||
latitude: (value: number) => this; | ||
longitude: (value: number) => this; | ||
exclude: (value: string) => this; | ||
standard: () => this; | ||
metric: () => this; | ||
imperial: () => this; | ||
language: (value: string) => this; | ||
get: (attributes?: getAtts | undefined) => Promise<any>; | ||
private getPrecipitation; | ||
} | ||
export default MiniOwm; |
import Units from "./Units"; | ||
export class MiniOwm { | ||
constructor(apiKey, latitude, longitude, exclude, units, language) { | ||
this.apiKey = (value) => { | ||
this._apiKey = value; | ||
return this; | ||
}; | ||
this.latitude = (value) => { | ||
this._latitude = value; | ||
return this; | ||
}; | ||
this.longitude = (value) => { | ||
this._longitude = value; | ||
return this; | ||
}; | ||
this.exclude = (value) => { | ||
this._exclude = value; | ||
return this; | ||
}; | ||
// temperature in Kelvin | ||
// wind in meter/sec | ||
this.standard = () => { | ||
this._units = Units.Standard; | ||
return this; | ||
}; | ||
// temperature in Celsius | ||
// wind in meter/sec | ||
this.metric = () => { | ||
this._units = Units.Metric; | ||
return this; | ||
}; | ||
// temperature in Fahrenheit | ||
// wind in miles/hour | ||
this.imperial = () => { | ||
this._units = Units.Imperial; | ||
return this; | ||
}; | ||
// set output of description field | ||
// see possible values here: https://openweathermap.org/api/one-call-api | ||
this.language = (value) => { | ||
this._language = (value && value.trim()) ? value.trim().toLowerCase() : ''; | ||
return this; | ||
}; | ||
this.get = (attributes) => { | ||
const { _latitude, _longitude, _exclude, _apiKey, _units, _language, } = this, atts = attributes || {}, key = atts.apiKey || _apiKey, lat = (atts.coords && atts.coords.latitude) ? atts.coords.latitude : _latitude, lon = (atts.coords && atts.coords.longitude) ? atts.coords.longitude : _longitude, lang = (atts.language && atts.language.trim()) ? atts.language.trim().toLowerCase() : _language, units = (atts.units && atts.units.trim()) ? atts.units.trim().toLowerCase() : _units, part = atts.exclude || _exclude; | ||
if (!key | ||
|| (!lat && lat !== 0) | ||
|| (!lon && lon !== 0)) { | ||
throw new Error('Missing required parameters for Open Weather Map api call.'); | ||
} | ||
let uri = `https://api.openweathermap.org/data/2.5/onecall?lat=${lat}&lon=${lon}&exclude=${part}&appid=${key}`; | ||
if (units && units !== Units.Standard) { | ||
uri = `${uri}&units=${units}`; | ||
} | ||
if (lang) { | ||
uri = `${uri}&lang=${lang}`; | ||
} | ||
return fetch(uri) | ||
.then(res => res.json()) | ||
.then(res => { | ||
if (res.current) { | ||
res.current.rain = this.getPrecipitation(res.current.rain); | ||
res.current.snow = this.getPrecipitation(res.current.snow); | ||
} | ||
if (res.daily) { | ||
res.daily = res.daily.map(item => { | ||
item.rain = item.rain || 0; | ||
item.snow = item.snow || 0; | ||
return item; | ||
}); | ||
} | ||
if (res.hourly) { | ||
res.hourly = res.hourly.map(item => { | ||
item.rain = this.getPrecipitation(item.rain); | ||
item.snow = this.getPrecipitation(item.snow); | ||
return item; | ||
}); | ||
} | ||
return res; | ||
}); | ||
}; | ||
// owm puts precip amount on a nested property | ||
this.getPrecipitation = (value) => { | ||
return !value | ||
? 0 | ||
: (value['1h'] | ||
? value['1h'] | ||
: 0); | ||
}; | ||
this._apiKey = apiKey || ''; | ||
@@ -14,88 +100,4 @@ this._latitude = latitude || 0; | ||
} | ||
apiKey(value) { | ||
this._apiKey = value; | ||
return this; | ||
} | ||
latitude(value) { | ||
this._latitude = value; | ||
return this; | ||
} | ||
longitude(value) { | ||
this._longitude = value; | ||
return this; | ||
} | ||
exclude(value) { | ||
this._exclude = value; | ||
return this; | ||
} | ||
// temperature in Kelvin | ||
// wind in meter/sec | ||
standard() { | ||
this._units = Units.Standard; | ||
return this; | ||
} | ||
// temperature in Celsius | ||
// wind in meter/sec | ||
metric() { | ||
this._units = Units.Metric; | ||
return this; | ||
} | ||
// temperature in Fahrenheit | ||
// wind in miles/hour | ||
imperial() { | ||
this._units = Units.Imperial; | ||
return this; | ||
} | ||
// set output of description field | ||
// see possible values here: https://openweathermap.org/api/one-call-api | ||
language(value) { | ||
this._language = (value && value.trim()) ? value.trim().toLowerCase() : ''; | ||
return this; | ||
} | ||
get(attributes) { | ||
const { _latitude, _longitude, _exclude, _apiKey, _units, _language, } = this, atts = attributes || {}, key = atts.apiKey || _apiKey, lat = atts.coords ? atts.coords.latitude : _latitude, lon = atts.coords ? atts.coords.longitude : _longitude, lang = (atts.language && atts.language.trim()) ? atts.language.trim().toLowerCase() : _language, units = (atts.units && atts.units.trim()) ? atts.units.trim().toLowerCase() : _units, part = atts.exclude || _exclude; | ||
if (!key || !lat || !lon) { | ||
throw new Error('Missing required parameters for Open Weather Map api call.'); | ||
} | ||
let uri = `https://api.openweathermap.org/data/2.5/onecall?lat=${lat}&lon=${lon}&exclude=${part}&appid=${key}`; | ||
if (units && units !== Units.Standard) { | ||
uri = `${uri}&units=${units}`; | ||
} | ||
if (lang) { | ||
uri = `${uri}&lang=${lang}`; | ||
} | ||
return fetch(uri) | ||
.then(res => res.json()) | ||
.then(res => { | ||
if (res.current) { | ||
res.current.rain = this.getPrecipitation(res.current.rain); | ||
res.current.snow = this.getPrecipitation(res.current.snow); | ||
} | ||
if (res.daily) { | ||
res.daily = res.daily.map(item => { | ||
item.rain = item.rain || 0; | ||
item.snow = item.snow || 0; | ||
return item; | ||
}); | ||
} | ||
if (res.hourly) { | ||
res.hourly = res.hourly.map(item => { | ||
item.rain = this.getPrecipitation(item.rain); | ||
item.snow = this.getPrecipitation(item.snow); | ||
return item; | ||
}); | ||
} | ||
return res; | ||
}); | ||
} | ||
// owm puts precip amount on a nested property | ||
getPrecipitation(value) { | ||
return !value | ||
? 0 | ||
: (value['1h'] | ||
? value['1h'] | ||
: 0); | ||
} | ||
} | ||
export default MiniOwm; | ||
//# sourceMappingURL=MiniOwm.js.map |
{ | ||
"name": "mini-owm", | ||
"version": "1.3.5", | ||
"version": "1.3.6", | ||
"description": "Mini ES wrapper for OpenWeatherMap api", | ||
@@ -42,2 +42,3 @@ "author": "Dean Verleger", | ||
"@babel/core": "^7.9.6", | ||
"@babel/plugin-proposal-class-properties": "^7.10.4", | ||
"@babel/preset-env": "^7.9.6", | ||
@@ -44,0 +45,0 @@ "@babel/preset-typescript": "^7.9.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
195343
195
15
1