# require-package-name

> gets the package name for a require statement

Latest version **2.0.1** (published 2015-05-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install require-package-name
pnpm add require-package-name
yarn add require-package-name
bun add require-package-name
```

## 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.0.1 |
| Published | 2015-05-07 |
| First published | 2015-04-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Matt DesLauriers |
| Maintainers | mattdesl |
| Keywords | package, name, regex, split, base, basedir, basepath, path, require, requires, npm, module |

## Links

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

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 2.0.1 (latest) — 2015-05-07
- 2.0.0 — 2015-04-26
- 1.0.0 — 2015-04-26

## README

# require-package-name

[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)

Gets the base package name for a module path in a require statement. Assumes the path [is not relative](https://www.npmjs.com/package/relative-require-regex).

```js
var name = require('require-package-name')

//get the module name for a require path
name('events')                  => 'events'
name('events/')                 => 'events'
name('events/index.js')         => 'events'
name('@username/button/a.js')   => '@username/button'
name('@username//foo/a.js')     => '@username/foo'

//or, get the base name excluding any scope
name.base('@username/button/a.js')   => 'button'
name.base('@username//foo/a.js')     => 'foo'
```

## Usage

[![NPM](https://nodei.co/npm/require-package-name.png)](https://www.npmjs.com/package/require-package-name)

#### `name = packageName(str)`

Gets the name of a module for a require string like `'xtend'` from `'xtend/mutable.js'`.

#### `base = packageName.base(str)`

Gets the *base* name of a module. This is the same as above, except it excludes scoped usernames.

## License

MIT, see [LICENSE.md](http://github.com/mattdesl/require-package-name/blob/master/LICENSE.md) for details.

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