# has-require

> Check if code requires any module or a specific id

Latest version **1.2.2** (published 2016-02-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install has-require
pnpm add has-require
yarn add has-require
bun add has-require
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.2 |
| Published | 2016-02-11 |
| First published | 2015-01-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Ben Drucker |
| Maintainers | bendrucker |
| Keywords | require, browserify |

## Links

- npm: https://www.npmjs.com/package/has-require
- Repository: https://github.com/bendrucker/has-require
- Issues: https://github.com/bendrucker/has-require/issues
- npm.io page: https://npm.io/package/has-require

## Dependencies (1)

- [escape-string-regexp](https://npm.io/package/escape-string-regexp.md) ^1.0.3

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.2.2 (latest) — 2016-02-11
- 1.2.1 — 2015-06-23
- 1.2.0 — 2015-06-05
- 1.1.0 — 2015-01-13
- 1.0.0 — 2015-01-13

## README

# has-require [![Build Status](https://travis-ci.org/bendrucker/has-require.svg?branch=master)](https://travis-ci.org/bendrucker/has-require)

> Check if code requires any module or a specific id

## Installing

```bash
$ npm install --save has-require
```

## Usage

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

## API

For full implementation details, see the [`Checker`](#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.

<hr>

### `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](http://bendrucker.me)

---
_Source: https://npm.io/package/has-require · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
