dinky.js
JavaScript bindings for Philomena JSON API. Supports sites such as Derpibooru and Furbooru.
Installation
You can install this package from npm:
npm install dinky.js
Or with yarn:
yarn add dinky.js
Or via pnpm:
pnpm add dinky.js
Usage
Dinky implements individual class for each API resourse to build a request. Each class is request builder and will return Promise
when you commit the request.
- The minimal example that will return an image by known ID:
import {Images} from "dinky.js"
const images = new Images()
await images.getById(0)
- Search for images by their tags using the
Search
class:
import {Search} from "dinky.js"
const search = new Search()
await search.query(["artist:rainbow", "safe"]).random().limit(1)
- Every dinky.js class constructor allows to set a custom base URL, allowing you to use it with any Philomena compatible APIs.
import {Search} from "dinky.js"
const search = new Search({url: "https://furbooru.org"})
await search.query(["safe", "loona"])
- Dinky has shortcuts for both
entites
and search
interfaces, so you can build request in similar to v1 manner:
import {images, search} from "dinky.js"
await images().getById(0)
await search.reverse("https://derpicdn.net/img/2019/12/24/2228439/full.jpg")
await search.images().query(["pinke pie", "safe"])
- Every class keeps its state between request, which means you can re-use same object to perform multiple requests.
import {Search} from "dinky.js"
const search = new Search()
search
.query(["scootaloo", "princess luna", "safe", "sleepless in ponyville"])
.minScore(200)
.random()
.limit(1)
await search
await search
- You can navigate through search results with
.page()
method. Note that after each .page()
call you have to send a new request to API:
import {Search} from "dinky.js"
const search = new Search()
serch.query(["twilight sparkle"]).minScore(200)
await search
await search.page(2)
- You can set a filter to use for requests:
import {Search} from "dinky.js"
const search = new Search({filter: 37430})
search.query(["dinky", "derpy hooves"])
await search.exec()
await search.exec({filter: 100073})
- Search for "my:faves" images using a key taken from account page:
import {Search} from "dinky.js"
const search = new Search({key: "<your key here>"})
await search.query(["trixie", "safe"]).faves()
API
Full documentation can be found in /docs
directory.
Related
Another API bindings: