$ gnpm install has-require
Check if code requires any module or a specific id
$ npm install --save has-require
var hasRequire = require('has-require')
hasRequire('require("foo")', 'foo') // => true
hasRequire.any('require') // => false
For full implementation details, see the Checker API.
hasRequire(code, id) -> booleanRequired
Type: string
The code to check.
Required
Type: string
The module id to check, e.g. 'http'.
hasRequire.any(code) -> booleanRequired
Type: string
The code to check.
Checkernew hasRequire.Checker(code) -> checkerRequired
Type: string
The code to store on the checker.
checker.any() -> booleanChecks if any string literal is required. The result is cached. The following code won't be matched:
requirerequire()require('')checker.has(id) -> booleanRequired
Type: string
The module id to check, e.g. 'http'.
Uses checker.any() first, so calling has for multiple ids when no require is present (!checker.any()) will avoid needlessly re-testing the code.
MIT © Ben Drucker
Copyright 2013 - present © cnpmjs.org | Home |