# ilib-env

> Common environment detection functions for ilib. iLib is a cross-engine library of internationalization (i18n) classes written in pure JS

Latest version **1.4.3** (published 2026-07-02) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install ilib-env
pnpm add ilib-env
yarn add ilib-env
bun add ilib-env
```

## Health

**Score 65/100 (B)** — status: active.

Positive: esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 1.4.3 |
| Published | 2026-07-02 |
| First published | 2021-04-15 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=12 <23 |
| Dependencies | 0 |
| Unpacked size | 66.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 6 |
| Author | Edwin Hoogerbeets |
| Maintainers | ehoogerbeets |
| Keywords | internationalization, i18n, localization, l10n, globalization, g11n, date, time, format, locale, translation |

## Links

- npm: https://www.npmjs.com/package/ilib-env
- Repository: https://github.com/iLib-js/ilib-mono
- Homepage: https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-env
- Issues: https://github.com/iLib-js/ilib-mono/issues
- npm.io page: https://npm.io/package/ilib-env

## Alternatives

- [messageformat](https://npm.io/package/messageformat.md) — 329.7K weekly downloads
- [@mintlify/scraping](https://npm.io/package/@mintlify/scraping.md) — 294.8K weekly downloads
- [@mintlify/previewing](https://npm.io/package/@mintlify/previewing.md) — 209.5K weekly downloads
- [@mintlify/prebuild](https://npm.io/package/@mintlify/prebuild.md) — 209.5K weekly downloads
- [@mintlify/link-rot](https://npm.io/package/@mintlify/link-rot.md) — 206.3K weekly downloads

## Recent versions

- 1.4.3 (latest) — 2026-07-02
- 1.4.2 — 2025-06-07
- 1.4.1 — 2024-12-19
- 1.4.0 — 2024-02-11
- 1.3.3 — 2023-12-04
- 1.3.2 — 2022-08-29
- 1.3.1 — 2022-08-02
- 1.3.0 — 2022-06-21
- 1.2.1 — 2022-05-13
- 1.2.0 — 2022-04-11
- 1.1.0 — 2022-04-04
- 1.0.2 — 2021-10-03
- 1.0.1 — 2021-06-10
- 1.0.0 — 2021-04-15

## README

# ilib-env

Detect various things in the runtime environment.

## Usage

This package can be used to detect the following things:

- The current platform
- The current locale
- The current time zone
- The current browser
- The top scope and whether variables are global in the current environment

See the [full API documentation](./docs/ilibEnv.md).

## Installation

```sh
npm install ilib-env
# or
yarn add ilib-env
```

### The Current Platform

Return the name of the platform upon which the code is currently running.

```javascript
// ES5
var ilibEnv = require("ilib-env");
var platform = ilibEnv.getPlatform();

// ES6
import { getPlatform } from "ilib-env";
const platform = getPlatform();
// or
import ilibEnv from "ilib-env";
const platform = ilibEnv.getPlatform();
```

This will return a string that names the platform upon which the package is running.
The string will have one of the following values:

- browser: this code is running in a browser. Use getBrowser() to you need to know which one.
- nodejs: this code is running on nodejs
- qt: this code is running under QML inside of QT
- rhino: this code is running inside of Rhino or Nashorn
- trireme: this code is running inside of Trireme
- unknown: the platform is not recognized
- webos-webapp: the code is running in a web application on WebOS
- webos: the code is running in a WebOS app

### The Current Locale

Return the BCP-47 locale specifier for the platform on which this code is running.

```javascript
// ES5
var ilibEnv = require("ilib-env");
var locale = ilibEnv.getLocale();

// ES6
import { getLocale } from "ilib-env";
const locale = getLocale();
// or
import ilibEnv from "ilib-env";
const locale = ilibEnv.getLocale();
```

If the platform supports the `Intl` object, this function will use it to determine
the current locale. (This includes most modern browsers and nodejs). If there is no
`Intl` object, or the locale is not specified in the `Intl` object, this function
will check various environment variables to find the locale. If none can be found,
it will return a default of "en-US".

### The Current Time Zone

Return the IANA timezone specifier for the platform on which this code is running.

```javascript
// ES5
var ilibEnv = require("ilib-env");
var timezone = ilibEnv.getTimeZone();

// ES6
import { getTimeZone } from "ilib-env";
const timezone = getTimeZone();
// or
import ilibEnv from "ilib-env";
const timezone = ilibEnv.getTimeZone();
```

If the platform supports the `Intl` object, this function will use it to determine
the current timezone. (This includes most modern browsers and nodejs). If there is no
`Intl` object, or the timezone is not specified in the `Intl` object, this function
will check various environment variables to find the timezone. If none can be found,
it will return a default of "local".

### The Current Browser

Return the name of the browser on which this code is running. If the code is not
runningn on a browser (ie. the getPlatform() function does not return "browser")
then the return value of this function is undefined.

```javascript
// ES5
var ilibEnv = require("ilib-env");
if (ilibEnv.getPlatform() === "browser") {
  browser = ilibEnv.getBrowser();
}

// ES6
import { getPlatform, getBrowser } from "ilib-env";
if (getPlatform() === "browser") {
  browser = getBrowser();
}
// or
import ilibEnv from "ilib-env";
if (ilibEnv.getPlatform() === "browser") {
  browser = ilibEnv.getBrowser();
}
```

This function returns one of the following values:

- firefox
- opera
- chrome
- ie
- safari
- Edge
- iOS

If the browser name cannot be determined, this function returns undefined

### The Top Scope

You can retrieve the top scope of the platform using the `top()` function
and you can check whether or not a variable is defined in the top scope
using the `isGlobal()` function.

```javascript
// ES5
var ilibEnv = require("ilib-env");
var top = ilibEnv.top();
if (ilibEnv.isGlobal("variableName")) {
  // safe to reference variableName
}

// ES6
import { top, isGlobal } from "ilib-env";
const top = top();
if (isGlobal("variableName")) {
  // safe to reference variableName
}
// or
import ilibEnv from "ilib-env";
const top = ilibEnv.top();
if (ilibEnv.isGlobal("variableName")) {
  // safe to reference variableName
}
```

## License

Copyright © 2021-2026, JEDLSoft

This package is released under the [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0). The full license text is available in the [LICENSE](https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-env/LICENSE) file in the ilib-mono repository on GitHub.

## Release Notes

See [CHANGELOG.md](https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-env/CHANGELOG.md).

---
_Source: https://npm.io/package/ilib-env · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
