# to-caption

> Converts camelCase and delimited strings to captions

Latest version **1.1.3** (published 2019-05-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install to-caption
pnpm add to-caption
yarn add to-caption
bun add to-caption
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.3 |
| Published | 2019-05-18 |
| First published | 2017-01-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 20.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Steven Spungin |
| Maintainers | spungin |
| Keywords | label, caption, camelcase, snakecase, ui, gui, editor |

## Links

- npm: https://www.npmjs.com/package/to-caption
- Repository: https://github.com/flamenco/to-caption
- Homepage: https://github.com/flamenco/to-caption#readme
- Issues: https://github.com/flamenco/to-caption/issues
- npm.io page: https://npm.io/package/to-caption

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.1.3 (latest) — 2019-05-18
- 1.1.2 — 2019-05-09
- 1.1.1 — 2019-05-09
- 1.1.0 — 2019-05-09
- 1.0.4 — 2019-04-27
- 1.0.3 — 2017-01-07
- 1.0.2 — 2017-01-07
- 1.0.1 — 2017-01-07
- 1.0.0 — 2017-01-07

## README

# to-caption

Converts camelCase and delimited strings to captions.

>Delimiters are dot, underscore, and dash. \[ . _ - \]

## Examples
foo.bar / foo_bar / fooBar / foo-bar
>Foo Bar

\_hello_world\_
>Hello World

thisIsATest
>This Is A Test

## Usage
### Node / NPM
```bash
npm install --save to-caption
```

```javascript
const toCaption = require('to-caption');
const myCaption = toCaption('helloWorld');
// myCaption should now be 'Hello World';
```
### Browser
A webpacked distribution is included at dist/toCaption.js.  The function is exported at `window.toCaption(...)`
```html
<html>
<head>
  <script src="../dist/bundle.js"></script>
  <script>
    console.log(toCaption('helloWorld'))
  </script>
</head>
</html>
```


## Rules
* Delimiters are period, dash, and underscore.
* Leading and trailing delimiters are ignored.
* The first non-delimited character is capitalized (if not already capitalized).
* Underscores, dots, and slashes are replaced with spaces and the following non-delimiter character is uppercased.
* Uppercase letters are prefixed with spaces.

# More Samples
This table should give you an idea of the process.

ID|Label| Comment
-|-|-
this.is.a.test | This Is A Test
foo|Foo
Foo|Foo
foobar|Foobar
fooBar| Foo Bar
foo_bar | Foo Bar
foo.bar| Foo Bar
foo-bar | Foo Bar
\_foo|Foo
foo_ | Foo
\_foo\_| Foo
\_foo_bar\_ | Foo Bar
\_\_foo | Foo
foo\_\_ | Foo
\-\-foo--bar\-\- | Foo Bar
FOOBAR | F O O B A R | See option for `onAllUppercase` to avoid this behavior.
FOOBAR | FOOBAR | onAllUppercase = 'keep'
FOOBAR | Foobar | onAllUppercase = 'titlecase'

# Options

## onAllUppercase

```
toCaption('HELLO', {onAllUppercase: 'keep'})
```

This option will set the default behavior when the string is all uppercase
### 'keep'
The string will remain all uppercase. (HELLO)

### 'titlecase'
The string will become titlecase. (Hello)

### 'default', undefined, null, or anything else
The string will have spaces between each letter, as if each letter was a word. (H E L L O)

# License
MIT. Check the LICENSE file for all the details.

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