# varname

> Convert strings between different variable naming formats

Latest version **8.1.0** (published 2026-09-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install varname
pnpm add varname
yarn add varname
bun add varname
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 8.1.0 |
| Published | 2026-09-11 |
| First published | 2013-02-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | 22.x \|\| 24.x \|\| 26.x |
| Dependencies | 0 |
| Unpacked size | 9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 1 |
| Author | Rowan Manning |
| Maintainers | rowanmanning |
| Keywords | camelcase, camelback, naming, string, variable |

## Links

- npm: https://www.npmjs.com/package/varname
- Repository: https://github.com/rowanmanning/varname
- Issues: https://github.com/rowanmanning/varname/issues
- npm.io page: https://npm.io/package/varname

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 8.1.0 (latest) — 2026-09-11
- 8.0.0 — 2026-09-11
- 7.1.0 — 2025-05-21
- 7.0.0 — 2025-03-04
- 6.2.1 — 2024-07-27
- 6.2.0 — 2024-06-23
- 6.1.0 — 2024-01-30
- 6.0.0 — 2023-09-11
- 5.0.2 — 2023-07-25
- 5.0.1 — 2023-04-18
- 5.0.0 — 2023-03-25
- 4.1.4 — 2023-02-14
- 4.1.3 — 2023-01-08
- 4.1.2 — 2022-11-14
- 4.1.1 — 2022-07-09
- … 13 more at https://npm.io/package/varname/versions

## README

# Varname

Convert strings between different variable naming formats.


## Table of Contents

  * [Requirements](#requirements)
  * [Usage](#usage)
  * [Contributing](#contributing)
  * [License](#license)


## Requirements

This library requires the following to run:

  * [Node.js](https://nodejs.org/) 22+


## Usage

Install with [npm](https://www.npmjs.com/):

```sh
npm install varname
```

Import the library into your code:

```js
import * as varname from 'varname';
// or
import { camelback, camelcase, dash, split, underscore } from 'varname';
```


### varname.camelback( name )

Convert a variable name to camelBack format (capitalize the first letter of all but the first word).  
**name:** *(string)* The variable name to convert.  
**return:** *(string)* Returns the converted variable name.

```js
varname.camelback('foo_bar_baz'); // 'fooBarBaz'
```


### varname.camelcase( name )

Convert a variable name to CamelCase format (capitalize the first letter of each word).  
**name:** *(string)* The variable name to convert.  
**return:** *(string)* Returns the converted variable name.

```js
varname.camelcase('foo_bar_baz'); // 'FooBarBaz'
```


### varname.dash( name )

Convert a variable name to dash format.  
**name:** *(string)* The variable name to convert.  
**return:** *(string)* Returns the converted variable name.

```js
varname.dash('FooBarBaz'); // 'foo-bar-baz'
```


### varname.underscore( name )

Convert a variable name to underscore format.  
**name:** *(string)* The variable name to convert.  
**return:** *(string)* Returns the converted variable name.

```js
varname.underscore('FooBarBaz'); // 'foo_bar_baz'
```


### varname.split( name )

Split a string into separate variable parts. This allows you to write your own format converters easily.
**name:** *(string)* The variable name to split.  
**return:** *(array)* Returns an array of parts.

```js
varname.split('fooBarBaz');
varname.split('FooBarBaz');
varname.split('FOOBarBAZ');
varname.split('foo-bar-baz');
varname.split('foo_bar_baz');
varname.split('♥~foo|bar|baz~♥');
// all return ['foo', 'bar', 'baz']
```


## Contributing

[The contributing guide is available here](docs/contributing.md). All contributors must follow [this library's code of conduct](docs/code_of_conduct.md).


## License

Licensed under the [MIT](LICENSE) license.<br/>
Copyright &copy; 2015, Rowan Manning

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