Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

individual

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

individual

Garantueed individual values

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1M
increased by18.85%
Maintainers
1
Weekly downloads
 
Created
Source

individual

build status Coverage Status Davis Dependency status

NPM

browser support

Garantueed individual values

Example

var Individual = require("individual")

var moduleCache = Individual("__MY_MODULE_CACHE", {})

// moduleCache is a individual variable local to this file.
// It will always be the same value and defaults to {}.

This gives you a singleton value by a unique name (it stores it as a global variable).

Use cases

Your module has an internal cache. If your module is loaded twice, (someone didn't npm dedup and has two copies of your module) you would have two seperate caches that dont talk to each other.

Best case your cache is less efficient. Worst case you have a cache because the native C++ extension you talk to crashes if you instantiate something twice.

You need a garantuee that this value is an individual, there is only one of it.

I use it myself because opening a SockJS websocket to the same URI twice causes an infinite loop. I need a garantuee that I have an individual value for the SockJS connection so I can see whether I already have an open connection.

WHY GLOBALS >:(

I can't imagine any other way to do it. I hate it too. Make a pull request if you know the real solution

Installation

npm install individual

Contributors

  • Raynos

MIT Licenced

FAQs

Package last updated on 21 Dec 2014

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