Skip to content

Commit be910d0

Browse files
just show bytes for languages instead of estimated LOC
1 parent f2eed67 commit be910d0

File tree

4 files changed

+20
-26
lines changed

4 files changed

+20
-26
lines changed

app/src/pages/PageCoreProject.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ import AppTable, { type Cols } from "@/components/AppTable.vue";
347347
import AppTimeChart from "@/components/AppTimeChart.vue";
348348
import { findJournal } from "@/pages/PageHome.vue";
349349
import { carve, limit } from "@/util/array";
350-
import { ago, format, match, printObject, span } from "@/util/string";
350+
import { ago, bytes, format, match, printObject, span } from "@/util/string";
351351
import { getEntries } from "@/util/types";
352352
import analytics from "~/analytics.json";
353353
import coreProjects from "~/core-projects.json";
@@ -626,7 +626,7 @@ const repoCols: Cols<typeof projectRepos.value> = [
626626
name: "Languages",
627627
attrs: (row) => ({
628628
title: row?.languages
629-
.map(({ name, bytes }) => `${name}: ${bytes}`)
629+
.map((row) => `${row.name}: ${bytes(row.bytes)}`)
630630
.join("\n"),
631631
}),
632632
},

app/src/pages/PageHome.vue

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@
190190
<span>
191191
{{
192192
format(
193-
repoProp === "languages" ? entryCount / 160 : entryCount,
193+
repoProp === "languages" ? bytes(entryCount) : entryCount,
194194
true,
195195
)
196196
}}
@@ -199,22 +199,6 @@
199199
</dd>
200200
</div>
201201
</dl>
202-
203-
<div class="col">
204-
<AppHeading level="3">Notes</AppHeading>
205-
206-
<ul>
207-
<li>
208-
<code>contributors</code> are unique users that have committed, opened
209-
an issue, or otherwise participated in the repo.
210-
</li>
211-
<li>
212-
<code>language</code> lines of code estimated from
213-
<code>bytes / 160</code> (UTF-8, ~2 bytes per char, ~80 chars per
214-
line).
215-
</li>
216-
</ul>
217-
</div>
218202
</section>
219203
</template>
220204

@@ -252,7 +236,7 @@ import type { Cols } from "@/components/AppTable.vue";
252236
import AppTable from "@/components/AppTable.vue";
253237
import AppTimeChart from "@/components/AppTimeChart.vue";
254238
import { carve } from "@/util/array";
255-
import { format } from "@/util/string";
239+
import { bytes, format } from "@/util/string";
256240
import coreProjects from "~/core-projects.json";
257241
import rawProjects from "~/projects.json";
258242
import publications from "~/publications.json";

app/src/util/string.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,15 @@ export const match = (a: string, b: string) =>
7272

7373
/** format bytes */
7474
export const bytes = (bytes: number) => {
75-
const units = ["B", "KB", "MB", "GB"];
76-
while (bytes > 1024 && units.length) {
75+
const units = ["byte", "kilobyte", "megabyte", "gigabyte"];
76+
while (bytes >= 100 && units.length) {
7777
bytes /= 1024;
7878
units.shift();
7979
}
80-
return bytes.toFixed(1) + " " + units[0]!;
80+
return bytes.toLocaleString(undefined, {
81+
style: "unit",
82+
unit: units[0],
83+
unitDisplay: "narrow",
84+
maximumFractionDigits: 1,
85+
});
8186
};

data/util/string.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,17 @@ export const match = (a: string, b: string) =>
2020

2121
/** format bytes */
2222
export const bytes = (bytes: number) => {
23-
const units = ["B", "KB", "MB", "GB"];
24-
while (bytes > 1024 && units.length) {
23+
const units = ["byte", "kilobyte", "megabyte", "gigabyte"];
24+
while (bytes >= 100 && units.length) {
2525
bytes /= 1024;
2626
units.shift();
2727
}
28-
return bytes.toFixed(1) + " " + units[0]!;
28+
return bytes.toLocaleString(undefined, {
29+
style: "unit",
30+
unit: units[0],
31+
unitDisplay: "narrow",
32+
maximumFractionDigits: 1,
33+
});
2934
};
3035

3136
/** truncate string from middle */

0 commit comments

Comments
 (0)