UNPKG

qsu

Version:

qsu is a utility library that contains useful and frequently used functions. Start with your preferred language and the modern development environment.

1 lines 369 B
import{readFile as t}from"fs/promises";import{EOL as r}from"os";export async function tailFile(n,e=1){try{const l=(await t(n,"utf-8")).split(r);let o="";l[l.length-1].length<1&&l.pop();for(let t=l.length,r=l.length-e;t>r;t-=1)o=`${l[t-1]}${o.length<1||t-1===r?"":"\n"}${o}`;return o.length<1?null:o}catch(t){if(t instanceof Error)throw new Error(t.message)}return null}