# elegant-slug

> Elegant & SEO-friendly slugger

Latest version **0.0.2** (published 2020-11-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install elegant-slug
pnpm add elegant-slug
yarn add elegant-slug
bun add elegant-slug
```

## Health

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

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

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2020-11-13 |
| First published | 2020-11-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 41.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Ping Cheng |
| Maintainers | aboudicheng |
| Keywords | slug, slugify, url, utf-8, utf8, seo, unicode |

## Links

- npm: https://www.npmjs.com/package/elegant-slug
- npm.io page: https://npm.io/package/elegant-slug

## Dependencies (3)

- [uniqid](https://npm.io/package/uniqid.md) ^5.2.0
- [npm-run-all](https://npm.io/package/npm-run-all.md) ^4.1.5
- [lodash.deburr](https://npm.io/package/lodash.deburr.md) ^4.1.0

## 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

- 0.0.2 (latest) — 2020-11-13

## README

# elegant-slug

🧹 Elegant & SEO-friendly slugger for URLs

## Installation

Using npm:
```
npm install elegant-slug
```

Using yarn:
```
yarn add elegant-slug
```

## Usage

```javascript
import slug from 'elegant-slug';

slug('déjà vu');
// 'deja-vu'

slug('some title', { separator: 'underscore' });
// 'some_title'

slug('this is a really long title and it should not exceed 50 characters', {
  maxLength: 50,
});
// 'this-is-a-really-long-title'

slug('LOWERCASE---PLEASE!', {
  letterCase: 'lowercase',
});
// 'lowercase-please'

slug('مرحبا مرحبا', {
  charMap: {
    ا: 'a',
    ب: 'b',
    ح: 'h',
    ر: 'r',
    م: 'm',
  },
});
// mrhba-mrhba

slug('this is the title', { unique: true });
// this-is-the-title-fqgkhg5dra2

```

## API Documentation

`slug(str: string, options?: Options)`

**`str`**

String to be converted into a slug

**`options` (optional)**

Additional options to format the slug. See below for the available options.

### Options

| Name                      | Default | Type | Description |
| ------------------------- | ------- | ---- | ------------|
| separator | 'hyphen'  | 'hyphen' \| 'underscore' | The separator symbol that will be used in between the concatenated strings. `hyphen` uses the `-` symbol while `underscore` uses the `_` symbol. |
| maxLength | | number | The maximum length of the converted slug. Once exceeding the specified length, the words get cropped out. |
| letterCase |  | 'lowercase' \| 'uppercase' \| 'capitalize' | The letter case the slug should be transformed into. If nothing is provided, the original casing will be used. |
| unique | | boolean | If set to `true`, a unique id generated using [`uniqid`](https://github.com/adamhalasz/uniqid/) will be appended to the end of the slug. |
| charMap | | Record<string, string> | A map of key-value pairs that are used to replace occurrences with the given values. |

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