wscfan-ai-tools
v1.0.0
Published
A useful front-end tool library with debounce, throttle and encryption/decryption functions
Downloads
2
Readme
wscfan-ai-tools 🛠️
一个轻量级的前端工具库,提供防抖、节流以及常见的加解密功能。
安装 💾
npm install wscfan-ai-tools使用方法 🚀
浏览器引入
<script src="node_modules/wscfan-ai-tools/dist/wscfan-ai-tools.min.js"></script>模块引入
import WscfanAiTools from 'wscfan-ai-tools';
// 或者
const WscfanAiTools = require('wscfan-ai-tools');功能列表 📋
防抖函数 (Debounce)
// 基础用法
const debouncedFunc = WscfanAiTools.debounce(myFunction, 300);
window.addEventListener('resize', debouncedFunc);
// 高级用法(带取消功能)
const advancedDebounce = WscfanAiTools.debounceAdvanced(myFunction, 500, {
leading: true,
trailing: false
});
advancedDebounce.cancel(); // 取消防抖节流函数 (Throttle)
// 限制函数每秒最多执行一次
const throttledFunc = WscfanAiTools.throttle(myFunction, 1000);
window.addEventListener('scroll', throttledFunc);加密解密功能 🔐
MD5加密
const hash = WscfanAiTools.md5('hello world');
console.log(hash); // 输出: 5eb63bbbe01eeed093cb22bb8f5acdc3SHA256加密
const hash = WscfanAiTools.sha256('hello world');
console.log(hash); // 输出SHA256哈希值AES加密解密
const encrypted = WscfanAiTools.aesEncrypt('敏感数据', '密钥');
const decrypted = WscfanAiTools.aesDecrypt(encrypted, '密钥');
console.log(decrypted); // 输出: 敏感数据Base64编码解码
const encoded = WscfanAiTools.base64Encode('Hello World');
const decoded = WscfanAiTools.base64Decode(encoded);
console.log(decoded); // 输出: Hello WorldHMAC-SHA256签名
const signature = WscfanAiTools.hmacSha256('data', 'secret');
console.log(signature); // 输出HMAC签名API文档 📚
debounce(func, wait, immediate)
- func: 需要防抖的函数
- wait: 延迟时间(毫秒)
- immediate: 是否立即执行,默认false
throttle(func, limit)
- func: 需要节流的函数
- limit: 时间限制(毫秒)
aesEncrypt(data, key)
- data: 需要加密的数据
- key: 密钥
aesDecrypt(encryptedData, key)
- encryptedData: 需要解密的数据
- key: 密钥
版本信息 ℹ️
当前版本: v1.0.0
许可证 📄
MIT License
