1.0.1 • Published 7 months ago
npm-plugin-demo123 v1.0.1
npm-plugin-demo
一个实用的 JavaScript 工具函数库。
安装
npm install npm-plugin-demo
使用方法
const utils = require('npm-plugin-demo');
// 格式化日期
console.log(utils.formatDate(new Date(), 'YYYY-MM-DD')); // 2025-02-11
// 深拷贝
const obj = { a: 1, b: { c: 2 } };
const clonedObj = utils.deepClone(obj);
// 防抖函数
const debouncedFn = utils.debounce(() => {
console.log('debounced function called');
}, 1000);
// 节流函数
const throttledFn = utils.throttle(() => {
console.log('throttled function called');
}, 1000);
// 数组去重
console.log(utils.uniqueArray([1, 1, 2, 2, 3])); // [1, 2, 3]
// 判断是否为空对象
console.log(utils.isEmptyObject({})); // true
// 获取URL参数
console.log(utils.getUrlParams('https://example.com?name=test&age=18'));
// { name: 'test', age: '18' }
API
formatDate(date, format)
格式化日期,支持自定义格式。
deepClone(obj)
对象深拷贝。
debounce(func, wait)
创建一个防抖函数。
throttle(func, wait)
创建一个节流函数。
uniqueArray(arr)
数组去重。
isEmptyObject(obj)
判断是否为空对象。
getUrlParams(url)
获取URL参数。
许可证
ISC