Library to access the Derpibooru / Booru-on-rails JSON API from JavaScript easily.
import derpiJS from "./derpi.js"; //Import Class
const Derpi = new derpiJS;
An important note: Most methods return promises, so please expect this!
For Derpibooru's API reference, see https://derpibooru.org/pages/api
Change the target domain.
It's https://derpibooru.org
by default.
To change, do
Derpi.domain = "http://example.com"
Returns or sets the filter ID (numerical only).
When setting filters, you can use Derpibooru's aliases for the default filters in place of numerical IDs.
Examples
Derpi.filter; //Returns 100073 if unmodified
Derpi.filter = 1234; //Sets filter ID to 1234
Derpi.filter = EVERYTHING; //Sets filter ID to 56027
Filter Aliases (Setting Only)
Alias | ID (Click to view on Derpibooru) |
---|---|
DEFAULT | 100073 |
EVERYTHING | 56027 |
18+DARK | 37429 |
MAXSPOILERS | 37430 |
LEGACYDEFAULT | 37431 |
18+R34 | 37432 |
Returns a promise for the Derpibooru search result JSON.
Searches Derpibooru for the specified query. You can use the extraParams
to modify the results. See the reference below for details. (ex: https://derpibooru.org/search.json?q=dashie%2C+hugging%2C+cake)
Examples
//Basic
Derpi.search("dashie, hugging, cake").then(
results => {
//output result JSON to terminal
console.log(results);
}
)
//With all OPTIONAL extraParams included (same as above)
Derpi.search("dashie, hugging, cake", {
"filter": "DEFAULT",
"sortDir": "desc",
"sortBy": "created_at",
"perPage": 20,
"page": 1
}).then(
results => {
//output result JSON to terminal
console.log(results);
}
)
Optional Extra Params
Parameter | Values | Function |
---|---|---|
filter | Numerical or Filter Alias | Overrides current set filter. (derpiJS.filter by default) |
sortDir | asc or desc |
Changes the sort direction of results to ascending or descending respectively (desc by default) |
sortBy | created_at , score , wilson , relevance , width , height , comments ,random or random: + Numerical Value |
Changes how results are sorted (created_at by default) |
perPage | 0 -50 |
Changes the number of results per page (20 by default) |
page | Numerical value | Selects page of results (1 by default) |
Identical to Derpi.search("faved_by:USER")
Examples
Derpi.favedBy("USER").then(
result => {
console.log(result);
}
)
//Identical to the above
Derpi.search("faved_by:USER").then(
result => {
console.log(result);
}
)
Returns JSON Data for a specific post. (ex: https://derpibooru.org/0.json)
Examples
Derpi.post(0).then(
postJSON => {
console.log(postJSON);
}
)
Gets the oEmbed JSON for a post
Derpi.postOembed(0).then(
postJSON => {
console.log(postJSON);
}
)
Returns post lists (ex: https://derpibooru.org/lists.json)
Examples
Derpi.lists().then(
listJSON => {
console.log(listJSON);
}
)