
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
This is a proof of concept for a TypeScript wrapper for the Reddit API.
Example bootstrap code:
require('dotenv').config()
import { TSRAW } from "./TSRAW.js"
import { SubmitArgs } from "./types.js"
const { REDDIT_USER_AGENT, REDDIT_CLIENT_ID, REDDIT_CLIENT_SECRET, REDDIT_USERNAME, REDDIT_PASSWORD } = process.env
const CREDENTIALS = {
user_agent: REDDIT_USER_AGENT!,
client_id: REDDIT_CLIENT_ID!,
client_secret: REDDIT_CLIENT_SECRET!,
username: REDDIT_USERNAME!,
password: REDDIT_PASSWORD!,
}
export class RedditBot {
private r: TSRAW
constructor(r: TSRAW) {
this.r = r
}
async start() {
const thread = await this.createThread('test', dailyThread())
}
async createThread(subreddit: string, content: ThreadContent) {
const submission: SubmitArgs = {
sr: subreddit,
title: content.title,
text: content.body,
kind: 'self',
sendreplies: false
}
return this.r.submit(submission)
}
}
interface ThreadContent { title: string, body: string }
const dailyThread = (): ThreadContent => {
const title =
`Daily Discussion Thread (${new Date().toISOString().split('T')[0]})`
const body =
`Talk about anything your heart desires. Be polite and upvote everything!\n\n`+
`How has your day been?`
return { title, body }
}
const main = async () => {
try {
const r = await TSRAW.init(CREDENTIALS)
const bot = new RedditBot(r)
await bot.start()
} catch (cause) {
console.error(new Date().toISOString(), cause)
process.exit(1312)
}
}
main()
Interaces, see src/types.d.ts for more details
constructor(token: string)
static init(credentials: TSRAWCredentials): Promise<TSRAW>
private rq<T extends RedditRes>(request: AxiosRequestConfig, raw?: boolean): Promise<T>
submit (submission: SubmitArgs): Promise<SubmitResp>
edit (post: EditArgs): Promise<SubmitResp>
sticky (id: string): Promise<RedditRes> // Returns 500 (https://redd.it/1h41n06)
getSettings (subreddit: string): Promise<SettingsResp>
getMe (): Promise<AboutResp>
updateSidebar (subreddit: string, description: string): Promise<RedditRes>
threads (params: ThreadsReq): Promise<Thread[]>
comments (params: CommentsReq): Promise<Comment[]>
FAQs
TypeScript Reddit API Wrapper
The npm package tsraw receives a total of 24 weekly downloads. As such, tsraw popularity was classified as not popular.
We found that tsraw demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.