1. has-require
Check if code requires any module or a specific id
has-require
Package: has-require
Created by: bendrucker
Last modified: Sat, 18 Jun 2022 19:26:07 GMT
Version: 1.2.2
License: MIT
Downloads: 123,800
Repository: https://github.com/bendrucker/has-require

Install

npm install has-require
yarn add has-require

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

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code