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

grafana-logs-to-csv

v1.0.0

Published

Convert Grafana-style log text files (tab-separated with JSON per line) to CSV

Readme

grafana-logs-to-csv

Convert Grafana-style log text files (tab-separated: timestamp, ISO date, JSON object per line) to CSV. CSV headers are the JSON keys; each row is one log line’s JSON values.

Install

npm install grafana-logs-to-csv
# or
pnpm add grafana-logs-to-csv
# or
yarn add grafana-logs-to-csv

Usage

Single file

import { convertFile } from "grafana-logs-to-csv";

// Convert sample.txt → sample.csv in the same directory
const csvPath = await convertFile("./sample.txt");
console.log("Written:", csvPath);

// Write to a specific directory
await convertFile("./sample.txt", { outputDir: "./output" });

// Custom output file name (without extension)
await convertFile("./sample.txt", {
  outputDir: "./output",
  outputFileName: "my-logs",
});
// → output/my-logs.csv

Directory

import { convertDirectory } from "grafana-logs-to-csv";

// Convert all .txt files in a directory; CSVs next to each file
const paths = await convertDirectory("./logs");
console.log("Written:", paths);

// Write all CSVs into one folder
await convertDirectory("./logs", { outputDir: "./csv-output" });

Options

| Option | Description | | --------------- | ---------------------------------------------------------- | | outputDir | Directory for CSV output (default: same as input). | | outputFileName | Override output file name without extension (single file). | | encoding | File encoding (default: "utf-8"). |

Input format

The text file should have data lines with three tab-separated fields:

  1. Unix timestamp (ms)
  2. ISO8601 date
  3. A JSON object (string keys and values)

Header/metadata lines (e.g. “1000 lines shown…”, “Common labels: …”) are skipped. Only the third field is used for the CSV; headers and columns are taken from the JSON keys.

Development

  • pnpm test – run tests (Vitest)
  • pnpm run test:watch – run tests in watch mode
  • pnpm lint – run ESLint
  • pnpm run lint:fix – fix lint issues
  • pnpm format – format with Prettier
  • pnpm run format:check – check formatting

Suggested improvements

  • CLI: Add a small CLI (e.g. with commander or yargs) so users can run npx grafana-logs-to-csv ./logs.txt --out-dir ./csv without writing a script.
  • Streaming: For very large files, read/parse line-by-line with a stream and write CSV rows incrementally to avoid loading the whole file into memory.
  • Configurable extension: Allow convertDirectory to accept a custom file extension or glob (e.g. .log) instead of only .txt.
  • Validation: Optionally validate that the third column is valid JSON and report line numbers for parse errors instead of silently skipping.
  • CI: Add a GitHub Actions workflow to run lint, format:check, and test on push/PR.
  • Changelog: Keep a CHANGELOG.md and follow semantic versioning when publishing.

Publish to npm

  1. Set name, author, and repository in package.json.
  2. Log in: npm login.
  3. Build and publish: pnpm run build && npm publish (or npm publish --access public for a scoped package).

License

ISC