Skip to content

Commit

Permalink
sync.
Browse files Browse the repository at this point in the history
sync.
  • Loading branch information
dojyorin authored Sep 29, 2023
1 parent 1236119 commit c917d06
Show file tree
Hide file tree
Showing 28 changed files with 270 additions and 233 deletions.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions .github/workflows/to_yaml.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
set -eu

while [[ ${#} -ge 1 ]]; do
if [[ -f ./${1}.json ]]; then
yq -I 4 -o y ./${1}.json | head -c -1 > ./${1}.yaml
fi

shift
done
6 changes: 0 additions & 6 deletions .github/workflows_json/to_yaml.sh

This file was deleted.

6 changes: 3 additions & 3 deletions deps.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export {assertEquals} from "https://deno.land/std@0.198.0/assert/mod.ts";
export {dirname, fromFileUrl} from "https://deno.land/std@0.198.0/path/mod.ts";
export {exists} from "https://deno.land/std@0.198.0/fs/mod.ts";
export {assertEquals} from "https://deno.land/std@0.203.0/assert/mod.ts";
export {dirname, fromFileUrl} from "https://deno.land/std@0.203.0/path/mod.ts";
export {exists} from "https://deno.land/std@0.203.0/fs/mod.ts";
6 changes: 3 additions & 3 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export {dirname, fromFileUrl} from "https://deno.land/std@0.198.0/path/mod.ts";
export {Logger, handlers} from "https://deno.land/std@0.198.0/log/mod.ts";
export {format} from "https://deno.land/std@0.198.0/datetime/mod.ts";
export {dirname, fromFileUrl} from "https://deno.land/std@0.203.0/path/mod.ts";
export {Logger, handlers} from "https://deno.land/std@0.203.0/log/mod.ts";
export {format} from "https://deno.land/std@0.203.0/datetime/mod.ts";
2 changes: 1 addition & 1 deletion mod.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "./test/base64.test.ts";
import "./test/blob.test.ts";
import "./test/byte.test.ts";
import "./test/crypto.test.ts";
import "./test/deep.test.ts";
import "./test/deflate.test.ts";
Expand Down
2 changes: 1 addition & 1 deletion mod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from "./src/base64.ts";
export * from "./src/blob.ts";
export * from "./src/byte.ts";
export * from "./src/crypto.ts";
export * from "./src/deep.ts";
export * from "./src/deflate.ts";
Expand Down
2 changes: 1 addition & 1 deletion mod.universal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from "./src/base64.ts";
export * from "./src/blob.ts";
export * from "./src/byte.ts";
export * from "./src/crypto.ts";
export * from "./src/deep.ts";
export * from "./src/deflate.ts";
Expand Down
18 changes: 9 additions & 9 deletions src/base64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* @example
* ```ts
* const bin = await Deno.readFile("./file");
* const converted = base64Encode(bin);
* const restored = base64Decode(converted);
* const encode = b64Encode(bin);
* const decode = b64Decode(encode);
* ```
*/
export function base64Encode(data:Uint8Array):string{
export function b64Encode(data:Uint8Array):string{
return btoa([...data].map(v => String.fromCharCode(v)).join(""));
}

Expand All @@ -16,11 +16,11 @@ export function base64Encode(data:Uint8Array):string{
* @example
* ```ts
* const bin = await Deno.readFile("./file");
* const converted = base64Encode(bin);
* const restored = base64Decode(converted);
* const encode = b64Encode(bin);
* const decode = b64Decode(encode);
* ```
*/
export function base64Decode(data:string):Uint8Array{
export function b64Decode(data:string):Uint8Array{
return new Uint8Array([...atob(data)].map(v => v.charCodeAt(0)));
}

Expand All @@ -30,9 +30,9 @@ export function base64Decode(data:string):Uint8Array{
* @example
* ```ts
* const bin = await Deno.readFile("./file");
* const url = base64DataURL(bin);
* const data = b64DataURL(bin);
* ```
*/
export function base64DataURL(data:Uint8Array, mime?:string):string{
return `data:${mime ?? "application/octet-stream"};base64,${base64Encode(data)}`;
export function b64DataURL(data:Uint8Array, mime?:string):string{
return `data:${mime ?? "application/octet-stream"};base64,${b64Encode(data)}`;
}
29 changes: 0 additions & 29 deletions src/blob.ts

This file was deleted.

48 changes: 48 additions & 0 deletions src/byte.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {b64Encode} from "./base64.ts";

/**
* Assignment of types convertible from blob.
*/
export interface BlobType{
"text": string;
"base64": string;
"byte": Uint8Array;
"buffer": ArrayBuffer;
}

/**
* Convert from blob to specified data type.
* @example
* ```ts
* const file = new File(["my-text"], "example.txt");
* const data = await blobConvert(file, "text");
* ```
*/
export async function blobConvert<T extends keyof BlobType>(blob:Blob, type:T):Promise<BlobType[T]>{
switch(type){
case "text": return <BlobType[T]>await blob.text();
case "base64": return <BlobType[T]>b64Encode(new Uint8Array(await blob.arrayBuffer()));
case "byte": return <BlobType[T]>new Uint8Array(await blob.arrayBuffer());
case "buffer": return <BlobType[T]>await blob.arrayBuffer();
default: throw new Error();
}
}

/**
* Concat multiple buffer sources into single Uint8Array.
* @example
* ```ts
* const byte = byteConcat(new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6]));
* ```
*/
export function byteConcat(...parts:BufferSource[]):Uint8Array{
const output = new Uint8Array(parts.reduce((n, {byteLength}) => n + byteLength , 0));
let i = 0;

for(const part of parts){
output.set(new Uint8Array(part instanceof ArrayBuffer ? part : part.buffer), i);
i += part.byteLength;
}

return output;
}
Loading

0 comments on commit c917d06

Please sign in to comment.