Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsr support. #106

Merged
merged 5 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/std@0.224.0/csv/mod.ts"
export {parse, stringify} from "https://esm.sh/gh/denoland/deno_std@0.224.0/csv/mod.ts?bundle&target=esnext";
// @deno-types="https://deno.land/x/zipjs@v2.7.45/index.d.ts"
export {ZipReader, ZipWriter, Uint8ArrayReader, Uint8ArrayWriter} from "https://esm.sh/gh/gildas-lormeau/zip.js@v2.7.45/index.js?bundle&target=esnext";
export {parse, stringify} from "https://esm.sh/jsr/@std/csv@0.224.3?bundle&target=esnext";
export {ZipReader, ZipWriter, Uint8ArrayReader, Uint8ArrayWriter} from "https://esm.sh/jsr/@zip-js/zip-js@2.7.45?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/std@0.224.0/assert/mod.ts";
export {dirname, fromFileUrl} from "https://deno.land/std@0.224.0/path/mod.ts";
export {exists} from "https://deno.land/std@0.224.0/fs/mod.ts";
export {delay} from "https://deno.land/std@0.224.0/async/mod.ts";

export {DOMParser} from "https://deno.land/x/deno_dom@v0.1.46/deno-dom-wasm.ts";
export {assertEquals} from "jsr:@std/assert@0.226.0";
export {dirname, fromFileUrl} from "jsr:@std/path@0.225.2";
export {exists} from "jsr:@std/fs@0.229.3";
export {delay} from "jsr:@std/async@0.224.2";
export {DOMParser} from "jsr:@b-fuze/deno-dom@0.1.47";

export {init as smtpTest} from "npm:smtp-tester@2.1.0";
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/std@0.224.0/log/mod.ts";
export {format} from "https://deno.land/std@0.224.0/datetime/mod.ts";

export {type Element, DOMParser} from "https://deno.land/x/deno_dom@v0.1.46/deno-dom-wasm.ts";
export {Logger, ConsoleHandler, FileHandler} from "jsr:@std/log@0.224.3";
export {format} from "jsr:@std/datetime@0.224.1";
export {type Element, DOMParser} from "jsr:@b-fuze/deno-dom@0.1.47";

// @deno-types="npm:@types/nodemailer@6.4.15"
export {createTransport} from "npm:nodemailer@6.9.13";
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