Add string literal types to function
This commit is contained in:
parent
a20bdacbe5
commit
b1c7de7e8c
3 changed files with 2 additions and 42 deletions
|
@ -1,6 +1,6 @@
|
|||
export default interface ICliOptions {
|
||||
subreddit: string,
|
||||
json?: boolean,
|
||||
sort: string,
|
||||
sort: "new" | "hot" | "top",
|
||||
queryMetadata?: boolean,
|
||||
}
|
10
src/index.ts
10
src/index.ts
|
@ -7,15 +7,7 @@ import { ErrorCode } from "./constants/ErrorCode";
|
|||
import ErrorMessages from "./constants/ErrorMessages";
|
||||
import ImageHelper from "./imageHelper";
|
||||
|
||||
const sortable = [
|
||||
'new',
|
||||
'hot',
|
||||
'top'
|
||||
];
|
||||
|
||||
export default async function randomBunny(subreddit: string, sortBy: string = 'hot'): Promise<IReturnResult> {
|
||||
if (!sortable.includes(sortBy)) sortBy = 'hot';
|
||||
|
||||
export default async function randomBunny(subreddit: string, sortBy: "new" | "hot" | "top" = 'hot'): Promise<IReturnResult> {
|
||||
const result = await fetch(`https://reddit.com/r/${subreddit}/${sortBy}.json?limit=100`)
|
||||
.then((res) => {
|
||||
return res;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue