New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-require-fallback

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-require-fallback - npm Package Compare versions

Comparing version 0.1.2 to 1.0.0

20

index.js

@@ -1,4 +0,4 @@

function exists(nodeModule) {
function exists(m) {
try {
require.resolve(nodeModule)
require.resolve(m)
} catch (e) {

@@ -11,15 +11,9 @@ return false;

function requireIfExists(nodeModule, fallbackModule1, fallbackModule2) {
if (exists(nodeModule)) {
return require(nodeModule)
function requireIfExists(...modules) {
for (m of modules) {
if (exists(m)) {
return require(m);
}
}
if (exists(fallbackModule1)) {
return require(fallbackModule1);
}
if (exists(fallbackModule2)) {
return require(fallbackModule2);
}
return null;

@@ -26,0 +20,0 @@ }

{
"name": "node-require-fallback",
"version": "0.1.2",
"version": "1.0.0",
"description": "Require another package in Node.js if your first choice doesn't exist.",

@@ -9,2 +9,5 @@ "repository": {

},
"engines": {
"node": ">= 6"
},
"main": "index.js",

@@ -11,0 +14,0 @@ "keywords": [

@@ -6,3 +6,4 @@ # node-require-fallback

Useful for development, where you want to use a local copy of your package,
but it shouldn't break the application for your team, which is depending an npm package.
but it shouldn't break the application for your team, which is depending on a
npm package.

@@ -15,2 +16,4 @@ # Installation

> Node.js >= 6 is required for this package.
# Example Usage

@@ -21,6 +24,7 @@

var myModule = requireIfExists('module1', 'module2');
var myModule = requireIfExists('./module1', 'module2', 'module3');
```
`myModule` will now hold `module1` if it exists or `module2` otherwise.
`myModule` will be `null`, if `module2` wasn't available as well.
You can pass as many modules to `requireIfExists` as you want.
The first one that can be found will be loaded, otherwise `null`
will be returned.
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