# @hugov/shorter-string

> short string compression using Burrows-Wheeler transform, move to front and Elias-gamma variable length encoding

Latest version **6.1.0** (published 2023-10-01) · ISC license · 0 weekly downloads

## Install

```sh
npm install @hugov/shorter-string
pnpm add @hugov/shorter-string
yarn add @hugov/shorter-string
bun add @hugov/shorter-string
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 6.1.0 |
| Published | 2023-10-01 |
| First published | 2021-04-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Hugo Villeneuve |
| Maintainers | hugov |
| Keywords | bwt, Burrows-Wheeler transform, mtf, move to front, Elias-gamma, vle, variable length encoding, compression, compressURIComponent |

## Links

- npm: https://www.npmjs.com/package/@hugov/shorter-string
- Repository: https://github.com/hville/shorter-string
- Homepage: https://github.com/hville/shorter-string#readme
- Issues: https://github.com/hville/shorter-string/issues
- npm.io page: https://npm.io/package/@hugov/shorter-string

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 6.1.0 (latest) — 2023-10-01
- 6.0.0 — 2023-09-30
- 5.0.0 — 2023-03-23
- 4.0.1 — 2022-02-27
- 4.0.0 — 2022-02-27
- 3.0.1 — 2022-02-21
- 3.0.0 — 2022-02-21
- 2.0.0 — 2022-02-21
- 1.0.0 — 2022-02-20
- 0.2.1 — 2021-06-12
- 0.2.0 — 2021-05-29
- 0.1.0 — 2021-05-11
- 0.0.3 — 2021-04-25
- 0.0.2 — 2021-04-25
- 0.0.1 — 2021-04-25

## README

<!-- markdownlint-disable MD004 MD007 MD010 MD041 MD022 MD024 MD029 MD031 MD032 MD034 MD036 -->
# shorter-string

*small string to string compression for short strings using Burrows-Wheeler transform (BWT), move to front (MTF) and Elias-gamma variable length encoding*

• [Example](#example) • [API](#api) • [Notes](#notes) • [License](#license)

## Example

```javascript
import {encode, decode} from './index.js'

const text = `Si six chasseurs savent chasser sans six chiens, soixante-six chasseurs savent chasser sans soixante-six chiens.`,

const code = encode(text)
// 'PFp_Dd#sCa;F/f+QjYY/IEqySuqvq2JQ&=a2*?org~9T+r.:qp,yW6q

console.log( decode(code) === text),  )
// true, with 50% compression in character length
```

## API

exports            | Note
------------------ | -------------------------------
**string constants**|
BASE62             | `0-9A-Za-z`
BASE64             | BASE62 + `-_`
UNRESERVED         | BASE62 + `-._~`; [RFC 3986](https://tools.ietf.org/html/rfc3986) base:66
PCHAR              | UNRESERVED + `%!$&'()*+,;=:@`; [RFC 3986](https://tools.ietf.org/html/rfc3986) base:80
QUERY              | PCHAR without `'` for [chrome](https://bugs.chromium.org/p/chromium/issues/detail?id=292740) base:79
RFC1924            | [RFC1924](https://datatracker.ietf.org/doc/html/rfc192485) base:85
HASH               | PCHAR + `/?#`; base:83
**functions**      |
encode             | `( text:string, [keys:string=HASH] ) => code:string`
decode:            | `( code:string, [keys:string=HASH] ) => text:string`

## Notes

* inpired from the blog post [reddad.ca/2020/09/27/burrows-wheeler-revisited](https://reddad.ca/2020/09/27/burrows-wheeler-revisited/)
* modified to facilitate URI friendly encoding
* optimized for short strings
* not optimized for large inputs
* other alternatives considered
  * lz-string (small but no es6 exports and not the best compression for URI components)
  * lzbase62 (better compression)
  * lzutf8 (best compression, too big at 68.5 kb minified, no es6 exports)

[Live Demo](<https://schem.ist/bwt/index.html#en/exi_hL?ZiKNQ$_GjNm7p@).PdmyIa1Up%T%(+'K_jiUzi!=LTIkOd,C;>)


# License

[MIT](http://www.opensource.org/licenses/MIT) © [Hugo Villeneuve](https://github.com/hville)

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