From a154afb5f34b864dcd1125d17d154762b69983ee Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Thu, 19 Aug 2021 22:19:42 -0400 Subject: =?UTF-8?q?Account=20for=20trailing=20newlines=20in=20Node.js=20?= =?UTF-8?q?=E2=80=A2file.Lines?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bqn.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bqn.js b/bqn.js index 9c2424a0..850e0ef5 100755 --- a/bqn.js +++ b/bqn.js @@ -26,7 +26,7 @@ let ff = (fr,fw,o) => resolve => (x,w) => { else { return fr(fs.readFileSync(f,o)); } }; let fchars = ff(str,unstr,"utf-8"); -let flines = ff(s=>list(s.split('\n').map(str)),s=>s.map(unstr).join('\n'),"utf-8"); +let flines = ff(s=>list(s.replace(/\n$/,'').split('\n').map(str)),s=>s.map(unstr).join('\n')+'\n',"utf-8"); let fbytes = ff(s=>list(Array.from(s).map(c=>String.fromCodePoint(c))),s=>Buffer.from(s.map(c=>c.codePointAt(0)))); sysvals.fchars = withres("•FChars",fchars); sysvals.flines = withres("•FLines",flines); -- cgit v1.2.3