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

@kazweda/opendata-astro

v0.1.14

Published

Open data chart components for Astro, fetching data at build time.

Downloads

315

Readme

opendata-astro

オープンデータをビルド時に取得してチャート表示する Astro 用 React コンポーネントライブラリ。

背景・目的

kazweda/astro-starlight で進めていた issue #59#201(e-Stat / 環境省オープンデータのチャート表示)を Webサイト管理と切り離すために独立させたリポジトリ。

npm に @kazweda/opendata-astro として公開し、astro-starlight から利用する。

npm install @kazweda/opendata-astro

設計方針

データ取得タイミング: ビルド時

  • クライアントサイドでは API を叩かない — APIキーの露出・CORSを避けるため
  • Astro のビルド時(astro build)にデータを取得して静的 JSON に焼き込む
  • コンポーネントはビルド済み JSON を受け取って描画するだけ
  • outDir(デフォルト src/data/opendata-astro)に ${id}.json が既に存在する場合は APIフェッチをスキップしてキャッシュ済み JSON をそのまま使う
    • これにより CI 環境では ESTAT_API_KEY なしでビルドでき、外部APIの障害・レート制限の影響を受けない
    • 最新データに更新したい場合は、該当 JSON を削除してから npm run dev / npm run build を実行すると再フェッチされる
    • もしくは openDataIntegration({ force: true, ... }) を指定する、または環境変数 OPENDATA_ASTRO_FORCE=true を設定して npm run build を実行すると、JSON を削除せずに 全データセットを強制的に再フェッチして上書きできる(force オプション未指定時のみ環境変数を参照)

使い方のイメージ(MDX / Astroページ内)

import { OpenDataChart } from '@kazweda/opendata-astro';

<OpenDataChart
  statsDataId="0003348423"
  chartType="bar"
  title="ごみ排出量の推移"
/>

ディレクトリ構成(予定)

src/
├── index.ts                  # エクスポート
├── OpenDataChart.tsx         # メインコンポーネント(Chart.js or Recharts)
└── fetchers/
      └── estat.ts            # e-Stat API クライアント

対象データソース

フェーズ1: e-Stat API(#59)

  • URL: https://api.e-stat.go.jp/rest/3.0/app/json/getStatsData
  • 政府統計コード例: 00650101(一般廃棄物処理実態調査)
  • APIキーは環境変数 ESTAT_API_KEY で渡す

フェーズ2: 環境省(#201)

  • 全国各地のごみ分別状況・1人1日あたりごみ排出量
  • 最新: 令和5年度(2023年度)実績、全国平均 851g/人日

astro-starlight との連携

  • このパッケージを npm install @kazweda/opendata-astro でインストール
  • .envESTAT_API_KEY を設定
  • MDX or Astroページで import { OpenDataChart } from '@kazweda/opendata-astro' して使う

開発の進め方

  1. package.json 作成(scratchblocks-astro を参考に)
  2. e-Stat API クライアント(src/fetchers/estat.ts
  3. チャートコンポーネント(src/OpenDataChart.tsx
  4. ビルド時データ取得の仕組み
  5. astro-starlight 側でインストール・動作確認