licos-tools

1.0.66 • Public • Published

licos tools lib

安装

npm i licos-tools

使用

import tools from 'licos-tools'

convert 转换

驼峰转下划线

camelToUnderline(str: string): string

下划线转驼峰

underlineToCamel(str: string): string

对象转数组

objectToArray(Obj: Object):Array<object>

数组转树形结构

arrayToTree(list: [], parentKey = ''): Array<object>

树形结构转数组

treeToArray(list: any, newArr: any): Array<object>

根据 Key 将数组转换为树形结构

arrayToTreeByKey(list: Array<object>, pid = '', customField = { key: 'id', parentKey: 'pid' }): Array<Object>

common 工具类

获取UUID

uuid (len: number, radix: number): string
实例:tools.common.uuid(8,16);//获取8位16进制的字符串
返回:1f2a3c41

获取GUID

guid = (): string
实例:tools.common.guid();//获取8位16进制的字符串
返回:1d4ac2d2-11c8-4bdb-adb9-e5b96e96d027

检测版本号

checkVer(oldVer: string, newVer: string): boolean
实例:tools.common.checkVer('10.0.1','10.0.2');
返回:true

截取自定义长度的字符串

fixLen(str: string, len: number): string
实例:tools.common.fixLen('我们是联诚科技',3);
返回:我们是...

屏幕尺寸缩放时触发回调

screen(cb: Function): void
实例:tools.common.screen((resizedWinWidth, resizedWinHeight, scale)=>{

});

express 代码执行

const context={title:'',name:''}
const exp=new tools.express(context);
//模板解析
const text = exp.template('<div>{{title}}</div><span>{{name}}</span>');

//计算
const ret = exp.compute('1+1');


//代码执行
const ret = exp.execute('let a = title; return a;');

msgBus 消息总线

监听消息

on(topic: string, cb: Function): void
实例:tools.msgBus.on('topic',(type,e)=>{

});

发送消息

emit(topic: string, data: Object): void
实例:tools.msgBus.emit('topic',{a:1});

Package Sidebar

Install

npm i licos-tools

Weekly Downloads

0

Version

1.0.66

License

none

Unpacked Size

578 kB

Total Files

15

Last publish

Collaborators

  • lckj