diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index a4fce2940..fe3392479 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -52,6 +52,7 @@ All definitions files include a header with the author and editors, so at some p * [bunyan-logentries](https://github.com/nemtsov/node-bunyan-logentries) (by [Aymeric Beaumet](http://aymericbeaumet.me)) * [CasperJS](http://casperjs.org) (by [Jed Mao](https://github.com/jedmao)) * [CanvasJS](http://canvasjs.com) (by [Mark Overholt](https://github.com/mover5)) +* [checksum](https://github.com/dshaw/checksum) (by [Rogier Schouten](https://github.com/rogierschouten)) * [Cheerio](https://github.com/MatthewMueller/cheerio) (by [Bret Little](https://github.com/blittle)) * [Chosen](http://harvesthq.github.com/chosen/) (by [Boris Yankov](https://github.com/borisyankov)) * [Chroma.js](https://github.com/gka/chroma.js) (by [Sebastian Brückner](https://github.com/invliD)) diff --git a/checksum/checksum-tests.ts b/checksum/checksum-tests.ts new file mode 100644 index 000000000..de9faaa98 --- /dev/null +++ b/checksum/checksum-tests.ts @@ -0,0 +1,14 @@ +/// + +import checksum = require("checksum"); + +var s: string = checksum("abcd"); +var t: string = checksum("abcd", { algorithm: 'sha1' }); + +checksum.file("myfile.txt", (error: Error, hash: string): void => { + // do nothing +}); + +checksum.file("myfile.txt", { algorithm: 'sha1' }, (error: Error, hash: string): void => { + // do nothing +}); diff --git a/checksum/checksum.d.ts b/checksum/checksum.d.ts new file mode 100644 index 000000000..63f24224e --- /dev/null +++ b/checksum/checksum.d.ts @@ -0,0 +1,44 @@ +// Type definitions for checksum 0.1.1 +// Project: https://github.com/dshaw/checksum +// Definitions by: Rogier Schouten +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "checksum" { + + module checksum { + /** + * Options object for all functions + */ + interface ChecksumOptions { + /** + * Algorithm to use, default 'sha1' + * Can be 'sha1' or 'md5' (see module 'crypto'). + */ + algorithm?: string; + } + + /** + * Generate the checksum for a file on disk + * @param filename The file name + * @param callback Callback which is called with the result or an error + */ + function file(filename: string, callback: (error: Error, hash: string) => void): void; + /** + * Generate the checksum for a file on disk + * @param filename The file name + * @param options Options object to indicate hash algo + * @param callback Callback which is called with the result or an error + */ + function file(filename: string, options: ChecksumOptions, callback: (error: Error, hash: string) => void): void; + } + + /** + * Generates a checksum for the given value + * @param value Any value + * @param options Allows to set the algorithm + * @returns Checksum + */ + function checksum(value: any, options?: checksum.ChecksumOptions): string; + + export = checksum; +}