{"_id":"try-require","_rev":"4177176","name":"try-require","description":"Conditional load modules.","dist-tags":{"latest":"1.2.1"},"maintainers":[{"name":"rrragan","email":""}],"time":{"modified":"2026-03-01T21:37:24.000Z","created":"2014-10-22T04:52:39.441Z","1.2.1":"2015-05-21T23:22:57.842Z","1.1.0":"2015-05-19T04:07:36.784Z","1.0.0":"2014-10-22T04:52:39.441Z"},"users":{},"author":{"name":"Richard Ragan"},"repository":{"type":"git","url":"git://github.com/rragan/try-require.git"},"versions":{"1.2.1":{"name":"try-require","version":"1.2.1","description":"Conditional load modules.","repository":{"type":"git","url":"git://github.com/rragan/try-require.git"},"author":{"name":"Richard Ragan"},"dependencies":{},"devDependencies":{"mocha":"2.2.5","async":"1.0.0"},"scripts":{"test":"npm update; node_modules/mocha/bin/mocha -b -u tdd --reporter list test/*.test.js"},"license":"MIT","main":"./index.js","gitHead":"fe64842e775838042f7749269856dd759972b89b","bugs":{"url":"https://github.com/rragan/try-require/issues"},"homepage":"https://github.com/rragan/try-require","_id":"try-require@1.2.1","_shasum":"34489a2cac0c09c1cc10ed91ba011594d4333be2","_from":".","_npmVersion":"2.5.1","_nodeVersion":"0.12.0","_npmUser":{"name":"rrragan","email":"rragan@gmail.com"},"maintainers":[{"name":"rrragan","email":""}],"dist":{"shasum":"34489a2cac0c09c1cc10ed91ba011594d4333be2","size":2116,"noattachment":false,"key":"/try-require/-/try-require-1.2.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/try-require/download/try-require-1.2.1.tgz"},"directories":{},"publish_time":1432250577842,"_hasShrinkwrap":false,"_cnpm_publish_time":1432250577842,"_cnpmcore_publish_time":"2021-12-16T19:37:07.428Z"},"1.1.0":{"name":"try-require","version":"1.1.0","description":"Conditional load modules.","repository":{"type":"git","url":"git://github.com/rragan/try-require.git"},"author":{"name":"Richard Ragan"},"dependencies":{},"license":"MIT","main":"./index.js","gitHead":"fabdc896e3b864df48232b87bd6e70fb6dbfeea2","bugs":{"url":"https://github.com/rragan/try-require/issues"},"homepage":"https://github.com/rragan/try-require","_id":"try-require@1.1.0","scripts":{},"_shasum":"2556d57cb73371e9d1ccb20378c4672b67f56d08","_from":".","_npmVersion":"2.5.1","_nodeVersion":"0.12.0","_npmUser":{"name":"rrragan","email":"rragan@gmail.com"},"maintainers":[{"name":"rrragan","email":""}],"dist":{"shasum":"2556d57cb73371e9d1ccb20378c4672b67f56d08","size":1066,"noattachment":false,"key":"/try-require/-/try-require-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/try-require/download/try-require-1.1.0.tgz"},"directories":{},"publish_time":1432008456784,"_hasShrinkwrap":false,"_cnpm_publish_time":1432008456784,"_cnpmcore_publish_time":"2021-12-16T19:37:07.649Z"},"1.0.0":{"name":"try-require","version":"1.0.0","description":"Conditional load modules.","repository":{"type":"git","url":"git://github.com/rragan/try-require.git"},"author":{"name":"Richard Ragan"},"dependencies":{},"license":"MIT","main":"./index.js","gitHead":"172e9662b6c7e931f1614d74239baad11bf141ab","bugs":{"url":"https://github.com/rragan/try-require/issues"},"homepage":"https://github.com/rragan/try-require","_id":"try-require@1.0.0","scripts":{},"_shasum":"38d6f1a8ad67ebd96dfe7aab2884d904a8a9583f","_from":".","_npmVersion":"1.4.23","_npmUser":{"name":"rrragan","email":"rragan@gmail.com"},"maintainers":[{"name":"rrragan","email":""}],"dist":{"shasum":"38d6f1a8ad67ebd96dfe7aab2884d904a8a9583f","size":1056,"noattachment":false,"key":"/try-require/-/try-require-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/try-require/download/try-require-1.0.0.tgz"},"directories":{},"publish_time":1413953559441,"_hasShrinkwrap":false,"_cnpm_publish_time":1413953559441,"_cnpmcore_publish_time":"2021-12-16T19:37:07.854Z"}},"readme":"try-require\n===========\n\ntry/require mechanism to conditionally load a module using require.\n\n# Installation\n```bash\nnpm install try-require --save\n```\n\n# Usage\n\ntry-require lets you try to require a module and not fail if the\nmodule is not installed. You could do this inline but the try/catch\nblock will prevent V8 from optimizing your entire function. Therefore,\nmaking try-require standalone means only this module is not optimizable.\n\nSometimes you don't need to load the module, just determine if it is available.\nFor this, a `resolve` function is provided with `try-require.``\n\n```javascript\n// Conditionally require a module\nvar tryRequire = require('try-require');\nvar maybe = tryRequire('maybeModule');\n\n// If `maybeModule` is not available, then `maybe` will\n// be undefined. If available it is equivalent to:\n// var maybe = require('maybeModule');\n```\n\n```javascript\n// Determine if a module is available without loading it into memory\nvar tryRequire = require('try-require');\nvar maybePath = tryRequire.resolve('maybeModule');\n\n// If available, maybePath holds the path to the module\n// and the module is not loaded. If `maybeModule` is not available,\n// then `maybePath` will be undefined.\n```\n\nOptionally, check require and resolution exceptions with lastError. Note that\nlastError will return null if no error has ever been triggered, or if the most\nrecent call to require or resolve was successful.\n\n```javascript\nvar tryRequire = require('try-require');\nvar maybe = tryRequire('notAModule');\n\nconsole.error( tryRequire.lastError() );\n```\n\nNote that both tryRequire and tryRequire.resolve accept an optional second\nargument if you want to provide your own version of require.\n\n# Contribute\n\nIf you would like to add to this library, please ensure that all existing test\ncases pass and that all new code has proper test coverage in test/all.test.js. \n\nTo run tests, simply execute:\n\n```bash\nnpm test\n```\n\nAlso, match styles within the project where language of the file allows. Some \ncore styles to follow are:\n\n- indent lines with 4 spaces\n- spaces around parameters in function definitions and calls\n- opening/closing brackets on same line\n\n# License\n\nMIT\n","_attachments":{},"homepage":"https://github.com/rragan/try-require","bugs":{"url":"https://github.com/rragan/try-require/issues"},"license":"MIT"}