diff --git a/README.md b/README.md index 3424333..b2e63b1 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,14 @@ List of well known providers can be found from [./src/providers.ts](./src/provid import { env } from "std-env"; ``` +## Platform agnostic process + +`std-env` provides a lightweight proxy to access [`process`](https://nodejs.org/api/process.html) object in a platform agnostic way. + +```ts +import { process } from "std-env"; +``` + ## License MIT diff --git a/src/_process.ts b/src/_process.ts deleted file mode 100644 index f8cc217..0000000 --- a/src/_process.ts +++ /dev/null @@ -1,2 +0,0 @@ -export const _process: typeof process = - typeof process === "undefined" ? ({} as typeof process) : process; diff --git a/src/index.ts b/src/index.ts index 09a3eb4..fd3f4b7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ -export * from "./providers"; export * from "./env"; export * from "./flags"; +export * from "./process"; +export * from "./providers"; diff --git a/src/process.ts b/src/process.ts new file mode 100644 index 0000000..43687ab --- /dev/null +++ b/src/process.ts @@ -0,0 +1,12 @@ +import { env } from "./env"; + +export const process = new Proxy(globalThis.process || Object.create(null), { + get(target, prop) { + if (prop in target) { + return target[prop]; + } + if (prop === "env") { + return env; + } + }, +}); diff --git a/test/index.test.ts b/test/index.test.ts index 53f06cb..df21f8c 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -5,7 +5,6 @@ describe("std-env", () => { it("has expected exports", () => { expect(Object.keys(stdEnv)).toMatchInlineSnapshot(` [ - "detectProvider", "env", "nodeENV", "platform", @@ -23,6 +22,8 @@ describe("std-env", () => { "isLinux", "isMacOS", "isColorSupported", + "process", + "detectProvider", ] `); });