Skip to content

crapthings/readline-es

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

readline-es

Tiny ESM helpers for reading files line by line.

Why It's Useful

  • Lightweight: tiny wrapper around Node.js core modules with no dependencies.
  • Functional API: simple read(handler)(path) style for quick scripting.
  • JSONL-friendly: readJson parses one JSON object per line.
  • Node 22+ ready: modern ESM and node: imports.

Installation

npm i readline-es

Usage

import { read, readJson } from 'readline-es';

read((line) => {
  console.log('text line:', line);
})('./example.txt');

readJson((obj) => {
  console.log('json line:', obj);
})('./example.json');

API

read(onLine)(filepath)

  • Creates and returns a Node.js readline.Interface
  • Calls onLine(line) for each line when onLine is provided

readJson(onLine)(filepath)

  • Same as read, but each line is parsed with JSON.parse
  • Calls onLine(parsedObject) for each JSON line

About

a tiny helper for read by line

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors