Skip to content

Commit

Permalink
change method name.
Browse files Browse the repository at this point in the history
  • Loading branch information
dojyorin committed Apr 19, 2024
1 parent 9c32a82 commit 3b22ba8
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 52 deletions.
4 changes: 2 additions & 2 deletions src/deno/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* Run command as subprocess.
* @example
* ```ts
* const success = await runCommand("echo", "foobar");
* const success = await processRun("echo", "foobar");
* ```
*/
export async function runCommand(...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
38 changes: 19 additions & 19 deletions src/deno_ext/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ function extractValue(element?:Element){
* @see https://deno.land/x/deno_dom
* @example
* ```ts
* const dom = parseDOM("<div>foo</div>");
* const dom = domParse("<div>foo</div>");
* ```
*/
export function parseDOM(html:string):Element{
export function domParse(html:string):Element{
const element = new DOMParser().parseFromString(html, "text/html")?.documentElement;

if(!element){
Expand All @@ -45,11 +45,11 @@ export function parseDOM(html:string):Element{
* Find all `input` `textarea` elements with `id` attribute and convert them to key-value record.
* @example
* ```ts
* const dom = parseDOM("<input id='foo'><textarea id='bar'></textarea>");
* const result = collectInputById(dom);
* const dom = domParse("<input id='foo'><textarea id='bar'></textarea>");
* const result = domValuesPerId(dom);
* ```
*/
export function collectInputById(element:Element):Record<string, string>{
export function domValuesPerId(element:Element):Record<string, string>{
const records:Record<string, string> = {};

for(const input of element.getElementsByTagName("INPUT")){
Expand All @@ -75,11 +75,11 @@ export function collectInputById(element:Element):Record<string, string>{
* Find all elements with `name` attribute.
* @example
* ```ts
* const dom = parseDOM("<input name='foo'>");
* const result = getElementsByName(dom, "foo");
* const dom = domParse("<input name='foo'>");
* const result = domElementsByName(dom, "foo");
* ```
*/
export function getElementsByName(element:Element, name:string):Element[]{
export function domElementsByName(element:Element, name:string):Element[]{
return element.getElementsByTagName("*").filter(v => v.getAttribute("name") === name);
}

Expand All @@ -88,11 +88,11 @@ export function getElementsByName(element:Element, name:string):Element[]{
* `.value` for `<input>`, `.textContent` for `<textarea>` and `.value` of `.selected` for `<select>` `<dataset>`.
* @example
* ```ts\
* const dom = parseDOM("<input id='foo'>");
* const result = getValueById(dom, "foo");
* const dom = domParse("<input id='foo'>");
* const result = domValueById(dom, "foo");
* ```
*/
export function getValueById(element:Element, id:string):string{
export function domValueById(element:Element, id:string):string{
return extractValue(element.getElementById(id) ?? undefined);
}

Expand All @@ -101,24 +101,24 @@ export function getValueById(element:Element, id:string):string{
* `.value` for `<input>`, `.textContent` for `<textarea>` and `.value` of `.selected` for `<select>` `<dataset>`.
* @example
* ```ts
* const dom = parseDOM("<input name='foo'>");
* const result = getValuesByName(dom, "foo");
* const dom = domParse("<input name='foo'>");
* const result = domValuesByName(dom, "foo");
* ```
*/
export function getValuesByName(element:Element, name:string):string[]{
return getElementsByName(element, name).map(v => extractValue(v));
export function domValuesByName(element:Element, name:string):string[]{
return domElementsByName(element, name).map(v => extractValue(v));
}

/**
* Gets value of `.checked` in group of radio buttons.
* @example
* ```ts
* const dom = parseDOM("<input type='radio' name='foo' value='1' checked><input type='radio' name='foo' value='2'>");
* const result = getValueByRadioActive(dom, "foo");
* const dom = domParse("<input type='radio' name='foo' value='1' checked><input type='radio' name='foo' value='2'>");
* const result = domValueByRadioActive(dom, "foo");
* ```
*/
export function getValueByRadioActive(element:Element, name:string):string{
const elements = getElementsByName(element, name);
export function domValueByRadioActive(element:Element, name:string):string{
const elements = domElementsByName(element, name);

if(elements.some(v => v.tagName !== "INPUT" || v.getAttribute("type") !== "radio")){
return "";
Expand Down
6 changes: 3 additions & 3 deletions src/pure/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ const AES_BIT = 128;
const FORMAT_PUB = "spki";
const FORMAT_PRI = "pkcs8";

const CURVE_ECDH = Object.freeze({
const CURVE_ECDH = Object.freeze<EcKeyAlgorithm>({
name: "ECDH",
namedCurve: "P-256"
});

const CURVE_ECDSA = Object.freeze({
const CURVE_ECDSA = Object.freeze<EcKeyAlgorithm>({
name: "ECDSA",
namedCurve: "P-256"
});

const MAC_ECDSA = Object.freeze({
const MAC_ECDSA = Object.freeze<EcdsaParams>({
name: "ECDSA",
hash: "SHA-256"
});
Expand Down
14 changes: 7 additions & 7 deletions src/pure/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function textDecode(data:Uint8Array, codec?:string):string{
* ```
*/
export function hexEncode(data:Uint8Array):string{
return [...data].map(v => pad0(v, 2, 16)).join("");
return [...data].map(v => padZero(v, 2, 16)).join("");
}

/**
Expand Down Expand Up @@ -117,10 +117,10 @@ export function fixWidth(data:string):string{
* Clean up text with `fixWidth()` and `trimExtend()`.
* @example
* ```ts
* const format = cleanText("1 + 1 = 2 ");
* const format = textAdjust("1 + 1 = 2 ");
* ```
*/
export function cleanText(data:string):string{
export function textAdjust(data:string):string{
return trimExtend(fixWidth(data));
}

Expand All @@ -129,10 +129,10 @@ export function cleanText(data:string):string{
* Useful for calculate number of characters with string contains emoji.
* @example
* ```ts
* const characters = accurateSegment("😀😃😄😁😆😅😂🤣");
* const characters = splitSegment("😀😃😄😁😆😅😂🤣");
* ```
*/
export function accurateSegment(data:string):string[]{
export function splitSegment(data:string):string[]{
return [...new Intl.Segmenter().segment(data)].map(({segment}) => segment);
}

Expand All @@ -141,9 +141,9 @@ export function accurateSegment(data:string):string[]{
* Output is 2 digits by default.
* @example
* ```ts
* const pad = pad0(8);
* const pad = padZero(8);
* ```
*/
export function pad0(data:number, digit?:number, radix?:number):string{
export function padZero(data:number, digit?:number, radix?:number):string{
return data.toString(radix).toUpperCase().padStart(digit ?? 2, "0");
}
8 changes: 4 additions & 4 deletions src/pure/time.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {pad0} from "./text.ts";
import {padZero} from "./text.ts";

/**
* UNIX time in seconds.
Expand Down Expand Up @@ -60,13 +60,13 @@ export async function delay(time:number):Promise<number>{
* Generate serialized string from current or any `Date` to "yyyyMMddhhmmss".
* @example
* ```ts
* const format = dtSerial();
* const format = timeSerial();
* ```
*/
export function dtSerial(date?:Date, split?:boolean):string{
export function timeSerial(date?:Date, split?:boolean):string{
const d = date ?? new Date();
const ss = split ? "/" : "";
const sc = split ? ":" : "";

return `${d.getFullYear()}${ss}${pad0(d.getMonth() + 1)}${ss}${pad0(d.getDate())}${split ? " " : ""}${pad0(d.getHours())}${sc}${pad0(d.getMinutes())}${sc}${pad0(d.getSeconds())}`;
return `${d.getFullYear()}${ss}${padZero(d.getMonth() + 1)}${ss}${padZero(d.getDate())}${split ? " " : ""}${padZero(d.getHours())}${sc}${padZero(d.getMinutes())}${sc}${padZero(d.getSeconds())}`;
}
4 changes: 2 additions & 2 deletions src/pure_ext/excel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {type RawWorkBook, type RawWorkSheet, type RawWorkCell, xlsxcp, set_cptable, xlsxRead, xlsxWrite, xlsxUtil} from "../../deps.pure_ext.ts";
import {dtSerial} from "../pure/time.ts";
import {timeSerial} from "../pure/time.ts";

export type {RawWorkBook, RawWorkSheet, RawWorkCell};

Expand Down Expand Up @@ -116,7 +116,7 @@ export function excelDecode(data:Uint8Array, cp?:number, pw?:string):Record<stri
}
else if(column.v instanceof Date){
column.v.setMinutes(new Date().getTimezoneOffset());
columns.push(dtSerial(column.v, true));
columns.push(timeSerial(column.v, true));
}
else{
columns.push(`${column.v}`);
Expand Down
4 changes: 2 additions & 2 deletions test/deno/process.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {assertEquals} from "../../deps.test.ts";
import {runCommand} from "../../src/deno/process.ts";
import {processRun} from "../../src/deno/process.ts";

Deno.test({
name: "Process: Run (no args)",
async fn(){
const result = await runCommand("echo", "abcdefg");
const result = await processRun("echo", "abcdefg");

assertEquals(result, true);
}
Expand Down
14 changes: 7 additions & 7 deletions test/deno_ext/dom.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {assertEquals, DOMParser} from "../../deps.test.ts";
import {parseDOM, collectInputById, getElementsByName, getValueById, getValuesByName, getValueByRadioActive} from "../../src/deno_ext/dom.ts";
import {domParse, domValuesPerId, domElementsByName, domValueById, domValuesByName, domValueByRadioActive} from "../../src/deno_ext/dom.ts";

const sample1 = "<input type='radio' id='aaa' name='aaa' value='123' checked><input type='radio' name='aaa' value='456'>";
const sample2 = new DOMParser().parseFromString(sample1, "text/html")?.documentElement;
Expand All @@ -11,7 +11,7 @@ if(!sample2){
Deno.test({
name: "DOM: Parse HTML",
fn(){
const result = parseDOM(sample1);
const result = domParse(sample1);

assertEquals(result.innerHTML, sample2.innerHTML);
}
Expand All @@ -20,7 +20,7 @@ Deno.test({
Deno.test({
name: "DOM: Collect input/textarea by ID",
fn(){
const result = collectInputById(sample2);
const result = domValuesPerId(sample2);

assertEquals(result.aaa, "123");
}
Expand All @@ -29,7 +29,7 @@ Deno.test({
Deno.test({
name: "DOM: Get value by ID",
fn(){
const result = getValueById(sample2, "aaa");
const result = domValueById(sample2, "aaa");

assertEquals(result, "123");
}
Expand All @@ -38,7 +38,7 @@ Deno.test({
Deno.test({
name: "DOM: Get element by Name",
fn(){
const result = getElementsByName(sample2, "aaa");
const result = domElementsByName(sample2, "aaa");

assertEquals(result.length, 2);
}
Expand All @@ -47,7 +47,7 @@ Deno.test({
Deno.test({
name: "DOM: Get values by Name",
fn(){
const result = getValuesByName(sample2, "aaa");
const result = domValuesByName(sample2, "aaa");

assertEquals(result, ["123", "456"]);
}
Expand All @@ -56,7 +56,7 @@ Deno.test({
Deno.test({
name: "DOM: Get value by RadioActive",
fn(){
const result = getValueByRadioActive(sample2, "aaa");
const result = domValueByRadioActive(sample2, "aaa");

assertEquals(result, "123");
}
Expand Down
8 changes: 4 additions & 4 deletions test/pure/text.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {assertEquals} from "../../deps.test.ts";
import {u8Encode, u8Decode, textDecode, hexEncode, hexDecode, trimExtend, fixWidth, cleanText, accurateSegment, pad0} from "../../src/pure/text.ts";
import {u8Encode, u8Decode, textDecode, hexEncode, hexDecode, trimExtend, fixWidth, textAdjust, splitSegment, padZero} from "../../src/pure/text.ts";

const sampleText = " Lorem ipsum\r dolor sit \r\r amet. ";
const sampleBin = new Uint8Array([
Expand Down Expand Up @@ -62,7 +62,7 @@ Deno.test({
Deno.test({
name: "Text: Clean Up",
fn(){
const result = cleanText("1 + 1 = 2 ");
const result = textAdjust("1 + 1 = 2 ");

assertEquals(result, "1 + 1 = 2");
}
Expand All @@ -71,7 +71,7 @@ Deno.test({
Deno.test({
name: "Text: Segment",
fn(){
const {length} = accurateSegment("😄😁😆😅😂");
const {length} = splitSegment("😄😁😆😅😂");

assertEquals(length, 5);
}
Expand All @@ -80,7 +80,7 @@ Deno.test({
Deno.test({
name: "Text: Pad 0",
fn(){
const pad = pad0(8);
const pad = padZero(8);

assertEquals(pad, "08");
}
Expand Down
4 changes: 2 additions & 2 deletions test/pure/time.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {assertEquals} from "../../deps.test.ts";
import {utEncode, utDecode, utParse, delay, dtSerial} from "../../src/pure/time.ts";
import {utEncode, utDecode, utParse, delay, timeSerial} from "../../src/pure/time.ts";

const sample = new Date(2000, 0, 1, 0, 0, 0, 0);

Expand Down Expand Up @@ -34,7 +34,7 @@ Deno.test({
Deno.test({
name: "Time: Serial",
fn(){
const result = dtSerial(sample);
const result = timeSerial(sample);

assertEquals(result, "20000101000000");
}
Expand Down

0 comments on commit 3b22ba8

Please sign in to comment.