diff options
author | Rebecca Turner <me@re-becca.org> | 2017-04-12 21:47:49 -0700 |
---|---|---|
committer | Jeremiah Senkpiel <fishrock123@rocketmail.com> | 2017-04-25 10:52:01 -0400 |
commit | 00842604483e4c2e622dfdb3a97440e07646158f (patch) | |
tree | f3346902636a44b6037652523767636bf7e4f2c9 /deps/npm/node_modules/update-notifier/node_modules/lazy-req/index.js | |
parent | 061c5da010e0d249379618382a499840d38247b8 (diff) | |
download | android-node-v8-00842604483e4c2e622dfdb3a97440e07646158f.tar.gz android-node-v8-00842604483e4c2e622dfdb3a97440e07646158f.tar.bz2 android-node-v8-00842604483e4c2e622dfdb3a97440e07646158f.zip |
deps: upgrade npm to 4.5.0
PR-URL: https://github.com/nodejs/node/pull/12480
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'deps/npm/node_modules/update-notifier/node_modules/lazy-req/index.js')
-rw-r--r-- | deps/npm/node_modules/update-notifier/node_modules/lazy-req/index.js | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/deps/npm/node_modules/update-notifier/node_modules/lazy-req/index.js b/deps/npm/node_modules/update-notifier/node_modules/lazy-req/index.js new file mode 100644 index 0000000000..307f08f393 --- /dev/null +++ b/deps/npm/node_modules/update-notifier/node_modules/lazy-req/index.js @@ -0,0 +1,53 @@ +'use strict'; +const lazy = (mod, fn, id) => mod === undefined ? fn(id) : mod; + +module.exports = fn => { + return id => { + let mod; + + return function () { + if (arguments.length === 0) { + mod = lazy(mod, fn, id); + return mod; + } + + const ret = {}; + + [].forEach.call(arguments, prop => { + Object.defineProperty(ret, prop, { + get: () => { + mod = lazy(mod, fn, id); + if (typeof mod[prop] === 'function') { + return function () { + return mod[prop].apply(mod, arguments); + }; + } + + return mod[prop]; + } + }); + }); + + return ret; + }; + }; +}; + +module.exports.proxy = fn => { + return id => { + let mod; + + const handler = { + get: (target, property) => { + mod = lazy(mod, fn, id); + return Reflect.get(mod, property); + }, + apply: (target, thisArg, argumentsList) => { + mod = lazy(mod, fn, id); + return Reflect.apply(mod, thisArg, argumentsList); + } + }; + + return new Proxy(() => {}, handler); + }; +}; |