Skip to content

Built for people who want to own their automations. Join the waitlist for an invite.

Package listing

@kody/reddit

src/search.ts

17 lines · 682 B · TypeScript
import { requireRecord, requireStringField, searchReddit } from './client.ts'
import type { SearchInput } from './client.ts'

/**
 * Search Reddit posts, optionally restricted to one subreddit.
 * @example
 * import search from 'kody:@kody/reddit/search'
 * const results = await search({ query: 'cloudflare workers', subreddit: 'programming', limit: 5 })
 * // => { listing: { posts: [{ title: '...', permalink: '...' }] } }
 */
export default async function searchEntrypoint(
	params: Partial<SearchInput> & Record<string, unknown> = {},
) {
	const input = requireRecord(params, 'search')
	requireStringField(input, 'query', 'search')
	return searchReddit(input as SearchInput)
}