Skip to content

Commit

Permalink
Move to ESM and require minimum node 16 (#32)
Browse files Browse the repository at this point in the history
* Refactor: move to [ESM](https://nodejs.org/api/esm.html), refer to https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
* Update doc and comments.
* Require minimum node version 16.
  • Loading branch information
huiyifyj committed Jan 5, 2024
1 parent a0f803d commit d8b232d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -16,8 +16,7 @@ npm i @xn-02f/md5
## Usage

```javascript
const md5 = require('@xn-02f/md5');
// import md5 from '@xn-02f/md5'
import md5 from '@xn-02f/md5'

md5('xn-02f'); // => '54d30fa674d13e3598970bc9c5e2388e'
```
Expand Down
5 changes: 2 additions & 3 deletions md5.d.ts
Expand Up @@ -5,11 +5,10 @@
* @return {string} The hexadecimal hash string that is handled and converted.
* @example
* ```
* import md5 = require('@xn-02f/md5');
* // import md5 from '@xn-02f/md5';
* import md5 from '@xn-02f/md5';
* md5('xn-02f'); //=> '54d30fa674d13e3598970bc9c5e2388e'
* ```
*/
declare const md5: (data: string) => string;

export = md5;
export default md5;
5 changes: 2 additions & 3 deletions md5.js
Expand Up @@ -11,12 +11,11 @@
* @return {string} The hexadecimal hash string that is handled and converted.
* @example
* ```
* const md5 = require('@xn-02f/md5');
* // import md5 from '@xn-02f/md5';
* import md5 from '@xn-02f/md5';
* md5('xn-02f'); //=> '54d30fa674d13e3598970bc9c5e2388e'
* ```
*/
module.exports = data => {
export default data => {
const stringUTF8 = unescape(encodeURIComponent(data));

const stringNumArr = rstr2binl(stringUTF8);
Expand Down
5 changes: 5 additions & 0 deletions package.json
Expand Up @@ -2,6 +2,8 @@
"name": "@xn-02f/md5",
"version": "2.4.4",
"description": "A tiny MD5 library without dependencies for node, convert string to MD5 hash.",
"type": "module",
"exports": "./md5.js",
"main": "md5.js",
"types": "md5.d.ts",
"scripts": {
Expand All @@ -24,6 +26,9 @@
"ava": "5.x",
"tsd": "^0.28.1"
},
"engines": {
"node": ">=16"
},
"files": [
"md5.js",
"md5.d.ts"
Expand Down
4 changes: 2 additions & 2 deletions test/md5.test.js
@@ -1,9 +1,9 @@
/*
* This file is used to test.
*/
const test = require('ava');
import test from 'ava';

const md5 = require('../md5');
import md5 from '../md5.js';

// Instance object for testing
const example = {
Expand Down

0 comments on commit d8b232d

Please sign in to comment.