Skip to content

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

Package listing

@kody/reddit

src/get-post.ts

18 lines · 711 B · TypeScript
import { getPost, requireRecord, requireStringField } from './client.ts'
import type { GetPostInput } from './client.ts'

/**
 * Read one Reddit post and its comment tree.
 * @param params.id - `t3_…` fullname or the bare post id.
 * @example
 * import getPost from 'kody:@kody/reddit/get-post'
 * const thread = await getPost({ id: 'abc123', commentLimit: 10 })
 * // => { post: { title: '...', permalink: '...' }, comments: [{ author, body, score }] }
 */
export default async function getPostEntrypoint(
	params: Partial<GetPostInput> & Record<string, unknown> = {},
) {
	const input = requireRecord(params, 'get-post')
	requireStringField(input, 'id', 'get-post')
	return getPost(input as GetPostInput)
}