diff --git a/README.md b/README.md index a198a6d..d974a56 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,14 @@ The actual binary structure looks like this: This structure is repeats for the number of files. -# Compatible +# Browser Collected only parts of this module that not use the `Deno` namespace and prepared as browser-compatible code to [`mod.universal.ts`](./mod.universal.ts). -You can get bundled script in [releases](https://github.com/dojyorin/deno_simple_utility/releases). + +You can use script from [esm.sh](https://esm.sh). + +```ts +import {fetchExtend} from "https://esm.sh/gh/dojyorin/deno_simple_utility@version/mod.universal.ts?bundle&target=esnext"; +``` # API See [Deno Document](https://deno.land/x/simple_utility/mod.ts) for details. \ No newline at end of file diff --git a/deps.test.ts b/deps.test.ts index 81726f5..a3d0cb9 100644 --- a/deps.test.ts +++ b/deps.test.ts @@ -1,4 +1,4 @@ -export {assertEquals} from "https://deno.land/std@0.190.0/testing/asserts.ts"; -export {dirname, fromFileUrl} from "https://deno.land/std@0.190.0/path/mod.ts"; -export {serve} from "https://deno.land/std@0.190.0/http/mod.ts"; -export {exists} from "https://deno.land/std@0.190.0/fs/mod.ts"; \ No newline at end of file +export {assertEquals} from "https://deno.land/std@0.192.0/testing/asserts.ts"; +export {dirname, fromFileUrl} from "https://deno.land/std@0.192.0/path/mod.ts"; +export {serve} from "https://deno.land/std@0.192.0/http/mod.ts"; +export {exists} from "https://deno.land/std@0.192.0/fs/mod.ts"; \ No newline at end of file diff --git a/deps.ts b/deps.ts index be29af8..4b59692 100644 --- a/deps.ts +++ b/deps.ts @@ -1,4 +1,4 @@ -export {dirname, fromFileUrl} from "https://deno.land/std@0.190.0/path/mod.ts"; -export {Logger} from "https://deno.land/std@0.190.0/log/mod.ts"; -export {ConsoleHandler, FileHandler} from "https://deno.land/std@0.190.0/log/handlers.ts"; -export {format as formatDate} from "https://deno.land/std@0.190.0/datetime/mod.ts"; \ No newline at end of file +export {dirname, fromFileUrl} from "https://deno.land/std@0.192.0/path/mod.ts"; +export {Logger} from "https://deno.land/std@0.192.0/log/mod.ts"; +export {ConsoleHandler, FileHandler} from "https://deno.land/std@0.192.0/log/handlers.ts"; +export {format as formatDate} from "https://deno.land/std@0.192.0/datetime/mod.ts"; \ No newline at end of file diff --git a/src/fetch.ts b/src/fetch.ts index 3f86f58..21deb22 100644 --- a/src/fetch.ts +++ b/src/fetch.ts @@ -6,7 +6,7 @@ export type QueryInit = Exclude | URLSearchParams; /** * `RequestInit` with added `query` property that can specify query string. */ -export interface FetchInit extends Omit{ +export interface FetchInit extends Omit{ query?: QueryInit; } @@ -34,7 +34,7 @@ export interface ResponseType{ * ``` */ export async function fetchExtend(path:string, type:T, option?:FetchInit):Promise{ - const {origin, pathname} = new URL(path, location?.href); + const {origin, pathname} = new URL(path, globalThis?.location?.href); const query = new URLSearchParams(option?.query).toString(); const response = await fetch(`${origin}${pathname}${query && "?"}${query}`, { @@ -45,12 +45,10 @@ export async function fetchExtend(path:string, typ redirect: option?.redirect ?? "follow", keepalive: option?.keepalive ?? false, referrerPolicy: option?.referrerPolicy ?? "no-referrer", - referrer: option?.referrer ?? "", - integrity: option?.integrity ?? "", - signal: option?.signal ?? null, - headers: option?.headers ?? {}, - body: option?.body ?? null, - window: null + referrer: option?.referrer, + signal: option?.signal, + headers: option?.headers, + body: option?.body }); switch(type){ diff --git a/src/json.deno.ts b/src/json.deno.ts index 5ff6148..726283d 100644 --- a/src/json.deno.ts +++ b/src/json.deno.ts @@ -34,20 +34,20 @@ export async function jsonWrite(path:string, data:T):Promise< * const resource = await jsonLoad("./resource.json", dresource); * ``` */ -export async function jsonLoad(path:string, defaultv:T):Promise{ +export async function jsonLoad(path:string, def:T):Promise{ try{ return await jsonRead(path); } catch(e){ if(e instanceof Deno.errors.NotFound){ - await jsonWrite(path, defaultv); + await jsonWrite(path, def); } else{ throw e; } } - return defaultv; + return def; } /** @@ -59,6 +59,6 @@ export async function jsonLoad(path:string, defaultv:T):Promi * const config = await configLoad(dconfig); * ``` */ -export async function configLoad(defaultv:T):Promise{ - return await jsonLoad(`${mainPath()}/config.json`, defaultv); +export async function configLoad(def:T):Promise{ + return await jsonLoad(`${mainPath()}/config.json`, def); } \ No newline at end of file diff --git a/src/log.deno.ts b/src/log.deno.ts index 3811c9e..d74f9f2 100644 --- a/src/log.deno.ts +++ b/src/log.deno.ts @@ -8,14 +8,14 @@ function logRecord(date:Date, level:string, message:string){ /** * Instantiate logger with general configuration. * Output to console and file. -* Log file default save path is `${Deno.mainModule}/execution.log`. +* Log file default save path is `${Deno.mainModule}/operation.log`. * @example * ```ts -* const log = logSet(); +* const log = logEntry(); * ``` */ -export function logSet(name?:string):Logger{ - const logName = name ?? "execution"; +export function logEntry(name?:string):Logger{ + const logName = name ?? "operation"; const level = "INFO"; const log = new Logger(logName, level, { diff --git a/test/log.deno.test.ts b/test/log.deno.test.ts index f8318fa..6e410a5 100644 --- a/test/log.deno.test.ts +++ b/test/log.deno.test.ts @@ -1,13 +1,13 @@ import {assertEquals, exists} from "../deps.test.ts"; -import {logSet} from "../src/log.deno.ts"; +import {logEntry} from "../src/log.deno.ts"; Deno.test({ - name: "Log: Setup", + name: "Log: Entry", async fn(){ - const log = logSet(); + const log = logEntry(); log.info("Lorem ipsum dolor sit amet."); - const result = await exists("./execution.log", { + const result = await exists("./operation.log", { isFile: true });