LZW is a compression algorithm which can be used to compress a configuration into a smaller format for sharing. The LZW Utility offers two methods, .encode()
and .decode()
.
import LZW from '@nycopportunity/pttrn-scripts/src/lzw/lzw';
let myConfig = {
'key': 'value'
};
let myConfigBase64 = btoa(JSON.strinify(myConfig));
// Accepts a Base64 encoded string.
let myConfigLZW = LZW.encode(myConfigBase64);
let myConfig = JSON.parse(atob(LZW.decode(myConfigLZW)));
// Accepts a Base64 decoded string.
LZW.decode(myConfig);