From 22d3931665c03c7a815754bf828c8ac2953c3af9 Mon Sep 17 00:00:00 2001 From: ddmt Date: Fri, 21 Feb 2025 10:50:04 +0800 Subject: [PATCH] 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 --- index.js | 39 +++++++++++++++++++++++++++++++++++++-- package.json | 6 ++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 2909edb..36218f7 100644 --- a/index.js +++ b/index.js @@ -7,12 +7,15 @@ * @Description: ddmt-index file * @FilePath: /index.js */ -export { + +// 导入所有函数 +import { animateStart, setClassVar, getStyleVar } from './Tool/animate.js'; -export { + +import { randomNum, nextArray, ArrayDeHeavy, @@ -23,4 +26,36 @@ export { objectToJSON } 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!! 😺'); \ No newline at end of file diff --git a/package.json b/package.json index 3014fc8..ddd6ab4 100644 --- a/package.json +++ b/package.json @@ -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.", "main": "index.js", "type": "module", + "exports": { + ".": { + "import": "./index.js", + "require": "./index.js" + } + }, "types": "types/index.d.ts", "scripts": { "dev": "node index.js"