has-require
Check if code requires any module or a specific id
Last updated 9 years ago by bendrucker .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install has-require 
SYNC missed versions from official npm registry.

has-require Build Status

Check if code requires any module or a specific id

Installing

$ npm install --save has-require

Usage

var hasRequire = require('has-require')
hasRequire('require("foo")', 'foo') // => true
hasRequire.any('require') // => false

API

For full implementation details, see the Checker API.

hasRequire(code, id) -> boolean

code

Required
Type: string

The code to check.

id

Required
Type: string

The module id to check, e.g. 'http'.

hasRequire.any(code) -> boolean

code

Required
Type: string

The code to check.


Checker

new hasRequire.Checker(code) -> checker

code

Required
Type: string

The code to store on the checker.

checker.any() -> boolean

Checks if any string literal is required. The result is cached. The following code won't be matched:

  • require
  • require()
  • require('')
checker.has(id) -> boolean
id

Required
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.

License

MIT © Ben Drucker

Current Tags

  • 1.2.2                                ...           latest (9 years ago)

5 Versions

  • 1.2.2                                ...           9 years ago
  • 1.2.1                                ...           9 years ago
  • 1.2.0                                ...           10 years ago
  • 1.1.0                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (2)
Dependents (2)

Copyright 2013 - present © cnpmjs.org | Home |