Socket
Socket
Sign inDemoInstall

has-require

Package Overview
Dependencies
1
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    has-require

Check if code requires any module or a specific id


Version published
Weekly downloads
28K
increased by0.61%
Maintainers
1
Install size
10.6 kB
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Last updated on 11 Feb 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc