This commit is contained in:
Raven Scott
2026-04-03 19:01:57 -04:00
parent 7c9c9ae83c
commit 8002a66f6e
28 changed files with 533 additions and 78 deletions
+4 -4
View File
@@ -60,10 +60,10 @@ function barePosixBlocks(size) {
return Math.ceil(Number(size) / 512) || 0
}
function count(s) {
function count(s, b4a) {
const lines = (s.match(/\n/g) || []).length
const words = s.trim() ? s.trim().split(/\s+/).length : 0
const bytes = new TextEncoder().encode(s).length
const bytes = b4a.from(s, 'utf8').length
return { lines, words, bytes }
}
@@ -72,7 +72,7 @@ async function run(ctx, argv) {
const files = argv.slice(1).filter((a) => !a.startsWith('-'))
if (!files.length) {
const s = bareStdin(ctx)
const c = count(s)
const c = count(s, ctx.b4a)
ctx.console.log(' ' + c.lines + ' ' + c.words + ' ' + c.bytes)
return
}
@@ -86,7 +86,7 @@ async function run(ctx, argv) {
continue
}
const s = ctx.b4a.toString(buf)
const c = count(s)
const c = count(s, ctx.b4a)
tLines += c.lines
tWords += c.words
tBytes += c.bytes