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

lazy-req

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

lazy-req

Require modules lazily

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
122K
decreased by-2.42%
Maintainers
1
Weekly downloads
 
Created
Source

lazy-req Build Status

Require modules lazily

Install

$ npm install --save lazy-req

Usage

// pass in `require` or a custom require function
const lazyReq = require('lazy-req')(require);
const _ = lazyReq('lodash');

// Where you would normally do
_.isNumber(2);

// You now instead call it as a function
_().isNumber(2);

// It's cached on consecutive calls
_().isString('unicorn');

// Extract lazy variations of the props you need
const members = lazyReq('lodash')('isNumber', 'isString');

// Useful when using destructuring assignment in ES2015
const {isNumber, isString} = lazyReq('lodash')('isNumber', 'isString');

// Works out of the box for functions and regular properties
const stuff = lazyReq('./math-lib')('sum', 'PHI');
console.log(stuff.sum(1, 2)); // => 3
console.log(stuff.PHI); // => 1.618033

Proxy support in Node.js 6 or later

If you use Node.js 6 or later, you can take advantage of ES2015 proxies and don't need to call it as a function.

const lazyReq = require('lazy-req').proxy(require);
const _ = lazyReq('lodash');

// No need to call it as a function but still lazily required
_.isNumber(2);
  • resolve-from - Resolve the path of a module from a given path
  • req-from - Require a module from a given path
  • resolve-pkg - Resolve the path of a package regardless of it having an entry point
  • lazy-value - Create a lazily evaluated value
  • define-lazy-prop - Define a lazily evaluated property on an object

License

MIT © Sindre Sorhus

Keywords

FAQs

Package last updated on 08 Nov 2018

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