From 39dab203ea194aa15e53f25ff163ac2bbac0b99f Mon Sep 17 00:00:00 2001 From: Kazuki Ota Date: Fri, 5 Jul 2024 00:46:28 +0900 Subject: [PATCH] Code format (#107) * change interface name * code format. --- src/deno_ext/smtp.ts | 4 ++-- src/pure/fetch.ts | 26 +++++++++++++------------- src/pure/minipack.ts | 8 ++++---- src/pure/primitive.ts | 20 ++++++++++---------- src/pure_ext/sheet.ts | 4 ++-- src/pure_ext/zip.ts | 8 ++++---- test/deno_ext/smtp.test.ts | 6 +++--- 7 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/deno_ext/smtp.ts b/src/deno_ext/smtp.ts index a72e66c..a10d3c3 100644 --- a/src/deno_ext/smtp.ts +++ b/src/deno_ext/smtp.ts @@ -1,5 +1,5 @@ import {createTransport} from "../../deps.ts"; -import {type DataMap} from "../pure/minipack.ts"; +import {type DataEntry} from "../pure/minipack.ts"; /** * E-MAIL message. @@ -11,7 +11,7 @@ export interface MailMessage { body: string; cc?: string[]; bcc?: string[]; - files?: DataMap[]; + files?: DataEntry[]; } /** diff --git a/src/pure/fetch.ts b/src/pure/fetch.ts index 96ed9bf..cee482d 100644 --- a/src/pure/fetch.ts +++ b/src/pure/fetch.ts @@ -1,4 +1,4 @@ -interface ResponseType { +interface ReturnTypeMap { "text": string; "json": unknown; "form": FormData; @@ -29,7 +29,7 @@ export interface FetchInit extends Omit { * const response = await fetchExtend("./asset", "byte"); * ``` */ -export async function fetchExtend(path: string, type: T, option?: FetchInit): Promise { +export async function fetchExtend(path: string, type: T, option?: FetchInit): Promise { const u = new URL(path, globalThis?.location?.href); u.hash = ""; @@ -52,17 +52,17 @@ export async function fetchExtend(path: string, ty }); switch(type) { - case "text": return await response.text(); - case "json": return await response.json(); - case "form": return await response.formData(); - case "byte": return new Uint8Array(await response.arrayBuffer()); - case "buffer": return await response.arrayBuffer(); - case "blob": return await response.blob(); - case "stream": return (response.body ?? undefined); - case "ok": await response.body?.cancel(); return response.ok; - case "code": await response.body?.cancel(); return response.status; - case "header": await response.body?.cancel(); return response.headers; - case "response": return response; + case "text": return await response.text(); + case "json": return await response.json(); + case "form": return await response.formData(); + case "byte": return new Uint8Array(await response.arrayBuffer()); + case "buffer": return await response.arrayBuffer(); + case "blob": return await response.blob(); + case "stream": return (response.body ?? undefined); + case "ok": await response.body?.cancel(); return response.ok; + case "code": await response.body?.cancel(); return response.status; + case "header": await response.body?.cancel(); return response.headers; + case "response": return response; default: throw new Error(); } } \ No newline at end of file diff --git a/src/pure/minipack.ts b/src/pure/minipack.ts index 1b47c33..681f8aa 100644 --- a/src/pure/minipack.ts +++ b/src/pure/minipack.ts @@ -6,7 +6,7 @@ const BODY_SIZE = 4; /** * Simple name and body pair. */ -export interface DataMap { +export interface DataEntry { name: string; body: Uint8Array; } @@ -24,7 +24,7 @@ export interface DataMap { * const decode = minipackDecode(encode); * ``` */ -export function minipackEncode(files: DataMap[]): Uint8Array { +export function minipackEncode(files: DataEntry[]): Uint8Array { const archive = new Uint8Array(files.reduce((size, {name, body}) => size + NAME_SIZE + BODY_SIZE + textEncode(name).byteLength + body.byteLength, 0)); let i = 0; @@ -60,8 +60,8 @@ export function minipackEncode(files: DataMap[]): Uint8Array { * const decode = minipackDecode(encode); * ``` */ -export function minipackDecode(archive: Uint8Array): DataMap[] { - const files: DataMap[] = []; +export function minipackDecode(archive: Uint8Array): DataEntry[] { + const files: DataEntry[] = []; for(let i = 0; i < archive.byteLength;) { const ns = new DataView(archive.buffer, i).getUint8(0); diff --git a/src/pure/primitive.ts b/src/pure/primitive.ts index d1dc99f..1736519 100644 --- a/src/pure/primitive.ts +++ b/src/pure/primitive.ts @@ -2,7 +2,7 @@ type WidenLiteral = T extends string ? string : T extends number ? number : T type MaybeString = string | null | undefined; type TypeStrict = U extends true ? T : T | undefined; -interface TypeMap { +interface PrimitiveTypeMap { "string": string; "number": number; "boolean": boolean; @@ -24,15 +24,15 @@ function strictUndef(strict?: boolean) { * const value = primitiveParse("123", "number", true); * ``` */ -export function primitiveParse(text: MaybeString, type: T, strict?: U): TypeStrict { +export function primitiveParse(text: MaybeString, type: T, strict?: U): TypeStrict { if(text === undefined || text === null) { - return >strictUndef(strict); + return > strictUndef(strict); } switch(type) { - case "string": return >text.toString(); - case "number": return >parseInt(text); - case "boolean": return >(text === "true"); + case "string": return > text.toString(); + case "number": return > parseInt(text); + case "boolean": return > (text === "true"); default: throw new Error(); } } @@ -48,13 +48,13 @@ export function primitiveParse(text: */ export function primitiveParseX(text: MaybeString, def: T): WidenLiteral { if(text === undefined || text === null) { - return >def; + return > def; } switch(typeof def) { - case "string": return >text.toString(); - case "number": return >parseInt(text); - case "boolean": return >(text === "true"); + case "string": return > text.toString(); + case "number": return > parseInt(text); + case "boolean": return > (text === "true"); default: throw new Error(); } } \ No newline at end of file diff --git a/src/pure_ext/sheet.ts b/src/pure_ext/sheet.ts index 36a4372..e760f47 100644 --- a/src/pure_ext/sheet.ts +++ b/src/pure_ext/sheet.ts @@ -107,10 +107,10 @@ export function sheetDecode(data: Uint8Array, cp?: number, pw?: string): Record< for(const [name, sheet] of Object.entries(Sheets)) { const rows: string[][] = []; - for(const row of <(RawWorkCell[] | undefined)[]>sheet["!data"] ?? []) { + for(const row of <(RawWorkCell[] | undefined)[]> sheet["!data"] ?? []) { const columns: string[] = []; - for(const column of <(RawWorkCell | undefined)[]>row ?? []) { + for(const column of <(RawWorkCell | undefined)[]> row ?? []) { if(!column || column.t === "e" || column.v === undefined) { columns.push(""); } else if(column.v instanceof Date) { diff --git a/src/pure_ext/zip.ts b/src/pure_ext/zip.ts index 25800a5..bb17432 100644 --- a/src/pure_ext/zip.ts +++ b/src/pure_ext/zip.ts @@ -1,5 +1,5 @@ import {ZipReader, ZipWriter, Uint8ArrayReader, Uint8ArrayWriter} from "../../deps.pure.ts"; -import {type DataMap} from "../pure/minipack.ts"; +import {type DataEntry} from "../pure/minipack.ts"; /** * Convert from named binary to ZIP archive. @@ -14,7 +14,7 @@ import {type DataMap} from "../pure/minipack.ts"; * const files = await zipDecode(zip); * ``` */ -export async function zipEncode(files: DataMap[], pw?: string, weak?: boolean): Promise { +export async function zipEncode(files: DataEntry[], pw?: string, weak?: boolean): Promise { const zip = new ZipWriter(new Uint8ArrayWriter(), { password: pw, zipCrypto: weak @@ -42,8 +42,8 @@ export async function zipEncode(files: DataMap[], pw?: string, weak?: boolean): * const files = await zipDecode(zip); * ``` */ -export async function zipDecode(archive: Uint8Array, pw?: string, encode?: string): Promise { - const files: DataMap[] = []; +export async function zipDecode(archive: Uint8Array, pw?: string, encode?: string): Promise { + const files: DataEntry[] = []; const zip = new ZipReader(new Uint8ArrayReader(archive), { useWebWorkers: false, filenameEncoding: encode, diff --git a/test/deno_ext/smtp.test.ts b/test/deno_ext/smtp.test.ts index 530bc26..78915c3 100644 --- a/test/deno_ext/smtp.test.ts +++ b/test/deno_ext/smtp.test.ts @@ -15,9 +15,9 @@ Deno.test({ const result = new Promise((res) => { server.bind((_, __, {headers, body}) => { res({ - from: headers.from, - to: [headers.to], - title: headers.subject, + from: headers.from, + to: [ headers.to], + title: headers.subject, body: body ?? "" }); });