mirror of
https://git.ddmt.top/ddmt/ddmt-tool.git
synced 2026-03-23 05:17:06 +00:00
Compare commits
4 Commits
8e018f34be
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 5d696abd78 | |||
| caeca23cfa | |||
| 6421bcbbf0 | |||
| 22d3931665 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
node_modules/
|
||||
@@ -186,4 +186,25 @@ export function objectToJSON(ObjectText) {
|
||||
} catch (error) {
|
||||
console.error("解析失败:", error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字段映射表重新命名对象的属性
|
||||
* renameObjectKeys
|
||||
* @param {Array} filteredRows - 过滤后的行数据数组,每个元素是一个对象
|
||||
* @param {Object} fieldMapping - 字段映射表,键是原始字段名,值是新的字段名
|
||||
* @returns {Array} - 返回一个新的数组,其中对象的属性根据字段映射表进行了重命名
|
||||
*/
|
||||
export function renameObjectKeys(filteredRows, fieldMapping) {
|
||||
return filteredRows.map(row => {
|
||||
return Object.keys(row).reduce((acc, key) => {
|
||||
// 如果字段在映射表中,则使用映射的字段名
|
||||
if (fieldMapping[key]) {
|
||||
const newKey = fieldMapping[key];
|
||||
acc[newKey] = row[key];
|
||||
}
|
||||
// 如果字段不在映射表中,则直接跳过(不加入新对象)
|
||||
return acc;
|
||||
}, {});
|
||||
});
|
||||
}
|
||||
9
babel.config.json
Normal file
9
babel.config.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"presets": [
|
||||
["@babel/preset-env", {
|
||||
"targets": {
|
||||
"node": "current"
|
||||
}
|
||||
}]
|
||||
]
|
||||
}
|
||||
261
dist/index.cjs
vendored
Normal file
261
dist/index.cjs
vendored
Normal file
@@ -0,0 +1,261 @@
|
||||
'use strict';
|
||||
|
||||
/*
|
||||
* @Author: ddmt
|
||||
* @Date: 2024-9-29 20:50:12
|
||||
* @LastEditTime: 2024-9-30 0:12:12
|
||||
* @LastEditors: ddmt
|
||||
* @Description: ddmt-index file
|
||||
* @FilePath: /Tool/animate.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* 动画函数
|
||||
* @param {HTMLElement} HTMLElement
|
||||
* @param {string} classname
|
||||
* @param {boolean} forceExecute
|
||||
* @returns {void}
|
||||
*/
|
||||
function animateStart(HTMLElement, className, forceExecute = false) {
|
||||
if (forceExecute) HTMLElement.target.classList.remove(className); // 清洗动画
|
||||
HTMLElement.classList.add(className);
|
||||
HTMLElement.addEventListener('animationend', event => {
|
||||
event.target.classList.remove(className); // 清洗动画
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置CSS变量值
|
||||
* @param {string} varName
|
||||
* @param {string} value
|
||||
*/
|
||||
function setClassVar(varName, value) {
|
||||
document.documentElement.style.setProperty(varName, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取CSS变量值
|
||||
* @param {string} varName
|
||||
* @returns
|
||||
*/
|
||||
function getStyleVar(varName) {
|
||||
return getComputedStyle(document.documentElement).getPropertyValue(varName);
|
||||
}
|
||||
|
||||
/*
|
||||
* @Author: ddmt
|
||||
* @Date: 2024-9-29 20:50:12
|
||||
* @LastEditTime: 2025-2-18 00:55:00
|
||||
* @LastEditors: ddmt
|
||||
* @Description: ddmt-index file
|
||||
* @FilePath: /Tool/number.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* 生成从minNum到maxNum的随机数
|
||||
* @param {number} minNum - 最小值
|
||||
* @param {number} [maxNum] - 最大值
|
||||
* @returns {number} - 生成的随机数
|
||||
*/
|
||||
function randomNum(minNum, maxNum) {
|
||||
switch (arguments.length) {
|
||||
case 1:
|
||||
return parseInt(Math.random() * minNum + 1, 10);
|
||||
case 2:
|
||||
return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 数组循环函数
|
||||
* @param {Array} arr - 数组
|
||||
* @param {number} index - 索引
|
||||
* @returns {Array} - 循环后的数组
|
||||
*/
|
||||
function nextArray(arr, index) {
|
||||
index--;
|
||||
return arr.slice(index + 1, arr.length).concat(arr.slice(0, index + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* 数组去重函数
|
||||
* @param {Array} arr - 数组
|
||||
* @returns {Array} - 去重后的数组
|
||||
*/
|
||||
function ArrayDeHeavy(arr) {
|
||||
let newArr = new Set();
|
||||
arr.forEach(item => {
|
||||
newArr.add(item);
|
||||
});
|
||||
return Array.from(newArr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取相对时间(中文)
|
||||
* @param {Date} date - 日期对象
|
||||
* @returns {string} - 相对时间字符串
|
||||
*/
|
||||
function getRelativeTime(date) {
|
||||
const now = new Date();
|
||||
const diffInSeconds = Math.floor((now.getTime() - date.getTime()) / 1000);
|
||||
if (diffInSeconds < 60) {
|
||||
return '刚刚';
|
||||
}
|
||||
const diffInMinutes = Math.floor(diffInSeconds / 60);
|
||||
if (diffInMinutes < 60) {
|
||||
return `${diffInMinutes}分钟前`;
|
||||
}
|
||||
const diffInHours = Math.floor(diffInMinutes / 60);
|
||||
if (diffInHours < 24) {
|
||||
return `${diffInHours}小时前`;
|
||||
}
|
||||
const diffInDays = Math.floor(diffInHours / 24);
|
||||
if (diffInDays < 30) {
|
||||
return `${diffInDays}天前`;
|
||||
}
|
||||
const diffInMonths = Math.floor(diffInDays / 30);
|
||||
if (diffInMonths < 12) {
|
||||
return `${diffInMonths}个月前`;
|
||||
}
|
||||
const diffInYears = Math.floor(diffInMonths / 12);
|
||||
if (diffInYears < 5) {
|
||||
return `${diffInYears}年前`;
|
||||
}
|
||||
return '很久以前';
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析nginx日志(单行)
|
||||
* @param {string} log - 日志字符串
|
||||
* @returns {Object|null} - 解析后的日志对象或null
|
||||
*/
|
||||
function parseNginxLog(log) {
|
||||
const logPattern = /^(\S+) - - \[([^\]]+)\] "(\S+) (\S+) HTTP\/\d\.\d" (\d+) (\d+) "([^"]*)" "([^"]*)"/;
|
||||
try {
|
||||
const match = log.match(logPattern);
|
||||
if (match) {
|
||||
return {
|
||||
ip: match[1],
|
||||
timestamp: match[2],
|
||||
method: match[3],
|
||||
url: match[4],
|
||||
status: parseInt(match[5]),
|
||||
responseSize: parseInt(match[6]),
|
||||
referrer: match[7],
|
||||
userAgent: match[8]
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* cookies 解析函数
|
||||
* @param {string} cookies - cookies字符串
|
||||
* @returns {Object} - 解析后的cookies对象
|
||||
*/
|
||||
function toCookiesArray(cookies) {
|
||||
if (!cookies || cookies.length === 0) return;
|
||||
|
||||
// 解析旧的 cookies
|
||||
const cookieMap = {};
|
||||
cookies.split("; ").forEach(cookie => {
|
||||
const [key, value] = cookie.split("=");
|
||||
if (key) cookieMap[key] = value;
|
||||
});
|
||||
return cookieMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* cookies 更新函数
|
||||
* @param {string} cookies - 原始cookies字符串
|
||||
* @param {Array} setCookieArray - 新的 Set-Cookie 数组
|
||||
* @returns {string} - 更新后的cookies字符串
|
||||
*/
|
||||
function updateCookies(cookies, setCookieArray) {
|
||||
if (!setCookieArray || setCookieArray.length === 0) return;
|
||||
|
||||
// 解析旧的 cookies
|
||||
const cookieMap = toCookiesArray(cookies);
|
||||
|
||||
// 解析新的 Set-Cookie 数组并更新
|
||||
setCookieArray.forEach(cookieStr => {
|
||||
const cookiePair = cookieStr.split(";")[0]; // 只取 key=value
|
||||
const [key, value] = cookiePair.split("=");
|
||||
if (key) cookieMap[key] = value;
|
||||
});
|
||||
|
||||
// 重新拼接成字符串存回全局 cookies
|
||||
return Object.entries(cookieMap).map(([key, value]) => `${key}=${value}`).join("; ");
|
||||
}
|
||||
|
||||
/**
|
||||
* object 转 json
|
||||
* @param {string} ObjectText - 对象字符串
|
||||
* @returns {string|undefined} - 标准 JSON 字符串或undefined
|
||||
*/
|
||||
function objectToJSON(ObjectText) {
|
||||
try {
|
||||
// 修复键没有双引号的问题
|
||||
let fixedString = ObjectText.replace(/(\w+):/g, '"$1":');
|
||||
|
||||
// 修复单引号字符串值的问题
|
||||
fixedString = fixedString.replace(/'/g, '"');
|
||||
|
||||
// 修复尾随逗号的问题
|
||||
fixedString = fixedString.replace(/,\s*([}\]])/g, '$1');
|
||||
|
||||
// 解析为对象
|
||||
const outputObj = JSON.parse(fixedString);
|
||||
|
||||
// 转换为标准 JSON 字符串
|
||||
return JSON.stringify(outputObj);
|
||||
} catch (error) {
|
||||
console.error("解析失败:", error);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @Author: ddmt
|
||||
* @version: 1.0.11
|
||||
* @Date: 2024-9-29 20:50:12
|
||||
* @LastEditTime: 2025-2-18 00:55:00
|
||||
* @LastEditors: ddmt
|
||||
* @Description: ddmt-index file
|
||||
* @FilePath: /index.js
|
||||
*/
|
||||
|
||||
|
||||
// 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!! 😺');
|
||||
|
||||
exports.ArrayDeHeavy = ArrayDeHeavy;
|
||||
exports.animateStart = animateStart;
|
||||
exports.getRelativeTime = getRelativeTime;
|
||||
exports.getStyleVar = getStyleVar;
|
||||
exports.nextArray = nextArray;
|
||||
exports.objectToJSON = objectToJSON;
|
||||
exports.parseNginxLog = parseNginxLog;
|
||||
exports.randomNum = randomNum;
|
||||
exports.setClassVar = setClassVar;
|
||||
exports.toCookiesArray = toCookiesArray;
|
||||
exports.updateCookies = updateCookies;
|
||||
249
dist/index.mjs
vendored
Normal file
249
dist/index.mjs
vendored
Normal file
@@ -0,0 +1,249 @@
|
||||
/*
|
||||
* @Author: ddmt
|
||||
* @Date: 2024-9-29 20:50:12
|
||||
* @LastEditTime: 2024-9-30 0:12:12
|
||||
* @LastEditors: ddmt
|
||||
* @Description: ddmt-index file
|
||||
* @FilePath: /Tool/animate.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* 动画函数
|
||||
* @param {HTMLElement} HTMLElement
|
||||
* @param {string} classname
|
||||
* @param {boolean} forceExecute
|
||||
* @returns {void}
|
||||
*/
|
||||
function animateStart(HTMLElement, className, forceExecute = false) {
|
||||
if (forceExecute) HTMLElement.target.classList.remove(className); // 清洗动画
|
||||
HTMLElement.classList.add(className);
|
||||
HTMLElement.addEventListener('animationend', event => {
|
||||
event.target.classList.remove(className); // 清洗动画
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置CSS变量值
|
||||
* @param {string} varName
|
||||
* @param {string} value
|
||||
*/
|
||||
function setClassVar(varName, value) {
|
||||
document.documentElement.style.setProperty(varName, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取CSS变量值
|
||||
* @param {string} varName
|
||||
* @returns
|
||||
*/
|
||||
function getStyleVar(varName) {
|
||||
return getComputedStyle(document.documentElement).getPropertyValue(varName);
|
||||
}
|
||||
|
||||
/*
|
||||
* @Author: ddmt
|
||||
* @Date: 2024-9-29 20:50:12
|
||||
* @LastEditTime: 2025-2-18 00:55:00
|
||||
* @LastEditors: ddmt
|
||||
* @Description: ddmt-index file
|
||||
* @FilePath: /Tool/number.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* 生成从minNum到maxNum的随机数
|
||||
* @param {number} minNum - 最小值
|
||||
* @param {number} [maxNum] - 最大值
|
||||
* @returns {number} - 生成的随机数
|
||||
*/
|
||||
function randomNum(minNum, maxNum) {
|
||||
switch (arguments.length) {
|
||||
case 1:
|
||||
return parseInt(Math.random() * minNum + 1, 10);
|
||||
case 2:
|
||||
return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 数组循环函数
|
||||
* @param {Array} arr - 数组
|
||||
* @param {number} index - 索引
|
||||
* @returns {Array} - 循环后的数组
|
||||
*/
|
||||
function nextArray(arr, index) {
|
||||
index--;
|
||||
return arr.slice(index + 1, arr.length).concat(arr.slice(0, index + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* 数组去重函数
|
||||
* @param {Array} arr - 数组
|
||||
* @returns {Array} - 去重后的数组
|
||||
*/
|
||||
function ArrayDeHeavy(arr) {
|
||||
let newArr = new Set();
|
||||
arr.forEach(item => {
|
||||
newArr.add(item);
|
||||
});
|
||||
return Array.from(newArr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取相对时间(中文)
|
||||
* @param {Date} date - 日期对象
|
||||
* @returns {string} - 相对时间字符串
|
||||
*/
|
||||
function getRelativeTime(date) {
|
||||
const now = new Date();
|
||||
const diffInSeconds = Math.floor((now.getTime() - date.getTime()) / 1000);
|
||||
if (diffInSeconds < 60) {
|
||||
return '刚刚';
|
||||
}
|
||||
const diffInMinutes = Math.floor(diffInSeconds / 60);
|
||||
if (diffInMinutes < 60) {
|
||||
return `${diffInMinutes}分钟前`;
|
||||
}
|
||||
const diffInHours = Math.floor(diffInMinutes / 60);
|
||||
if (diffInHours < 24) {
|
||||
return `${diffInHours}小时前`;
|
||||
}
|
||||
const diffInDays = Math.floor(diffInHours / 24);
|
||||
if (diffInDays < 30) {
|
||||
return `${diffInDays}天前`;
|
||||
}
|
||||
const diffInMonths = Math.floor(diffInDays / 30);
|
||||
if (diffInMonths < 12) {
|
||||
return `${diffInMonths}个月前`;
|
||||
}
|
||||
const diffInYears = Math.floor(diffInMonths / 12);
|
||||
if (diffInYears < 5) {
|
||||
return `${diffInYears}年前`;
|
||||
}
|
||||
return '很久以前';
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析nginx日志(单行)
|
||||
* @param {string} log - 日志字符串
|
||||
* @returns {Object|null} - 解析后的日志对象或null
|
||||
*/
|
||||
function parseNginxLog(log) {
|
||||
const logPattern = /^(\S+) - - \[([^\]]+)\] "(\S+) (\S+) HTTP\/\d\.\d" (\d+) (\d+) "([^"]*)" "([^"]*)"/;
|
||||
try {
|
||||
const match = log.match(logPattern);
|
||||
if (match) {
|
||||
return {
|
||||
ip: match[1],
|
||||
timestamp: match[2],
|
||||
method: match[3],
|
||||
url: match[4],
|
||||
status: parseInt(match[5]),
|
||||
responseSize: parseInt(match[6]),
|
||||
referrer: match[7],
|
||||
userAgent: match[8]
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* cookies 解析函数
|
||||
* @param {string} cookies - cookies字符串
|
||||
* @returns {Object} - 解析后的cookies对象
|
||||
*/
|
||||
function toCookiesArray(cookies) {
|
||||
if (!cookies || cookies.length === 0) return;
|
||||
|
||||
// 解析旧的 cookies
|
||||
const cookieMap = {};
|
||||
cookies.split("; ").forEach(cookie => {
|
||||
const [key, value] = cookie.split("=");
|
||||
if (key) cookieMap[key] = value;
|
||||
});
|
||||
return cookieMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* cookies 更新函数
|
||||
* @param {string} cookies - 原始cookies字符串
|
||||
* @param {Array} setCookieArray - 新的 Set-Cookie 数组
|
||||
* @returns {string} - 更新后的cookies字符串
|
||||
*/
|
||||
function updateCookies(cookies, setCookieArray) {
|
||||
if (!setCookieArray || setCookieArray.length === 0) return;
|
||||
|
||||
// 解析旧的 cookies
|
||||
const cookieMap = toCookiesArray(cookies);
|
||||
|
||||
// 解析新的 Set-Cookie 数组并更新
|
||||
setCookieArray.forEach(cookieStr => {
|
||||
const cookiePair = cookieStr.split(";")[0]; // 只取 key=value
|
||||
const [key, value] = cookiePair.split("=");
|
||||
if (key) cookieMap[key] = value;
|
||||
});
|
||||
|
||||
// 重新拼接成字符串存回全局 cookies
|
||||
return Object.entries(cookieMap).map(([key, value]) => `${key}=${value}`).join("; ");
|
||||
}
|
||||
|
||||
/**
|
||||
* object 转 json
|
||||
* @param {string} ObjectText - 对象字符串
|
||||
* @returns {string|undefined} - 标准 JSON 字符串或undefined
|
||||
*/
|
||||
function objectToJSON(ObjectText) {
|
||||
try {
|
||||
// 修复键没有双引号的问题
|
||||
let fixedString = ObjectText.replace(/(\w+):/g, '"$1":');
|
||||
|
||||
// 修复单引号字符串值的问题
|
||||
fixedString = fixedString.replace(/'/g, '"');
|
||||
|
||||
// 修复尾随逗号的问题
|
||||
fixedString = fixedString.replace(/,\s*([}\]])/g, '$1');
|
||||
|
||||
// 解析为对象
|
||||
const outputObj = JSON.parse(fixedString);
|
||||
|
||||
// 转换为标准 JSON 字符串
|
||||
return JSON.stringify(outputObj);
|
||||
} catch (error) {
|
||||
console.error("解析失败:", error);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @Author: ddmt
|
||||
* @version: 1.0.11
|
||||
* @Date: 2024-9-29 20:50:12
|
||||
* @LastEditTime: 2025-2-18 00:55:00
|
||||
* @LastEditors: ddmt
|
||||
* @Description: ddmt-index file
|
||||
* @FilePath: /index.js
|
||||
*/
|
||||
|
||||
|
||||
// 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!! 😺');
|
||||
|
||||
export { ArrayDeHeavy, animateStart, getRelativeTime, getStyleVar, nextArray, objectToJSON, parseNginxLog, randomNum, setClassVar, toCookiesArray, updateCookies };
|
||||
44
index.js
44
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,
|
||||
@@ -20,7 +23,42 @@ export {
|
||||
parseNginxLog,
|
||||
toCookiesArray,
|
||||
updateCookies,
|
||||
objectToJSON
|
||||
objectToJSON,
|
||||
renameObjectKeys
|
||||
} from './Tool/number.js';
|
||||
|
||||
// ES Module 导出
|
||||
export {
|
||||
animateStart,
|
||||
setClassVar,
|
||||
getStyleVar,
|
||||
randomNum,
|
||||
nextArray,
|
||||
ArrayDeHeavy,
|
||||
getRelativeTime,
|
||||
parseNginxLog,
|
||||
toCookiesArray,
|
||||
updateCookies,
|
||||
objectToJSON,
|
||||
renameObjectKeys
|
||||
};
|
||||
|
||||
// CommonJS 导出
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = {
|
||||
animateStart,
|
||||
setClassVar,
|
||||
getStyleVar,
|
||||
randomNum,
|
||||
nextArray,
|
||||
ArrayDeHeavy,
|
||||
getRelativeTime,
|
||||
parseNginxLog,
|
||||
toCookiesArray,
|
||||
updateCookies,
|
||||
objectToJSON,
|
||||
renameObjectKeys
|
||||
};
|
||||
}
|
||||
|
||||
console.log('ddmt-tool Loading successfully!! 😺');
|
||||
2442
package-lock.json
generated
Normal file
2442
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
23
package.json
23
package.json
@@ -1,22 +1,37 @@
|
||||
{
|
||||
"name": "ddmt-tool",
|
||||
"version": "0.0.3",
|
||||
"version": "0.0.4",
|
||||
"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": {
|
||||
".": {
|
||||
"require": "./dist/index.cjs",
|
||||
"import": "./dist/index.mjs"
|
||||
}
|
||||
},
|
||||
"types": "types/index.d.ts",
|
||||
"scripts": {
|
||||
"dev": "node index.js"
|
||||
"dev": "node index.js",
|
||||
"build": "rollup -c"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.ddmt.top/ddmt/ddmt-tool.git"
|
||||
},
|
||||
},
|
||||
"keywords": [
|
||||
"ddmt",
|
||||
"tool",
|
||||
"animate"
|
||||
],
|
||||
"author": "ddmt",
|
||||
"license": "MIT"
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.26.9",
|
||||
"@babel/preset-env": "^7.26.9",
|
||||
"@rollup/plugin-babel": "^6.0.4",
|
||||
"@rollup/plugin-commonjs": "^28.0.2",
|
||||
"@rollup/plugin-node-resolve": "^16.0.0",
|
||||
"rollup": "^4.34.8"
|
||||
}
|
||||
}
|
||||
|
||||
30
rollup.config.js
Normal file
30
rollup.config.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import babel from '@rollup/plugin-babel';
|
||||
import resolve from '@rollup/plugin-node-resolve';
|
||||
import commonjs from '@rollup/plugin-commonjs';
|
||||
|
||||
export default [
|
||||
{
|
||||
input: 'index.js', // 入口文件
|
||||
output: {
|
||||
file: 'dist/index.mjs', // 输出 ESM 文件
|
||||
format: 'esm', // 输出格式为 ESM
|
||||
},
|
||||
plugins: [
|
||||
resolve(), // 解析第三方模块
|
||||
commonjs(), // 将 CommonJS 模块转换为 ESM
|
||||
babel({ babelHelpers: 'bundled' }), // 使用 Babel 转译
|
||||
],
|
||||
},
|
||||
{
|
||||
input: 'index.js', // 入口文件
|
||||
output: {
|
||||
file: 'dist/index.cjs', // 输出 CommonJS 文件
|
||||
format: 'cjs', // 输出格式为 CommonJS
|
||||
},
|
||||
plugins: [
|
||||
resolve(), // 解析第三方模块
|
||||
commonjs(), // 将 CommonJS 模块转换为 ESM
|
||||
babel({ babelHelpers: 'bundled' }), // 使用 Babel 转译
|
||||
],
|
||||
},
|
||||
];
|
||||
1
types/index.d.ts
vendored
1
types/index.d.ts
vendored
@@ -14,4 +14,5 @@ declare module 'ddmt-tool' {
|
||||
export function toCookiesArray(cookies: string): { [key: string]: string };
|
||||
export function updateCookies(cookies: string, setCookieArray: string[]): string;
|
||||
export function objectToJSON(ObjectText: string): string | undefined;
|
||||
export function renameObjectKeys(filteredRows: Array<{ [key: string]: any }>, fieldMapping: { [key: string]: string }): Array<{ [key: string]: any }>;
|
||||
}
|
||||
Reference in New Issue
Block a user