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.
- Host: GitHub
- URL: https://github.com/hugoalh-studio/cross-env-es
- Owner: hugoalh-studio
- License: other
- Created: 2024-03-17T06:45:11.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-23T03:33:01.000Z (over 1 year ago)
- Last Synced: 2024-05-23T09:29:51.612Z (over 1 year ago)
- Topics: cross, env, environment-variables, es, javascript, js, modulejs, ts, typescript
- Language: TypeScript
- Homepage:
- Size: 88.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
- Citation: CITATION.cff
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# Cross Env (ES)
[**âī¸** MIT](./LICENSE.md)
[](https://github.com/hugoalh-studio/cross-env-es)
[](https://jsr.io/@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
```