UNPKG

lesetid

Version:

A dead simple read time estimation

68 lines (65 loc) 2.34 kB
//#region rolldown:runtime var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) { key = keys[i]; if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: ((k) => from[k]).bind(null, key), enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod)); //#endregion require('./utils-TNF-mJTC.cjs'); const require_src = require('./src-aahT0FaZ.cjs'); const node_stream = __toESM(require("node:stream")); //#region src/stream.ts /** * Creates a new reading time stream transform that calculates reading statistics. * * @param {Options} options - Configuration options for reading time calculation * @returns {ReadingTimeStream} A new ReadingTimeStream instance */ function createReadingTimeStream(options = require_src.DEFAULT_OPTIONS) { return new ReadingTimeStream(options); } /** * A Transform stream that calculates reading time statistics from text data. * * This stream processes text chunks and accumulates word and character counts, * then outputs the final reading statistics when the stream ends. */ var ReadingTimeStream = class extends node_stream.Transform { reading = { words: 0, chars: 0 }; options; constructor(options = require_src.DEFAULT_OPTIONS) { super({ objectMode: true }); this.options = options; } _transform(chunk, encoding, callback) { const { words, chars } = require_src.count(chunk.toString(encoding), this.options); this.reading.words += words; this.reading.chars += chars; callback(); } _flush(callback) { this.push(this.reading); callback(); } }; //#endregion exports.ReadingTimeStream = ReadingTimeStream; exports.createReadingTimeStream = createReadingTimeStream;