Skip to content

Commit f020eb2

Browse files
pi0onmax
andauthored
refactor: improve jsdocs (#166)
Co-authored-by: Maxi <maximogarciamtnez@gmail.com>
1 parent c2fef7f commit f020eb2

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed

src/env.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
const _envShim = Object.create(null);
22

3+
/**
4+
* Represents an environment variable object, where each key is the name of the variable
5+
* and its value is a string or undefined.
6+
*/
37
export type EnvObject = Record<string, string | undefined>;
48

59
const _getEnv = (useShim?: boolean) =>
@@ -10,6 +14,9 @@ const _getEnv = (useShim?: boolean) =>
1014
globalThis.__env__ ||
1115
(useShim ? _envShim : globalThis);
1216

17+
/**
18+
* A proxy handler for environment variables that supports reading, writing and deleting properties as well as listing all environment variable keys with a shim fallback.
19+
*/
1320
export const env: EnvObject = new Proxy<EnvObject>(_envShim, {
1421
get(_, prop) {
1522
const env = _getEnv();
@@ -38,5 +45,10 @@ export const env: EnvObject = new Proxy<EnvObject>(_envShim, {
3845
},
3946
});
4047

48+
/**
49+
* Current value of the `NODE_ENV` environment variable (or static value if replaced during build).
50+
*
51+
* If `NODE_ENV` is not set, this will be an empty `""` string.
52+
*/
4153
export const nodeENV: string =
4254
(typeof process !== "undefined" && process.env && process.env.NODE_ENV) || "";

src/process.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { type EnvObject, env } from "./env.ts";
22

3+
/**
4+
* An interface that partially shims the Node.js `global.process`.
5+
*/
36
export interface Process
47
extends Partial<Omit<typeof globalThis.process, "versions">> {
58
env: EnvObject;
@@ -13,6 +16,9 @@ const processShims: Partial<Process> = {
1316
versions: {},
1417
};
1518

19+
/**
20+
* A proxy for managing access to properties of the process with a shim fallback.
21+
*/
1622
export const process: Process = new Proxy<Process>(_process, {
1723
get(target, prop: keyof Process) {
1824
if (prop === "env") {

src/providers.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// Reference: https://github.com/watson/ci-info/blob/v3.2.0/vendors.json
22

3+
/**
4+
* Represents the name of a CI/CD or Deployment provider.
5+
*/
36
export type ProviderName =
47
| ""
58
| "appveyor"
@@ -114,9 +117,23 @@ const providers: InternalProvider[] = [
114117
["FIREBASE_APP_HOSTING", "FIREBASE_APP_HOSTING", { ci: true }],
115118
];
116119

120+
/**
121+
* Provides information about a CI/CD or Deployment provider, including its name and possibly other metadata.
122+
*/
117123
export type ProviderInfo = {
124+
/**
125+
* The name of the CI/CD or Deployment provider. See {@link ProviderName} for possible values.
126+
*/
118127
name: ProviderName;
128+
129+
/**
130+
* If is set to `true`, the environment is recognised as a CI/CD provider.
131+
*/
119132
ci?: boolean;
133+
134+
/**
135+
* Arbitrary metadata associated with the provider.
136+
*/
120137
[meta: string]: any;
121138
};
122139

@@ -151,6 +168,13 @@ function _detectProvider(): ProviderInfo {
151168
};
152169
}
153170

154-
/** Current provider info */
171+
/**
172+
* The detected provider information for the current execution context.
173+
* This value is evaluated once at module initialisation.
174+
*/
155175
export const providerInfo: ProviderInfo = _detectProvider();
176+
177+
/**
178+
* A convenience reference to the name of the detected provider.
179+
*/
156180
export const provider: ProviderName = providerInfo.name;

src/runtimes.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// https://runtime-keys.proposal.wintercg.org/
2+
23
export type RuntimeName =
34
| "workerd"
45
| "deno"
@@ -9,7 +10,12 @@ export type RuntimeName =
910
| "fastly"
1011
| "";
1112

12-
export type RuntimeInfo = { name: RuntimeName };
13+
export type RuntimeInfo = {
14+
/**
15+
* The name of the detected runtime.
16+
*/
17+
name: RuntimeName;
18+
};
1319

1420
/**
1521
* Indicates if running in Node.js or a Node.js compatible runtime.
@@ -72,6 +78,13 @@ function _detectRuntime(): RuntimeInfo | undefined {
7278
}
7379
}
7480

81+
/**
82+
* Contains information about the detected runtime, if any.
83+
*/
7584
export const runtimeInfo: RuntimeInfo | undefined = _detectRuntime();
7685

86+
/**
87+
* A convenience constant that returns the name of the detected runtime,
88+
* defaults to an empty string if no runtime is detected.
89+
*/
7790
export const runtime: RuntimeName = runtimeInfo?.name || "";

0 commit comments

Comments
 (0)