You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

nice-require

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nice-require

Tries to import a module. Ignores any error that occurs.

1.1.0
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

nice-require

Tries to import modules. It gracefully returns undefined if fails.

Install

$ npm i nice-require

Usage

const niceRequire = require('nice-require');

const myModule = niceRequire('my-module-name');

if (myModule) {
    // Module was successfully imported.
}

Good solution when working with optional dependencies.

API

niceRequire (module)

Tries importing a specified module, returns undefined if fails.

niceRequire.promise (module)

Tries dynamically importing a specified module, returns undefined if fails.
Note: This won't work with file paths like ./index.js.

module

Type: string
Module you want to import.

License

MIT

Keywords

nice

FAQs

Package last updated on 12 Sep 2023

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