From 0346917afeb5db22eb14befbd17af1b39dd0940b Mon Sep 17 00:00:00 2001 From: Monsignor Date: Sun, 11 May 2014 11:45:26 +0200 Subject: [PATCH] Add definitions for lz-string Definitions apply to lz-string v1.3.3. --- CONTRIBUTORS.md | 1 + lz-string/lz-string-tests.ts | 12 +++++++ lz-string/lz-string.d.ts | 61 ++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 lz-string/lz-string-tests.ts create mode 100644 lz-string/lz-string.d.ts diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 01b5025d20..073ff08a9c 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -195,6 +195,7 @@ All definitions files include a header with the author and editors, so at some p * [localForage](https://github.com/mozilla/localForage) (by [david pichsenmeister](https://github.com/3x14159265)) * [Lodash](http://lodash.com/) (by [Brian Zengel](https://github.com/bczengel)) * [Logg](https://github.com/dpup/node-logg) (by [Bret Little](https://github.com/blittle)) +* [lz-string](https://github.com/pieroxy/lz-string) (by [Roman Nikitin](https://github.com/M0ns1gn0r)) * [Marked](https://github.com/chjj/marked) (by [William Orr](https://github.com/worr)) * [mCustomScrollbar](https://github.com/malihu/malihu-custom-scrollbar-plugin) (by [Sarah Williams](https://github.com/flurg)) * [Meteor](https://www.meteor.com) (by [Dave Allen](https://github.com/fullflavedave)) diff --git a/lz-string/lz-string-tests.ts b/lz-string/lz-string-tests.ts new file mode 100644 index 0000000000..48d4616458 --- /dev/null +++ b/lz-string/lz-string-tests.ts @@ -0,0 +1,12 @@ +/// + +var input = "Someting to compress"; +var encoded: string; +var decoded: string; + +encoded = LZString.compress(input); +decoded = LZString.decompress(encoded); +encoded = LZString.compressToUTF16(input); +decoded = LZString.decompressFromUTF16(encoded); +encoded = LZString.compressToBase64(input); +decoded = LZString.decompressFromBase64(encoded); \ No newline at end of file diff --git a/lz-string/lz-string.d.ts b/lz-string/lz-string.d.ts new file mode 100644 index 0000000000..60c1129331 --- /dev/null +++ b/lz-string/lz-string.d.ts @@ -0,0 +1,61 @@ +// Type definitions for lz-string v1.3.3 +// Project: https://github.com/pieroxy/lz-string +// Definitions by: Roman Nikitin +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare var LZString: LZString.LZStringStatic; + +declare module LZString { + /** + * LZ-based compression algorithm for JavaScript. + */ + interface LZStringStatic { + /** + * Compresses input string producing an instance of an "invalid" UTF-16 string. + * Such string could be stored in localStorage only on webkit + * browsers (tested on Android, Chrome, Safari). + * + * @param uncompressed A string which should be compressed. + */ + compress(uncompressed: string): string; + + /** + * Decompresses "invalid" input string created by the method compress(). + * + * @param compressed A string obtained from a call to compress(). + */ + decompress(compressed: string): string; + + /** + * Compresses input string producing an instance of a "valid" UTF-16 string, + * in the sense that all browsers can store them safely. + * + * @param uncompressed A string which should be compressed. + */ + compressToUTF16(uncompressed: string): string; + + /** + * Decompresses "valid" input string created by the method compressToUTF16(). + * + * @param compressed A string obtained from a call to compressToUTF16(). + */ + decompressFromUTF16(compressed: string): string; + + /** + * Compresses input string producing an instance of a ASCII UTF-16 string, + * which represents the original string encoded in Base64. + * The result can be safely transported outside the browser with a + * guarantee that none of the characters produced need to be URL-encoded. + * + * @param uncompressed A string which should be compressed. + */ + compressToBase64(uncompressed: string): string; + + /** + * Decompresses ASCII UTF-16 input string created by the method compressToBase64(). + * + * @param compressed A string obtained from a call to compressToBase64(). + */ + decompressFromBase64(compressed: string): string; + } +} \ No newline at end of file