summaryrefslogtreecommitdiff
path: root/u/leftpadesque
diff options
context:
space:
mode:
Diffstat (limited to 'u/leftpadesque')
-rw-r--r--u/leftpadesque/debug.ts15
-rw-r--r--u/leftpadesque/index.ts4
-rw-r--r--u/leftpadesque/memoize.ts22
-rw-r--r--u/leftpadesque/mod.ts4
-rw-r--r--u/leftpadesque/object.ts3
-rw-r--r--u/leftpadesque/prepend.ts8
6 files changed, 25 insertions, 31 deletions
diff --git a/u/leftpadesque/debug.ts b/u/leftpadesque/debug.ts
index e50b2e0..074e567 100644
--- a/u/leftpadesque/debug.ts
+++ b/u/leftpadesque/debug.ts
@@ -1,13 +1,8 @@
-const _hasEnv = !Deno.permissions.querySync({ name: "env" });
+const _hasEnv = true; // Node.js always has access to environment variables
-const _env: "development" | "production" =
- _hasEnv && (Deno.env.get("ENVIRONMENT") ?? "").toLowerCase().includes("prod")
- ? "production"
- : "development";
-export const isProd = () => _env === "production";
+const _env: 'development' | 'production' =
+ _hasEnv && (process.env.ENVIRONMENT ?? '').toLowerCase().includes('prod') ? 'production' : 'development';
+export const isProd = () => _env === 'production';
-const _debug =
- !isProd() ||
- (_hasEnv &&
- ["y", "t"].some((Deno.env.get("DEBUG") ?? "").toLowerCase().startsWith));
+const _debug = !isProd() || (_hasEnv && ['y', 't'].some((process.env.DEBUG ?? '').toLowerCase().startsWith));
export const isDebug = () => _debug;
diff --git a/u/leftpadesque/index.ts b/u/leftpadesque/index.ts
new file mode 100644
index 0000000..6403e4a
--- /dev/null
+++ b/u/leftpadesque/index.ts
@@ -0,0 +1,4 @@
+export * from './object.js';
+export * from './prepend.js';
+export * from './debug.js';
+export * from './memoize.js';
diff --git a/u/leftpadesque/memoize.ts b/u/leftpadesque/memoize.ts
index 95e6019..541bd20 100644
--- a/u/leftpadesque/memoize.ts
+++ b/u/leftpadesque/memoize.ts
@@ -1,14 +1,14 @@
-import type { Callable } from "@emprespresso/pengueno";
+import type { Callable } from '@emprespresso/pengueno';
export const memoize = <R, F extends Callable<R>>(fn: F): F => {
- const cache = new Map<string, R>();
- return ((...args: unknown[]): R => {
- const key = JSON.stringify(args);
- if (cache.has(key)) {
- return cache.get(key)!;
- }
- const res = fn.apply(args);
- cache.set(key, res);
- return res;
- }) as F;
+ const cache = new Map<string, R>();
+ return ((...args: unknown[]): R => {
+ const key = JSON.stringify(args);
+ if (cache.has(key)) {
+ return cache.get(key)!;
+ }
+ const res = fn.apply(args);
+ cache.set(key, res);
+ return res;
+ }) as F;
};
diff --git a/u/leftpadesque/mod.ts b/u/leftpadesque/mod.ts
deleted file mode 100644
index 63d8d7a..0000000
--- a/u/leftpadesque/mod.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-export * from "./object.ts";
-export * from "./prepend.ts";
-export * from "./debug.ts";
-export * from "./memoize.ts";
diff --git a/u/leftpadesque/object.ts b/u/leftpadesque/object.ts
index 73f7f80..fe97999 100644
--- a/u/leftpadesque/object.ts
+++ b/u/leftpadesque/object.ts
@@ -1,2 +1 @@
-export const isObject = (o: unknown): o is object =>
- typeof o === "object" && !Array.isArray(o) && !!o;
+export const isObject = (o: unknown): o is object => typeof o === 'object' && !Array.isArray(o) && !!o;
diff --git a/u/leftpadesque/prepend.ts b/u/leftpadesque/prepend.ts
index 0f1ce30..d80f6b6 100644
--- a/u/leftpadesque/prepend.ts
+++ b/u/leftpadesque/prepend.ts
@@ -1,5 +1,5 @@
export const prependWith = (arr: string[], prep: string) =>
- Array(arr.length * 2)
- .fill(0)
- .map((_, i) => i % 2 === 0)
- .map((isPrep, i) => (isPrep ? prep : arr[i]));
+ Array(arr.length * 2)
+ .fill(0)
+ .map((_, i) => i % 2 === 0)
+ .map((isPrep, i) => (isPrep ? prep : arr[i]!));