diff --git a/README.md b/README.md index 2d552bfc16..8da9aed86e 100755 --- a/README.md +++ b/README.md @@ -168,6 +168,7 @@ List of Definitions * [Moment.js](https://github.com/timrwood/moment) (by [Michael Lakerveld](https://github.com/Lakerfield)) * [MongoDB](http://mongodb.github.io/node-mongodb-native/) (from TypeScript samples, updated by [Niklas Mollenhauer](https://github.com/nikeee)) * [Mousetrap](http://craig.is/killing/mice) (by [Dániel Tar](https://github.com/qcz)) +* [msgpack.js](https://github.com/uupaa/msgpack.js) (by [Shinya Mochizuki](https://github.com/enrapt-mochizuki)) * [Mustache.js](https://github.com/janl/mustache.js) (by [Boris Yankov](https://github.com/borisyankov)) * [Node.js](http://nodejs.org/) (from TypeScript samples) * [node_redis](https://github.com/mranney/node_redis) (by [Boris Yankov](https://github.com/borisyankov)) diff --git a/msgpack/msgpack-tests.ts b/msgpack/msgpack-tests.ts new file mode 100644 index 0000000000..1a4b2eb396 --- /dev/null +++ b/msgpack/msgpack-tests.ts @@ -0,0 +1,28 @@ +/// + +var packed = msgpack.pack(""); +msgpack.unpack(packed); + +var packedString = msgpack.pack("", true); +msgpack.unpack(packedString); + +var url = "http://example.com"; + +var uploadOption = { + data: "", + worker: false, + timeout: 10, + before: (xhr: XMLHttpRequest, option: MsgPackUploadOption) => { }, + after: (xhr: XMLHttpRequest, option: MsgPackUploadOption, result: MsgPackCallbackResult) => { } +}; +var uploadCallback = (data: string, option: MsgPackUploadOption, result: MsgPackCallbackResult) => { }; +msgpack.upload(url, uploadOption, uploadCallback); + +var downloadOption = { + worker: false, + timeout: 10, + before: (xhr: XMLHttpRequest, option: MsgPackDownloadOption) => { }, + after: (xhr: XMLHttpRequest, option: MsgPackDownloadOption, result: MsgPackCallbackResult) => { } +}; +var downloadCallback = (data: any, option: MsgPackDownloadOption, result: MsgPackCallbackResult) => { }; +msgpack.download(url, downloadOption, downloadCallback); diff --git a/msgpack/msgpack.d.ts b/msgpack/msgpack.d.ts new file mode 100644 index 0000000000..ff6eb5b72c --- /dev/null +++ b/msgpack/msgpack.d.ts @@ -0,0 +1,83 @@ +// Type definitions for msgpack.js - MessagePack JavaScript Implementation +// Project: https://github.com/uupaa/msgpack.js/ +// Definitions by: Shinya Mochizuki +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +interface MsgPackStatic { + /** + * @param data string or ByteArray. + * @param toString return string value if true. + * + * @return string or ByteArray or false. pack failed if false. + */ + pack(data: any, toString?: boolean): any; + + /** + * @param data string or ByteArray. + * + * @return string or ByteArray or undefined. unpack failed if undefined. + */ + unpack(data: any): any; + + worker: string; + + upload(url: string, option: MsgPackUploadOption, callback: MsgPackUploadCallback): void; + + download(url: string, option: MsgPackDownloadOption, callback: MsgPackDownloadCallback): void; +} + +interface MsgPackUploadOption { + /** + * string or ByteArray + */ + data: any; + + /** + * use WebWorker if true. + */ + worker?: boolean; + + /** + * timeout sec. + */ + timeout?: number; + + before?: (xhr: XMLHttpRequest, option: MsgPackUploadOption) => void; + + after?: (xhr: XMLHttpRequest, option: MsgPackUploadOption, result: MsgPackCallbackResult) => void; +} + +interface MsgPackUploadCallback { + (data: string, option: MsgPackUploadOption, result: MsgPackCallbackResult): void; +} + +interface MsgPackDownloadOption { + /** + * use WebWorker if true. + */ + worker?: boolean; + + /** + * timeout sec. + */ + timeout?: number; + + before?: (xhr: XMLHttpRequest, option: MsgPackDownloadOption) => void; + + after?: (xhr: XMLHttpRequest, option: MsgPackDownloadOption, result: MsgPackCallbackResult) => void; +} + +interface MsgPackDownloadCallback { + /** + * @param data string or ByteArray + */ + (data: any, option: MsgPackDownloadCallback, result: MsgPackCallbackResult): void; +} + +interface MsgPackCallbackResult { + status: number; + + ok: boolean; +} + +declare var msgpack: MsgPackStatic;