@linronglang/js-code
v0.2.0
Published
常用的js代码片段
Downloads
77
Readme
封装常用的 js 方法
- install
npm install @linronglang/js-code -S
- datejs
const { datejs } = require("@linronglang/js-code");
// 几个常用的时间转换
console.log(datejs.format("YYYY-MM-DD HH:mm:ss"));
console.log(datejs.format("YYYY-MM-DD"));
console.log(datejs.format("HH:mm:ss"));
- url
const { url } = require("@linronglang/js-code");
// url参数的解析
console.log(url.parse("http://baidu.com?a=1&b=2&xxx=xxxx"));
console.log(url.params({ a: 1, b: 2, c: 3 }));
- uuid
const { uuid } = require("@linronglang/js-code");
// 生成不重复的id
console.log(uuid());
- downLoad
const { downLoad } = require("@linronglang/js-code");
// 下载
downLoad("地址", "文件的名字.xxx");
- debounce, throttle
const { debounce, throttle } = require("@linronglang/js-code");
// 防抖
document.addEventListener("input", e =>
debounce(fun, 1000, this, [e, a, b, c])
);
// 节流
document.addEventListener("input", e =>
throttle(fun, 1000, this, [e, a, b, c])
);
- deepCopy
const { deepCopy } = require("@linronglang/js-code");
// 深拷贝
let a = { a: 1 };
console.log(deepCopy(a));
- isOs
const { isOs } = require("@linronglang/js-code");
// 判断操作系统
console.log(isOs()); // Mac
- loadScript
const { loadScript } = require("@linronglang/js-code");
// 加载js文件
loadScript("http://cdn.staticfile.org/jquery/1.6.2/jquery.min.js").then(() => {
console.log("load", $("body"));
});
- randomRGB
// 随机生成rgb
const { randomRGB } = require("@linronglang/js-code");
console.log(randomRGB());
// { r: 235, g: 181, b: 60 }