lx2-tool
v1.1.1
Published
My utility library
Readme
lx2-tool
工具类
安装
npm install lx2-tool
# cookie相关
// 1. 设置一个 7 天有效期的 Cookie
setCookie('username', 'Alice', { expires: 7, path: '/' });
// 2. 设置一个特定时间的 Cookie(2026-12-31 过期)
const expiry = new Date('2026-12-31T23:59:59Z');
setCookie('session', 'abc123', { expires: expiry, secure: true, sameSite: 'Strict' });
// 3. 获取 Cookie
const user = getCookie('username'); // 'Alice'
// 4. 获取所有 Cookie
const all = getAllCookies(); // { username: 'Alice', session: 'abc123' }
// 5. 删除 Cookie(需路径一致)
removeCookie('username', { path: '/' });
# 数据类型
getDataType(data)
isArray(data)
isObject(data)
isNull(data)
isUndefined(data)
isBoolean(data)
isString(data)
# 对象判空
isEmptyObject(data)
# 拓展数组原型方法
extendArray() -- intersection 交集; findItem 获取某一项;getIndex 获取某个元素对应的序号;remove 清除某一项