@beariscoming/xtool

js tool functions

Usage no npm install needed!

<script type="module">
  import beariscomingXtool from 'https://cdn.skypack.dev/@beariscoming/xtool';
</script>

README

日期时间


生成指定的日期时间

Clock('20200521 13:59:59'); // 返回类型为Date

格式化(Date原型上增加format函数)

new Date().format('yyyyMMdd HH:mm:ss')

时间加减(Date原型上增加plus函数)

// 参数1, 加减数量, 减法须传递负数
// 参数2, 加减单位: y/Y 年, M 月, d 日, H/h时, m分, s/S秒
new Date().plus(1, 'd')
Clock('20200101').plus(-1, 'y');

对象深拷贝

cloneDeep(origin, target?) // target为可选参数;

千分计数法

ThousandthsNumber(num)
ThousandthsNumber(111123444.2345)
// 111,123,444.2345

数组去重

const arr = [1, 2, 2, 5, 1, 3, 4, 3].single();
// arr = [1, 2, 5, 3, 4]

圣杯模式~继承

inherit(Target, Origin)   // 继承自他,更改自己又不会影响他

Cookie操作

Cookie.get(key); // 获取
Cookie.set(key, value, days?); // 设置, days可选, 单位/天
Cookie.del(key); // 删除