🐛 Fix bugs, typos, and refine type definitions in deno libraries

This commit is contained in:
2026-04-28 23:08:51 +08:00
parent 66f9443dc3
commit 1a252523db
2 changed files with 11 additions and 11 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ import {
term, term,
} from "https://script.hatter.ink/@71/deno-commons-mod.ts"; } from "https://script.hatter.ink/@71/deno-commons-mod.ts";
export async function howto(message: string): Promise<string> { export async function howto(message: string): Promise<string | null> {
const response = await fetchDataWithTimeout( const response = await fetchDataWithTimeout(
"https://hatter.ink/ai/command-line-howto.json", "https://hatter.ink/ai/command-line-howto.json",
{ {
+10 -10
View File
@@ -35,7 +35,7 @@ export function stdin(): ReadableStream {
return isDeno() ? Deno.stdin.readable : process.stdin; return isDeno() ? Deno.stdin.readable : process.stdin;
} }
function streamToArrayBuffer(stream) { function streamToArrayBuffer(stream): Promise<ArrayBuffer> {
const chunks = []; const chunks = [];
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
stream.on("error", (err) => reject(err)); stream.on("error", (err) => reject(err));
@@ -291,15 +291,15 @@ export function formatHumanTime2(timeMillis: number): string {
if (timeMinutes < 60) { if (timeMinutes < 60) {
return `${timeMinutes} minutes`; return `${timeMinutes} minutes`;
} }
const timeHours = timeMinutes / 60; const timeHours = Math.floor(timeMinutes / 60);
if (timeHours < 24) { if (timeHours < 24) {
return `${formatNumber(timeHours)} hours`; return `${formatNumber(timeHours)} hours`;
} }
const timeDays = timeHours / 24; const timeDays = Math.floor(timeHours / 24);
if (timeDays < 365) { if (timeDays < 365) {
return `${formatNumber(timeDays)} days`; return `${formatNumber(timeDays)} days`;
} }
const timeYears = timeDays / 365; const timeYears = Math.floor(timeDays / 365);
return `${formatNumber(timeYears)} years`; return `${formatNumber(timeYears)} years`;
} }
@@ -588,7 +588,7 @@ function __getColorCode(color: string): string {
return COLOR_MAP[color]; return COLOR_MAP[color];
} }
function renderColorTokens(tokens: ColorToken[], renderColor: bool): string { function renderColorTokens(tokens: ColorToken[], renderColor: boolean): string {
const text: string[] = []; const text: string[] = [];
const colorMapStack = new Map<string, number[]>(); const colorMapStack = new Map<string, number[]>();
for (const token of tokens) { for (const token of tokens) {
@@ -849,7 +849,7 @@ function __isDenoNotFound(e) {
} }
function __isNodeNotFound(e) { function __isNodeNotFound(e) {
return (e.errno ?? 0 === -2) && e.message && return ((e.errno ?? 0) === -2) && e.message &&
e.message.includes("no such file or directory"); e.message.includes("no such file or directory");
} }
@@ -924,7 +924,7 @@ export async function writeStringToFile(
export async function removePath(path: string): Promise<void> { export async function removePath(path: string): Promise<void> {
if (isDeno()) { if (isDeno()) {
await Deno.remove(newFilename); await Deno.remove(path);
} else { } else {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
rm(path, (err) => { rm(path, (err) => {
@@ -964,7 +964,7 @@ export function uint8ArrayToHexString(uint8: Uint8Array): string {
.join(""); .join("");
} }
export function uint8ArrayToBase32String(uint8: Unit8Array): string { export function uint8ArrayToBase32String(uint8: Uint8Array): string {
return encodeBase32(uint8).replaceAll(/=/g, "").toLowerCase(); return encodeBase32(uint8).replaceAll(/=/g, "").toLowerCase();
} }
@@ -1523,7 +1523,7 @@ export async function fetchAlibabaCloudInstanceIdentityV1(
pkcs7Options, pkcs7Options,
); );
if (pkcs7Response.status != 200) { if (pkcs7Response.status != 200) {
throw new Error("Get PKCS#7 failed: ${pkcs7Response.status}`)"); throw new Error(`Get PKCS#7 failed: ${pkcs7Response.status}`);
} }
return await pkcs7Response.text(); return await pkcs7Response.text();
} }
@@ -1636,7 +1636,7 @@ export interface GetSecretValueOptions {
maxCacheTimeSecs?: number; maxCacheTimeSecs?: number;
} }
export function getRunEnv(): stirng | null { export function getRunEnv(): string | null {
return getEnv("RUN_ENV"); return getEnv("RUN_ENV");
} }