An open API service indexing awesome lists of open source software.

https://github.com/hugoalh-studio/cross-env-es

An ES (JavaScript & TypeScript) module for cross runtime environment variables interface.
https://github.com/hugoalh-studio/cross-env-es

cross env environment-variables es javascript js modulejs ts typescript

Last synced: 3 months ago
JSON representation

An ES (JavaScript & TypeScript) module for cross runtime environment variables interface.

Awesome Lists containing this project

README

          

# Cross Env (ES)

[**âš–ī¸** MIT](./LICENSE.md)

[![GitHub: hugoalh-studio/cross-env-es](https://img.shields.io/github/v/release/hugoalh-studio/cross-env-es?label=hugoalh-studio/cross-env-es&labelColor=181717&logo=github&logoColor=ffffff&sort=semver&style=flat "GitHub: hugoalh-studio/cross-env-es")](https://github.com/hugoalh-studio/cross-env-es)
[![JSR: @hugoalh/cross-env](https://img.shields.io/jsr/v/@hugoalh/cross-env?label=@hugoalh/cross-env&labelColor=F7DF1E&logo=jsr&logoColor=000000&style=flat "JSR: @hugoalh/cross-env")](https://jsr.io/@hugoalh/cross-env)
[![NPM: @hugoalh/cross-env](https://img.shields.io/npm/v/@hugoalh/cross-env?label=@hugoalh/cross-env&labelColor=CB3837&logo=npm&logoColor=ffffff&style=flat "NPM: @hugoalh/cross-env")](https://www.npmjs.com/package/@hugoalh/cross-env)

An ES (JavaScript & TypeScript) module for cross runtime environment variables interface.

## 🔰 Begin

### đŸŽ¯ Targets

| | **Registry - JSR** | **Registry - NPM** | **Remote Import** |
|:--|:--|:--|:--|
| **[Bun](https://bun.sh/)** >= v1.1.0 | [âœ”ī¸ `node_modules`](https://jsr.io/docs/npm-compatibility) | [âœ”ī¸ Specifier `npm:`](https://bun.sh/docs/runtime/autoimport) | ❌ |
| **[Deno](https://deno.land/)** >= v1.42.0 | [âœ”ī¸ Specifier `jsr:`](https://jsr.io/docs/with/deno) | [âœ”ī¸ Specifier `npm:`](https://docs.deno.com/runtime/manual/node/npm_specifiers) | [âœ”ī¸](https://docs.deno.com/runtime/manual/basics/modules/#remote-import) |
| **[NodeJS](https://nodejs.org/)** >= v16.13.0 | [âœ”ī¸ `node_modules`](https://jsr.io/docs/with/node) | [âœ”ī¸ `node_modules`](https://docs.npmjs.com/using-npm-packages-in-your-projects) | ❌ |

> **â„šī¸ Note**
>
> It is possible to use this module in other methods/ways which not listed in here, however it is not officially supported.

### #ī¸âƒŖ Registries Identifier

- **JSR:**
```
@hugoalh/cross-env
```
- **NPM:**
```
@hugoalh/cross-env
```

> **â„šī¸ Note**
>
> - Although it is recommended to import the entire module, it is also able to import part of the module with sub path if available, please visit [file `jsr.jsonc`](./jsr.jsonc) property `exports` for available sub paths.
> - It is recommended to use this module with tag for immutability.

### #ī¸âƒŖ Remote Import Paths

- **GitHub Raw:** (Require Tag)
```
https://raw.githubusercontent.com/hugoalh-studio/cross-env-es/${Tag}/mod.ts
```

> **â„šī¸ Note**
>
> - Although it is recommended to import the entire module with the main path `mod.ts`, it is also able to import part of the module with sub path if available, but do not import if:
>
> - it's file path has an underscore prefix (e.g.: `_foo.ts`, `_util/bar.ts`), or
> - it is a benchmark or test file (e.g.: `foo.bench.ts`, `foo.test.ts`), or
> - it's symbol has an underscore prefix (e.g.: `export function _baz() {}`).
>
> These elements are not considered part of the public API, thus no stability is guaranteed for them.
> - Although there have 3rd party services which provide enhanced, equal, or similar methods/ways to remote import the module, beware these services maybe inject unrelated elements and thus affect the security.

### đŸ›Ąī¸ Permissions

| **Target** | **Type** | **Coverage** |
|:--|:--|:--|
| Deno | Environment Variable (`allow-env`) | All |

## 🧩 APIs

- ```ts
const env: CrossEnv;
```
- ```ts
const envPath: CrossEnvPath;
```
- ```ts
const envPathExt: CrossEnvPathExt;
```
- ```ts
function isEnvironmentCI(): boolean;
```
- ```ts
function isEnvironmentDocker(): Promise;
```
- ```ts
function isEnvironmentHeroku(): boolean;
```
- ```ts
function isEnvironmentHyper(): boolean;
```
- ```ts
function isEnvironmentPodman(): Promise;
```
- ```ts
function isEnvironmentRoot(): boolean;
```
- ```ts
function isEnvironmentSSH(): boolean;
```
- ```ts
function isEnvironmentTravis(): boolean;
```
- ```ts
function isEnvironmentWSL(): Promise;
```
- ```ts
interface CrossEnv {
delete(key: string): void;
get(key: string): string | undefined;
getAll(): { [key: string]: string; };
has(key: string): boolean;
set(key: string, value: string): void;
}
```
- ```ts
interface CrossEnvPath {
add(...values: string[]): void;
delete(...values: string[]): void;
get(): string[];
}
```
- ```ts
interface CrossEnvPathExt {
add(...values: string[]): void;
delete(...values: string[]): void;
get(): string[] | null;
}
```

> **â„šī¸ Note**
>
> For the prettier documentation, can visit via:
>
> - [Deno CLI `deno doc`](https://deno.land/manual/tools/documentation_generator)
> - [JSR](https://jsr.io/@hugoalh/cross-env)

## âœī¸ Examples

- ```ts
env.delete("SOME_VAR");
```
- ```ts
env.get("HOME");
//=> "/home/alice"
```
- ```ts
env.get("SOME_VAR");
//=> undefined
```