feat(module): Improve module exports and compatibility

- Add explicit ES Module and CommonJS exports in index.js
- Update package.json to support both import and require
- Ensure consistent function exports across module systems
This commit is contained in:
ddmt 2025-02-21 10:50:04 +08:00
parent 8e018f34be
commit 22d3931665
2 changed files with 43 additions and 2 deletions

View File

@ -7,12 +7,15 @@
* @Description: ddmt-index file * @Description: ddmt-index file
* @FilePath: /index.js * @FilePath: /index.js
*/ */
export {
// 导入所有函数
import {
animateStart, animateStart,
setClassVar, setClassVar,
getStyleVar getStyleVar
} from './Tool/animate.js'; } from './Tool/animate.js';
export {
import {
randomNum, randomNum,
nextArray, nextArray,
ArrayDeHeavy, ArrayDeHeavy,
@ -23,4 +26,36 @@ export {
objectToJSON objectToJSON
} from './Tool/number.js'; } from './Tool/number.js';
// ES Module 导出
export {
animateStart,
setClassVar,
getStyleVar,
randomNum,
nextArray,
ArrayDeHeavy,
getRelativeTime,
parseNginxLog,
toCookiesArray,
updateCookies,
objectToJSON
};
// CommonJS 导出
if (typeof module !== 'undefined' && module.exports) {
module.exports = {
animateStart,
setClassVar,
getStyleVar,
randomNum,
nextArray,
ArrayDeHeavy,
getRelativeTime,
parseNginxLog,
toCookiesArray,
updateCookies,
objectToJSON
};
}
console.log('ddmt-tool Loading successfully!! 😺'); console.log('ddmt-tool Loading successfully!! 😺');

View File

@ -4,6 +4,12 @@
"description": "A utility library that provides commonly used functions to simplify everyday development tasks. Whether it's string manipulation, array operations, or other frequent functionalities, `ddmt-tool` helps you work more efficiently.", "description": "A utility library that provides commonly used functions to simplify everyday development tasks. Whether it's string manipulation, array operations, or other frequent functionalities, `ddmt-tool` helps you work more efficiently.",
"main": "index.js", "main": "index.js",
"type": "module", "type": "module",
"exports": {
".": {
"import": "./index.js",
"require": "./index.js"
}
},
"types": "types/index.d.ts", "types": "types/index.d.ts",
"scripts": { "scripts": {
"dev": "node index.js" "dev": "node index.js"