JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 757898
  • Score
    100M100P100Q182076F
  • License Apache-2.0

Optional Require

Package Exports

  • optional-require

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (optional-require) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Optional Require

Allows you to require a module only if it exists.

Usage

const optionalRequire = require("optional-require")(require);

const foo = optionalRequire("foo") || {};
const bar = optionalRequire("bar", true); // true enables console.log a message
const xyz = optionalRequire("xyz", "test"); // "test" enables console.log a message with "test" added.
const fbPath = optionalRequire.resolve("foo", "foo doesn't exist");

Install

$ npm i optional-require --save

LICENSE

Apache-2.0 © Joel Chen