-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
515 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export {Logger, ConsoleHandler, FileHandler} from "https://deno.land/[email protected]/log/mod.ts"; | ||
export {format} from "https://deno.land/[email protected]/datetime/mod.ts"; | ||
|
||
export {type Element, DOMParser} from "https://deno.land/x/[email protected]/deno-dom-wasm.ts"; | ||
|
||
// @deno-types="npm:@types/[email protected]" | ||
export {createTransport} from "npm:[email protected]"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export {parse, stringify} from "https://deno.land/[email protected]/csv/mod.ts"; | ||
|
||
// @deno-types="https://cdn.sheetjs.com/xlsx-0.20.1/package/types/index.d.ts" | ||
export * as excel from "https://cdn.sheetjs.com/xlsx-0.20.1/package/xlsx.mjs"; | ||
export * as excelcp from "https://cdn.sheetjs.com/xlsx-0.20.1/package/dist/cpexcel.full.mjs"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export {assertEquals} from "https://deno.land/[email protected]/assert/mod.ts"; | ||
export {dirname, fromFileUrl} from "https://deno.land/[email protected]/path/mod.ts"; | ||
export {exists} from "https://deno.land/[email protected]/fs/mod.ts"; | ||
export {exists} from "https://deno.land/[email protected]/fs/mod.ts"; | ||
|
||
export {DOMParser} from "https://deno.land/x/[email protected]/deno-dom-wasm.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export * from "./src/pure/base64.ts"; | ||
export * from "./src/pure/byte.ts"; | ||
export * from "./src/pure/crypto.ts"; | ||
export * from "./src/pure/deep.ts"; | ||
export * from "./src/pure/deflate.ts"; | ||
export * from "./src/pure/fetch.ts"; | ||
export * from "./src/pure/minipack.ts"; | ||
export * from "./src/pure/primitive.ts"; | ||
export * from "./src/pure/stream.ts"; | ||
export * from "./src/pure/text.ts"; | ||
export * from "./src/pure/time.ts"; | ||
export * from "./src/pure/worker.ts"; | ||
|
||
export * from "./src/pure_ext/csv.ts"; | ||
export * from "./src/pure_ext/excel.ts"; | ||
|
||
export * from "./src/deno/json.ts"; | ||
export * from "./src/deno/os.ts"; | ||
export * from "./src/deno/path.ts"; | ||
export * from "./src/deno/process.ts"; | ||
|
||
export * from "./src/deno_ext/dom.ts"; | ||
export * from "./src/deno_ext/log.ts"; | ||
export * from "./src/deno_ext/smtp.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export * from "./src/pure/base64.ts"; | ||
export * from "./src/pure/byte.ts"; | ||
export * from "./src/pure/crypto.ts"; | ||
export * from "./src/pure/deep.ts"; | ||
export * from "./src/pure/deflate.ts"; | ||
export * from "./src/pure/fetch.ts"; | ||
export * from "./src/pure/minipack.ts"; | ||
export * from "./src/pure/primitive.ts"; | ||
export * from "./src/pure/stream.ts"; | ||
export * from "./src/pure/text.ts"; | ||
export * from "./src/pure/time.ts"; | ||
export * from "./src/pure/worker.ts"; | ||
|
||
export * from "./src/pure_ext/csv.ts"; | ||
export * from "./src/pure_ext/excel.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
import "./test/pure/base64.test.ts"; | ||
import "./test/pure/byte.test.ts"; | ||
import "./test/pure/crypto.test.ts"; | ||
import "./test/pure/deep.test.ts"; | ||
import "./test/pure/deflate.test.ts"; | ||
import "./test/pure/fetch.test.ts"; | ||
import "./test/pure/import.test.ts"; | ||
import "./test/pure/primitive.test.ts"; | ||
import "./test/pure/minipack.test.ts"; | ||
import "./test/pure/stream.test.ts"; | ||
import "./test/pure/text.test.ts"; | ||
import "./test/pure/time.test.ts"; | ||
import "./test/pure/worker.test.ts"; | ||
export * from "./test/pure/base64.test.ts"; | ||
export * from "./test/pure/byte.test.ts"; | ||
export * from "./test/pure/crypto.test.ts"; | ||
export * from "./test/pure/deep.test.ts"; | ||
export * from "./test/pure/deflate.test.ts"; | ||
export * from "./test/pure/fetch.test.ts"; | ||
export * from "./test/pure/minipack.test.ts"; | ||
export * from "./test/pure/primitive.test.ts"; | ||
export * from "./test/pure/stream.test.ts"; | ||
export * from "./test/pure/text.test.ts"; | ||
export * from "./test/pure/time.test.ts"; | ||
export * from "./test/pure/worker.test.ts"; | ||
|
||
import "./test/deno/csv.test.ts"; | ||
import "./test/deno/json.test.ts"; | ||
import "./test/deno/log.test.ts"; | ||
import "./test/deno/path.test.ts"; | ||
import "./test/deno/platform.test.ts"; | ||
import "./test/deno/process.test.ts"; | ||
export * from "./test/pure_ext/csv.test.ts"; | ||
export * from "./test/pure_ext/excel.test.ts"; | ||
|
||
export * from "./test/deno/json.test.ts"; | ||
export * from "./test/deno/path.test.ts"; | ||
export * from "./test/deno/os.test.ts"; | ||
export * from "./test/deno/process.test.ts"; | ||
|
||
export * from "./test/deno_ext/dom.test.ts"; | ||
export * from "./test/deno_ext/log.test.ts"; | ||
export * from "./test/deno_ext/smtp.test.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Are you running on Windows? | ||
* @example | ||
* ```ts | ||
* const isWin = osWin; | ||
* ``` | ||
*/ | ||
export const osWin = Deno.build.os === "windows"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import {type Element, DOMParser} from "../../deps.deno_ext.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"); | ||
} | ||
|
||
function getContent({textContent}:Element){ | ||
return cleanText(textContent); | ||
} | ||
|
||
function getValue(element?:Element){ | ||
return cleanText(element?.getAttribute("value") ?? ""); | ||
} | ||
|
||
function extractValue(element?:Element){ | ||
if(!element){ | ||
return ""; | ||
} | ||
|
||
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); | ||
case "INPUT": return getValue(element); | ||
case "TEXTAREA": return getContent(element); | ||
default: return ""; | ||
} | ||
} | ||
|
||
/** | ||
* Convert from HTML to DOM. | ||
* @example | ||
* ```ts | ||
* const html = "<div>foo</div>"; | ||
* const element = parseHtml(html); | ||
* ``` | ||
*/ | ||
export function parseHtml(html:string):Element{ | ||
const element = new DOMParser().parseFromString(html, "text/html")?.documentElement; | ||
|
||
if(!element){ | ||
throw new Error(); | ||
} | ||
|
||
return element; | ||
} | ||
|
||
/** | ||
* Find all `input` `textarea` elements with `id` attribute and convert them to key-value record. | ||
* @example | ||
* ```ts | ||
* const html = "<input id='foo'><textarea id='bar'></textarea>"; | ||
* const element = parseHtml(html); | ||
* const result = collectInputById(element); | ||
* ``` | ||
*/ | ||
export function collectInputById(element:Element):Record<string, string>{ | ||
const records:Record<string, string> = {}; | ||
|
||
for(const e of element.getElementsByTagName("INPUT")){ | ||
if(!e.id){ | ||
continue; | ||
} | ||
|
||
records[e.id] = getValue(e); | ||
} | ||
|
||
for(const e of element.getElementsByTagName("TEXTAREA")){ | ||
if(!e.id){ | ||
continue; | ||
} | ||
|
||
records[e.id] = getContent(e); | ||
} | ||
|
||
return deepClone(records); | ||
} | ||
|
||
/** | ||
* Find all elements with `name` attribute. | ||
* @example | ||
* ```ts | ||
* const html = "<input name='foo'>"; | ||
* const element = parseHtml(html); | ||
* const result = getElementsByName(element, "foo"); | ||
* ``` | ||
*/ | ||
export function getElementsByName(element:Element, name:string):Element[]{ | ||
return element.getElementsByTagName("*").filter(e => e.getAttribute("name") === name); | ||
} | ||
|
||
/** | ||
* Get value by `id` search. | ||
* `.value` for `<input>`, `.textContent` for `<textarea>` and `.value` of `.selected` for `<select>` `<dataset>`. | ||
* @example | ||
* ```ts | ||
* const html = "<input id='foo'>"; | ||
* const element = parseHtml(html); | ||
* const result = getValueById(element, "foo"); | ||
* ``` | ||
*/ | ||
export function getValueById(element:Element, id:string):string{ | ||
return extractValue(element.getElementById(id) ?? undefined); | ||
} | ||
|
||
/** | ||
* Get value by `name` search. | ||
* `.value` for `<input>`, `.textContent` for `<textarea>` and `.value` of `.selected` for `<select>` `<dataset>`. | ||
* @example | ||
* ```ts | ||
* const html = "<input name='foo'>"; | ||
* const element = parseHtml(html); | ||
* const result = getValuesByName(element, "foo"); | ||
* ``` | ||
*/ | ||
export function getValuesByName(element:Element, name:string):string[]{ | ||
return getElementsByName(element, name).map(e => extractValue(e)); | ||
} | ||
|
||
/** | ||
* Gets value of `.checked` in group of radio buttons. | ||
* @example | ||
* ```ts | ||
* const html = "<input type='radio' name='foo' value='1' checked><input type='radio' name='foo' value='2'>"; | ||
* const element = parseHtml(html); | ||
* const result = getValueByRadioActive(element, "foo"); | ||
* ``` | ||
*/ | ||
export function getValueByRadioActive(element:Element, name:string):string{ | ||
const elements = getElementsByName(element, name); | ||
|
||
if(elements.some(e => e.tagName !== "INPUT" || e.getAttribute("type") !== "radio")){ | ||
return ""; | ||
} | ||
|
||
return extractValue(selectedElement(elements, "checked")); | ||
} |
Oops, something went wrong.