用各种语言实现的基本库 library for common use
libcu aim to provide a common use lib for JavaScript
libcu致力于提供一个JS的通用方法库
const libcu = require('libcu');
console.log(libcu.tools.sleep(100));
const libcu = require('libcu')
1.findLackNumArr(arr)
Find the missing number in a contiguous array
在连续的数组里面找到缺少的数字
let a = [1,2,4,6,10];
a = libcu.tools.findLackNumArr(a);
console.log(a);
'[ 3, 5, 7, 8, 9 ]'
2.sleep(ms)
async sleep
异步睡眠函数
await libcu.tools.sleep(1000);
3.contains(arr, obj)
Judge whether obj is in arr
判断obj是否在arr里面
([1,2,3] , 1) will return true
let a = [1,2,4,6,10];
let b = 3;
console.log(libcu.tools.contains(a,b));
'false'
4.ascii2Hex(buf)
omited
5.hex2Ascii(buf)
omited
6.padZero(num, len)
Left padding zero, len is the number of zeros
左补零,len为补0的个数
let a = 1;
let b = libcu.tools.padZero(a,3);
console.log(b);
'001'
7.padZero(num, len)
Hexadecimal left padding zero
十六进制左补零
let a = 1;
let b = libcu.tools.padZero16(a,3);
console.log(b);
'001'
8.buf2String(buf)
let a = Buffer.alloc(10)
a.fill('wtx',0,10);
console.log(libcu.tools.buf2String(a));
'wtxwtxwtxw'
9.readUInt24BE(inBuf, begin, end)
In part, it is similar to readUInt32BE
部分和readUInt32BE类似
let a = Buffer.alloc(10)
a.fill('wtx',0,10);
let b = libcu.tools.readUInt24BE(a);
console.log(libcu.tools.buf2String(b));
'7828600'
10.str2arr(str,flag)
!flag : '[1,2,3]' to [1,2,3]
flag : '["1","2","3"]' to [1,2,3]
let a = '[1,2,3]';
let b = libcu.tools.str2arr(a);
console.log(b);
`[ '1', '2', '3' ]`
11.acc2Decimal(value)
1.1 to 1.10
1 to 1.00
1.10 to 1.10
let a = 1.2;
console.log(libcu.tools.acc2Decimal(a));
'1.20'
12.isNumber(value)
let a = '1.4f'
console.log(libcu.tools.isNumber(a));
'false'
13.safeJsonStringfy(json)
let a = "1"
console.log(libcu.tools.safeJsonStringfy(a));
'1'
14.safeJsonParse(json)
let a = "1"
console.log(libcu.tools.safeJsonParse(a));
'1'
15.delQuotation(number)
let a = `"1"`
console.log(libcu.tools.delQuptation(a));
'1'
The main API is the following
1.async walkFolder(dirname, option)
Get all the files and folders in the directory
获取目录下的所有文件和文件夹
return {
fileList : [],
dirList : []
}
2.async copyFolder(srcDir, tarDir, filter)
Copy entire directory
复制整个目录
1.init(connect)
Tell MySQL connection information
告诉mysql连接信息
connect : {
"host" : "127.0.0.1",
"user" : "test",
"password":"123456",
"database" : "mydb",
}
2.async beginTrans()
Start a transaction
开启一段事务
usage:
try {
let conn = await beginTrans();
}catch(error) {
}
3.async dbop(sql, sqlParam)
try {
let res = await dbop('select * from test');
} catch(error) {
}
4.async dbOpInTrans(sql, sqlParam, connection)
5.async commit(conn)
6.async rollback(conn)
try {
let conn = await beginTrans();
try {
await dbOpInTrans(sql,sqlParam,conn);
await commit(conn);
}catch (error) {
await rollback(conn);
}
}catch(error) {
}
1.getMd5Buffer(data)
let a = 1.2
console.log(libcu.cipher.getMd5Buffer(a));
'<Buffer 56 76 54 72 68 04 01 49 9c 79 73 24 68 ba 43 40>'
2.getMd5Str(data)
let a = 1.2
console.log(libcu.cipher.getMd5Str(a));
'56765472680401499c79732468ba4340'
3.getMd5UpperStr(data)
let a = 1.2
console.log(libcu.cipher.getMd5UpperStr(a));
'56765472680401499C79732468BA4340'
4.setAesKey(key)
defalut is "/GwhjXbE1SCPaIY=" (AvenirLibcu)
5.AesEncode(info)
6.AesDecode(info)
let a = 1.2
let b = libcu.cipher.AesEncode(a);
console.log(b);
let c = libcu.cipher.AesDecode(b);
console.log(c);
'b = rXtFTnkfN1IXmvO94PoeQA=='
'c = 1.2'
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。