egoist / wallhaven

API for alpha.wallhaven.cc
https://wallhaven.now.sh
MIT License
47 stars 8 forks source link

No Types for Typescript #3

Open WickedSik opened 5 years ago

WickedSik commented 5 years ago

Hi! I realise this is a fairly old project, but still. I decided to add a typescript definition file 🗡

declare module 'wallhaven-api' {
    type SearchCategory = 'general' | 'anime' | 'people'
    type SearchCategoryUC = 'General' | 'Anime' | 'People'
    type SearchSorting = 'relevance' | 'random' | 'date_added' | 'views' | 'favorites'

    type SearchOptions = {
        categories?: SearchCategory[]
        page?: number
        sorting?: SearchSorting
        nsfw?: boolean
        sketchy?: boolean
    }

    type Tag = {
        id: number
        text: string
    }

    type SearchResultItem = {
        id: number
        width: number
        height: number
        thumb: string
    }

    type SearchResult = {
        end: boolean
        totalPages: number
        images: SearchResultItem[]
    }

    type DetailResult = {
        fullImage: string
        tags: Tag[]
        category: SearchCategoryUC
        size: string
        views: number
        width: number
        height: number
        colors: string[]
    }

    export default class Wallhaven {
        search(keyword: string, options?: SearchOptions): Promise<SearchResult>
        details(id: number): Promise<DetailResult>
    }
}
WickedSik commented 5 years ago

Also, the package name is wallhaven-api not wallhaven like it shows in the README.md