diff --git a/types/md5/index.d.ts b/types/md5/index.d.ts index 071c5306fc..550b07c648 100644 --- a/types/md5/index.d.ts +++ b/types/md5/index.d.ts @@ -1,6 +1,8 @@ -// Type definitions for md5 v2.1.0 +// Type definitions for md5 2.2 // Project: https://github.com/pvorb/node-md5 -// Definitions by: Bill Sourour , Cameron Crothers +// Definitions by: Bill Sourour +// Cameron Crothers +// Piotr Błażejewicz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -8,11 +10,18 @@ /** * js function for hashing messages with MD5 * - * @param {(string | Buffer)} message - a string or buffer to hash - * @returns {string} the resultant MD5 hash of the given message + * @param message - a string or buffer to hash + * @param options + * @returns the resultant MD5 hash of the given message */ -declare function md5(message: string | Buffer | Array): string; +declare function md5(message: string | Buffer | number[], options?: md5.Options): string; -declare namespace md5 {} +declare namespace md5 { + interface Options { + asBytes?: boolean; + asString?: boolean; + encoding?: 'binary' | string; + } +} export = md5; diff --git a/types/md5/md5-tests.ts b/types/md5/md5-tests.ts index 9e7cc52ef2..107ebbacc4 100644 --- a/types/md5/md5-tests.ts +++ b/types/md5/md5-tests.ts @@ -1,34 +1,13 @@ -import md5 = require("md5"); -/** - * API - * md5(message) - * message -- String or Buffer - * returns String - * - * Usage - **************************************************** - * var md5 = require('md5'); * - * console.log(md5('message')); * - **************************************************** - * This will print the following - * 78e731027d8fd50ed642340b7c9a63b3 - * - * It supports buffers, too - **************************************************** - * var fs = require('fs'); * - * var md5 = require('md5'); * - * * - * fs.readFile('example.txt', function(err, buf) { * - * console.log(md5(buf)); * - * }); * - * ************************************************** - */ -const message = 'message'; +import md5 = require('md5'); +const message = 'message'; console.log(md5(message)); // should print 78e731027d8fd50ed642340b7c9a63b3 const array = new Array(message.length); -for (let i = 0; i < message.length; ++i) - array[i] = message.charCodeAt(i); +for (let i = 0; i < message.length; ++i) array[i] = message.charCodeAt(i); const buffer = new Buffer(array); -console.log(md5(buffer)); // Should be same result as above. +console.log(md5(buffer)); // Should be same result as above. + +const hash1 = md5('abc', { asString: true }); +const hash2 = md5(hash1 + 'a', { asString: true, encoding: 'binary' }); +const hash3 = md5(hash1 + 'a', { encoding: 'binary' }); diff --git a/types/md5/tslint.json b/types/md5/tslint.json index 92c1202c0e..3db14f85ea 100644 --- a/types/md5/tslint.json +++ b/types/md5/tslint.json @@ -1,12 +1 @@ -{ - "extends": "dtslint/dt.json", - "rules": { - "array-type": false, - "callable-types": false, - "dt-header": false, - "jsdoc-format": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "prefer-method-signature": false - } -} \ No newline at end of file +{ "extends": "dtslint/dt.json" }