Comparing version 1.0.4 to 1.0.5
{ | ||
"name": "pageviews", | ||
"main": "pageviews", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"homepage": "https://github.com/tomayac/pageviews.js", | ||
@@ -6,0 +6,0 @@ "authors": [ |
{ | ||
"name": "pageviews", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "A lightweight JavaScript client library for the Wikimedia Pageviews API for Wikipedia and various of its sister projects for Node.js and the browser.", | ||
@@ -5,0 +5,0 @@ "main": "pageviews.js", |
/** | ||
* @license | ||
* Copyright 2015 Thomas Steiner (@tomayac). All Rights Reserved. | ||
* Copyright 2016 Thomas Steiner (@tomayac). All Rights Reserved. | ||
* | ||
@@ -17,2 +17,2 @@ * Licensed under the Apache License, Version 2.0 (the "License"); | ||
*/ | ||
var request,USER_AGENT="pageviews.js",environment="undefined"==typeof window?"node":"browser";if("node"===environment){request=require("request");var package=require("./package.json");USER_AGENT="pageviews.js–v"+package.version+" ("+package.repository.url+")"}else request=function(e,r){var t=new XMLHttpRequest;t.addEventListener("load",function(){return r(null,{statusCode:this.status},this.responseText)}),t.addEventListener("error",function(e){return r(e)}),t.open("GET",e.url),t.send()};var pageviews=function(){var e="https://wikimedia.org/api/rest_v1",r={"default":"all-access",allowed:["all-access","desktop","mobile-web","mobile-app"]},t={"default":"all-agents",allowed:["all-agents","user","spider","bot"]},a={"default":"hourly",allowed:["daily","hourly","monthly"]},i={"default":"daily",allowed:["daily"]},n=function(e,n){if(!e)return new Error("Required parameters missing.");if(!e.project&&!e.projects)return"getAggregatedPageviews"===n||"getTopPageviews"===n?new Error('Required parameter "project" or "projects" missing.'):new Error('Required parameter "project" missing.');if(e.project&&-1===e.project.indexOf("."))return new Error('Required parameter "project" invalid.');if(("getAggregatedPageviews"===n||"getTopPageviews"===n)&&e.projects&&(!Array.isArray(e.projects)||!e.projects.length||e.projects.filter(function(e){return-1===e.indexOf(".")}).length))return new Error('Required parameter "projects" invalid.');if("getPerArticlePageviews"===n){if(!e.article&&!e.articles)return new Error('Required parameter "article" or "articles" missing.');if(e.articles&&(!Array.isArray(e.articles)||!e.articles.length))return new Error('Required parameter "articles" invalid.')}if("getPerArticlePageviews"===n){if(!e.start||!/^(?:19|20)\d\d[- \/.]?(?:0[1-9]|1[012])[- \/.]?(?:0[1-9]|[12][0-9]|3[01])$/.test(e.start))return new Error('Required parameter "start" missing or invalid.');if(!e.end||!/^(19|20)\d\d[- \/.]?(0[1-9]|1[012])[- \/.]?(0[1-9]|[12][0-9]|3[01])$/.test(e.end))return new Error('Required parameter "end" missing or invalid.')}else if("getAggregatedPageviews"===n){if(!e.start||!/^(?:19|20)\d\d[- \/.]?(?:0[1-9]|1[012])[- \/.]?(?:0[1-9]|[12][0-9]|3[01])[- \/.]?(?:[012][0-9])$/.test(e.start))return new Error('Required parameter "start" missing or invalid.');if(!e.end||!/^(19|20)\d\d[- \/.]?(0[1-9]|1[012])[- \/.]?(0[1-9]|[12][0-9]|3[01])[- \/.]?(?:[012][0-9])$/.test(e.end))return new Error('Required parameter "end" missing or invalid.')}if("getTopPageviews"===n){if(!e.year||!/^(?:19|20)\d\d$/.test(e.year))return new Error('Required parameter "year" missing or invalid.');if(!e.month||!/^(?:0?[1-9]|1[012])$/.test(e.month))return new Error('Required parameter "month" missing or invalid.');if(!e.day||!/^(?:0?[1-9]|[12][0-9]|3[01])$/.test(e.day))return new Error('Required parameter "day" missing or invalid.');if(e.limit&&!/^\d+$/.test(e.limit)&&0<e.limit&&e.limit<=1e3)return new Error('Invalid optional parameter "limit".')}if(e.access&&-1===r.allowed.indexOf(e.access))return new Error('Invalid optional parameter "access".');if(e.agent&&-1===t.allowed.indexOf(e.agent))return new Error('Invalid optional parameter "agent".');if(e.granularity)if("getAggregatedPageviews"===n){if(-1===a.allowed.indexOf(e.granularity))return new Error('Invalid optional parameter "granularity".')}else if("getPerArticlePageviews"===n&&-1===i.allowed.indexOf(e.granularity))return new Error('Invalid optional parameter "granularity".');return e},s=function(e,r,t){var a;if(e||200!==r.statusCode){if(e)return e;if(404===r.statusCode)try{return a=JSON.parse(t),new Error(a.detail)}catch(i){return new Error(i)}return new Error("Status code "+r.statusCode)}try{a=JSON.parse(t)}catch(i){return new Error(i)}return a},o=function(a){return new Promise(function(u,l){if(a=n(a,"getPerArticlePageviews"),a.stack)return l(a);if(a.articles){var d=[];return a.articles.map(function(e,r){var t=a;delete t.articles,t.article=e,d[r]=o(t)}),u(Promise.all(d))}var c=a.project,g=encodeURIComponent(a.article.replace(/\s/g,"_")),p=a.start,f=a.end,m=a.access?a.access:r["default"],v=a.agent?a.agent:t["default"],w=a.granularity?a.granularity:i["default"],E={url:e+"/metrics/pageviews/per-article/"+c+"/"+m+"/"+v+"/"+g+"/"+w+"/"+p+"/"+f,headers:{"User-Agent":USER_AGENT}};request(E,function(e,r,t){var a=s(e,r,t);return a.stack?l(a):u(a)})})},u=function(i){return new Promise(function(o,l){if(i=n(i,"getAggregatedPageviews"),i.stack)return l(i);if(i.projects){var d=[];return i.projects.map(function(e,r){var t=i;delete t.projects,t.project=e,d[r]=u(t)}),o(Promise.all(d))}var c=i.project,g=i.start,p=i.end,f=i.access?i.access:r["default"],m=i.agent?i.agent:t["default"],v=i.granularity?i.granularity:a["default"],w={url:e+"/metrics/pageviews/aggregate/"+c+"/"+f+"/"+m+"/"+v+"/"+g+"/"+p,headers:{"User-Agent":USER_AGENT}};request(w,function(e,r,t){var a=s(e,r,t);return a.stack?l(a):o(a)})})},l=function(t){return new Promise(function(a,i){if(t=n(t,"getTopPageviews"),t.stack)return i(t);if(t.projects){var o=[];return t.projects.map(function(e,r){var a=t;delete a.projects,a.project=e,o[r]=l(a)}),a(Promise.all(o))}var u=t.project,d=t.year,c="number"==typeof t.month&&t.month<10?"0"+t.month:t.month,g="number"==typeof t.day&&t.day<10?"0"+t.day:t.day,p=t.limit||!1,f=t.access?t.access:r["default"],m={url:e+"/metrics/pageviews/top/"+u+"/"+f+"/"+d+"/"+c+"/"+g,headers:{"User-Agent":USER_AGENT}};request(m,function(e,r,t){var n=s(e,r,t);return n.stack?i(n):(p&&(n.items[0].articles=n.items[0].articles.slice(0,p)),a(n))})})},d=function(){return new Promise(function(r,t){var a={url:e+"/metrics/pageviews/",headers:{"User-Agent":USER_AGENT}};request(a,function(e,a,i){var n=s(e,a,i);return n.stack?t(n):r(n)})})};return{getPageviewsDimensions:d,getPerArticlePageviews:o,getAggregatedPageviews:u,getTopPageviews:l}}();"node"===environment&&(module.exports=pageviews); | ||
var request,USER_AGENT="pageviews.js",environment="undefined"==typeof window?"node":"browser";if("node"===environment){request=require("request");var packageJson=require("./package.json");USER_AGENT="pageviews.js–v"+packageJson.version+" ("+packageJson.repository.url+")"}else request=function(e,r){var t=new XMLHttpRequest;t.addEventListener("load",function(){return r(null,{statusCode:this.status},this.responseText)}),t.addEventListener("error",function(e){return r(e)}),t.open("GET",e.url),t.send()};var pageviews=function(){var e="https://wikimedia.org/api/rest_v1",r={"default":"all-access",allowed:["all-access","desktop","mobile-web","mobile-app"]},t={"default":"all-agents",allowed:["all-agents","user","spider","bot"]},a={"default":"hourly",allowed:["daily","hourly","monthly"]},n={"default":"daily",allowed:["daily"]},i=function(e,i){var s=function(e){return 10>e?"0"+e:e};if(!e)return new Error("Required parameters missing.");if(!e.project&&!e.projects)return"getAggregatedPageviews"===i||"getTopPageviews"===i?new Error('Required parameter "project" or "projects" missing.'):new Error('Required parameter "project" missing.');if(e.project&&-1===e.project.indexOf("."))return new Error('Required parameter "project" invalid.');if(("getAggregatedPageviews"===i||"getTopPageviews"===i)&&e.projects&&(!Array.isArray(e.projects)||!e.projects.length||e.projects.filter(function(e){return-1===e.indexOf(".")}).length))return new Error('Required parameter "projects" invalid.');if("getPerArticlePageviews"===i){if(!e.article&&!e.articles)return new Error('Required parameter "article" or "articles" missing.');if(e.articles&&(!Array.isArray(e.articles)||!e.articles.length))return new Error('Required parameter "articles" invalid.')}if("getPerArticlePageviews"===i){if(!e.start)return new Error('Required parameter "start" missing.');if(e.start="object"==typeof e.start?e.start.getFullYear()+s(e.start.getMonth()+1)+s(e.start.getDate()):e.start,!/^(?:19|20)\d\d[- \/.]?(?:0[1-9]|1[012])[- \/.]?(?:0[1-9]|[12][0-9]|3[01])$/.test(e.start))return new Error('Required parameter "start" invalid.');if(!e.end)return new Error('Required parameter "end" missing.');if(e.end="object"==typeof e.end?e.end.getFullYear()+s(e.end.getMonth()+1)+s(e.end.getDate()):e.end,!/^(19|20)\d\d[- \/.]?(0[1-9]|1[012])[- \/.]?(0[1-9]|[12][0-9]|3[01])$/.test(e.end))return new Error('Required parameter "end" invalid.')}else if("getAggregatedPageviews"===i){if(!e.start)return new Error('Required parameter "end" missing.');if(e.start="object"==typeof e.start?e.start.getFullYear()+s(e.start.getMonth()+1)+s(e.start.getDate())+s(e.start.getHours()):e.start,!/^(?:19|20)\d\d[- \/.]?(?:0[1-9]|1[012])[- \/.]?(?:0[1-9]|[12][0-9]|3[01])[- \/.]?(?:[012][0-9])$/.test(e.start))return new Error('Required parameter "start" missing or invalid.');if(!e.end)return new Error('Required parameter "end" missing.');if(e.end="object"==typeof e.end?e.end.getFullYear()+s(e.end.getMonth()+1)+s(e.end.getDate())+s(e.end.getHours()):e.end,!/^(19|20)\d\d[- \/.]?(0[1-9]|1[012])[- \/.]?(0[1-9]|[12][0-9]|3[01])[- \/.]?(?:[012][0-9])$/.test(e.end))return new Error('Required parameter "end" missing or invalid.')}if("getTopPageviews"===i){if(e.date&&(e.date="object"==typeof e.date?e.date:new Date(e.date.substr(0,4)+"-"+e.date.substr(4,2)+"-"+e.date.substr(6,2)),e.year=e.date.getFullYear(),e.month=s(e.date.getMonth()+1),e.day=s(e.date.getDate())),!e.year||!/^(?:19|20)\d\d$/.test(e.year))return new Error('Required parameter "year" missing or invalid.');if(!e.month||!/^(?:0?[1-9]|1[012])$/.test(e.month))return new Error('Required parameter "month" missing or invalid.');if(!e.day||!/^(?:0?[1-9]|[12][0-9]|3[01])$/.test(e.day))return new Error('Required parameter "day" missing or invalid.');if(e.limit&&!/^\d+$/.test(e.limit)&&0<e.limit&&e.limit<=1e3)return new Error('Invalid optional parameter "limit".')}if(e.access&&-1===r.allowed.indexOf(e.access))return new Error('Invalid optional parameter "access".');if(e.agent&&-1===t.allowed.indexOf(e.agent))return new Error('Invalid optional parameter "agent".');if(e.granularity)if("getAggregatedPageviews"===i){if(-1===a.allowed.indexOf(e.granularity))return new Error('Invalid optional parameter "granularity".')}else if("getPerArticlePageviews"===i&&-1===n.allowed.indexOf(e.granularity))return new Error('Invalid optional parameter "granularity".');return e},s=function(e,r,t){var a;if(e||200!==r.statusCode){if(e)return e;if(404===r.statusCode)try{return a=JSON.parse(t),new Error(a.detail)}catch(n){return new Error(n)}return new Error("Status code "+r.statusCode)}try{a=JSON.parse(t)}catch(n){return new Error(n)}return a},o=function(a){return new Promise(function(d,u){if(a=i(a,"getPerArticlePageviews"),a.stack)return u(a);if(a.articles){var l=[];return a.articles.map(function(e,r){var t=a;delete t.articles,t.article=e,l[r]=o(t)}),d(Promise.all(l))}var g=a.project,c=encodeURIComponent(a.article.replace(/\s/g,"_")),p=a.start,f=a.end,m=a.access?a.access:r["default"],w=a.agent?a.agent:t["default"],v=a.granularity?a.granularity:n["default"],y={url:e+"/metrics/pageviews/per-article/"+g+"/"+m+"/"+w+"/"+c+"/"+v+"/"+p+"/"+f,headers:{"User-Agent":USER_AGENT}};request(y,function(e,r,t){var a=s(e,r,t);return a.stack?u(a):d(a)})})},d=function(n){return new Promise(function(o,u){if(n=i(n,"getAggregatedPageviews"),n.stack)return u(n);if(n.projects){var l=[];return n.projects.map(function(e,r){var t=n;delete t.projects,t.project=e,l[r]=d(t)}),o(Promise.all(l))}var g=n.project,c=n.start,p=n.end,f=n.access?n.access:r["default"],m=n.agent?n.agent:t["default"],w=n.granularity?n.granularity:a["default"],v={url:e+"/metrics/pageviews/aggregate/"+g+"/"+f+"/"+m+"/"+w+"/"+c+"/"+p,headers:{"User-Agent":USER_AGENT}};request(v,function(e,r,t){var a=s(e,r,t);return a.stack?u(a):o(a)})})},u=function(t){return new Promise(function(a,n){if(t=i(t,"getTopPageviews"),t.stack)return n(t);if(t.projects){var o=[];return t.projects.map(function(e,r){var a=t;delete a.projects,a.project=e,o[r]=u(a)}),a(Promise.all(o))}var d=t.project,l=t.year,g="number"==typeof t.month&&t.month<10?"0"+t.month:t.month,c="number"==typeof t.day&&t.day<10?"0"+t.day:t.day,p=t.limit||!1,f=t.access?t.access:r["default"],m={url:e+"/metrics/pageviews/top/"+d+"/"+f+"/"+l+"/"+g+"/"+c,headers:{"User-Agent":USER_AGENT}};request(m,function(e,r,t){var i=s(e,r,t);return i.stack?n(i):(p&&(i.items[0].articles=i.items[0].articles.slice(0,p)),a(i))})})},l=function(){return new Promise(function(r,t){var a={url:e+"/metrics/pageviews/",headers:{"User-Agent":USER_AGENT}};request(a,function(e,a,n){var i=s(e,a,n);return i.stack?t(i):r(i)})})};return{getPageviewsDimensions:l,getPerArticlePageviews:o,getAggregatedPageviews:d,getTopPageviews:u}}();"node"===environment&&(module.exports=pageviews); |
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
49755