Skip to content

Commit

Permalink
Merge pull request #61 from dojyorin/dev
Browse files Browse the repository at this point in the history
update deps.
  • Loading branch information
dojyorin authored Jun 28, 2023
2 parents c3fac22 + e31315b commit 747d7f1
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 31 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
8 changes: 4 additions & 4 deletions deps.test.ts
Original file line number Diff line number Diff line change
@@ -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";
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";
8 changes: 4 additions & 4 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -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";
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";
14 changes: 6 additions & 8 deletions src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type QueryInit = Exclude<HeadersInit, Headers> | URLSearchParams;
/**
* `RequestInit` with added `query` property that can specify query string.
*/
export interface FetchInit extends Omit<RequestInit, "window">{
export interface FetchInit extends Omit<RequestInit, "integrity" | "window">{
query?: QueryInit;
}

Expand Down Expand Up @@ -34,7 +34,7 @@ export interface ResponseType{
* ```
*/
export async function fetchExtend<T extends keyof ResponseType>(path:string, type:T, option?:FetchInit):Promise<ResponseType[T]>{
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}`, {
Expand All @@ -45,12 +45,10 @@ export async function fetchExtend<T extends keyof ResponseType>(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){
Expand Down
10 changes: 5 additions & 5 deletions src/json.deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ export async function jsonWrite<T extends unknown>(path:string, data:T):Promise<
* const resource = await jsonLoad("./resource.json", dresource);
* ```
*/
export async function jsonLoad<T extends unknown>(path:string, defaultv:T):Promise<T>{
export async function jsonLoad<T extends unknown>(path:string, def:T):Promise<T>{
try{
return await jsonRead<T>(path);
}
catch(e){
if(e instanceof Deno.errors.NotFound){
await jsonWrite(path, defaultv);
await jsonWrite(path, def);
}
else{
throw e;
}
}

return defaultv;
return def;
}

/**
Expand All @@ -59,6 +59,6 @@ export async function jsonLoad<T extends unknown>(path:string, defaultv:T):Promi
* const config = await configLoad(dconfig);
* ```
*/
export async function configLoad<T extends unknown>(defaultv:T):Promise<T>{
return await jsonLoad(`${mainPath()}/config.json`, defaultv);
export async function configLoad<T extends unknown>(def:T):Promise<T>{
return await jsonLoad(`${mainPath()}/config.json`, def);
}
8 changes: 4 additions & 4 deletions src/log.deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
8 changes: 4 additions & 4 deletions test/log.deno.test.ts
Original file line number Diff line number Diff line change
@@ -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
});

Expand Down

0 comments on commit 747d7f1

Please sign in to comment.