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

danbooru

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

danbooru - npm Package Compare versions

Comparing version 1.3.1 to 1.4.0

75

lib/index.js
// Generated by LiveScript 1.4.0
(function(){
var https, request, deepExtend, argsJs, search, util, baseUrl, exports, slice$ = [].slice;
var https, request, deepExtend, argsJs, search, baseUrl, exports, slice$ = [].slice;
https = require('https');

@@ -9,3 +9,2 @@ request = require('request');

search = require('./search');
util = require('./util');
baseUrl = 'https://danbooru.donmai.us/';

@@ -50,4 +49,2 @@ module.exports = function(it){

doRequest = function(self, method, body, path, params, callback){
var stacktrace;
stacktrace = util.stacktrace(doRequest);
(function(){

@@ -62,17 +59,6 @@ var data, dataName, uri, ref$;

}, ref$[dataName] = data, ref$.json = true, ref$), function(e, response, body){
try {
if (e != null) {
throw e;
}
if (response.statusCode !== 200) {
throw new Error(danbooruErrors[response.statusCode]);
}
return callback(void 8, body);
} catch (e$) {
e = e$;
if (e.stack != null) {
e.stack = stacktrace;
}
return callback(e, body);
if (response.statusCode !== 200) {
e == null && (e = new Error(danbooruErrors[response.statusCode]));
}
return callback(e, body);
});

@@ -82,25 +68,16 @@ }.call(self));

optionalArgs = function(){
var stacktrace, ref$, path, params, callback, e;
stacktrace = util.stacktrace(optionalArgs);
try {
ref$ = argsJs([
{
path: argsJs.STRING | argsJs.Optional,
_default: ''
}, {
params: argsJs.OBJECT | argsJs.Optional,
_default: {}
}, {
callback: argsJs.FUNCTION | argsJs.Optional,
_default: function(){}
}
], arguments), path = ref$.path, params = ref$.params, callback = ref$.callback;
return [path, params, callback];
} catch (e$) {
e = e$;
if (e.stack != null) {
e.stack = stacktrace;
var ref$, path, params, callback;
ref$ = argsJs([
{
path: argsJs.STRING | argsJs.Optional,
_default: ''
}, {
params: argsJs.OBJECT | argsJs.Optional,
_default: {}
}, {
callback: argsJs.FUNCTION | argsJs.Optional,
_default: function(){}
}
throw e;
}
], arguments), path = ref$.path, params = ref$.params, callback = ref$.callback;
return [path, params, callback];
};

@@ -120,3 +97,2 @@ prototype.get = function(path, params, callback){

prototype.request = function(options, callback){
var stacktrace;
callback == null && (callback = function(){});

@@ -144,18 +120,3 @@ options = (function(){

}
stacktrace = util.stacktrace;
return request(options, function(){
var ref$, e;
try {
if (((ref$ = arguments[0]) != null ? ref$.stack : void 8) != null) {
arguments[0].stack = stacktrace;
}
return callback.apply(null, arguments);
} catch (e$) {
e = e$;
if (e.stack != null) {
e.stack = stacktrace;
}
throw e;
}
});
return request(options, callback);
};

@@ -162,0 +123,0 @@ return exports;

// Generated by LiveScript 1.4.0
(function(){
var util, argsJs, deepExtend, defaultParams, search, out$ = typeof exports != 'undefined' && exports || this, split$ = ''.split, join$ = [].join;
util = require('./util');
var argsJs, deepExtend, defaultParams, search, out$ = typeof exports != 'undefined' && exports || this, split$ = ''.split, join$ = [].join;
argsJs = require('args-js');

@@ -11,3 +10,3 @@ deepExtend = require('deep-extend');

out$.search = search = function(){
var ref$, tags, params, callback, stacktrace, tagsArray, i$, len$, tag, e, helpers, helperify;
var ref$, tags, params, callback, tagsArray, i$, len$, tag, helpers, postHelpers, helperify;
ref$ = argsJs([

@@ -25,37 +24,28 @@ {

], arguments), tags = ref$.tags, params = ref$.params, callback = ref$.callback;
stacktrace = util.stacktrace();
try {
if (params.page != null) {
params.page = Number(params.page);
if (isNaN(params.page)) {
throw new Error('page parameter must be a Number');
}
params.page >= 1 || (params.page = 1);
} else {
params.page = 1;
if (params.page != null) {
params.page = Number(params.page);
if (isNaN(params.page)) {
throw new Error('page parameter must be a Number');
}
tags = tags.trim();
tagsArray = split$.call(tags, /\s+/);
tags = [];
for (i$ = 0, len$ = tagsArray.length; i$ < len$; ++i$) {
tag = tagsArray[i$];
if (!in$(tag, tags)) {
tags.push(tag);
}
params.page >= 1 || (params.page = 1);
} else {
params.page = 1;
}
tags = tags.trim();
tagsArray = split$.call(tags, /\s+/);
tags = [];
for (i$ = 0, len$ = tagsArray.length; i$ < len$; ++i$) {
tag = tagsArray[i$];
if (!in$(tag, tags)) {
tags.push(tag);
}
tags = join$.call(tags, ' ');
params = deepExtend(defaultParams, params, {
tags: tags
});
} catch (e$) {
e = e$;
if (e.stack != null) {
e.stack = stacktrace;
}
throw e;
}
tags = join$.call(tags, ' ');
params = deepExtend(defaultParams, params, {
tags: tags
});
(function(self){
helpers = {
load: function(){
var ref$, page, callback, myParams, stacktrace;
var ref$, page, callback, myParams;
ref$ = argsJs([

@@ -73,12 +63,6 @@ {

});
stacktrace = util.stacktrace;
return self.search(this.tags, myParams, function(e, data){
if ((e != null ? e.stack : void 8) != null) {
e.stack = stacktrace;
}
return callback(e, data);
});
return self.search(this.tags, myParams, callback);
},
next: function(){
var ref$, modifier, callback, stacktrace;
var ref$, modifier, callback;
ref$ = argsJs([

@@ -93,12 +77,6 @@ {

], arguments), modifier = ref$.modifier, callback = ref$.callback;
stacktrace = util.stacktrace;
return this.load(this.page + modifier, function(e, data){
if ((e != null ? e.stack : void 8) != null) {
e.stack = stacktrace;
}
return callback(e, data);
});
return this.load(this.page + modifier, callback);
},
prev: function(){
var ref$, modifier, callback, stacktrace;
var ref$, modifier, callback;
ref$ = argsJs([

@@ -113,12 +91,6 @@ {

], arguments), modifier = ref$.modifier, callback = ref$.callback;
stacktrace = util.stacktrace;
return this.load(this.page - modifier, function(e, data){
if ((e != null ? e.stack : void 8) != null) {
e.stack = stacktrace;
}
return callback(e, data);
});
return this.load(this.page - modifier, callback);
},
add: function(){
var ref$, tagMod, callback, myParams, stacktrace;
var ref$, tagMod, callback, myParams;
ref$ = argsJs([

@@ -136,12 +108,6 @@ {

});
stacktrace = util.stacktrace;
return self.search(this.tags + (" " + tagMod), myParams, function(e, data){
if ((e != null ? e.stack : void 8) != null) {
e.stack = stacktrace;
}
return callback(e, data);
});
return self.search(this.tags + (" " + tagMod), myParams, callback);
},
rem: function(){
var ref$, tagMod, callback, newTags, tags, i$, len$, tag, myParams, stacktrace;
var ref$, tagMod, callback, newTags, tags, i$, len$, tag, myParams;
ref$ = argsJs([

@@ -169,14 +135,42 @@ {

});
stacktrace = util.stacktrace;
return self.search(newTags, myParams, function(e, data){
if ((e != null ? e.stack : void 8) != null) {
e.stack = stacktrace;
}
return callback(e, data);
});
return self.search(newTags, myParams, callback);
},
random: function(){
if (this.length) {
return this[Math.floor(this.length * Math.random())];
}
}
};
postHelpers = {
get: function(it){
return self.request(this.file_url, it);
},
getLarge: function(it){
return self.request(this.large_file_url, it);
},
getPreview: function(it){
return self.request(this.preview_file_url, it);
},
favorite: function(favorite, callback){
favorite == null && (favorite = true);
callback == null && (callback = function(){});
if (typeof favorite === 'function') {
callback = favorite;
favorite = true;
}
if (favorite) {
return self.post('favorites', {
post_id: this.id
}, callback);
} else {
return self['delete']("favorites/" + this.id, callback);
}
}
};
}.call(this, this));
helperify = function(it){
var ref$;
var i$, len$, ref$;
for (i$ = 0, len$ = it.length; i$ < len$; ++i$) {
(fn$.call(this, it[i$]));
}
return ref$ = import$(it, helpers), Object.defineProperty(ref$, 'page', {

@@ -195,8 +189,14 @@ get: function(){

}), ref$;
function fn$(post){
Object.defineProperty(import$(post, postHelpers), 'url', {
get: function(){
return "https://danbooru.donmai.us/posts/" + post.id;
},
configurable: true,
enumerable: true
});
}
};
this.get('posts', params, function(e, data){
if (e != null) {
if (e.stack != null) {
e.stack = stacktrace;
}
return callback(e, data);

@@ -203,0 +203,0 @@ }

{
"name": "danbooru",
"version": "1.3.1",
"version": "1.4.0",
"description": "danbooru api wrapper",

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

@@ -37,3 +37,3 @@ # danbooru-node

* `options` _string_. _object_. A url or options for your request.
* `callback` _function(err, response, body)_. Callback function.
* `callback` _function(err, response, body)_. Callback function. `response` is a usual node HTTP response, while `body` is the body of that response, ready for using.
* **returns** _request_. Request object.

@@ -131,1 +131,34 @@

#### searchData.random()
Gives you a random post from the set of posts you've found. Doesn't return anything when you don't have any posts.
* **returns** _object_. A random post from `searchData`.
### Danbooru.search -> posts
When you're searching, you're probably looking for posts. When you're looking for posts, you probably wannya make get requests to their image URLs to be able to use them. Rather than make you write `Danbooru.request(post.file_url)` over and over again, how about we make things simpler for you? This example uses `random`, but you could also just go to any valid index and it would still work.
```javascript
authedBooru.search('maid', function(err, data) {
if(err) throw err;
data.random().favorite(); // Favoriting a random maid~ H-how bold!
});
```
#### post.get([callback])
This does a get request to your post's `file_url`, which is usually your post's full size image. This also uses [request](https://www.npmjs.com/package/request), just like `Danbooru.request()`
* `callback` _function(err, response, body)_. Callback function. `response` is a usual node HTTP response, while `body` is your image data.
* **returns** _request_. Request object.
#### post.getLarge([callback])
This does a get request to your post's `large_file_url`, which is a large image appropriate for browsers, but not original size. It's sometimes the same image as `file_url`. This also uses [request](https://www.npmjs.com/package/request), just like `Danbooru.request()`
* `callback` _function(err, response, body)_. Callback function. `response` is a usual node HTTP response, while `body` is your image data.
* **returns** _request_. Request object.
#### post.getPreview([callback])
This does a get request to your post's `preview_file_url`, which is usually your post's tiny preview image, useful for thumbnails. This also uses [request](https://www.npmjs.com/package/request), just like `Danbooru.request()`
* `callback` _function(err, response, body)_. Callback function. `response` is a usual node HTTP response, while `body` is your image data.
* **returns** _request_. Request object.
#### post.favorite([yes], [callback])
This function only really works with an authenticated Danbooru object, but you can use it to quickly favorite or unfavorite a post!
* `yes` _boolean_. Defaults to yes. Pass `false` to perform an unfavorite instead.
* `callback` _function(err, data)_. It's a callback.
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