0.1.2 • Published 2 years ago

@scinorandex/nhentai-wrapper v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

nhentai-wrapper

A promise-based nhentai API wrapper for degenerate developers alike

Example Usage

import { NhentaiWrapper, Options } from "@scinorandex/nhentai-wrapper";
const Nhentai = new NhentaiWrapper();

(async () => {
	const options: Options = { includePages: false, includeTags: false };
	const result = await Nhentai.searchDoujin(177013, options);
	console.log(result);
})();

Expected output:

{
  id: 177013,
  media_id: '987560',
  title: {
    english: '[ShindoLA] METAMORPHOSIS (Complete) [English]',
    japanese: '',
    pretty: 'METAMORPHOSIS'
  },
  images: {
    cover: { t: 'j', w: 350, h: 506 },
    thumbnail: { t: 'j', w: 250, h: 362 }
  },
  scanlator: '',
  upload_date: 1476793729,
  num_pages: 225,
  num_favorites: 44548
}

Options

All the fetching/searching methods of the library take a Partial<> version of this interface

PropertyTypeDescription
paginationnumberThe page of results to be retrieved
includePagesbooleanDictates if page dimensions will be removed
includeTagsbooleanDictates if tags will be removed
sortbooleanDictates if the doujins will be sorted based on num_favorites

Methods

convertTagNameToId

converts a tag from their name to their id

const wrapper = new NhentaiWrapper();
wrapper.convertTagNameToId("unbirth").then((data) => {
	console.log(data); // output is 9116
});

fetchAllDoujins

fetches all the doujin given a tag or a term, limited to the doujinsLimit property

PropertyTypeDescription
querystringThe query string to be used, must be compatible with the type parameter
type"term" or "tag"The type of query to be done
optsPartial\<Options> or undefinedThe options to be used

returns: Promise\<QueryResponse>

fetchRelatedDoujins

fetches all the doujins related to a specific doujin, based on their id

PropertyTypeDescription
idnumberthe id of the doujin to base the results from
optsPartial\<Options> or undefinedThe options to be used

returns: Promise\<RelatedDoujins>

getRandomDoujin

gets a single random doujin. This might take a while to resolve because it uses recursion

PropertyTypeDescription
optsPartial\<Options> or undefinedThe options to be used

returns: Promise\<Doujin>

searchDoujin

searches for a single doujin based on the id / "nuclear codes"

PropertyTypeDescription
idnumberthe id of the doujin to search
optsPartial\<Options> or undefinedThe options to be used

returns: Promise\<Doujin | null>

searchTag

searches for a single page of doujins containing a certain tag

PropertyTypeDescription
tagstringthe id of the tag
optsPartial\<Options> or undefinedThe options to be used

returns: Promise\<QueryResponse>

searchTerm

searches for a single page of doujins containing a term in their title

PropertyTypeDescription
termstringthe term to be grepped against
optsPartial\<Options> or undefinedThe options to be used

returns: Promise\<QueryResponse>

Output Interfaces

These are typed nhentai API responses

Doujin

Represents a single doujin

PropertyTypeDescription
idnumberThe nuclear codes
media_idnumberInternal ID used by nhentai for pages / covers / thumbnails
titleTitleThe titles of the doujin
imagesImagesThe dimensions of the images associated with the doujin
scanlatorstring
upload_datenumberUNIX Epoch Timestamp of doujin upload date
tagsTag[] or undefinedA list of the tags that the doujin has
num_pagesnumberThe number of pages that the doujin has
num_favoritesnumberThe number of times that the doujin has been favorited

RelatedDoujins

Represents a group of doujins

PropertyTypeDescription
resultDoujin[]An array of doujins
errorstring or boolean or undefinedErrors encountered by the query

QueryResponse extends RelatedDoujins

Represents a group of doujins with pagination information

PropertyTypeDescription
num_pagesnumberThe number of queries it takes to fetch all doujins
per_pagenumberThe number of doujins that will be fetched per query

TagType

A union type of all possibletag types that nhentai uses

Value: "tag" | "language" | "artist" | "category" | "group" | "parody" | "character"

Tag

Represents a single tag

PropertyTypeDescription
idnumberInternal tag id used by nhentai
typeTagTypeThe type of the tag
namestringThe name of the tag
urlstringThe path of the tag without the domain
countnumberThe number of doujins with this tag

Image

Represents the dimensions of an image

PropertyTypeDescription
tstringThe file extension of the image
wnumberThe width of the image
hnumberThe height of the image

Images

Represents the images of the doujin, such as cover, thumbnails, and pages

PropertyTypeDescription
pagesImage[] or undefinedThe pages of the doujin
coverImageThe cover of the doujin
thumbnailImageThe thumbnail of the doujin (This is used in the doujin browser)

Title

Represents the different titles of the doujin

PropertyType
englishstring
japanesestring
prettystring