Socket
Socket
Sign inDemoInstall

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 - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

license

29

index.js

@@ -5,6 +5,33 @@ 'use strict';

var mod;
return function () {
return mod !== undefined ? mod : mod = fn(id);
if (!arguments.length) {
mod = lazy(mod, fn, id);
return mod;
}
var ret = {};
[].forEach.call(arguments, function (prop) {
Object.defineProperty(ret, prop, {
get: function () {
mod = lazy(mod, fn, id);
if (typeof mod[prop] === 'function') {
return function () {
return mod[prop].apply(mod, arguments);
};
}
return mod[prop];
}
});
});
return ret;
};
};
function lazy(mod, fn, id) {
return mod !== undefined ? mod : fn(id);
}
};

13

package.json
{
"name": "lazy-req",
"version": "1.0.0",
"version": "1.1.0",
"description": "Require modules lazily",

@@ -12,2 +12,8 @@ "license": "MIT",

},
"contributors": [
{
"name": "Jorge Bucaran",
"email": "jbucaran@me.com"
}
],
"engines": {

@@ -17,3 +23,3 @@ "node": ">=0.10.0"

"scripts": {
"test": "node test.js"
"test": "xo && node test.js"
},

@@ -34,4 +40,5 @@ "files": [

"devDependencies": {
"ava": "0.0.3"
"ava": "0.0.4",
"xo": "*"
}
}

@@ -8,3 +8,3 @@ # lazy-req [![Build Status](https://travis-ci.org/sindresorhus/lazy-req.svg?branch=master)](https://travis-ci.org/sindresorhus/lazy-req)

```sh
```
$ npm install --save lazy-req

@@ -19,3 +19,3 @@ ```

var lazyReq = require('lazy-req')(require);
var lodash = require('lodash');
var _ = lazyReq('lodash');

@@ -30,2 +30,13 @@ // where you would normally do

_().isString('unicorn');
// extract lazy variations of the props you need
var 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
var stuff = lazyReq('./math-lib')('sum', 'PHI');
console.log(stuff.sum(1, 2)); // => 3
console.log(stuff.PHI); // => 1.618033
```

@@ -32,0 +43,0 @@

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