# match-require

> find require calls from string using regexp

Latest version **2.1.0** (published 2017-03-31) · 0 weekly downloads

## Install

```sh
npm install match-require
pnpm add match-require
yarn add match-require
bun add match-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 | 2.1.0 |
| Published | 2017-03-31 |
| First published | 2015-06-29 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 16 |
| Author | yiminghe@gmail.com |
| Maintainers | yiminghe |
| Keywords | require, regexp |

## Links

- npm: https://www.npmjs.com/package/match-require
- Repository: https://github.com/yiminghe/match-require
- Homepage: http://github.com/yiminghe/match-require
- Issues: http://github.com/yiminghe/match-require/issues
- npm.io page: https://npm.io/package/match-require

## Dependencies (1)

- [uuid](https://npm.io/package/uuid.md) ^3.0.0

## Recent versions

- 2.1.0 (latest) — 2017-03-31
- 2.0.1 — 2017-03-03
- 2.0.0 — 2016-06-08
- 1.1.1 — 2015-07-14
- 1.1.0 — 2015-07-07
- 1.0.3 — 2015-07-07
- 1.0.2 — 2015-06-29
- 1.0.1 — 2015-06-29
- 1.0.0 — 2015-06-29

## README

# match-require

[![NPM version](https://nodei.co/npm/match-require.png)](https://npmjs.org/package/match-require)
[![NPM downloads](http://img.shields.io/npm/dm/match-require.svg)](https://npmjs.org/package/match-require)
[![Build Status](https://travis-ci.org/yiminghe/match-require.svg?branch=master)](https://travis-ci.org/yiminghe/match-require)
[![Coverage Status](https://coveralls.io/repos/yiminghe/match-require/badge.svg?branch=master)](https://coveralls.io/r/yiminghe/match-require?branch=master)

find/replace dependencies using regexp

## examples

```js
const matchRequire = require('match-require');

  it('findAll works', () => {
    const content = ['// require("2")',
      'require("3");',
      '/* require("2") */',
      'require("4")'
    ].join('\n');

    const ret = matchRequire.findAll(content);

    expect(ret).to.eql(['3', '4']);
  });

  it('replaceAll works', () => {
    const content = ['// require("2")',
      'require("3");',
      '/* require("2") */',
      'require("4")'
    ].join('\n');

    const ret = matchRequire.replaceAll(content, (dep) => {
      return dep === '4' ? '5' : dep;
    });

    expect(ret).to.eql([
      'require("3");',
      '',
      'require("5")'
    ].join('\n'));
  });

  it('import works', () => {
    const content = ['// import "2"',
      'import x from "3";',
      'console.import("1")',
      '/* import "2" */',
      'import {z} from "4";',
      `import {
 x,
 y,
 z,
} from "5";`,
    ].join('\n');

    const ret = matchRequire.findAll(content);

    expect(ret).to.eql(['3', '4', '5']);
  });

```

## history

### 2.1.0

- add replaceAll

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