# aslug

> A lossless slug that preserves uniqueness

Latest version **0.5.2** (published 2024-07-29) · MIT license · 0 weekly downloads

## Install

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

## 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.5.2 |
| Published | 2024-07-29 |
| First published | 2018-09-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=22 |
| Dependencies | 3 |
| Unpacked size | 21.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | rafamel |
| Maintainers | rafamel |
| Keywords | slug, safe, string, unique, ascii, encode, decode |

## Links

- npm: https://www.npmjs.com/package/aslug
- Repository: https://github.com/rafamel/utils
- Homepage: https://github.com/rafamel/utils/tree/master/packages/aslug
- Issues: https://github.com/rafamel/utils/issues
- npm.io page: https://npm.io/package/aslug

## Dependencies (3)

- [base-x](https://npm.io/package/base-x.md) ^5.0.0
- [unidecode](https://npm.io/package/unidecode.md) ^1.1.0
- [escape-string-regexp](https://npm.io/package/escape-string-regexp.md) ^5.0.0

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 0.5.2 (latest) — 2024-07-29
- 0.5.1 — 2024-07-17
- 0.5.0 — 2022-05-31
- 0.4.3 — 2020-07-15
- 0.4.2 — 2020-03-26
- 0.4.1 — 2020-02-09
- 0.4.0 — 2019-11-11
- 0.3.7 — 2019-07-02
- 0.3.6 — 2019-06-30
- 0.3.5 — 2019-06-02
- 0.3.4 — 2019-05-16
- 0.3.3 — 2019-05-08
- 0.3.2 — 2019-04-20
- 0.3.1 — 2019-04-20
- 0.3.0 — 2019-04-09
- … 3 more at https://npm.io/package/aslug/versions

## README

# aslug

[![Version](https://img.shields.io/npm/v/aslug.svg)](https://www.npmjs.com/package/aslug)
[![Types](https://img.shields.io/npm/types/aslug.svg)](https://www.npmjs.com/package/aslug)
[![License](https://img.shields.io/github/license/rafamel/utils.svg)](https://github.com/rafamel/utils/blob/master/LICENSE)

> A lossless slug that preserves uniqueness.

## Install

[`npm install aslug`](https://www.npmjs.com/package/aslug)

## Features

An example use case for `aslug` would be a set of *ids* that have to be made safe for some character set, while maintaining readability and ensuring they won't conflict with other valid *ids.* Hence, `aslug`:

* Produces a **readable, lossless, encoding.**
* Includes a decoder to **recover the original string.**
* Allows the character set to be modified via options.

## Usage

### `new Slug(alphabet?: string | null, options?: Slug.Options)`

* [`Slug` documentation](https://rafamel.github.io/utils/aslug/classes/Slug-1.html)

The `Slug` class optionally takes an `alphabet` *string* and an `options` *object*.

* `alphabet` defaults to: `'0123456789ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-'`
* `options` fields include:
  * A `separator` to be used between the readable string and the payload. Defaults to `'.'`.
  * A `map` function to determine the strategy to use when replacing characters with a string within `alphabet` -otherwise an empty string. It can be used to remove diacritics, leave empty, or any other alternative. Defaults to replacing characters for their *ASCII* equivalent, if in `alphabet`.

### Simple example

```javascript
import { Slug } from 'aslug';

const slug = new Slug();

slug.encode('string w/ special chars'); // string-w-special-chars.EjhdB6y8T2PsDU0e6zUv
slug.decode('string-w-special-chars.EjhdB6y8T2PsDU0e6zUv'); // string w/ special chars
```

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