feat: add justfile
This commit is contained in:
9
justfile
Normal file
9
justfile
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
alias tl:=test-libraries
|
||||||
|
|
||||||
|
_:
|
||||||
|
@just --list
|
||||||
|
|
||||||
|
# test all libraries
|
||||||
|
test-libraries:
|
||||||
|
deno test --allow-all libraries/*
|
||||||
|
|
||||||
@@ -42,25 +42,21 @@ export function isOn(val: string | undefined | null): boolean {
|
|||||||
lowerVal === "true";
|
lowerVal === "true";
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getEnv(key: string): Promise<string | null> {
|
export function getEnv(envKey: string): string | null {
|
||||||
const homeDir = getHomeDir();
|
const homeDir = getHomeDir();
|
||||||
if ((homeDir !== null) && key) {
|
if ((homeDir !== null) && envKey) {
|
||||||
const envValue = await readFileToString(
|
const envValue = readFileToStringSync(
|
||||||
`${homeDir}/.config/envs/${key}`,
|
`${homeDir}/.config/envs/${envKey}`,
|
||||||
);
|
);
|
||||||
if (envValue !== null) {
|
if (envValue !== null) {
|
||||||
return envValue.trim();
|
return envValue.trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Deno.env.get(key) || null;
|
return Deno.env.get(envKey) || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isEnvOn(envKey: string): boolean {
|
export function isEnvOn(envKey: string): boolean {
|
||||||
return isOn(Deno.env.get(envKey));
|
return isOn(getEnv(envKey));
|
||||||
}
|
|
||||||
|
|
||||||
export async function isEnvOnAsync(envKey: string): Promise<boolean> {
|
|
||||||
return isOn(await getEnv(envKey));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatHumanTime(timeMillis: number): string {
|
export function formatHumanTime(timeMillis: number): string {
|
||||||
@@ -311,6 +307,17 @@ export async function readFileToString(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function readFileToStringSync(filename: string): string | null {
|
||||||
|
try {
|
||||||
|
return Deno.readTextFileSync(resolveFilename(filename));
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof Error && e.name == "NotFound") {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function writeStringToFile(
|
export async function writeStringToFile(
|
||||||
filename: string,
|
filename: string,
|
||||||
data: string | null,
|
data: string | null,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
encodeBase64Url,
|
encodeBase64Url,
|
||||||
getHomeDirOrDie,
|
getHomeDirOrDie,
|
||||||
hexStringToUint8Array,
|
hexStringToUint8Array,
|
||||||
} from "https://global.hatter.ink/script/get/@8/deno-commons-mod.ts";
|
} from "https://global.hatter.ink/script/get/@9/deno-commons-mod.ts";
|
||||||
import {getRandomValues} from "node:crypto";
|
import {getRandomValues} from "node:crypto";
|
||||||
import {assertEquals} from "jsr:@std/assert";
|
import {assertEquals} from "jsr:@std/assert";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user