npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

libcu

v1.1.5

Published

Nodejs 通用方法库

Downloads

18

Readme

libcu

libcu aim to provide a common use lib for JavaScript

libcu致力于提供一个JS的通用方法库


example

const libcu = require('libcu');
console.log(libcu.tools.sleep(100));

APIS & Usage

const libcu = require('libcu')

I.tools

  • 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'
  • 16.antiJsonStick(string)

    Handle sticky packets, only for JSON type packets.

    处理粘包用,仅限于JSON类型报文

    
    let a = '{a:1}{b:2}';
    
    console.log(a);
    
    
    let arr = libcu.tools.antiJsonStick(a);
    
    console.log(arr);
    {a:1}{b:2}
    [ '{a:1}', '{b:2}' ]
    

II.cf

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

    复制整个目录

III.mysql

  • 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) {
    
    }
    

IV.cipher

  • 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'