Socket
Socket
Sign inDemoInstall

uni-global

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uni-global

Global namespace without polluting the global scope


Version published
Weekly downloads
1M
decreased by-2.46%
Maintainers
1
Weekly downloads
 
Created
Source

Build status Tests coverage npm version

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:

// 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:

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

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

Installation

npm install uni-global

Keywords

FAQs

Package last updated on 06 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc