Skip to content

Commit

Permalink
jsr support. (#106)
Browse files Browse the repository at this point in the history
* jsr support.

* change name

* sheet.

* code format.

* code format.
  • Loading branch information
dojyorin authored Jul 4, 2024
1 parent 4e752b9 commit fbd3979
Show file tree
Hide file tree
Showing 51 changed files with 215 additions and 415 deletions.
10 changes: 4 additions & 6 deletions deps.pure.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// @deno-types="https://deno.land/[email protected]/csv/mod.ts"
export {parse, stringify} from "https://esm.sh/gh/denoland/[email protected]/csv/mod.ts?bundle&target=esnext";
// @deno-types="https://deno.land/x/[email protected]/index.d.ts"
export {ZipReader, ZipWriter, Uint8ArrayReader, Uint8ArrayWriter} from "https://esm.sh/gh/gildas-lormeau/[email protected]/index.js?bundle&target=esnext";
export {parse, stringify} from "https://esm.sh/jsr/@std/[email protected]?bundle&target=esnext";
export {ZipReader, ZipWriter, Uint8ArrayReader, Uint8ArrayWriter} from "https://esm.sh/jsr/@zip-js/[email protected]?bundle&target=esnext";

// @deno-types="https://cdn.sheetjs.com/xlsx-0.20.2/package/types/index.d.ts"
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.2/package/xlsx.mjs";
export * as xlsxcp from "https://cdn.sheetjs.com/xlsx-0.20.2/package/dist/cpexcel.full.mjs";
export {type WorkBook as RawWorkBook, type WorkSheet as RawWorkSheet, type CellObject as RawWorkCell, set_cptable, read as sheetRead, write as sheetWrite, utils as sheetUtil} from "https://cdn.sheetjs.com/xlsx-0.20.2/package/xlsx.mjs";
export * as excelcp from "https://cdn.sheetjs.com/xlsx-0.20.2/package/dist/cpexcel.full.mjs";
11 changes: 5 additions & 6 deletions deps.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
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 {delay} from "https://deno.land/[email protected]/async/mod.ts";

export {DOMParser} from "https://deno.land/x/[email protected]/deno-dom-wasm.ts";
export {assertEquals} from "jsr:@std/[email protected]";
export {dirname, fromFileUrl} from "jsr:@std/[email protected]";
export {exists} from "jsr:@std/[email protected]";
export {delay} from "jsr:@std/[email protected]";
export {DOMParser} from "jsr:@b-fuze/[email protected]";

export {init as smtpTest} from "npm:[email protected]";
7 changes: 3 additions & 4 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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";
export {Logger, ConsoleHandler, FileHandler} from "jsr:@std/[email protected]";
export {format} from "jsr:@std/[email protected]";
export {type Element, DOMParser} from "jsr:@b-fuze/[email protected]";

// @deno-types="npm:@types/[email protected]"
export {createTransport} from "npm:[email protected]";
2 changes: 0 additions & 2 deletions mod.full.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
export * from "./mod.pure.full.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";
Expand Down
2 changes: 1 addition & 1 deletion mod.pure.full.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from "./mod.pure.ts";

export * from "./src/pure_ext/csv.ts";
export * from "./src/pure_ext/excel.ts";
export * from "./src/pure_ext/sheet.ts";
export * from "./src/pure_ext/zip.ts";
4 changes: 1 addition & 3 deletions mod.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ import "./test/pure/time.test.ts";
import "./test/pure/worker.test.ts";

import "./test/pure_ext/csv.test.ts";
import "./test/pure_ext/excel.test.ts";
import "./test/pure_ext/sheet.test.ts";
import "./test/pure_ext/zip.test.ts";

import "./test/deno/json.test.ts";
import "./test/deno/os.test.ts";
import "./test/deno/path.test.ts";
import "./test/deno/process.test.ts";

import "./test/deno_ext/dom.test.ts";
Expand Down
2 changes: 0 additions & 2 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export * from "./mod.pure.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";
16 changes: 7 additions & 9 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,15 +34,13 @@ 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>{
try{
export async function jsonLoad<T extends Opt<T>>(path: string, def: T): Promise<T> {
try {
return await jsonRead<T>(path);
}
catch(e){
if(e instanceof Deno.errors.NotFound){
} catch(e) {
if(e instanceof Deno.errors.NotFound) {
await jsonWrite(path, def);
}
else{
} else {
throw e;
}
}
Expand Down
26 changes: 0 additions & 26 deletions src/deno/os.ts

This file was deleted.

88 changes: 0 additions & 88 deletions src/deno/path.ts

This file was deleted.

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
34 changes: 17 additions & 17 deletions src/deno_ext/dom.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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){
switch(element?.tagName){
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"));
case "OPTION": return getValue(element);
Expand All @@ -27,10 +27,10 @@ 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){
if(!element) {
throw new Error();
}

Expand All @@ -45,19 +45,19 @@ 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){
for(const input of element.getElementsByTagName("INPUT")) {
if(!input.id) {
continue;
}

records[input.id] = getValue(input);
}

for(const textarea of element.getElementsByTagName("TEXTAREA")){
if(!textarea.id){
for(const textarea of element.getElementsByTagName("TEXTAREA")) {
if(!textarea.id) {
continue;
}

Expand All @@ -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,10 +113,10 @@ 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")){
if(elements.some(v => v.tagName !== "INPUT" || v.getAttribute("type") !== "radio")) {
return "";
}

Expand Down
12 changes: 6 additions & 6 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,31 +13,31 @@ 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, {
handlers: [
new ConsoleHandler(level, {
formatter({datetime, levelName, msg}){
formatter({datetime, levelName, msg}) {
return logRecord(datetime, levelName, msg);
}
})
]
});

if(path){
if(path) {
log.handlers.push(
new FileHandler(level, {
filename: path,
formatter({datetime, levelName, msg}){
formatter({datetime, levelName, msg}) {
return logRecord(datetime, levelName, msg);
}
})
);
}

for(const h of log.handlers){
for(const h of log.handlers) {
h.setup();
}

Expand Down
Loading

0 comments on commit fbd3979

Please sign in to comment.