# uni-global

> Global namespace without polluting the global scope

Latest version **1.0.0** (published 2021-10-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install uni-global
pnpm add uni-global
yarn add uni-global
bun add uni-global
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2021-10-06 |
| First published | 2021-10-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 9.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Mariusz Nowak |
| Maintainers | medikoo |
| Keywords | global, globalThis |

## Links

- npm: https://www.npmjs.com/package/uni-global
- Repository: https://github.com/medikoo/uni-global
- Homepage: https://github.com/medikoo/uni-global#readme
- Issues: https://github.com/medikoo/uni-global/issues
- npm.io page: https://npm.io/package/uni-global

## Dependencies (1)

- [type](https://npm.io/package/type.md) ^2.5.0

## Recent versions

- 1.0.0 (latest) — 2021-10-06

## README

[![Build status][build-image]][build-url]
[![Tests coverage][cov-image]][cov-url]
[![npm version][npm-image]][npm-url]

# uni-global

## Global namespace with no global scope pollution

### Use case

In modules world, there's possiblity that two different instance of same modules (e.g. installed in different `node_modules`) are being run in same process.

If for any reason they need to operate on context instance that's same for the given application or process, then ocassionally introduced multiple installations may break the application.

This module provides interface wich can be used by those to modules to ensure that no matter how many instances of given module are loaded, in all cases they end with same context instance.

### Example usage:

```javascript
// No matter how many instances of given module are loaded in the process, they will always end with same context instance
const globalContext = require("uni-global")("my-scope-name");

// globalContext is a plain object, on which needed global data can be stored.
globalContext.someSingletonData = ...

```

### Adapt manually other realm

If there's a need to adapt other environment realm (e.g. coming from iframe) to share same uni-global directory.

Register it with `adaptRealm` util as below:

```javascript
const adaptRealm = require("uni-global/adapt-realm");

adaptRealm(iFrameWindow); // Pass global object of the other realm
```

### Installation

```bash
npm install uni-global
```

[build-image]: https://github.com/medikoo/uni-global/workflows/Integrate/badge.svg
[build-url]: https://github.com/medikoo/uni-global/actions?query=workflow%3AIntegrate
[cov-image]: https://img.shields.io/codecov/c/github/medikoo/uni-global.svg
[cov-url]: https://codecov.io/gh/medikoo/uni-global
[npm-image]: https://img.shields.io/npm/v/uni-global.svg
[npm-url]: https://www.npmjs.com/package/uni-global

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