From 702b8d00b18c3d47af068efc3b2507a770d14419 Mon Sep 17 00:00:00 2001 From: dojyorin Date: Sun, 28 Jan 2024 21:48:42 +0900 Subject: [PATCH] update. --- deps.pure_ext.ts | 2 +- src/deno/json.ts | 8 ++--- src/deno/path.ts | 2 +- src/deno_ext/dom.ts | 67 ++++++++++++++++---------------------- src/deno_ext/log.ts | 5 ++- src/deno_ext/smtp.ts | 12 +++---- src/pure/byte.ts | 8 ++--- src/pure/crypto.ts | 32 +++++++++--------- src/pure/deep.ts | 2 +- src/pure/deflate.ts | 20 +++++++----- src/pure/fetch.ts | 2 +- src/pure/minipack.ts | 18 +++++----- src/pure/primitive.ts | 12 +++---- src/pure/stream.ts | 11 ++++--- src/pure/text.ts | 26 +++++++-------- src/pure/time.ts | 16 ++++++--- src/pure/worker.ts | 19 +++++------ src/pure_ext/csv.ts | 2 +- src/pure_ext/excel.ts | 14 ++++---- test/deno/path.test.ts | 4 ++- test/deno_ext/smtp.test.ts | 2 +- test/pure/crypto.test.ts | 12 +++---- test/pure/text.test.ts | 6 ++-- test/pure/time.test.ts | 2 ++ 24 files changed, 149 insertions(+), 155 deletions(-) diff --git a/deps.pure_ext.ts b/deps.pure_ext.ts index f335867..9144e9d 100644 --- a/deps.pure_ext.ts +++ b/deps.pure_ext.ts @@ -3,5 +3,5 @@ export {parse, stringify} from "https://deno.land/std@0.213.0/csv/mod.ts"; export {ZipReader, ZipWriter, Uint8ArrayReader, Uint8ArrayWriter} from "https://deno.land/x/zipjs@v2.7.32/index.js"; // @deno-types="https://cdn.sheetjs.com/xlsx-0.20.1/package/types/index.d.ts" -export {type WorkBook, type WorkSheet, type CellObject, set_cptable, read as xlsxRead, write as xlsxWrite, utils as xlsxUtil} from "https://cdn.sheetjs.com/xlsx-0.20.1/package/xlsx.mjs"; +export {type WorkBook as RawWorkBook, type WorkSheet as RawWorkSheet, type CellObject as RawWorkCell, set_cptable, read as xlsxRead, write as xlsxWrite, utils as xlsxUtil} from "https://cdn.sheetjs.com/xlsx-0.20.1/package/xlsx.mjs"; export * as xlsxcp from "https://cdn.sheetjs.com/xlsx-0.20.1/package/dist/cpexcel.full.mjs"; \ No newline at end of file diff --git a/src/deno/json.ts b/src/deno/json.ts index 232f475..615a64c 100644 --- a/src/deno/json.ts +++ b/src/deno/json.ts @@ -4,7 +4,7 @@ import {type Opt} from "../pure/deep.ts"; * Read JSON file and convert to object. * @example * ```ts -* const json = await jsonRead("./resource.json"); +* const json = await jsonRead("./data.json"); * ``` */ export async function jsonRead>(path:string):Promise{ @@ -15,7 +15,7 @@ export async function jsonRead>(path:string):Promise{ * Convert from object to JSON and write to file. * @example * ```ts -* await jsonWrite("./resource.json", { +* await jsonWrite("./data.json", { * foo: "bar" * }); * ``` @@ -30,8 +30,8 @@ export async function jsonWrite>(path:string, data:T):Promise>(path:string, def:T):Promise{ diff --git a/src/deno/path.ts b/src/deno/path.ts index 85fc72e..696b86a 100644 --- a/src/deno/path.ts +++ b/src/deno/path.ts @@ -61,7 +61,7 @@ export function configPath():string{ } /** -* System-wide home path for each OS. +* System-wide home directory path for each OS. * `${HOME}` for UNIX and `%USERPROFILE%` for Windows. * @example * ```ts diff --git a/src/deno_ext/dom.ts b/src/deno_ext/dom.ts index d13dcb0..2a68e3a 100644 --- a/src/deno_ext/dom.ts +++ b/src/deno_ext/dom.ts @@ -1,26 +1,21 @@ import {type Element, DOMParser} from "../../deps.deno_ext.ts"; import {type FetchInit, fetchExtend} from "../pure/fetch.ts"; import {deepClone} from "../pure/deep.ts"; -import {cleanText} from "../pure/text.ts"; function selectedElement(elements:Element[], attribute:"checked" | "selected"){ - return elements.find(e => typeof e.getAttribute(attribute) === "string"); + return elements.find(v => typeof v.getAttribute(attribute) === "string"); } -function getContent({textContent}:Element){ - return cleanText(textContent); +function getValue(element?:Element){ + return element?.getAttribute("value") ?? ""; } -function getValue(element?:Element){ - return cleanText(element?.getAttribute("value") ?? ""); +function getContent({textContent}:Element){ + return textContent; } function extractValue(element?:Element){ - if(!element){ - return ""; - } - - switch(element.tagName){ + switch(element?.tagName){ case "SELECT": return getValue(selectedElement(element.getElementsByTagName("option"), "selected")); case "DATALIST": return getValue(selectedElement(element.getElementsByTagName("option"), "selected")); case "OPTION": return getValue(element); @@ -35,7 +30,7 @@ function extractValue(element?:Element){ * @see https://deno.land/x/deno_dom * @example * ```ts -* const element = await fetchDOM("https://www.google.com"); +* const dom = await fetchDOM("https://www.google.com"); * ``` */ export async function fetchDOM(path:string, option?:FetchInit):Promise{ @@ -47,8 +42,7 @@ export async function fetchDOM(path:string, option?:FetchInit):Promise{ * @see https://deno.land/x/deno_dom * @example * ```ts -* const html = "
foo
"; -* const element = parseDOM(html); +* const dom = parseDOM("
foo
"); * ``` */ export function parseDOM(html:string):Element{ @@ -65,28 +59,27 @@ export function parseDOM(html:string):Element{ * Find all `input` `textarea` elements with `id` attribute and convert them to key-value record. * @example * ```ts -* const html = ""; -* const element = parseHtml(html); -* const result = collectInputById(element); +* const dom = parseDOM(""); +* const result = collectInputById(dom); * ``` */ export function collectInputById(element:Element):Record{ const records:Record = {}; - for(const e of element.getElementsByTagName("INPUT")){ - if(!e.id){ + for(const input of element.getElementsByTagName("INPUT")){ + if(!input.id){ continue; } - records[e.id] = getValue(e); + records[input.id] = getValue(input); } - for(const e of element.getElementsByTagName("TEXTAREA")){ - if(!e.id){ + for(const textarea of element.getElementsByTagName("TEXTAREA")){ + if(!textarea.id){ continue; } - records[e.id] = getContent(e); + records[textarea.id] = getContent(textarea); } return deepClone(records); @@ -96,23 +89,21 @@ export function collectInputById(element:Element):Record{ * Find all elements with `name` attribute. * @example * ```ts -* const html = ""; -* const element = parseHtml(html); -* const result = getElementsByName(element, "foo"); +* const dom = parseDOM(""); +* const result = getElementsByName(dom, "foo"); * ``` */ export function getElementsByName(element:Element, name:string):Element[]{ - return element.getElementsByTagName("*").filter(e => e.getAttribute("name") === name); + return element.getElementsByTagName("*").filter(v => v.getAttribute("name") === name); } /** * Get value by `id` search. * `.value` for ``, `.textContent` for `