Comparing version 1.0.4 to 1.1.0
@@ -6,3 +6,5 @@ import coords from "./coords"; | ||
exclude?: string; | ||
language?: string; | ||
units?: string; | ||
}; | ||
export default getAtts; |
@@ -8,3 +8,7 @@ import getAtts from "./getAtts"; | ||
get: (atts?: getAtts) => Promise<any>; | ||
standard: () => IMiniOwm; | ||
metric: () => IMiniOwm; | ||
imperial: () => IMiniOwm; | ||
language: (value: string) => IMiniOwm; | ||
} | ||
export default IMiniOwm; |
@@ -5,1 +5,2 @@ export { default as coords } from './coords'; | ||
export { default as default } from './MiniOwm'; | ||
export { default as Units } from './Units'; |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("miniOwm",[],t):"object"==typeof exports?exports.miniOwm=t():e.miniOwm=t()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=3)}([function(e,t){},function(e,t){},function(e,t){},function(e,t,n){"use strict";n.r(t),n.d(t,"coords",(function(){return o.a})),n.d(t,"getAtts",(function(){return u.a})),n.d(t,"IMiniOwm",(function(){return c.a})),n.d(t,"default",(function(){return l}));var r=n(0),o=n.n(r),i=n(1),u=n.n(i),a=n(2),c=n.n(a);function f(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var l=function(){function e(t,n,r,o){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._apiKey=t||"",this._latitude=n||0,this._longitude=r||0,this._exclude=o||""}var t,n,r;return t=e,(n=[{key:"apiKey",value:function(e){return e&&(this._apiKey=e),this}},{key:"latitude",value:function(e){return e&&(this._latitude=e),this}},{key:"longitude",value:function(e){return e&&(this._longitude=e),this}},{key:"exclude",value:function(e){return e&&(this._exclude=e),this}},{key:"get",value:function(e){var t=this._latitude,n=this._longitude,r=this._exclude,o=this._apiKey,i=e||{},u=i.apiKey||o,a=i.coords?i.coords.latitude:t,c=i.coords?i.coords.longitude:n,f=i.exclude||r;if(!u||!a||!c)throw new Error("Missing required parameters for Open Weather Map api call.");var l="https://api.openweathermap.org/data/2.5/onecall?lat=".concat(a,"&lon=").concat(c,"&exclude=").concat(f,"&appid=").concat(u);return fetch(l).then((function(e){return e.json()}))}}])&&f(t.prototype,n),r&&f(t,r),e}()}]).default})); | ||
!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(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},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 i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(i,r,function(e){return t[e]}.bind(null,r));return i},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 r.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 i=n(0),r=n.n(i),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 i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}var f=function(){function t(e,n,i,r,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=i||0,this._exclude=r||"",this._units=u&&u.trim()?u.trim().toLowerCase():"",this._units===s.Standard&&(this._units=""),this._language=o&&o.trim()?o.trim().toLowerCase():""}var e,n,i;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._latitude,n=this._longitude,i=this._exclude,r=this._apiKey,u=this._units,o=this._language,a=t||{},c=a.apiKey||r,l=a.coords?a.coords.latitude:e,f=a.coords?a.coords.longitude:n,d=a.language&&a.language.trim()?a.language.trim().toLowerCase():o,p=a.units&&a.units.trim()?a.units.trim().toLowerCase():u,h=a.exclude||i;if(!c||!l||!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(c);return p&&p!==s.Standard&&(m="".concat(m,"&units=").concat(p)),d&&(m="".concat(m,"&lang=").concat(d)),fetch(m).then((function(t){return t.json()}))}}])&&l(e.prototype,n),i&&l(e,i),t}()}]).default})); | ||
//# sourceMappingURL=index.js.map |
@@ -8,3 +8,5 @@ import getAtts from "./getAtts"; | ||
private _exclude; | ||
constructor(apiKey?: string, latitude?: number, longitude?: number, exclude?: string); | ||
private _units; | ||
private _language; | ||
constructor(apiKey?: string, latitude?: number, longitude?: number, exclude?: string, units?: string, language?: string); | ||
apiKey(value: string): this; | ||
@@ -14,4 +16,8 @@ latitude(value: number): this; | ||
exclude(value: string): this; | ||
standard(): this; | ||
metric(): this; | ||
imperial(): this; | ||
language(value: string): this; | ||
get(attributes?: getAtts): Promise<any>; | ||
} | ||
export default MiniOwm; |
export { default as default } from './MiniOwm'; | ||
export { default as Units } from './Units'; | ||
//# sourceMappingURL=index.js.map |
@@ -0,3 +1,4 @@ | ||
import Units from "./Units"; | ||
export class MiniOwm { | ||
constructor(apiKey, latitude, longitude, exclude) { | ||
constructor(apiKey, latitude, longitude, exclude, units, language) { | ||
this._apiKey = apiKey || ''; | ||
@@ -7,33 +8,60 @@ this._latitude = latitude || 0; | ||
this._exclude = exclude || ''; | ||
this._units = (units && units.trim()) ? units.trim().toLowerCase() : ''; | ||
if (this._units === Units.Standard) { | ||
this._units = ''; | ||
} | ||
this._language = (language && language.trim()) ? language.trim().toLowerCase() : ''; | ||
} | ||
apiKey(value) { | ||
if (value) { | ||
this._apiKey = value; | ||
} | ||
this._apiKey = value; | ||
return this; | ||
} | ||
latitude(value) { | ||
if (value) { | ||
this._latitude = value; | ||
} | ||
this._latitude = value; | ||
return this; | ||
} | ||
longitude(value) { | ||
if (value) { | ||
this._longitude = value; | ||
} | ||
this._longitude = value; | ||
return this; | ||
} | ||
exclude(value) { | ||
if (value) { | ||
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, } = this, atts = attributes || {}, key = atts.apiKey || _apiKey, lat = atts.coords ? atts.coords.latitude : _latitude, lon = atts.coords ? atts.coords.longitude : _longitude, part = atts.exclude || _exclude; | ||
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.'); | ||
} | ||
const uri = `https://api.openweathermap.org/data/2.5/onecall?lat=${lat}&lon=${lon}&exclude=${part}&appid=${key}`; | ||
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) | ||
@@ -40,0 +68,0 @@ .then(res => res.json()); |
{ | ||
"name": "mini-owm", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"description": "Mini ES wrapper for OpenWeatherMap api", | ||
@@ -5,0 +5,0 @@ "author": "Dean Verleger", |
@@ -9,3 +9,3 @@ # mini-owm | ||
`npm install -D 'mini-owm'` | ||
`npm install mini-owm` | ||
@@ -15,3 +15,3 @@ ### Constructor parameters | ||
```js | ||
import MiniOwm from 'mini-owm'; | ||
import MiniOwm, { Units } from 'mini-owm'; | ||
@@ -24,2 +24,4 @@ // constructor parameters are all optional | ||
'hourly,minutely' // exclude | ||
Units.Metric // (or 'metric') units | ||
'de' // language | ||
); | ||
@@ -42,2 +44,4 @@ | ||
.exclude('hourly,minutely') | ||
.metric() | ||
.language('de') | ||
.get() | ||
@@ -52,3 +56,3 @@ .then(res => { | ||
```js | ||
import MiniOwm from 'mini-owm'; | ||
import MiniOwm, { Units } from 'mini-owm'; | ||
new MiniOwm() | ||
@@ -61,3 +65,5 @@ .get({ | ||
}, | ||
exclude: 'hourly,minutely' | ||
exclude: 'hourly,minutely', | ||
units: Units.Metric, // or 'metric' | ||
language: 'de', | ||
}) | ||
@@ -64,0 +70,0 @@ .then(res => { |
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
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
25747
23
162
88