-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat_hex.ts
More file actions
34 lines (28 loc) · 853 Bytes
/
format_hex.ts
File metadata and controls
34 lines (28 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import {
Project,
SyntaxKind,
} from "https://deno.land/x/ts_morph@21.0.1/mod.ts";
const project = new Project();
project.addSourceFilesAtPaths("./**/*.ts");
for (const sourceFile of project.getSourceFiles()) {
const path = sourceFile.getFilePath();
const stat = await Deno.stat(path);
if (stat.size >= 100_000) {
console.log("Skipping", path);
continue;
}
console.log("Checking", sourceFile.getFilePath());
const numericLiterals = sourceFile.getDescendantsOfKind(
SyntaxKind.NumericLiteral,
);
for (const numericLiteral of numericLiterals) {
if (numericLiteral.getText().startsWith("0x")) {
numericLiteral.replaceWithText(
"0x" +
numericLiteral.getText().replace("0x", "").replaceAll("_", "")
.toUpperCase().padStart(2, "0"),
);
}
}
await sourceFile.save();
}