
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
@jamsch/hacker-news-client
Advanced tools
A simple API wrapper for Hacker News with Typescript typings that supports browsers & Node.js.
npm install @jamsch/hacker-news-client
import Client from '@jamsch/hacker-news-client';
// Fetch the top 500 story IDs
const topStories = await Client.getTopStories();
// Latest stories, by any type
const newStories = await Client.getNewStories();
// Latest "Ask HN" stories
const askStories = await Client.getAskStories();
// Latest "Show HN" stories
const showStories = await Client.getShowStories();
// Latest "Jobs" stories
const jobStories = await Client.getJobStories();
// Fetch a single story
const story = await Client.getItem(topStories[0]));
// Fetch the user's info
const user = await Client.getUser(story.by);
// Fetch the first 5 stories in parallel.
// Note: this makes one request per item provided, and the order of the results is not guaranteed.
const topFiveStories = await Client.getItems(topStories.slice(0,5));
import Client, { Story, Ask, Comment, Job, Poll, PollOpt } from '@jamsch/hacker-news-client';
// Fetch an Item
const item = await Client.getItem(1); // "Item" type
console.log(item); // Item (Story | Comment | Ask | Job | Poll | PollOpt)
// Check what kind of item it is
if (Client.is(item, 'story')) {
console.log(item); // Story
} else if (Client.is(item, 'ask')) {
console.log(item); // Ask
}
// If you know the item ID belongs to a specific item type:
const storyId = 123;
const storyItem = await Client.getItem<Story>(storyId);
console.log(storyItem); // Story
const storyIds = [1,2,3,4];
const topFiveStories = await Client.getItems<Story>(storyIds);
console.log(topFiveStories); // Story[]
// Alternatively, use a switch statement to figure out the type
switch (item.type) {
case 'story': {
console.log('Ask | Story:', item); // Ask | Story
if ('text' in item) {
console.log('Ask:', item); // Ask
}
if ('url' in item) {
console.log('Story:', item); // Story
}
break;
}
case 'comment':
console.log('Comment:', item); // Comment
break;
case 'job':
console.log('Job:', item); // Job
break;
case 'poll':
console.log('Poll:', item); // Poll
break;
case 'pollopt':
console.log('Polopt', item); // PolOpt
break;
}
<script src="{path_to_package}/umd/hacker-news-client.production.min.js"></script>
<script>
HackerNewsClient.getTopStories().then(topStories => {
console.log(topStories);
});
</script>
FAQs
A universal API client for Hacker News with Typescript typings
We found that @jamsch/hacker-news-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.