Replace querystring with URLSearchParams
URLSearchParams has greater compatibility with browser code Created new PageOptions and LocaleOptions for easier use with URLSearchParams
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
import { MovieDiscoverResult, SortOption, TvShowDiscoverResult } from '../types';
|
||||
import { BaseEndpoint } from './base';
|
||||
import querystring, { ParsedUrlQueryInput } from 'querystring';
|
||||
|
||||
const BASE_DISCOVER = '/discover';
|
||||
|
||||
interface DiscoverQueryOptions extends ParsedUrlQueryInput{
|
||||
interface DiscoverQueryOptions {
|
||||
language?: string;
|
||||
sort_by?: SortOption;
|
||||
page?: number;
|
||||
@@ -66,12 +65,16 @@ export class DiscoverEndpoint extends BaseEndpoint {
|
||||
}
|
||||
|
||||
async movie(options?: MovieQueryOptions): Promise<MovieDiscoverResult> {
|
||||
const params = querystring.encode(options);
|
||||
const params = options
|
||||
? new URLSearchParams(Object.entries(options)).toString()
|
||||
: '';
|
||||
return await this.api.get<MovieDiscoverResult>(`${BASE_DISCOVER}/movie?${params}`);
|
||||
}
|
||||
|
||||
async tvShow(options?: TvShowQueryOptions): Promise<TvShowDiscoverResult> {
|
||||
const params = querystring.encode(options);
|
||||
const params = options
|
||||
? new URLSearchParams(Object.entries(options)).toString()
|
||||
: '';
|
||||
return await this.api.get<TvShowDiscoverResult>(`${BASE_DISCOVER}/tv?${params}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user