6.1.0 • Published 7 months ago

@hugov/shorter-string v6.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
7 months ago

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

ExampleAPINotesLicense

Example

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

exportsNote
string constants
BASE620-9A-Za-z
BASE64BASE62 + -_
UNRESERVEDBASE62 + -._~; RFC 3986 base:66
PCHARUNRESERVED + %!$&'()*+,;=:@; RFC 3986 base:80
QUERYPCHAR without ' for chrome base:79
RFC1924RFC1924 base:85
HASHPCHAR + /?#; 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
  • 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

License

MIT © Hugo Villeneuve

6.1.0

7 months ago

6.0.0

7 months ago

5.0.0

1 year ago

4.0.1

2 years ago

4.0.0

2 years ago

1.0.0

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.0.0

2 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago