zqw_tools
v1.0.2
Published
Common tools
Downloads
13
Maintainers
Readme
zqw_tools
Project setup
npm install
examples
------------ main.js ----------------------------------------
import * as zqw from 'zqw_tools';
------------ components ----------------------------------------
<template>
<div>zqw_tools</div>
</template>
<script>
import * as zqw from 'zqw_tools';
export default {
name: 'zqw_tools',
data() {
return {}
},
components: {
},
methods: {
throttleFun() {},
zqwToolsFun: zqw.throttle(throttleFun, 500)
}
}
</script>
方法列表
zqw.throttle(fn, delay)
某方法需要节流执行,传入方法和时延值
引入版本
1.0.0
参数
1、fn (function): 需要节流执行的方法 2、delay(number): 时延值,单位:ms
例子
function throttleFun() {};
let fun = zqw.throttle(throttleFun, 100);
=======================================================================================
zqw.findMaxMinVal(type, arr)
根据type查找传入arr数组中的最大或最小值
引入版本
1.0.0
参数
1、type (string): "max"或"min" 2、arr(array):
返回值
(number): 返回过滤出来的最大或最小值
例子
let arr = [1, 22, 3, 68, 98];
let num = zqw.findMaxMinVal('min', arr);
console.log(num)
// => 1
=======================================================================================
zqw.findAvg(arr)
根据传入arr数组,计算平均值
引入版本
1.0.0
参数
1、arr (array): 需要计算平均值的数组
返回值
(number): 返回过滤出来的平均值
例子
let arr = [1, 22, 3, 68, 98];
let num = zqw.findAvg(arr);
console.log(num)
// => 38.4
=======================================================================================
zqw.upFloat2Decimal(floatNum)
根据传入数字向上取两位小数
引入版本
1.0.0
参数
1、floatNum (number): 小数
返回值
(number): 返回过滤出来向上取两位小数的值
例子
let floatNum = 0.23222;
let num = zqw.upFloat2Decimal(floatNum);
console.log(num)
// => 0.24
=======================================================================================
zqw.keep2Decimal(floatNum)
根据传入数字四舍五入保留2位小数
引入版本
1.0.0
参数
1、floatNum (number): 小数
返回值
(number): 四舍五入保留2位小数(若第二位小数为0,则保留一位小数)
例子
let floatNum = 0.23422;
let num = zqw.keep2Decimal(floatNum);
console.log(num)
// => 0.23
=======================================================================================
zqw.fourDecimal2Percent(floatNum)
根据传入数字,小数点直接截取四位并转化成百分数
引入版本
1.0.0
参数
1、floatNum (number): 小数
返回值
(number): 小数点直接截取四位并转化成百分数
例子
let floatNum = 0.23422;
let num = zqw.fourDecimal2Percent(floatNum);
console.log(num)
// => 23.42%
=======================================================================================
zqw.accMul(num1, num2)
根据传入数字,解决浮点数乘法丢失精度问题
引入版本
1.0.0
参数
1、num1 (number): 2、num2 (number):
返回值
(number): 根据传入数字,解决浮点数乘法丢失精度问题
例子
let floatNum = 0.23422;
let num2 = 2;
let num = zqw.accMul(floatNum, num2);
console.log(num)
// => 0.46844
建议使用
=======================================================================================
zqw.accAdd(num1, num2)
根据传入数字,解决浮点数加法丢失精度问题
引入版本
1.0.0
参数
1、num1 (number): 2、num2 (number):
返回值
(number): 根据传入数字,解决浮点数加法丢失精度问题
例子
let floatNum = 0.1;
let num2 = 0.2;
let num = zqw.accAdd(floatNum, num2);
console.log(num)
// => 0.3
建议使用
=======================================================================================
zqw.checkDecimal(num1)
根据传入数字,判断数字是否为小数
引入版本
1.0.0
参数
1、num1 (number):
返回值
(boolean): 根据传入数字,判断数字是否为小数,返回布尔值
例子
let num1 = 0.2;
let boolean1 = zqw.checkDecimal(num1);
console.log(boolean1)
// => true
=======================================================================================
zqw.getMedian(arr)
根据传入数组,计算数组的中位数
引入版本
1.0.0
参数
1、arr (array):
返回值
(number): 根据传入数组,计算出来的中位数
例子
let arr = [2, 5, 8, 3];
let num = zqw.getMedian(arr);
console.log(num)
// => 4
=======================================================================================
zqw.getColorRandom()
随机生成颜色
引入版本
1.0.0
参数
1、
返回值
(color): 随机生成颜色
例子
let color = zqw.getColorRandom();
console.log(color)
// => #6740FD
=======================================================================================
zqw.arrRemoveRepeat(arr)
根据传入数组,去除重复值
引入版本
1.0.0
参数
1、arr (array):
返回值
(array): 根据传入数组,去除重复值,返回新数组
例子
let arr = [2, 5, 8, 3, 5];
let resArr = zqw.arrRemoveRepeat(arr);
console.log(resArr)
// => [2, 5, 8, 3]
=======================================================================================
zqw.arrKeyRemoveRepeat(arr, key)
根据传入数组和key,去除重复值
引入版本
1.0.0
参数
1、arr (array): 2、key (string):
返回值
(array): 根据传入数组和key,去除重复值,返回新数组
例子
let arr = [2, 5, 8, 3, 5];
let key = "id"
let resArr = zqw.arrKeyRemoveRepeat(arr, key);
console.log(resArr)
// => 4
=======================================================================================
zqw.getCookie(sName)
根据传入key,获取cookie中的值
引入版本
1.0.0
参数
1、key (string):
返回值
(string): 根据传入key,获取cookie中的值,返回cookie值
例子
let sName = "id"
let val = zqw.getCookie(sName);
console.log(val)
// => cookie中key=id的值
=======================================================================================
zqw.removeCookie(sName)
根据传入key,删除对应的cookie,并重新设置cookie
引入版本
1.0.0
参数
1、key (string):
返回值
():
例子
let sName = "id"
zqw.removeCookie(sName);
// => cookie中key=id的值
=======================================================================================
zqw.judgeDataType(anything)
根据传入anything,传入需要判断数据类型
引入版本
1.0.0
参数
1、anything (string|Number|object|boolean|null|undefine|array|Date):
返回值
(string):String|Number|Boolean|Null|Undefined|Array|Object|Date
例子
let anything = "id"
let any = zqw.judgeDataType(anything);
console.log(any)
// => String
=======================================================================================
zqw.getRepeatNum(arr)
根据传入arr,传入需要计算元素重复的个数
引入版本
1.0.0
参数
1、arr (array):
返回值
(object):
例子
let arr = [1,2,1,3]
let obj = zqw.getRepeatNum(arr);
console.log(obj)
// => {1: 2, 2: 1, 3: 1}
=======================================================================================
zqw.getStrsum(str, char)
根据传入str,传入需要计算元素重复个数的char
引入版本
1.0.0
参数
1、str (string): 2、char (char):
返回值
(number):
例子
let str = "abaac"
let num = zqw.getStrsum(str, "a");
console.log(num)
// => 3
=======================================================================================
zqw.html2Escape(sHtml)
根据传入sHtml,转换特殊字符(<|>|...)
引入版本
1.0.0
参数
1、sHtml (html-string): html字符串
返回值
(string):
例子
let str = "<html>"
let escapeStr = zqw.html2Escape(str);
console.log(escapeStr)
// => <html>
=======================================================================================
zqw.escape2Html(sHtml)
根据传入转换特殊字符(<|>|...)的sHtml,转换成HTML格式的字符串
引入版本
1.0.0
参数
1、sHtml (html-escape): 转换escape后的html字符串
返回值
(string):
例子
let str = "<html>"
let escapeStr = zqw.escape2Html(str);
console.log(escapeStr)
// => <html>
=======================================================================================
zqw.uniqueFunc(obj, uniKey)
根据传入[obj]数组对象,传入uniKey根据去重的key值
引入版本
1.0.0
参数
1、obj ([object]): 数组对象
返回值
([object]):去重后的数组对象
例子
let arr = [{a: 111, b: 222}, {a: 222, b: 333}, {a: 222, b: 333}, {a: 222, b: 333, c: 444}]
let obj = zqw.uniqueFunc(arr, "a");
console.log(obj)
// => [{a: 111, b: 222}, {a: 222, b: 333}]
=======================================================================================
其他
此工具插件会持续增加更新......