Skip to content

Commit

Permalink
code format.
Browse files Browse the repository at this point in the history
  • Loading branch information
dojyorin committed Jul 4, 2024
1 parent d3b2043 commit 126adf0
Show file tree
Hide file tree
Showing 22 changed files with 83 additions and 83 deletions.
6 changes: 3 additions & 3 deletions src/deno/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {type Opt} from "../pure/deep.ts";
* const json = await jsonRead("./data.json");
* ```
*/
export async function jsonRead<T extends Opt<T>>(path:string):Promise<T> {
export async function jsonRead<T extends Opt<T>>(path: string): Promise<T> {
return JSON.parse(await Deno.readTextFile(path));
}

Expand All @@ -20,7 +20,7 @@ export async function jsonRead<T extends Opt<T>>(path:string):Promise<T> {
* });
* ```
*/
export async function jsonWrite<T extends Opt<T>>(path:string, data:T):Promise<void> {
export async function jsonWrite<T extends Opt<T>>(path: string, data: T): Promise<void> {
await Deno.writeTextFile(path, JSON.stringify(data, undefined, 4));
}

Expand All @@ -34,7 +34,7 @@ export async function jsonWrite<T extends Opt<T>>(path:string, data:T):Promise<v
* const json = await jsonLoad("./data.json", data);
* ```
*/
export async function jsonLoad<T extends Opt<T>>(path:string, def:T):Promise<T> {
export async function jsonLoad<T extends Opt<T>>(path: string, def: T): Promise<T> {
try {
return await jsonRead<T>(path);
} catch(e) {
Expand Down
2 changes: 1 addition & 1 deletion src/deno/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* const success = await processRun("echo", "foobar");
* ```
*/
export async function processRun(...commands:string[]):Promise<boolean> {
export async function processRun(...commands: string[]): Promise<boolean> {
const {success} = await new Deno.Command(commands.shift() ?? "", {
args: commands,
stdin: "null",
Expand Down
20 changes: 10 additions & 10 deletions src/deno_ext/dom.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {type Element, DOMParser} from "../../deps.ts";

function selectedElement(elements:Element[], attribute:"checked" | "selected") {
function selectedElement(elements: Element[], attribute: "checked" | "selected") {
return elements.find(v => typeof v.getAttribute(attribute) === "string");
}

function getValue(element?:Element) {
function getValue(element?: Element) {
return element?.getAttribute("value") ?? "";
}

function extractValue(element?:Element) {
function extractValue(element?: Element) {
switch(element?.tagName) {
case "SELECT": return getValue(selectedElement(element.getElementsByTagName("option"), "selected"));
case "DATALIST": return getValue(selectedElement(element.getElementsByTagName("option"), "selected"));
Expand All @@ -27,7 +27,7 @@ function extractValue(element?:Element) {
* const dom = domDecode("<div>foo</div>");
* ```
*/
export function domDecode(html:string):Element {
export function domDecode(html: string): Element {
const element = new DOMParser().parseFromString(html, "text/html")?.documentElement;

if(!element) {
Expand All @@ -45,8 +45,8 @@ export function domDecode(html:string):Element {
* const result = domValuesPerId(dom);
* ```
*/
export function domValuesPerId(element:Element):Record<string, string> {
const records:Record<string, string> = {};
export function domValuesPerId(element: Element): Record<string, string> {
const records: Record<string, string> = {};

for(const input of element.getElementsByTagName("INPUT")) {
if(!input.id) {
Expand Down Expand Up @@ -76,7 +76,7 @@ export function domValuesPerId(element:Element):Record<string, string> {
* const result = domValueById(dom, "foo");
* ```
*/
export function domValueById(element:Element, id:string):string {
export function domValueById(element: Element, id: string): string {
return extractValue(element.getElementById(id) ?? undefined);
}

Expand All @@ -88,7 +88,7 @@ export function domValueById(element:Element, id:string):string {
* const result = domElementsByName(dom, "foo");
* ```
*/
export function domElementsByName(element:Element, name:string):Element[] {
export function domElementsByName(element: Element, name: string): Element[] {
return element.getElementsByTagName("*").filter(v => v.getAttribute("name") === name);
}

Expand All @@ -101,7 +101,7 @@ export function domElementsByName(element:Element, name:string):Element[] {
* const result = domValuesByName(dom, "foo");
* ```
*/
export function domValuesByName(element:Element, name:string):string[] {
export function domValuesByName(element: Element, name: string): string[] {
return domElementsByName(element, name).map(v => extractValue(v));
}

Expand All @@ -113,7 +113,7 @@ export function domValuesByName(element:Element, name:string):string[] {
* const result = domValueByRadioActive(dom, "foo");
* ```
*/
export function domValueByRadioActive(element:Element, name:string):string {
export function domValueByRadioActive(element: Element, name: string): string {
const elements = domElementsByName(element, name);

if(elements.some(v => v.tagName !== "INPUT" || v.getAttribute("type") !== "radio")) {
Expand Down
4 changes: 2 additions & 2 deletions src/deno_ext/log.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Logger, ConsoleHandler, FileHandler, format} from "../../deps.ts";

function logRecord(date:Date, level:string, message:string) {
function logRecord(date: Date, level: string, message: string) {
return `${format(date, "yyyy-MM-ddTHH:mm:ss")} [${level}] ${message}`;
}

Expand All @@ -13,7 +13,7 @@ function logRecord(date:Date, level:string, message:string) {
* const log = logEntry();
* ```
*/
export function logEntry(name?:string, path?:string):Logger {
export function logEntry(name?: string, path?: string): Logger {
const level = "INFO";

const log = new Logger(name ?? "log", level, {
Expand Down
2 changes: 1 addition & 1 deletion src/deno_ext/smtp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface MailMessage {
* });
* ```
*/
export async function smtpSend(path:string, message:MailMessage):Promise<void> {
export async function smtpSend(path: string, message: MailMessage): Promise<void> {
const {protocol, hostname, port, username, password} = new URL(path);

if(protocol !== "smtp:" && protocol !== "smtps:") {
Expand Down
4 changes: 2 additions & 2 deletions src/pure/base64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* const decode = base64Decode(encode);
* ```
*/
export function base64Encode(data:Uint8Array):string {
export function base64Encode(data: Uint8Array): string {
return btoa(Array.from(data, v => String.fromCharCode(v)).join(""));
}

Expand All @@ -20,6 +20,6 @@ export function base64Encode(data:Uint8Array):string {
* const decode = base64Decode(encode);
* ```
*/
export function base64Decode(data:string):Uint8Array {
export function base64Decode(data: string): Uint8Array {
return new Uint8Array(Array.from(atob(data), v => v.charCodeAt(0)));
}
2 changes: 1 addition & 1 deletion src/pure/byte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* const byte = byteConcat(new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6]));
* ```
*/
export function byteConcat(...sources:BufferSource[]):Uint8Array {
export function byteConcat(...sources: BufferSource[]): Uint8Array {
const output = new Uint8Array(sources.reduce((v, {byteLength}) => v + byteLength , 0));

let i = 0;
Expand Down
24 changes: 12 additions & 12 deletions src/pure/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const CURVE_DSA = Object.freeze<EcKeyAlgorithm & EcdsaParams>({
hash: "SHA-256"
});

async function generateKey(alg:EcKeyAlgorithm, usage:KeyUsage[]):Promise<PubKey> {
async function generateKey(alg: EcKeyAlgorithm, usage: KeyUsage[]): Promise<PubKey> {
const {publicKey, privateKey} = await crypto.subtle.generateKey(alg, true, usage);

return {
Expand All @@ -24,7 +24,7 @@ async function generateKey(alg:EcKeyAlgorithm, usage:KeyUsage[]):Promise<PubKey>
};
}

async function deriveKey(pub:Uint8Array, key:Uint8Array):Promise<CryptoKey> {
async function deriveKey(pub: Uint8Array, key: Uint8Array): Promise<CryptoKey> {
return await crypto.subtle.deriveKey({
name: CURVE_KEX.name,
public: await crypto.subtle.importKey("spki", pub, CURVE_KEX, false, [])
Expand All @@ -41,7 +41,7 @@ async function deriveKey(pub:Uint8Array, key:Uint8Array):Promise<CryptoKey> {
* const random = cryptoRandom(16);
* ```
*/
export function cryptoRandom(n:number):Uint8Array {
export function cryptoRandom(n: number): Uint8Array {
return crypto.getRandomValues(new Uint8Array(n));
}

Expand All @@ -54,7 +54,7 @@ export function cryptoRandom(n:number):Uint8Array {
* const hash = await cryptoHash(bin);
* ```
*/
export async function cryptoHash(data:Uint8Array, alg?:string):Promise<Uint8Array> {
export async function cryptoHash(data: Uint8Array, alg?: string): Promise<Uint8Array> {
return new Uint8Array(await crypto.subtle.digest(alg ?? "SHA-256", data));
}

Expand All @@ -68,7 +68,7 @@ export async function cryptoHash(data:Uint8Array, alg?:string):Promise<Uint8Arra
* const key2 = await cryptoGenerateEncryptKey();
* ```
*/
export async function cryptoGenerateEncryptKey():Promise<PubKey> {
export async function cryptoGenerateEncryptKey(): Promise<PubKey> {
return await generateKey(CURVE_KEX, ["deriveKey"]);
}

Expand All @@ -81,7 +81,7 @@ export async function cryptoGenerateEncryptKey():Promise<PubKey> {
* const {pub, key} = await cryptoGenerateSignKey();
* ```
*/
export async function cryptoGenerateSignKey():Promise<PubKey> {
export async function cryptoGenerateSignKey(): Promise<PubKey> {
return await generateKey(CURVE_DSA, ["sign", "verify"]);
}

Expand All @@ -98,8 +98,8 @@ export async function cryptoGenerateSignKey():Promise<PubKey> {
* const decrypt = await cryptoDecrypt(encrypt, key2.pub, key1.key);
* ```
*/
export async function cryptoEncrypt(data:Uint8Array, pub:Uint8Array, key:Uint8Array):Promise<Uint8Array> {
const aes:AesGcmParams = {
export async function cryptoEncrypt(data: Uint8Array, pub: Uint8Array, key: Uint8Array): Promise<Uint8Array> {
const aes: AesGcmParams = {
name: AES_MODE,
iv: cryptoRandom(12)
};
Expand All @@ -120,8 +120,8 @@ export async function cryptoEncrypt(data:Uint8Array, pub:Uint8Array, key:Uint8Ar
* const decrypt = await cryptoDecrypt(encrypt, key2.pub, key1.key);
* ```
*/
export async function cryptoDecrypt(data:Uint8Array, pub:Uint8Array, key:Uint8Array):Promise<Uint8Array> {
const aes:AesGcmParams = {
export async function cryptoDecrypt(data: Uint8Array, pub: Uint8Array, key: Uint8Array): Promise<Uint8Array> {
const aes: AesGcmParams = {
name: AES_MODE,
iv: data.subarray(0, 12)
};
Expand All @@ -139,7 +139,7 @@ export async function cryptoDecrypt(data:Uint8Array, pub:Uint8Array, key:Uint8Ar
* const verify = await cryptoVerify(bin, pub, sign);
* ```
*/
export async function cryptoSign(data:Uint8Array, key:Uint8Array):Promise<Uint8Array> {
export async function cryptoSign(data: Uint8Array, key: Uint8Array): Promise<Uint8Array> {
return new Uint8Array(await crypto.subtle.sign(CURVE_DSA, await crypto.subtle.importKey("pkcs8", key, CURVE_DSA, false, ["sign"]), data));
}

Expand All @@ -153,6 +153,6 @@ export async function cryptoSign(data:Uint8Array, key:Uint8Array):Promise<Uint8A
* const verify = await cryptoVerify(bin, pub, sign);
* ```
*/
export async function cryptoVerify(data:Uint8Array, pub:Uint8Array, sign:Uint8Array):Promise<boolean> {
export async function cryptoVerify(data: Uint8Array, pub: Uint8Array, sign: Uint8Array): Promise<boolean> {
return await crypto.subtle.verify(CURVE_DSA, await crypto.subtle.importKey("spki", pub, CURVE_DSA, false, ["verify"]), sign, data);
}
6 changes: 3 additions & 3 deletions src/pure/deep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
export type Opt<T> = Partial<Record<keyof T, unknown>>;

function hasObject(data:Record<string | number | symbol, unknown>, key:string) {
function hasObject(data: Record<string | number | symbol, unknown>, key: string) {
return Object.hasOwn(data, key) && typeof data[key] === "object" && data[key] !== null;
}

Expand All @@ -18,7 +18,7 @@ function hasObject(data:Record<string | number | symbol, unknown>, key:string) {
* });
* ```
*/
export function deepFreeze<T extends Opt<T>>(data:T):Readonly<T> {
export function deepFreeze<T extends Opt<T>>(data: T): Readonly<T> {
Object.freeze(data);

for(const key in data) {
Expand All @@ -41,7 +41,7 @@ export function deepFreeze<T extends Opt<T>>(data:T):Readonly<T> {
* });
* ```
*/
export function deepSeal<T extends Opt<T>>(data:T):T {
export function deepSeal<T extends Opt<T>>(data: T): T {
Object.seal(data);

for(const key in data) {
Expand Down
4 changes: 2 additions & 2 deletions src/pure/deflate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const COMPRESS_CODEC = "deflate-raw";
* const decode = await deflateDecode(encode);
* ```
*/
export async function deflateEncode(data:Uint8Array, codec?:string):Promise<Uint8Array> {
export async function deflateEncode(data: Uint8Array, codec?: string): Promise<Uint8Array> {
return await streamDecode(streamEncode(data).pipeThrough(new CompressionStream(codec ?? COMPRESS_CODEC)));
}

Expand All @@ -26,6 +26,6 @@ export async function deflateEncode(data:Uint8Array, codec?:string):Promise<Uint
* const decode = await deflateDecode(encode);
* ```
*/
export async function deflateDecode(data:Uint8Array, codec?:string):Promise<Uint8Array> {
export async function deflateDecode(data: Uint8Array, codec?: string): Promise<Uint8Array> {
return await streamDecode(streamEncode(data).pipeThrough(new DecompressionStream(codec ?? COMPRESS_CODEC)));
}
2 changes: 1 addition & 1 deletion src/pure/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface FetchInit extends Omit<RequestInit, "integrity" | "window"> {
* const response = await fetchExtend("./asset", "byte");
* ```
*/
export async function fetchExtend<T extends keyof ResponseType>(path:string, type:T, option?:FetchInit):Promise<ResponseType[T]> {
export async function fetchExtend<T extends keyof ResponseType>(path: string, type: T, option?: FetchInit): Promise<ResponseType[T]> {
const u = new URL(path, globalThis?.location?.href);
u.hash = "";

Expand Down
6 changes: 3 additions & 3 deletions src/pure/minipack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface DataMap {
* const decode = minipackDecode(encode);
* ```
*/
export function minipackEncode(files:DataMap[]):Uint8Array {
export function minipackEncode(files: DataMap[]): Uint8Array {
const archive = new Uint8Array(files.reduce((size, {name, body}) => size + NAME_SIZE + BODY_SIZE + textEncode(name).byteLength + body.byteLength, 0));

let i = 0;
Expand Down Expand Up @@ -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): DataMap[] {
const files: DataMap[] = [];

for(let i = 0; i < archive.byteLength;) {
const ns = new DataView(archive.buffer, i).getUint8(0);
Expand Down
6 changes: 3 additions & 3 deletions src/pure/primitive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface TypeMap {
"boolean": boolean;
}

function strictUndef(strict?:boolean) {
function strictUndef(strict?: boolean) {
if(strict){
throw new Error();
}
Expand All @@ -24,7 +24,7 @@ function strictUndef(strict?:boolean) {
* const value = primitiveParse("123", "number", true);
* ```
*/
export function primitiveParse<T extends keyof TypeMap, U extends boolean>(text:MaybeString, type:T, strict?:U):TypeStrict<TypeMap[T], U> {
export function primitiveParse<T extends keyof TypeMap, U extends boolean>(text: MaybeString, type: T, strict?: U): TypeStrict<TypeMap[T], U> {
if(text === undefined || text === null) {
return <TypeStrict<TypeMap[T], U>>strictUndef(strict);
}
Expand All @@ -46,7 +46,7 @@ export function primitiveParse<T extends keyof TypeMap, U extends boolean>(text:
* const value = primitiveParseX("123", 0);
* ```
*/
export function primitiveParseX<T extends string | number | boolean>(text:MaybeString, def:T):WidenLiteral<T> {
export function primitiveParseX<T extends string | number | boolean>(text: MaybeString, def: T): WidenLiteral<T> {
if(text === undefined || text === null) {
return <WidenLiteral<T>>def;
}
Expand Down
4 changes: 2 additions & 2 deletions src/pure/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* const data = await streamDecode(stream);
* ```
*/
export function streamEncode(...data:Uint8Array[]):ReadableStream<Uint8Array> {
export function streamEncode(...data: Uint8Array[]): ReadableStream<Uint8Array> {
return new Blob(data).stream();
}

Expand All @@ -18,6 +18,6 @@ export function streamEncode(...data:Uint8Array[]):ReadableStream<Uint8Array> {
* const data = await streamDecode(stream);
* ```
*/
export async function streamDecode(rs:ReadableStream<Uint8Array>):Promise<Uint8Array> {
export async function streamDecode(rs: ReadableStream<Uint8Array>): Promise<Uint8Array> {
return new Uint8Array(await new Blob(await Array.fromAsync(rs)).arrayBuffer());
}
Loading

0 comments on commit 126adf0

Please sign in to comment.