
Product
Announcing Precomputed Reachability Analysis in Socket
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
@jamsch/hacker-news-client
Advanced tools
A universal API client for Hacker News with Typescript typings
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
The npm package @jamsch/hacker-news-client receives a total of 0 weekly downloads. As such, @jamsch/hacker-news-client popularity was classified as not popular.
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.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
Product
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.