Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stackexchange

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stackexchange - npm Package Compare versions

Comparing version 1.2.2 to 1.2.3

95

lib/methods/tags.js

@@ -29,2 +29,3 @@ 'use strict';

}
var sortPattern2 = /^creation$|^applied$|^activity$/;

@@ -46,5 +47,2 @@ function sortValidator2(sort) {

return function() {
if (!period) {
return 'period is required';
}
if (!period.match(periodPattern)) {

@@ -57,8 +55,4 @@ return 'sort is invalid. [all_time|month]';

function validate(validators) {
function run(validators, tags, criteria, callback) {
var errors = [];
validators = validators || [];
if (!(validators instanceof Array)) {
validators = [validators];
}
validators.forEach(function(validator) {

@@ -70,6 +64,7 @@ var err = validator();

});
if (errors.length === 0) {
return false;
if (errors.length !== 0) {
process.nextTick(callback, new Error(errors.join(', ')));
return;
}
return errors;
query(tags, criteria, callback);
}

@@ -84,4 +79,4 @@

*/
function tags (criteria, callback) {
query('tags', criteria, callback);
function tags(criteria, callback) {
run([sortValidator1(criteria.sort)], 'tags', criteria, callback);
}

@@ -98,8 +93,3 @@

function info (criteria, callback, tags) {
var errors = validate([tagsValidator(tags), sortValidator1(criteria.sort)]);
if (errors) {
callback(new Error(errors.join(', ')));
return;
}
query('tags/' + tags.join(';') + '/info', criteria, callback);
run([tagsValidator(tags), sortValidator1(criteria.sort)], 'tags/' + tags.join(';') + '/info', criteria, callback);
}

@@ -115,8 +105,3 @@

function moderatorOnly (criteria, callback) {
var errors = validate([sortValidator1(criteria.sort)]);
if (errors) {
callback(new Error(errors.join(', ')));
return;
}
query('tags/moderator-only', criteria, callback);
run([sortValidator1(criteria.sort)], 'tags/moderator-only', criteria, callback);
}

@@ -132,8 +117,3 @@

function required (criteria, callback) {
var errors = validate([sortValidator1(criteria.sort)]);
if (errors) {
callback(new Error(errors.join(', ')));
return;
}
query('tags/required', criteria, callback);
run([sortValidator1(criteria.sort)], 'tags/required', criteria, callback);
}

@@ -149,8 +129,3 @@

function synonyms (criteria, callback) {
var errors = validate([sortValidator2(criteria.sort)]);
if (errors) {
callback(new Error(errors.join(', ')));
return;
}
query('tags/synonyms', criteria, callback);
run([sortValidator2(criteria.sort)], 'tags/synonyms', criteria, callback);
}

@@ -167,8 +142,3 @@

function faq (criteria, callback, tags) {
var errors = validate(tagsValidator(tags));
if (errors) {
callback(new Error(errors.join(', ')));
return;
}
query('tags/' + tags.join(';') + '/faq', criteria, callback);
run([tagsValidator(tags)], 'tags/' + tags.join(';') + '/faq', criteria, callback);
}

@@ -185,8 +155,3 @@

function related (criteria, callback, tags) {
var errors = validate(tagsValidator(tags));
if (errors) {
callback(new Error(errors.join(', ')));
return;
}
query('tags/' + tags.join(';') + '/related', criteria, callback);
run([tagsValidator(tags)], 'tags/' + tags.join(';') + '/related', criteria, callback);
}

@@ -203,8 +168,3 @@

function tagsSynonyms (criteria, callback, tags) {
var errors = validate([tagsValidator(tags), sortValidator2(criteria.sort)]);
if (errors) {
callback(new Error(errors.join(', ')));
return;
}
query('tags/' + tags.join(';') + '/synonyms', criteria, callback);
run([tagsValidator(tags), sortValidator2(criteria.sort)], 'tags/' + tags.join(';') + '/synonyms', criteria, callback);
}

@@ -223,9 +183,4 @@

period = period || 'all_time';
var errors = validate([tagsValidator(tags), periodValidator(period)]);
if (errors) {
callback(new Error(errors.join(', ')));
return;
}
query('tags/' + tags.join(';') + '/top-answerers/' + period,
criteria, callback);
run([tagsValidator(tags), periodValidator(period)], 'tags/' + tags.join(';') + '/top-answerers/' + period,
criteria, callback);
}

@@ -244,9 +199,4 @@

period = period || 'all_time';
var errors = validate([tagsValidator(tags), periodValidator(period)]);
if (errors) {
callback(new Error(errors.join(', ')));
return;
}
query('tags/' + tags.join(';') + '/top-askers/' + period,
criteria, callback);
run([tagsValidator(tags), periodValidator(period)], 'tags/' + tags.join(';') + '/top-askers/' + period,
criteria, callback);
}

@@ -263,8 +213,3 @@

function wiki (criteria, callback, tags) {
var errors = validate(tagsValidator(tags));
if (errors) {
callback(new Error(errors.join(', ')));
return;
}
query('tags/' + tags.join(';') + '/wikis', criteria, callback);
run([tagsValidator(tags)], 'tags/' + tags.join(';') + '/wikis', criteria, callback);
}

@@ -271,0 +216,0 @@

var zlib = require('zlib');
/**
* Parse the buffer, StackExchange promises to always deliver zipped content,
* but since JSON parsing is required just wrap it in a try/catch.
* Parse the buffer. StackExchange promises to always deliver zipped content.
*

@@ -13,7 +12,12 @@ * @param {Buffer} buffer response content

zlib.unzip(buffer, function Unzipped (error, body) {
if (error) {
return callback(error);
}
let jsonBody;
try {
callback(error, JSON.parse(body.toString()));
jsonBody = JSON.parse(body.toString());
} catch (error) {
callback(error);
return callback(error);
}
callback(undefined, jsonBody);
});

@@ -20,0 +24,0 @@ }

@@ -28,6 +28,13 @@ 'use strict';

// Execute the request on proper response call callback.
fetch(endpoint)
.then((res) => res.json())
.then((body) => callback(undefined, body))
.catch((error) => { callback(error); });
(async () => {
let body;
try {
const res = await fetch(endpoint);
body = await res.json();
} catch (error) {
return callback(error);
}
return callback(undefined, body);
})();
};
{
"name": "stackexchange",
"version": "1.2.2",
"version": "1.2.3",
"description": "Node.js implementation of the stackexchange/stackoverflow API",

@@ -25,4 +25,3 @@ "main": "./lib/stackexchange",

"mocha": "^8.2.0",
"sinon": "^4.5.0",
"sinon-chai": "^3.1.0"
"nock": "^13.0.11"
},

@@ -29,0 +28,0 @@ "keywords": [

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