mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
'md5.d.ts' doesn't exist in the repository, so running md5-test fails. Stop reading a file just for acquiring `Buffer`, and create it from array. ---- Please fill in this template. - [x] Use a meaningful title for the pull request. Include the name of the package modified. - [x] Test the change in your own code. (Compile and run.) - [x] Add or edit tests to reflect the change. (Run with `npm test`.) - [x] Follow the advice from the [readme](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#make-a-pull-request). - [x] Avoid [common mistakes](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#common-mistakes). - [x] Run `npm run lint package-name` (or `tsc` if no `tslint.json` is present). Select one of these and delete the others: If changing an existing definition: - ~~[ ] Provide a URL to documentation or source code which provides context for the suggested changes: <<url here>>~~ - ~~[ ] Increase the version number in the header if appropriate.~~ - ~~[ ] If you are making substantial changes, consider adding a `tslint.json` containing `{ "extends": "dtslint/dt.json" }`.~~
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
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';
|
|
|
|
console.log(md5(message)); // should print 78e731027d8fd50ed642340b7c9a63b3
|
|
|
|
const array = new Array<number>(message.length);
|
|
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.
|