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 🙏

© 2024 – Pkg Stats / Ryan Hefner

easy-read-last-lines

v3.1.0

Published

Read the last N lines in the file or text across platforms. (like tail -n)

Downloads

3

Readme

Easy-Read-Last-Lines

High performance read the last N lines in the file or text across platforms. (like tail -n)

Table of contents

Feature

  • High performance read
  • Compatible with newlines on different platforms/format: \r, \n, \r\n
  • Support setting character encoding
  • Support get a String or Buffer object from file

Installation

npm install easy-read-last-lines

Usage

const erll = require('easy-read-last-lines');

Read last N lines string from File

let fielPath='YOUR_FILE_PATH';

// Read last N lines string from File - Asynchronously
erll.readFromFile(filePath, 3).then(function(lines) {
    console.log(lines);
}).catch(function(err) {
    console.log(err.message);
});

//  Read last N lines string from File - Synchronously
let lines = await erll.readFromFile(filePath, 3, 'utf8');
console.log(lines);

// Read an array of last N line string from File
let linesArray = await erll.readArrayFromFile(filePath, 3, 'utf8');
console.log(linesArray);

Read last N lines buffer data from File

let fielPath='YOUR_FILE_PATH';

// Asynchronously
erll.readBufferFromFile(filePath, 1).then(function(buffer) {
    console.log(buffer.toString('base64'));
}).catch(function(err) {
    console.log(err.message);
});

// Synchronously
let buffer = await erll.readBufferFromFile(filePath, 1);
console.log(buffer.toString('base64'));

Read last N lines string from Text

var text = `
Easy 
Read 
Last
Line`;
var text2 = `Easy\nRead\rLast\r\nLine`
    
// Read last N lines string from Text
var lines = erll.readFromText(text, 2);
console.log(lines);

// Read an array of last N line string from Text
var linesArray = erll.readArrayFromText(text2, 3);
console.log(linesArray);

Convert multiline text to array of string

var text = `Easy\nRead\rLast\r\nLine`;

console.log(erll.linesToArray(lines));

Functions

  • readFromFile(filePath, maxLine, [encoding]): Promise

    • filePath: file path(direct or relative path to file)
    • maxLine: max number of last lines to read in
    • encoding: When converting between Buffers and strings, a character encoding may be specified. If no character encoding is specified, UTF-8 will be used as the default. buffers-and-character-encodings
  • readArrayFromFile(filePath, maxLine, [encoding]): Promise

    • filePath: file path(direct or relative path to file)
    • maxLine: max number of last lines to read in
    • encoding: When converting between Buffers and strings, a character encoding may be specified. If no character encoding is specified, UTF-8 will be used as the default. buffers-and-character-encodings
  • readBufferFromFile(filePath, maxLine): Promise

    • filePath: file path(direct or relative path to file)
    • maxLine: max number of last lines to read in
  • readFromText(text, maxLine): String

    • text: multiline string
    • maxLine: max number of last lines to read in
  • readArrayFromText(text, maxLine): String

    • text: multiline string
    • maxLine: max number of last lines to read in
  • linesToArray(text): Array

    • text: multiline string

License

MIT License

End

Email:[email protected]

http://www.easyproject.cn

Donation/捐助:

我们相信,每个人的点滴贡献,都将是推动产生更多、更好免费开源产品的一大步。

感谢慷慨捐助,以支持服务器运行和鼓励更多社区成员。

We believe that the contribution of each bit by bit, will be driven to produce more and better free and open source products a big step.

Thank you donation to support the server running and encourage more community members.