npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

lightweight-client

v2.5.0

Published

Lightweight TypeScript client library for content management - fetch blog articles, categories, tags, and SEO content

Readme

🚀 Lightweight Client

npm version TypeScript MIT License

A powerful TypeScript client library for content management. Effortlessly fetch blog articles, categories, tags, and SEO content with built-in caching and type safety.

✨ Features

  • 🔥 TypeScript Support - Full type safety and IntelliSense
  • Built-in Caching - Intelligent caching
  • 📄 Pagination - Easy pagination for articles and content
  • 🏷️ Category & Tag Filtering - Filter content by categories and tags
  • 🗺️ Sitemap Generation - Generate SEO-friendly sitemaps
  • 🌐 Modern Fetch API - Built on modern web standards

📦 Installation

npm install lightweight-client
yarn add lightweight-client
pnpm add lightweight-client

🚀 Quick Start

import { LightweightClient } from 'lightweight-client';

// Initialize the client
const client = new LightweightClient('your-api-key');

// Fetch the latest articles
const { articles, total } = await client.getPosts(0, 10);

console.log(`Found ${total} articles:`, articles);

📖 API Reference

Constructor

const client = new LightweightClient(key: string);
  • key - Your API key

Methods

📝 Articles

// Get paginated articles
const result = await client.getPosts(page: number, limit?: number);

// Get articles by category
const categoryPosts = await client.getCategoryPosts(
  slug: string, 
  page: number, 
  limit?: number
);

// Get articles by tag
const tagPosts = await client.getTagPosts(
  slug: string, 
  page: number, 
  limit?: number
);

// Get single article
const article = await client.getPost(slug: string);

🏷️ Categories & Tags

// Get all categories
const categories = await client.getCategories();

// Get all tags
const tags = await client.getTags();

📊 Analytics & SEO



// Generate XML sitemap string (returns complete XML ready for HTTP response)
const xmlSitemap = await client.getSitemap(baseUrl: string);

💡 Usage Examples

Basic Article Fetching

import { LightweightClient } from 'lightweight-client';

const client = new LightweightClient(process.env.API_KEY!);

async function getLatestArticles() {
  try {
    const { articles, total, pagination } = await client.getPosts(0, 5);
    
    console.log(`📄 Showing 5 of ${total} articles:`);
    articles.forEach(article => {
      console.log(`• ${article.title} (${article.publishedAt})`);
    });
    
    return articles;
  } catch (error) {
    console.error('❌ Failed to fetch articles:', error);
  }
}

Category-Based Content

async function getTechArticles() {
  const techPosts = await client.getCategoryPosts('technology', 0, 10);
  
  return techPosts.articles.map(post => ({
    title: post.title,
    excerpt: post.excerpt,
    url: `/blog/${post.slug}`
  }));
}

SEO Sitemap Generation

// In your sitemap route handler (e.g., /api/sitemap.xml)
async function generateSitemap() {
  const xmlSitemap = await client.getSitemap('https://yourdomain.com');
  
  // The getSitemap method returns a complete XML string ready to serve
  return new Response(xmlSitemap, {
    headers: {
      'Content-Type': 'application/xml',
      'Cache-Control': 'public, s-maxage=86400, stale-while-revalidate'
    }
  });
}

// Example output:
// <?xml version="1.0" encoding="UTF-8"?>
// <urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">
//   <url>
//     <loc>https://yourdomain.com</loc>
//     <lastmod>2024-01-01T00:00:00.000Z</lastmod>
//     <changefreq>daily</changefreq>
//     <priority>1.0</priority>
//   </url>
//   <url>
//     <loc>https://yourdomain.com/blog/post-1</loc>
//     <lastmod>2024-01-01T00:00:00.000Z</lastmod>
//     <changefreq>weekly</changefreq>
//     <priority>0.8</priority>
//   </url>
//   ...
// </urlset>

React Integration Example

import React, { useEffect, useState } from 'react';
import { LightweightClient } from 'lightweight-client';

const client = new LightweightClient(process.env.REACT_APP_API_KEY!);

function BlogList() {
  const [articles, setArticles] = useState([]);
  const [loading, setLoading] = useState(true);

  useEffect(() => {
    async function fetchArticles() {
      try {
        const { articles } = await client.getPosts(0, 10);
        setArticles(articles);
      } catch (error) {
        console.error('Failed to fetch articles:', error);
      } finally {
        setLoading(false);
      }
    }

    fetchArticles();
  }, []);

  if (loading) return <div>Loading articles...</div>;

  return (
    <div>
      {articles.map(article => (
        <article key={article.slug}>
          <h2>{article.title}</h2>
          <p>{article.excerpt}</p>
          <time>{article.publishedAt}</time>
        </article>
      ))}
    </div>
  );
}

🛠️ Configuration

Error Handling

try {
  const articles = await client.getPosts(0, 10);
} catch (error) {
  if (error.message.includes('HTTP 401')) {
    console.error('Invalid API key');
  } else if (error.message.includes('HTTP 429')) {
    console.error('Rate limit exceeded');
  } else {
    console.error('API error:', error.message);
  }
}

📋 Requirements

  • Node.js 16.0.0 or higher
  • TypeScript 4.0+ (for TypeScript projects)
  • Valid API key

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🔗 Links

🆘 Support

If you encounter any issues or have questions:

Our website Check the documentation

More resources


Made with ❤️ by Edvardh1