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 🙏

© 2025 – Pkg Stats / Ryan Hefner

bun-jsonl

v1.0.3

Published

A lightweight, type-safe JSONL (JSON Lines) file processor for Bun runtime that streams large files efficiently

Readme

bun-jsonl

A lightweight, type-safe JSONL (JSON Lines) file processor for Bun runtime that streams large files efficiently.

Features

  • 🚀 Fast streaming: Uses Bun's native file API for optimal performance
  • 💾 Memory efficient: Processes files line-by-line without loading entire file into memory
  • 🔒 Type safe: Full TypeScript support with generics
  • 🔄 Async/sync support: Works with both synchronous and asynchronous processor functions
  • 🛡️ Error handling: Detailed error messages with line numbers
  • 📦 Zero dependencies: Built specifically for Bun runtime

Installation

bun add bun-jsonl

Usage

Basic Example

import { processJsonl } from 'bun-jsonl';

// Process each line with a simple function
await processJsonl('data.jsonl', (data) => {
  console.log('Processed:', data);
  // Return anything to continue, bail to stop
});

With Type Safety

import { processJsonl } from 'bun-jsonl';

interface User {
  id: number;
  name: string;
  email: string;
}

await processJsonl<User>('users.jsonl', (user) => {
  console.log(`User: ${user.name} (${user.email})`);
});

Async Processing

import { processJsonl } from 'bun-jsonl';

await processJsonl('data.jsonl', async (data) => {
  // Simulate async processing (API calls, database operations, etc.)
  await fetch('/api/process', {
    method: 'POST',
    body: JSON.stringify(data)
  });
});

Error Handling

import { processJsonl } from 'bun-jsonl';

try {
  await processJsonl('data.jsonl', (data) => {
    if (!data.id) {
      throw new Error('Missing required ID field');
    }
    // Process valid data
    return processData(data);
  });
} catch (error) {
  console.error('Processing failed:', error);
  // Error includes line number for JSON parsing errors
}

Early Termination

import { processJsonl } from 'bun-jsonl';

// Stop processing after finding a specific item
await processJsonl('data.jsonl', (data, bail) => {
  console.log('Processing:', data);
  
  if (data.id === 'target-id') {
    console.log('Found target, stopping...');
    return bail; // Stop processing
  }
  
  // Continue processing (return anything else or nothing)
});

Filtering and Transformation

import { processJsonl } from 'bun-jsonl';

interface LogEntry {
  level: 'info' | 'warn' | 'error';
  message: string;
  timestamp: string;
}

await processJsonl<LogEntry>('logs.jsonl', (entry) => {
  // Only process error logs
  if (entry.level === 'error') {
    console.error(`[${entry.timestamp}] ${entry.message}`);
  }
  // Continue processing all entries
});

API Reference

processJsonl<T>(filePath, fn)

Processes a JSONL file line by line, calling the provided processor function for each parsed JSON object.

Parameters

  • filePath (string): Path to the JSONL file
  • fn ((data: T, bail?) => MaybePromise<unknown>): Function to process each parsed JSON object
    • Can be synchronous or asynchronous
    • Receives the parsed JSON object as first parameter
    • Receives optional bail value as second parameter
    • Return bail to stop processing, anything else to continue

Returns

  • Promise<void>: Resolves when all lines have been processed or fn returns bail

Throws

  • Error: If file doesn't exist
  • Error: If JSON parsing fails (includes line number in error message)
  • Error: If fn function throws an error

Exports

  • processJsonl: Main processing function

JSONL Format

JSONL (JSON Lines) is a text format where each line is a valid JSON object:

{"id": 1, "name": "Alice", "email": "[email protected]"}
{"id": 2, "name": "Bob", "email": "[email protected]"}
{"id": 3, "name": "Charlie", "email": "[email protected]"}

Performance

This library is optimized for processing large JSONL files:

  • ✅ Streams data instead of loading entire file into memory
  • ✅ Uses Bun's native file API for maximum performance
  • ✅ Processes lines as they're read from disk
  • ✅ Handles backpressure automatically

Requirements

  • Bun runtime (v1.0+)
  • This package is specifically designed for Bun and won't work with Node.js

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Make your changes and add tests
  4. Run tests: bun test
  5. Submit a pull request

License

MIT

Related