index

公共函数,使用'lj-utils'引入

Description:
  • 公共函数,使用'lj-utils'引入

Source:
Author:
  • linjielinlin 993353454@qq.com
Description:
  • 文件相关处理

Source:
Author:
  • linjielinlin 993353454@qq.com
Description:
  • 判断函数

Source:
Author:
  • linjielinlin 993353454@qq.com
Description:
  • 类型转换相关处理

Source:
Author:
  • linjielinlin 993353454@qq.com

Methods

(inner) arrayToObj(list, key, extraData) → {Object}

Description:
  • 指定数组key,转换为对象

Source:
Example
// 示例
const list = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
const obj = arrayToObj(list, 'id');
console.log(obj); // 输出: { '1': { id: 1, name: 'Alice' }, '2': { id: 2, name: 'Bob' } }
Parameters:
Name Type Description
list Array.<any>

数组。

key string

对象对应的键值。

extraData string | object

为string时,返回对象的键值对,为object时,返回对象。

Returns:
  • 返回的对象。
Type
Object

(inner) autoPlayAudio(audioUrl, isWeixin) → {HTMLAudioElement}

Description:
  • 自动播放音频并返回音频元素。

Source:
Parameters:
Name Type Description
audioUrl string

音频地址

isWeixin boolean

是否在微信中

Returns:
  • 音频元素
Type
HTMLAudioElement

(inner) blobToBase64(argBlob) → {Promise}

Description:
  • 将Blob对象转换为base64字符串

Source:
Example
blobToBase64(blob).then(base64 => console.log(base64));
Parameters:
Name Type Description
argBlob Blob

需要处理的Blob对象

Returns:

返回base64字符串

Type
Promise

(inner) blobToFile(argBlob, argName) → {File}

Description:
  • 将Blob对象转换为File对象

Source:
Example
const file = blobToFile(blob, 'example.txt');
Parameters:
Name Type Description
argBlob Blob

Blob对象

argName string

文件名,默认为当前时间戳

Returns:

返回File对象

Type
File

(inner) blobUrlToFile(argData) → {Promise}

Description:
  • 将blobUrl转换为File对象

Source:
Example
blobUrlToFile(url).then(file => console.log(file));
Parameters:
Name Type Description
argData string

blobUrl

Returns:

返回File对象

Type
Promise

(inner) dataURLtoBlob(argData) → {Blob}

Description:
  • 将图片的dataUrl base64转换为Blob对象

Source:
Example
const blob = dataURLtoBlob(dataUrl);
Parameters:
Name Type Description
argData string

dataUrl

Returns:

返回Blob对象

Type
Blob

(inner) debounce(func, delay) → {function}

Description:
  • 函数防抖,用于限制函数调用的频率。

Source:
Example
```
const debouncedHello = debounce(sayHello, 1000);
debouncedHello('Hello from 1');
debouncedHello('Hello from 2');
```
Parameters:
Name Type Description
func function

要进行防抖的函数

delay number

延迟时间,单位毫秒

Returns:

返回防抖后的函数

Type
function

(inner) decodeHtml(argHtml) → {string}

Description:
  • 反转义HTML标签。

Source:
Example
// 返回 "&lt;p&gt;Hello, World!&lt;/p&gt;"
decodeHtml("<p>Hello, World!</p>");
Parameters:
Name Type Description
argHtml string

需要反转义的文本。

Returns:

反转义后的文本。

Type
string

(inner) deepCopy(obj)

Source:
Parameters:
Name Type Description
obj

需要拷贝的对象

Returns:

拷贝后的对象

(inner) delCookie(argName)

Description:
  • 清除cookie

Source:
Parameters:
Name Type Description
argName string

要清除的值

(inner) delay(time)

Description:
  • 同步阻塞函数。

Source:
Parameters:
Name Type Default Description
time number 0

延迟的时间量,单位为毫秒

(inner) dlFile(argData, argName, argDelTime)

Description:
  • 下载文件

Source:
Example
dlFile(data, 'example.txt', 10000);
Parameters:
Name Type Description
argData string | Blob | File

Blob对象/File对象/dataUrl/base64

argName string

文件名

argDelTime number

移除dateUrl时间

(inner) encodeHtml(argHtml) → {string}

Description:
  • 转义html标签

Source:
Example
// returns '&lt;p&gt;Hello, World!&lt;/p&gt;'
encodeHtml('<p>Hello, World!</p>')
Parameters:
Name Type Description
argHtml string

需要转义的文本

Returns:
Type
string

(inner) formatNumber(argData, argNum) → {string}

Description:
  • 将数据转换为数量单位k/w

Source:
Example
// returns '2k'
formatNumber(2000, 2)
Parameters:
Name Type Description
argData number

数据

argNum number

保留的小数位数,默认为2

Returns:

计算结果

Type
string

(inner) formatSize(argData, argNum, argIndex, argRate, unit) → {string}

Description:
  • 将byte数据转换为容量单位

Source:
Example
// returns '1.95K'
formatSize(2000, 2, 0, 1024, ['B', 'K', 'M', 'G', 'T', 'P'])
Parameters:
Name Type Description
argData number

byte数据

argNum number

保留的小数位数,默认为2

argIndex number

起始单位偏移,例如: 0:b 1:k 2:m,默认为0

argRate number

进制,默认为1024

unit Array.<string>

进制,默认为['B', 'K', 'M', 'G', 'T', 'P']

Returns:

计算结果

Type
string

(inner) formatTime(date, fmt, emptyTip) → {string}

Description:
  • 日期格式化显示。

Source:
Example
// 返回 '2022-01-01 00:00:00'
formatTime(new Date(2022, 0, 1));
Parameters:
Name Type Description
date string | number | Date

时间对象或时间戳,默认为当前时间。

fmt string

格式化字符串,默认为'YYYY-MM-DD HH:mm:ss'。E为星期数,EEE:星期一,q为季度,S为毫秒数。

emptyTip string

当date为false时的默认值,默认为''。

Returns:

格式化后的日期字符串。

Type
string

(inner) friendlyTime(date, fmt, emptyTip) → {string}

Description:
  • 日期格式化友好显示。例如:刚刚,x分钟前,...。超过一年的按 fmt来格式化。

Source:
Example
// 返回 '刚刚'
friendlyTime(new Date());
Parameters:
Name Type Description
date string | number | Date

时间对象或时间戳,默认为当前时间。

fmt string

格式化字符串,默认为'YYYY-MM-DD HH:mm:ss'。

emptyTip string

当date为false时的默认值,默认为''。

Returns:

格式化后的友好日期字符串。

Type
string

(inner) getCookie(argName) → {string}

Description:
  • 获取cookie

Source:
Parameters:
Name Type Description
argName string

要获取的值

Returns:
Type
string

(inner) getCookieObj() → {object}

Description:
  • 获取cookie对象

Source:
Returns:
Type
object

(inner) getDuration(argFile) → {Promise}

Description:
  • 获取音视频文件的时长

Source:
Example
getDuration(file).then(duration => console.log(duration));
Parameters:
Name Type Description
argFile Blob | File | string

音视频数据,如果是string类型,则为链接

Returns:

返回时长(单位:秒)

Type
Promise

(inner) getEnv(key) → {string}

Description:
  • 获取env参数

Source:
Parameters:
Name Type Description
key string

要获取的值

Returns:

获取的值

Type
string

(inner) getInfo() → {Info}

Description:
  • 检测浏览器状态,系统状态 *

Source:
Returns:

{ ua: ua, platform: 平台, isMobile: 移动端, isWin: winPC端, isIphone: iphone, isIpad: ipad, isMac: mac, isAppleMobile: 苹果移动端webview isSafari: Safari浏览器, isIos: Ios平台, isAndroid: android平台, isIE: 显示8 9 10, true为11以上 ... }

Type
Info

(inner) getNetworkStatus() → {boolean}

Description:
  • 获取当前网络状态(H5)

Source:
Example
```
const status = getNetworkStatus();
```
Returns:
  • boolean

  • Type
    boolean

(inner) getObj(key, argData, isDeepCopy) → {AnyObject}

Description:
  • 获取object参数

Source:
Parameters:
Name Type Description
key string

要获取的值

argData string

要合并的值

isDeepCopy boolean

是否深拷贝

Returns:

获取的值

Type
AnyObject

(inner) getRandomColor()

Description:
  • 获取随机颜色

Source:
Returns:

string

(inner) getRegexp() → {object|object}

Description:
  • 正则收集

Source:
Example
```
const regex = getRegexp();
```
Returns:
  • Type
    object
  • Type
    object

(inner) getStorage(argKey, argNoJson) → {any}

Description:
  • 获取storage的值,默认将json转为obj

Source:
Parameters:
Name Type Description
argKey string

要获取的key

argNoJson string

true时不自动转换JSON字符串

Returns:

key对应的数据

Type
any

(inner) getUrlParam(argName, argUrl) → {string}

Description:
  • 获取url参数

Source:
Parameters:
Name Type Description
argName string

要获取的key

argUrl string

url数据

Returns:
Type
string

(inner) getUrlParamObj(argData) → {any}

Description:
  • 获取所有url参数,eg: a=1&b=2 to {a:1,b:2}

Source:
Parameters:
Name Type Description
argData string

要处理的数据

Returns:
Type
any

(inner) getUuid() → {string}

Description:
  • 获取简单uuid

Source:
Returns:

uuid

Type
string

(inner) hideInfo(argData, argStart, argEnd) → {string}

Description:
  • 数据中间加星号

Source:
Example
// 示例
const data = '1234567890';
const hiddenData = hideInfo(data, 3, 4);
console.log(hiddenData); // 输出: '123***7890'
Parameters:
Name Type Default Description
argData string | number

要处理的数据。

argStart number 3

前端显示多少位。

argEnd number 4

后面显示多少位。

Returns:
  • 返回处理好的数据。
Type
string

(inner) isBlob(argData) → {boolean}

Description:
  • 判断一个值是否为Blob

Source:
Example
isBlob(new Blob()); // true
Parameters:
Name Type Description
argData any

需要判断的数据

Returns:

如果是Blob返回true,否则返回false

Type
boolean

(inner) isFile(argData) → {boolean}

Description:
  • 判断一个值是否为File

Source:
Example
isFile(new File([""], "filename")); // true
Parameters:
Name Type Description
argData any

需要判断的数据

Returns:

如果是File返回true,否则返回false

Type
boolean

(inner) isIdCard(code) → {boolean}

Description:
  • 判断一个字符串是否为正确的身份证号码

Source:
Example
isIdCard('320311770706001'); // false
Parameters:
Name Type Description
code string

身份证号码

Returns:

如果是正确的身份证号码返回true,否则返回false

Type
boolean

(inner) isJson(argData) → {boolean}

Description:
  • 判断一个值是否为JSON

Source:
Example
isJson('{"name":"John"}'); // true
Parameters:
Name Type Description
argData any

需要判断的数据

Returns:

如果是JSON返回true,否则返回false

Type
boolean

(inner) isPrime(argValue) → {boolean}

Description:
  • 判断一个数是否为质数

Source:
Example
isPrime(5); // true
Parameters:
Name Type Description
argValue number

需要判断的数值

Returns:

如果是质数返回true,否则返回false

Type
boolean

(inner) loadFile(argUrl, argType, argOptions) → {Promise}

Description:
  • 动态加载html文件标签

Source:
Example
loadFile(url, 'js', {force: true}).then(() => console.log('Loaded'));
Parameters:
Name Type Description
argUrl string

要加载的url

argType string

加载类型 js/css

argOptions object
argOption.disCheck string

不检查是否有相同标签

argOption.force string

是否强制添加,true时先删除再添加

Returns:

返回Promise对象

Type
Promise

(inner) objToArray(obj, keyopt, valueopt, isReverseopt) → {array}

Description:
  • 将对象转换为键值对数组。

Source:
Example
// Example usage
const obj = { a: 1, b: 2 };
const result = objToArray(obj, 'id', 'v', true);
console.log(result); // Output: [{ v: 'a', id: 1 }, { v: 'b', id: 2 }]
Parameters:
Name Type Attributes Default Description
obj object

要转换的对象。

key string <optional>
'key'

每个键值对的键名称默认key。

value string <optional>
'value'

每个键值对的值名称默认value。

isReverse boolean <optional>
false

如果为true,则键值对将被颠倒,默认为false。

Returns:
  • 键值对数组。
Type
array

(inner) objToObj(obj, tmplObj, isAssign) → {Object}

Description:
  • 从原始对象中复制属性,并将其赋值给新对象,生成一个新对象。

Source:
Example
// 示例
const obj = { a: 1, b: 2 };
const tmplObj = { a: 0, c: 0 };
const newObj = objToObj(obj, tmplObj);
console.log(newObj); // 输出: { a: 1, c: '' }
Parameters:
Name Type Default Description
obj Object

要复制属性的原始对象。

tmplObj Object

要赋值属性的新对象模板。

isAssign boolean false

可选。确定是否将属性赋值给原始对象。

Returns:

复制了属性的新对象。

Type
Object

(inner) off(el, event, handler)

Description:
  • 移除事件绑定

Source:
Parameters:
Name Type Description
el Element

绑定元素

event string

事件名称

handler function

事件处理函数

(inner) on(el, event, handler)

Description:
  • 添加事件绑定

Source:
Parameters:
Name Type Description
el Element

绑定元素

event string

事件名称

handler function

事件处理函数

(inner) px2vw(argPx, argWith, argUnit, argNum) → {string}

Description:
  • 将px单位转换为vw单位

Source:
Example
// returns '187.5vw'
px2vw(200, 375, 'vw', 6)
Parameters:
Name Type Description
argPx number

px单位的数值

argWith number

px对应的最大宽度,默认为375

argUnit string

单位,'vw'或'%',默认为'vw'

argNum number

保留的小数位数,默认为6

Returns:

转换后的数值

Type
string

(inner) randomInt(min, max) → {number}

Description:
  • 获取随机数,含最大值,含最小值

Source:
Parameters:
Name Type Default Description
min number 0

最小值

max number 100

最大值

Returns:
Type
number

(inner) remInit(argBaseSize, argWidth)

Description:
  • 使用postcss-px2rem时使用

Source:
Parameters:
Name Type Default Description
argBaseSize number 16

基础大小 16px(要跟配置一致)

argWidth number 375

基准宽度

(inner) replaceUrlParam(name, value, url) → {string}

Description:
  • 通过正则匹配修改当前页面的url中的参数

Source:
Parameters:
Name Type Description
name string

key

value string | number | undefined | null

要替换的value

url string

要替换的网址,默认location.href

Returns:
Type
string

(inner) requestDeviceMotionPermission()

Description:
  • 摇一摇,请求使用 DeviceMotionEvent API 的权限。for ios

Source:
Example
```
const hasRequest = await requestDeviceMotionPermission()
if (hasRequest) {
   useEventListener(window, 'devicemotion', handleShake)
 } else {
   showToast('未授权访问运动传感器,请手动点击!')
 }
```
Returns:

Promise,指示是否已授予权限。

(inner) rmbPrice(argData, argRate, argUnit, argDef) → {string}

Description:
  • 显示人民币价格。

Source:
Example
// 返回 '¥100.00'
rmbPrice(100, 2);
Parameters:
Name Type Description
argData unknown

价格。

argRate number

保留多少位小数,默认为-1。

argUnit string

单位,默认为'¥'。

argDef string

空数据默认值,默认为'--'。

Returns:

格式化后的价格字符串,例如:'¥100'。

Type
string

(inner) safe(argData, argCheck, argValue, argSetValueForce) → {any}

Description:
  • 数据安全访问

Source:
Parameters:
Name Type Description
argData any

[原始数据]

argCheck string

[要返回的数据,用'.'连接,数组用'.+数字表示']

argValue any

[如果数据有误,返回的值,选填]

argSetValueForce boolean | 0 | 1

[是否强制赋值argValue]

Returns:
Type
any

(inner) safeData(argData, argCheck, argValue, argSetValueForce) → {any}

Description:
  • 数据安全访问

Source:
Parameters:
Name Type Description
argData any

[原始数据]

argCheck string

[要返回的数据,用'.'连接,数组用'.+数字表示']

argValue any

[如果数据为undefined/null,返回argValue,选填]

argSetValueForce boolean | 0 | 1

[是否强制赋值argValue,强制赋值时只返回true/false]

Returns:
Type
any

(inner) secondToTime(argData, argOption) → {string}

Description:
  • 将秒数转换为倒计时格式

Source:
Example
// returns '01h05s'
secondToTime(3905, {s: '秒', m: '分', h: '时', d: '天', M: '月', y: '年', minUtil: 's', maxUnit: 'y', hideZero: false, isAddZero: true})
Parameters:
Name Type Description
argData number

秒数

argOption Object

配置项

Properties
Name Type Description
s string

秒的单位,默认为'秒'

m string

分的单位,默认为'分'

h string

时的单位,默认为'时'

d string

天的单位,默认为'天'

M string

月的单位,默认为'月'

y string

年的单位,默认为'年'

minUtil string

最小显示的时间单位,小于该单位的舍去,默认为's'

maxUnit string

最大的时间单位,默认为'y',大于该单位的合入该单位 's,m,h,d,M,y 对应 秒 分 时 天 月 年',例如: 'm' '13月'

hideZero boolean

是否隐藏为0的时间单位,默认为false,例如 01h05s

isAddZero boolean

是否小于10时,是否添加0,默认为true

Returns:

转换后的倒计时格式的字符串

Type
string

(inner) setCookie(argName, argValue, argTime, argPath, domain)

Description:
  • 设置cookie

Source:
Parameters:
Name Type Default Description
argName string

要设置的key

argValue string

要设置的value

argTime number 24

过期时间/时 默认24

argPath number /

path

domain number

domain

(inner) setEnv(env)

Description:
  • 设置env参数,一般在main.js中调用

Source:
Example
setEnv(import.meta.env)
Parameters:
Name Type Description
env AnyObject

要设置的值

(inner) setLog(logConfig)

Description:
  • 设置日志输出logLevel 1 error 2 warn 3 info 4 log 5 debug

Source:
Example
setLog(localStorage.getItem('logLevel'),{
   error: (...arg) => {
     // todo
   }
 })
Parameters:
Name Type Description
logConfig AnyObject

重写配置

Properties
Name Type Description
error function

错误日志回调(做额外处理用)

(inner) setObj(key, data) → {AnyObject}

Description:
  • 设置object参数,可做运行时缓存

Source:
Parameters:
Name Type Description
key string

要设置的key

data AnyObject

要设置的值

Returns:
Type
AnyObject

(inner) setStorage(argKey, argData) → {string}

Description:
  • 设置storage的值,默认将obj转为json

Source:
Parameters:
Name Type Description
argKey string

要获取的key

argData unknown

要保存的数据

Returns:

保存的数据String

Type
string

(inner) setTitle(argTitle)

Description:
  • 设置标题

Source:
Parameters:
Name Type Description
argTitle string

标题

(inner) setUrlParams(argParams, noMarknullable) → {string}

Description:
  • obj转url参数

Source:
Parameters:
Name Type Attributes Description
argParams any

参数对象

noMark boolean <nullable>

默认带?,true时,不带

Returns:
Type
string

(inner) sleep(ms)

Description:
  • setTimeout promise版,异步阻塞函数

Source:
Parameters:
Name Type Description
ms number

时间,毫秒

(inner) string10to62(argData) → {string}

Description:
  • 将10进制数据转换为62进制,用于短网址转换。

Source:
Example
// 示例
const data = 123456;
const convertedData = string10to62(data);
console.log(convertedData); // 输出: 'w7E'
Parameters:
Name Type Description
argData number | string

要处理的数据。

Returns:
  • 返回处理好的数据。
Type
string

(inner) string62to10(argData) → {number}

Description:
  • 将62进制数据转换为10进制,用于短网址转换。

Source:
Example
// 示例
const data = 'w7E';
const convertedData = string62to10(data);
console.log(convertedData); // 输出: 123456
Parameters:
Name Type Description
argData string

要处理的数据。

Returns:
  • 返回处理好的数据。
Type
number

(inner) throttle(fn, delayopt, …extra) → {function}

Description:
  • 节流函数:该函数用于限制函数的执行频率,使其在指定的时间间隔内最多执行一次

Source:
Example
```
const sayHelloFn = (a: string,b:any) => {
  console.log(a,b);
}
const throttleHello = throttle(sayHelloFn, 300,'extra info);
throttleHello('Hello from 1');
throttleHello('Hello from 2');
// Hello from 1 extra info
```
Parameters:
Name Type Attributes Default Description
fn function

要节流的函数。

delay number <optional>
300

函数执行之间的延迟时间(毫秒)。默认为 300 毫秒。

extra any <repeatable>

可选的额外参数,传递给节流函数的原始调用。

Returns:

返回一个新的函数,该函数具有节流行为。

Type
function

(inner) toFixed(argData, argNum, argType) → {string}

Description:
  • 对数据进行toFixed处理。

Source:
Example
// 示例
const data = 123.456;
const fixedData = toFixed(data, 2, 'round');
console.log(fixedData); // 输出: '123.46'
Parameters:
Name Type Default Description
argData string | number

要处理的数据。

argNum number 2

要保留的位数,默认返回2位小数。

argType string round

返回类型,round:默认四舍五入,floor:向下取整,ceil:向上取整,abs:绝对值。

Returns:
  • 返回处理好的数据。
Type
string

(inner) toHump(argData, argUnit) → {string}

Description:
  • 将下划线字符串转换为驼峰字符串

Source:
Example
// 示例
const data = 'underscore_case';
const convertedData = toHump(data);
console.log(convertedData); // 输出: 'underscoreCase'
Parameters:
Name Type Default Description
argData string

要转换的字符串。

argUnit string _

要转换的字符,默认为“_”。

Returns:
  • 转换后的驼峰字符串。
Type
string

(inner) toLine(argData, argUnit) → {string}

Description:
  • 将驼峰字符串转换为下划线字符串

Source:
Example
// 示例
const data = 'camelCase';
const convertedData = toLine(data);
console.log(convertedData); // 输出: 'camel_case'
Parameters:
Name Type Default Description
argData string

要转换的字符串。

argUnit string _

要转换的字符,默认为“_”。

Returns:
  • 转换后的下划线字符串。
Type
string

文件相关处理

Description:
  • 公共函数,使用'lj-utils'引入

Source:
Author:
  • linjielinlin 993353454@qq.com
Description:
  • 文件相关处理

Source:
Author:
  • linjielinlin 993353454@qq.com
Description:
  • 判断函数

Source:
Author:
  • linjielinlin 993353454@qq.com
Description:
  • 类型转换相关处理

Source:
Author:
  • linjielinlin 993353454@qq.com

Methods

(inner) arrayToObj(list, key, extraData) → {Object}

Description:
  • 指定数组key,转换为对象

Source:
Example
// 示例
const list = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
const obj = arrayToObj(list, 'id');
console.log(obj); // 输出: { '1': { id: 1, name: 'Alice' }, '2': { id: 2, name: 'Bob' } }
Parameters:
Name Type Description
list Array.<any>

数组。

key string

对象对应的键值。

extraData string | object

为string时,返回对象的键值对,为object时,返回对象。

Returns:
  • 返回的对象。
Type
Object

(inner) autoPlayAudio(audioUrl, isWeixin) → {HTMLAudioElement}

Description:
  • 自动播放音频并返回音频元素。

Source:
Parameters:
Name Type Description
audioUrl string

音频地址

isWeixin boolean

是否在微信中

Returns:
  • 音频元素
Type
HTMLAudioElement

(inner) blobToBase64(argBlob) → {Promise}

Description:
  • 将Blob对象转换为base64字符串

Source:
Example
blobToBase64(blob).then(base64 => console.log(base64));
Parameters:
Name Type Description
argBlob Blob

需要处理的Blob对象

Returns:

返回base64字符串

Type
Promise

(inner) blobToFile(argBlob, argName) → {File}

Description:
  • 将Blob对象转换为File对象

Source:
Example
const file = blobToFile(blob, 'example.txt');
Parameters:
Name Type Description
argBlob Blob

Blob对象

argName string

文件名,默认为当前时间戳

Returns:

返回File对象

Type
File

(inner) blobUrlToFile(argData) → {Promise}

Description:
  • 将blobUrl转换为File对象

Source:
Example
blobUrlToFile(url).then(file => console.log(file));
Parameters:
Name Type Description
argData string

blobUrl

Returns:

返回File对象

Type
Promise

(inner) dataURLtoBlob(argData) → {Blob}

Description:
  • 将图片的dataUrl base64转换为Blob对象

Source:
Example
const blob = dataURLtoBlob(dataUrl);
Parameters:
Name Type Description
argData string

dataUrl

Returns:

返回Blob对象

Type
Blob

(inner) debounce(func, delay) → {function}

Description:
  • 函数防抖,用于限制函数调用的频率。

Source:
Example
```
const debouncedHello = debounce(sayHello, 1000);
debouncedHello('Hello from 1');
debouncedHello('Hello from 2');
```
Parameters:
Name Type Description
func function

要进行防抖的函数

delay number

延迟时间,单位毫秒

Returns:

返回防抖后的函数

Type
function

(inner) decodeHtml(argHtml) → {string}

Description:
  • 反转义HTML标签。

Source:
Example
// 返回 "&lt;p&gt;Hello, World!&lt;/p&gt;"
decodeHtml("<p>Hello, World!</p>");
Parameters:
Name Type Description
argHtml string

需要反转义的文本。

Returns:

反转义后的文本。

Type
string

(inner) deepCopy(obj)

Source:
Parameters:
Name Type Description
obj

需要拷贝的对象

Returns:

拷贝后的对象

(inner) delCookie(argName)

Description:
  • 清除cookie

Source:
Parameters:
Name Type Description
argName string

要清除的值

(inner) delay(time)

Description:
  • 同步阻塞函数。

Source:
Parameters:
Name Type Default Description
time number 0

延迟的时间量,单位为毫秒

(inner) dlFile(argData, argName, argDelTime)

Description:
  • 下载文件

Source:
Example
dlFile(data, 'example.txt', 10000);
Parameters:
Name Type Description
argData string | Blob | File

Blob对象/File对象/dataUrl/base64

argName string

文件名

argDelTime number

移除dateUrl时间

(inner) encodeHtml(argHtml) → {string}

Description:
  • 转义html标签

Source:
Example
// returns '&lt;p&gt;Hello, World!&lt;/p&gt;'
encodeHtml('<p>Hello, World!</p>')
Parameters:
Name Type Description
argHtml string

需要转义的文本

Returns:
Type
string

(inner) formatNumber(argData, argNum) → {string}

Description:
  • 将数据转换为数量单位k/w

Source:
Example
// returns '2k'
formatNumber(2000, 2)
Parameters:
Name Type Description
argData number

数据

argNum number

保留的小数位数,默认为2

Returns:

计算结果

Type
string

(inner) formatSize(argData, argNum, argIndex, argRate, unit) → {string}

Description:
  • 将byte数据转换为容量单位

Source:
Example
// returns '1.95K'
formatSize(2000, 2, 0, 1024, ['B', 'K', 'M', 'G', 'T', 'P'])
Parameters:
Name Type Description
argData number

byte数据

argNum number

保留的小数位数,默认为2

argIndex number

起始单位偏移,例如: 0:b 1:k 2:m,默认为0

argRate number

进制,默认为1024

unit Array.<string>

进制,默认为['B', 'K', 'M', 'G', 'T', 'P']

Returns:

计算结果

Type
string

(inner) formatTime(date, fmt, emptyTip) → {string}

Description:
  • 日期格式化显示。

Source:
Example
// 返回 '2022-01-01 00:00:00'
formatTime(new Date(2022, 0, 1));
Parameters:
Name Type Description
date string | number | Date

时间对象或时间戳,默认为当前时间。

fmt string

格式化字符串,默认为'YYYY-MM-DD HH:mm:ss'。E为星期数,EEE:星期一,q为季度,S为毫秒数。

emptyTip string

当date为false时的默认值,默认为''。

Returns:

格式化后的日期字符串。

Type
string

(inner) friendlyTime(date, fmt, emptyTip) → {string}

Description:
  • 日期格式化友好显示。例如:刚刚,x分钟前,...。超过一年的按 fmt来格式化。

Source:
Example
// 返回 '刚刚'
friendlyTime(new Date());
Parameters:
Name Type Description
date string | number | Date

时间对象或时间戳,默认为当前时间。

fmt string

格式化字符串,默认为'YYYY-MM-DD HH:mm:ss'。

emptyTip string

当date为false时的默认值,默认为''。

Returns:

格式化后的友好日期字符串。

Type
string

(inner) getCookie(argName) → {string}

Description:
  • 获取cookie

Source:
Parameters:
Name Type Description
argName string

要获取的值

Returns:
Type
string

(inner) getCookieObj() → {object}

Description:
  • 获取cookie对象

Source:
Returns:
Type
object

(inner) getDuration(argFile) → {Promise}

Description:
  • 获取音视频文件的时长

Source:
Example
getDuration(file).then(duration => console.log(duration));
Parameters:
Name Type Description
argFile Blob | File | string

音视频数据,如果是string类型,则为链接

Returns:

返回时长(单位:秒)

Type
Promise

(inner) getEnv(key) → {string}

Description:
  • 获取env参数

Source:
Parameters:
Name Type Description
key string

要获取的值

Returns:

获取的值

Type
string

(inner) getInfo() → {Info}

Description:
  • 检测浏览器状态,系统状态 *

Source:
Returns:

{ ua: ua, platform: 平台, isMobile: 移动端, isWin: winPC端, isIphone: iphone, isIpad: ipad, isMac: mac, isAppleMobile: 苹果移动端webview isSafari: Safari浏览器, isIos: Ios平台, isAndroid: android平台, isIE: 显示8 9 10, true为11以上 ... }

Type
Info

(inner) getNetworkStatus() → {boolean}

Description:
  • 获取当前网络状态(H5)

Source:
Example
```
const status = getNetworkStatus();
```
Returns:
  • boolean

  • Type
    boolean

(inner) getObj(key, argData, isDeepCopy) → {AnyObject}

Description:
  • 获取object参数

Source:
Parameters:
Name Type Description
key string

要获取的值

argData string

要合并的值

isDeepCopy boolean

是否深拷贝

Returns:

获取的值

Type
AnyObject

(inner) getRandomColor()

Description:
  • 获取随机颜色

Source:
Returns:

string

(inner) getRegexp() → {object|object}

Description:
  • 正则收集

Source:
Example
```
const regex = getRegexp();
```
Returns:
  • Type
    object
  • Type
    object

(inner) getStorage(argKey, argNoJson) → {any}

Description:
  • 获取storage的值,默认将json转为obj

Source:
Parameters:
Name Type Description
argKey string

要获取的key

argNoJson string

true时不自动转换JSON字符串

Returns:

key对应的数据

Type
any

(inner) getUrlParam(argName, argUrl) → {string}

Description:
  • 获取url参数

Source:
Parameters:
Name Type Description
argName string

要获取的key

argUrl string

url数据

Returns:
Type
string

(inner) getUrlParamObj(argData) → {any}

Description:
  • 获取所有url参数,eg: a=1&b=2 to {a:1,b:2}

Source:
Parameters:
Name Type Description
argData string

要处理的数据

Returns:
Type
any

(inner) getUuid() → {string}

Description:
  • 获取简单uuid

Source:
Returns:

uuid

Type
string

(inner) hideInfo(argData, argStart, argEnd) → {string}

Description:
  • 数据中间加星号

Source:
Example
// 示例
const data = '1234567890';
const hiddenData = hideInfo(data, 3, 4);
console.log(hiddenData); // 输出: '123***7890'
Parameters:
Name Type Default Description
argData string | number

要处理的数据。

argStart number 3

前端显示多少位。

argEnd number 4

后面显示多少位。

Returns:
  • 返回处理好的数据。
Type
string

(inner) isBlob(argData) → {boolean}

Description:
  • 判断一个值是否为Blob

Source:
Example
isBlob(new Blob()); // true
Parameters:
Name Type Description
argData any

需要判断的数据

Returns:

如果是Blob返回true,否则返回false

Type
boolean

(inner) isFile(argData) → {boolean}

Description:
  • 判断一个值是否为File

Source:
Example
isFile(new File([""], "filename")); // true
Parameters:
Name Type Description
argData any

需要判断的数据

Returns:

如果是File返回true,否则返回false

Type
boolean

(inner) isIdCard(code) → {boolean}

Description:
  • 判断一个字符串是否为正确的身份证号码

Source:
Example
isIdCard('320311770706001'); // false
Parameters:
Name Type Description
code string

身份证号码

Returns:

如果是正确的身份证号码返回true,否则返回false

Type
boolean

(inner) isJson(argData) → {boolean}

Description:
  • 判断一个值是否为JSON

Source:
Example
isJson('{"name":"John"}'); // true
Parameters:
Name Type Description
argData any

需要判断的数据

Returns:

如果是JSON返回true,否则返回false

Type
boolean

(inner) isPrime(argValue) → {boolean}

Description:
  • 判断一个数是否为质数

Source:
Example
isPrime(5); // true
Parameters:
Name Type Description
argValue number

需要判断的数值

Returns:

如果是质数返回true,否则返回false

Type
boolean

(inner) loadFile(argUrl, argType, argOptions) → {Promise}

Description:
  • 动态加载html文件标签

Source:
Example
loadFile(url, 'js', {force: true}).then(() => console.log('Loaded'));
Parameters:
Name Type Description
argUrl string

要加载的url

argType string

加载类型 js/css

argOptions object
argOption.disCheck string

不检查是否有相同标签

argOption.force string

是否强制添加,true时先删除再添加

Returns:

返回Promise对象

Type
Promise

(inner) objToArray(obj, keyopt, valueopt, isReverseopt) → {array}

Description:
  • 将对象转换为键值对数组。

Source:
Example
// Example usage
const obj = { a: 1, b: 2 };
const result = objToArray(obj, 'id', 'v', true);
console.log(result); // Output: [{ v: 'a', id: 1 }, { v: 'b', id: 2 }]
Parameters:
Name Type Attributes Default Description
obj object

要转换的对象。

key string <optional>
'key'

每个键值对的键名称默认key。

value string <optional>
'value'

每个键值对的值名称默认value。

isReverse boolean <optional>
false

如果为true,则键值对将被颠倒,默认为false。

Returns:
  • 键值对数组。
Type
array

(inner) objToObj(obj, tmplObj, isAssign) → {Object}

Description:
  • 从原始对象中复制属性,并将其赋值给新对象,生成一个新对象。

Source:
Example
// 示例
const obj = { a: 1, b: 2 };
const tmplObj = { a: 0, c: 0 };
const newObj = objToObj(obj, tmplObj);
console.log(newObj); // 输出: { a: 1, c: '' }
Parameters:
Name Type Default Description
obj Object

要复制属性的原始对象。

tmplObj Object

要赋值属性的新对象模板。

isAssign boolean false

可选。确定是否将属性赋值给原始对象。

Returns:

复制了属性的新对象。

Type
Object

(inner) off(el, event, handler)

Description:
  • 移除事件绑定

Source:
Parameters:
Name Type Description
el Element

绑定元素

event string

事件名称

handler function

事件处理函数

(inner) on(el, event, handler)

Description:
  • 添加事件绑定

Source:
Parameters:
Name Type Description
el Element

绑定元素

event string

事件名称

handler function

事件处理函数

(inner) px2vw(argPx, argWith, argUnit, argNum) → {string}

Description:
  • 将px单位转换为vw单位

Source:
Example
// returns '187.5vw'
px2vw(200, 375, 'vw', 6)
Parameters:
Name Type Description
argPx number

px单位的数值

argWith number

px对应的最大宽度,默认为375

argUnit string

单位,'vw'或'%',默认为'vw'

argNum number

保留的小数位数,默认为6

Returns:

转换后的数值

Type
string

(inner) randomInt(min, max) → {number}

Description:
  • 获取随机数,含最大值,含最小值

Source:
Parameters:
Name Type Default Description
min number 0

最小值

max number 100

最大值

Returns:
Type
number

(inner) remInit(argBaseSize, argWidth)

Description:
  • 使用postcss-px2rem时使用

Source:
Parameters:
Name Type Default Description
argBaseSize number 16

基础大小 16px(要跟配置一致)

argWidth number 375

基准宽度

(inner) replaceUrlParam(name, value, url) → {string}

Description:
  • 通过正则匹配修改当前页面的url中的参数

Source:
Parameters:
Name Type Description
name string

key

value string | number | undefined | null

要替换的value

url string

要替换的网址,默认location.href

Returns:
Type
string

(inner) requestDeviceMotionPermission()

Description:
  • 摇一摇,请求使用 DeviceMotionEvent API 的权限。for ios

Source:
Example
```
const hasRequest = await requestDeviceMotionPermission()
if (hasRequest) {
   useEventListener(window, 'devicemotion', handleShake)
 } else {
   showToast('未授权访问运动传感器,请手动点击!')
 }
```
Returns:

Promise,指示是否已授予权限。

(inner) rmbPrice(argData, argRate, argUnit, argDef) → {string}

Description:
  • 显示人民币价格。

Source:
Example
// 返回 '¥100.00'
rmbPrice(100, 2);
Parameters:
Name Type Description
argData unknown

价格。

argRate number

保留多少位小数,默认为-1。

argUnit string

单位,默认为'¥'。

argDef string

空数据默认值,默认为'--'。

Returns:

格式化后的价格字符串,例如:'¥100'。

Type
string

(inner) safe(argData, argCheck, argValue, argSetValueForce) → {any}

Description:
  • 数据安全访问

Source:
Parameters:
Name Type Description
argData any

[原始数据]

argCheck string

[要返回的数据,用'.'连接,数组用'.+数字表示']

argValue any

[如果数据有误,返回的值,选填]

argSetValueForce boolean | 0 | 1

[是否强制赋值argValue]

Returns:
Type
any

(inner) safeData(argData, argCheck, argValue, argSetValueForce) → {any}

Description:
  • 数据安全访问

Source:
Parameters:
Name Type Description
argData any

[原始数据]

argCheck string

[要返回的数据,用'.'连接,数组用'.+数字表示']

argValue any

[如果数据为undefined/null,返回argValue,选填]

argSetValueForce boolean | 0 | 1

[是否强制赋值argValue,强制赋值时只返回true/false]

Returns:
Type
any

(inner) secondToTime(argData, argOption) → {string}

Description:
  • 将秒数转换为倒计时格式

Source:
Example
// returns '01h05s'
secondToTime(3905, {s: '秒', m: '分', h: '时', d: '天', M: '月', y: '年', minUtil: 's', maxUnit: 'y', hideZero: false, isAddZero: true})
Parameters:
Name Type Description
argData number

秒数

argOption Object

配置项

Properties
Name Type Description
s string

秒的单位,默认为'秒'

m string

分的单位,默认为'分'

h string

时的单位,默认为'时'

d string

天的单位,默认为'天'

M string

月的单位,默认为'月'

y string

年的单位,默认为'年'

minUtil string

最小显示的时间单位,小于该单位的舍去,默认为's'

maxUnit string

最大的时间单位,默认为'y',大于该单位的合入该单位 's,m,h,d,M,y 对应 秒 分 时 天 月 年',例如: 'm' '13月'

hideZero boolean

是否隐藏为0的时间单位,默认为false,例如 01h05s

isAddZero boolean

是否小于10时,是否添加0,默认为true

Returns:

转换后的倒计时格式的字符串

Type
string

(inner) setCookie(argName, argValue, argTime, argPath, domain)

Description:
  • 设置cookie

Source:
Parameters:
Name Type Default Description
argName string

要设置的key

argValue string

要设置的value

argTime number 24

过期时间/时 默认24

argPath number /

path

domain number

domain

(inner) setEnv(env)

Description:
  • 设置env参数,一般在main.js中调用

Source:
Example
setEnv(import.meta.env)
Parameters:
Name Type Description
env AnyObject

要设置的值

(inner) setLog(logConfig)

Description:
  • 设置日志输出logLevel 1 error 2 warn 3 info 4 log 5 debug

Source:
Example
setLog(localStorage.getItem('logLevel'),{
   error: (...arg) => {
     // todo
   }
 })
Parameters:
Name Type Description
logConfig AnyObject

重写配置

Properties
Name Type Description
error function

错误日志回调(做额外处理用)

(inner) setObj(key, data) → {AnyObject}

Description:
  • 设置object参数,可做运行时缓存

Source:
Parameters:
Name Type Description
key string

要设置的key

data AnyObject

要设置的值

Returns:
Type
AnyObject

(inner) setStorage(argKey, argData) → {string}

Description:
  • 设置storage的值,默认将obj转为json

Source:
Parameters:
Name Type Description
argKey string

要获取的key

argData unknown

要保存的数据

Returns:

保存的数据String

Type
string

(inner) setTitle(argTitle)

Description:
  • 设置标题

Source:
Parameters:
Name Type Description
argTitle string

标题

(inner) setUrlParams(argParams, noMarknullable) → {string}

Description:
  • obj转url参数

Source:
Parameters:
Name Type Attributes Description
argParams any

参数对象

noMark boolean <nullable>

默认带?,true时,不带

Returns:
Type
string

(inner) sleep(ms)

Description:
  • setTimeout promise版,异步阻塞函数

Source:
Parameters:
Name Type Description
ms number

时间,毫秒

(inner) string10to62(argData) → {string}

Description:
  • 将10进制数据转换为62进制,用于短网址转换。

Source:
Example
// 示例
const data = 123456;
const convertedData = string10to62(data);
console.log(convertedData); // 输出: 'w7E'
Parameters:
Name Type Description
argData number | string

要处理的数据。

Returns:
  • 返回处理好的数据。
Type
string

(inner) string62to10(argData) → {number}

Description:
  • 将62进制数据转换为10进制,用于短网址转换。

Source:
Example
// 示例
const data = 'w7E';
const convertedData = string62to10(data);
console.log(convertedData); // 输出: 123456
Parameters:
Name Type Description
argData string

要处理的数据。

Returns:
  • 返回处理好的数据。
Type
number

(inner) throttle(fn, delayopt, …extra) → {function}

Description:
  • 节流函数:该函数用于限制函数的执行频率,使其在指定的时间间隔内最多执行一次

Source:
Example
```
const sayHelloFn = (a: string,b:any) => {
  console.log(a,b);
}
const throttleHello = throttle(sayHelloFn, 300,'extra info);
throttleHello('Hello from 1');
throttleHello('Hello from 2');
// Hello from 1 extra info
```
Parameters:
Name Type Attributes Default Description
fn function

要节流的函数。

delay number <optional>
300

函数执行之间的延迟时间(毫秒)。默认为 300 毫秒。

extra any <repeatable>

可选的额外参数,传递给节流函数的原始调用。

Returns:

返回一个新的函数,该函数具有节流行为。

Type
function

(inner) toFixed(argData, argNum, argType) → {string}

Description:
  • 对数据进行toFixed处理。

Source:
Example
// 示例
const data = 123.456;
const fixedData = toFixed(data, 2, 'round');
console.log(fixedData); // 输出: '123.46'
Parameters:
Name Type Default Description
argData string | number

要处理的数据。

argNum number 2

要保留的位数,默认返回2位小数。

argType string round

返回类型,round:默认四舍五入,floor:向下取整,ceil:向上取整,abs:绝对值。

Returns:
  • 返回处理好的数据。
Type
string

(inner) toHump(argData, argUnit) → {string}

Description:
  • 将下划线字符串转换为驼峰字符串

Source:
Example
// 示例
const data = 'underscore_case';
const convertedData = toHump(data);
console.log(convertedData); // 输出: 'underscoreCase'
Parameters:
Name Type Default Description
argData string

要转换的字符串。

argUnit string _

要转换的字符,默认为“_”。

Returns:
  • 转换后的驼峰字符串。
Type
string

(inner) toLine(argData, argUnit) → {string}

Description:
  • 将驼峰字符串转换为下划线字符串

Source:
Example
// 示例
const data = 'camelCase';
const convertedData = toLine(data);
console.log(convertedData); // 输出: 'camel_case'
Parameters:
Name Type Default Description
argData string

要转换的字符串。

argUnit string _

要转换的字符,默认为“_”。

Returns:
  • 转换后的下划线字符串。
Type
string

判断函数

Description:
  • 公共函数,使用'lj-utils'引入

Source:
Author:
  • linjielinlin 993353454@qq.com
Description:
  • 文件相关处理

Source:
Author:
  • linjielinlin 993353454@qq.com
Description:
  • 判断函数

Source:
Author:
  • linjielinlin 993353454@qq.com
Description:
  • 类型转换相关处理

Source:
Author:
  • linjielinlin 993353454@qq.com

Methods

(inner) arrayToObj(list, key, extraData) → {Object}

Description:
  • 指定数组key,转换为对象

Source:
Example
// 示例
const list = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
const obj = arrayToObj(list, 'id');
console.log(obj); // 输出: { '1': { id: 1, name: 'Alice' }, '2': { id: 2, name: 'Bob' } }
Parameters:
Name Type Description
list Array.<any>

数组。

key string

对象对应的键值。

extraData string | object

为string时,返回对象的键值对,为object时,返回对象。

Returns:
  • 返回的对象。
Type
Object

(inner) autoPlayAudio(audioUrl, isWeixin) → {HTMLAudioElement}

Description:
  • 自动播放音频并返回音频元素。

Source:
Parameters:
Name Type Description
audioUrl string

音频地址

isWeixin boolean

是否在微信中

Returns:
  • 音频元素
Type
HTMLAudioElement

(inner) blobToBase64(argBlob) → {Promise}

Description:
  • 将Blob对象转换为base64字符串

Source:
Example
blobToBase64(blob).then(base64 => console.log(base64));
Parameters:
Name Type Description
argBlob Blob

需要处理的Blob对象

Returns:

返回base64字符串

Type
Promise

(inner) blobToFile(argBlob, argName) → {File}

Description:
  • 将Blob对象转换为File对象

Source:
Example
const file = blobToFile(blob, 'example.txt');
Parameters:
Name Type Description
argBlob Blob

Blob对象

argName string

文件名,默认为当前时间戳

Returns:

返回File对象

Type
File

(inner) blobUrlToFile(argData) → {Promise}

Description:
  • 将blobUrl转换为File对象

Source:
Example
blobUrlToFile(url).then(file => console.log(file));
Parameters:
Name Type Description
argData string

blobUrl

Returns:

返回File对象

Type
Promise

(inner) dataURLtoBlob(argData) → {Blob}

Description:
  • 将图片的dataUrl base64转换为Blob对象

Source:
Example
const blob = dataURLtoBlob(dataUrl);
Parameters:
Name Type Description
argData string

dataUrl

Returns:

返回Blob对象

Type
Blob

(inner) debounce(func, delay) → {function}

Description:
  • 函数防抖,用于限制函数调用的频率。

Source:
Example
```
const debouncedHello = debounce(sayHello, 1000);
debouncedHello('Hello from 1');
debouncedHello('Hello from 2');
```
Parameters:
Name Type Description
func function

要进行防抖的函数

delay number

延迟时间,单位毫秒

Returns:

返回防抖后的函数

Type
function

(inner) decodeHtml(argHtml) → {string}

Description:
  • 反转义HTML标签。

Source:
Example
// 返回 "&lt;p&gt;Hello, World!&lt;/p&gt;"
decodeHtml("<p>Hello, World!</p>");
Parameters:
Name Type Description
argHtml string

需要反转义的文本。

Returns:

反转义后的文本。

Type
string

(inner) deepCopy(obj)

Source:
Parameters:
Name Type Description
obj

需要拷贝的对象

Returns:

拷贝后的对象

(inner) delCookie(argName)

Description:
  • 清除cookie

Source:
Parameters:
Name Type Description
argName string

要清除的值

(inner) delay(time)

Description:
  • 同步阻塞函数。

Source:
Parameters:
Name Type Default Description
time number 0

延迟的时间量,单位为毫秒

(inner) dlFile(argData, argName, argDelTime)

Description:
  • 下载文件

Source:
Example
dlFile(data, 'example.txt', 10000);
Parameters:
Name Type Description
argData string | Blob | File

Blob对象/File对象/dataUrl/base64

argName string

文件名

argDelTime number

移除dateUrl时间

(inner) encodeHtml(argHtml) → {string}

Description:
  • 转义html标签

Source:
Example
// returns '&lt;p&gt;Hello, World!&lt;/p&gt;'
encodeHtml('<p>Hello, World!</p>')
Parameters:
Name Type Description
argHtml string

需要转义的文本

Returns:
Type
string

(inner) formatNumber(argData, argNum) → {string}

Description:
  • 将数据转换为数量单位k/w

Source:
Example
// returns '2k'
formatNumber(2000, 2)
Parameters:
Name Type Description
argData number

数据

argNum number

保留的小数位数,默认为2

Returns:

计算结果

Type
string

(inner) formatSize(argData, argNum, argIndex, argRate, unit) → {string}

Description:
  • 将byte数据转换为容量单位

Source:
Example
// returns '1.95K'
formatSize(2000, 2, 0, 1024, ['B', 'K', 'M', 'G', 'T', 'P'])
Parameters:
Name Type Description
argData number

byte数据

argNum number

保留的小数位数,默认为2

argIndex number

起始单位偏移,例如: 0:b 1:k 2:m,默认为0

argRate number

进制,默认为1024

unit Array.<string>

进制,默认为['B', 'K', 'M', 'G', 'T', 'P']

Returns:

计算结果

Type
string

(inner) formatTime(date, fmt, emptyTip) → {string}

Description:
  • 日期格式化显示。

Source:
Example
// 返回 '2022-01-01 00:00:00'
formatTime(new Date(2022, 0, 1));
Parameters:
Name Type Description
date string | number | Date

时间对象或时间戳,默认为当前时间。

fmt string

格式化字符串,默认为'YYYY-MM-DD HH:mm:ss'。E为星期数,EEE:星期一,q为季度,S为毫秒数。

emptyTip string

当date为false时的默认值,默认为''。

Returns:

格式化后的日期字符串。

Type
string

(inner) friendlyTime(date, fmt, emptyTip) → {string}

Description:
  • 日期格式化友好显示。例如:刚刚,x分钟前,...。超过一年的按 fmt来格式化。

Source:
Example
// 返回 '刚刚'
friendlyTime(new Date());
Parameters:
Name Type Description
date string | number | Date

时间对象或时间戳,默认为当前时间。

fmt string

格式化字符串,默认为'YYYY-MM-DD HH:mm:ss'。

emptyTip string

当date为false时的默认值,默认为''。

Returns:

格式化后的友好日期字符串。

Type
string

(inner) getCookie(argName) → {string}

Description:
  • 获取cookie

Source:
Parameters:
Name Type Description
argName string

要获取的值

Returns:
Type
string

(inner) getCookieObj() → {object}

Description:
  • 获取cookie对象

Source:
Returns:
Type
object

(inner) getDuration(argFile) → {Promise}

Description:
  • 获取音视频文件的时长

Source:
Example
getDuration(file).then(duration => console.log(duration));
Parameters:
Name Type Description
argFile Blob | File | string

音视频数据,如果是string类型,则为链接

Returns:

返回时长(单位:秒)

Type
Promise

(inner) getEnv(key) → {string}

Description:
  • 获取env参数

Source:
Parameters:
Name Type Description
key string

要获取的值

Returns:

获取的值

Type
string

(inner) getInfo() → {Info}

Description:
  • 检测浏览器状态,系统状态 *

Source:
Returns:

{ ua: ua, platform: 平台, isMobile: 移动端, isWin: winPC端, isIphone: iphone, isIpad: ipad, isMac: mac, isAppleMobile: 苹果移动端webview isSafari: Safari浏览器, isIos: Ios平台, isAndroid: android平台, isIE: 显示8 9 10, true为11以上 ... }

Type
Info

(inner) getNetworkStatus() → {boolean}

Description:
  • 获取当前网络状态(H5)

Source:
Example
```
const status = getNetworkStatus();
```
Returns:
  • boolean

  • Type
    boolean

(inner) getObj(key, argData, isDeepCopy) → {AnyObject}

Description:
  • 获取object参数

Source:
Parameters:
Name Type Description
key string

要获取的值

argData string

要合并的值

isDeepCopy boolean

是否深拷贝

Returns:

获取的值

Type
AnyObject

(inner) getRandomColor()

Description:
  • 获取随机颜色

Source:
Returns:

string

(inner) getRegexp() → {object|object}

Description:
  • 正则收集

Source:
Example
```
const regex = getRegexp();
```
Returns:
  • Type
    object
  • Type
    object

(inner) getStorage(argKey, argNoJson) → {any}

Description:
  • 获取storage的值,默认将json转为obj

Source:
Parameters:
Name Type Description
argKey string

要获取的key

argNoJson string

true时不自动转换JSON字符串

Returns:

key对应的数据

Type
any

(inner) getUrlParam(argName, argUrl) → {string}

Description:
  • 获取url参数

Source:
Parameters:
Name Type Description
argName string

要获取的key

argUrl string

url数据

Returns:
Type
string

(inner) getUrlParamObj(argData) → {any}

Description:
  • 获取所有url参数,eg: a=1&b=2 to {a:1,b:2}

Source:
Parameters:
Name Type Description
argData string

要处理的数据

Returns:
Type
any

(inner) getUuid() → {string}

Description:
  • 获取简单uuid

Source:
Returns:

uuid

Type
string

(inner) hideInfo(argData, argStart, argEnd) → {string}

Description:
  • 数据中间加星号

Source:
Example
// 示例
const data = '1234567890';
const hiddenData = hideInfo(data, 3, 4);
console.log(hiddenData); // 输出: '123***7890'
Parameters:
Name Type Default Description
argData string | number

要处理的数据。

argStart number 3

前端显示多少位。

argEnd number 4

后面显示多少位。

Returns:
  • 返回处理好的数据。
Type
string

(inner) isBlob(argData) → {boolean}

Description:
  • 判断一个值是否为Blob

Source:
Example
isBlob(new Blob()); // true
Parameters:
Name Type Description
argData any

需要判断的数据

Returns:

如果是Blob返回true,否则返回false

Type
boolean

(inner) isFile(argData) → {boolean}

Description:
  • 判断一个值是否为File

Source:
Example
isFile(new File([""], "filename")); // true
Parameters:
Name Type Description
argData any

需要判断的数据

Returns:

如果是File返回true,否则返回false

Type
boolean

(inner) isIdCard(code) → {boolean}

Description:
  • 判断一个字符串是否为正确的身份证号码

Source:
Example
isIdCard('320311770706001'); // false
Parameters:
Name Type Description
code string

身份证号码

Returns:

如果是正确的身份证号码返回true,否则返回false

Type
boolean

(inner) isJson(argData) → {boolean}

Description:
  • 判断一个值是否为JSON

Source:
Example
isJson('{"name":"John"}'); // true
Parameters:
Name Type Description
argData any

需要判断的数据

Returns:

如果是JSON返回true,否则返回false

Type
boolean

(inner) isPrime(argValue) → {boolean}

Description:
  • 判断一个数是否为质数

Source:
Example
isPrime(5); // true
Parameters:
Name Type Description
argValue number

需要判断的数值

Returns:

如果是质数返回true,否则返回false

Type
boolean

(inner) loadFile(argUrl, argType, argOptions) → {Promise}

Description:
  • 动态加载html文件标签

Source:
Example
loadFile(url, 'js', {force: true}).then(() => console.log('Loaded'));
Parameters:
Name Type Description
argUrl string

要加载的url

argType string

加载类型 js/css

argOptions object
argOption.disCheck string

不检查是否有相同标签

argOption.force string

是否强制添加,true时先删除再添加

Returns:

返回Promise对象

Type
Promise

(inner) objToArray(obj, keyopt, valueopt, isReverseopt) → {array}

Description:
  • 将对象转换为键值对数组。

Source:
Example
// Example usage
const obj = { a: 1, b: 2 };
const result = objToArray(obj, 'id', 'v', true);
console.log(result); // Output: [{ v: 'a', id: 1 }, { v: 'b', id: 2 }]
Parameters:
Name Type Attributes Default Description
obj object

要转换的对象。

key string <optional>
'key'

每个键值对的键名称默认key。

value string <optional>
'value'

每个键值对的值名称默认value。

isReverse boolean <optional>
false

如果为true,则键值对将被颠倒,默认为false。

Returns:
  • 键值对数组。
Type
array

(inner) objToObj(obj, tmplObj, isAssign) → {Object}

Description:
  • 从原始对象中复制属性,并将其赋值给新对象,生成一个新对象。

Source:
Example
// 示例
const obj = { a: 1, b: 2 };
const tmplObj = { a: 0, c: 0 };
const newObj = objToObj(obj, tmplObj);
console.log(newObj); // 输出: { a: 1, c: '' }
Parameters:
Name Type Default Description
obj Object

要复制属性的原始对象。

tmplObj Object

要赋值属性的新对象模板。

isAssign boolean false

可选。确定是否将属性赋值给原始对象。

Returns:

复制了属性的新对象。

Type
Object

(inner) off(el, event, handler)

Description:
  • 移除事件绑定

Source:
Parameters:
Name Type Description
el Element

绑定元素

event string

事件名称

handler function

事件处理函数

(inner) on(el, event, handler)

Description:
  • 添加事件绑定

Source:
Parameters:
Name Type Description
el Element

绑定元素

event string

事件名称

handler function

事件处理函数

(inner) px2vw(argPx, argWith, argUnit, argNum) → {string}

Description:
  • 将px单位转换为vw单位

Source:
Example
// returns '187.5vw'
px2vw(200, 375, 'vw', 6)
Parameters:
Name Type Description
argPx number

px单位的数值

argWith number

px对应的最大宽度,默认为375

argUnit string

单位,'vw'或'%',默认为'vw'

argNum number

保留的小数位数,默认为6

Returns:

转换后的数值

Type
string

(inner) randomInt(min, max) → {number}

Description:
  • 获取随机数,含最大值,含最小值

Source:
Parameters:
Name Type Default Description
min number 0

最小值

max number 100

最大值

Returns:
Type
number

(inner) remInit(argBaseSize, argWidth)

Description:
  • 使用postcss-px2rem时使用

Source:
Parameters:
Name Type Default Description
argBaseSize number 16

基础大小 16px(要跟配置一致)

argWidth number 375

基准宽度

(inner) replaceUrlParam(name, value, url) → {string}

Description:
  • 通过正则匹配修改当前页面的url中的参数

Source:
Parameters:
Name Type Description
name string

key

value string | number | undefined | null

要替换的value

url string

要替换的网址,默认location.href

Returns:
Type
string

(inner) requestDeviceMotionPermission()

Description:
  • 摇一摇,请求使用 DeviceMotionEvent API 的权限。for ios

Source:
Example
```
const hasRequest = await requestDeviceMotionPermission()
if (hasRequest) {
   useEventListener(window, 'devicemotion', handleShake)
 } else {
   showToast('未授权访问运动传感器,请手动点击!')
 }
```
Returns:

Promise,指示是否已授予权限。

(inner) rmbPrice(argData, argRate, argUnit, argDef) → {string}

Description:
  • 显示人民币价格。

Source:
Example
// 返回 '¥100.00'
rmbPrice(100, 2);
Parameters:
Name Type Description
argData unknown

价格。

argRate number

保留多少位小数,默认为-1。

argUnit string

单位,默认为'¥'。

argDef string

空数据默认值,默认为'--'。

Returns:

格式化后的价格字符串,例如:'¥100'。

Type
string

(inner) safe(argData, argCheck, argValue, argSetValueForce) → {any}

Description:
  • 数据安全访问

Source:
Parameters:
Name Type Description
argData any

[原始数据]

argCheck string

[要返回的数据,用'.'连接,数组用'.+数字表示']

argValue any

[如果数据有误,返回的值,选填]

argSetValueForce boolean | 0 | 1

[是否强制赋值argValue]

Returns:
Type
any

(inner) safeData(argData, argCheck, argValue, argSetValueForce) → {any}

Description:
  • 数据安全访问

Source:
Parameters:
Name Type Description
argData any

[原始数据]

argCheck string

[要返回的数据,用'.'连接,数组用'.+数字表示']

argValue any

[如果数据为undefined/null,返回argValue,选填]

argSetValueForce boolean | 0 | 1

[是否强制赋值argValue,强制赋值时只返回true/false]

Returns:
Type
any

(inner) secondToTime(argData, argOption) → {string}

Description:
  • 将秒数转换为倒计时格式

Source:
Example
// returns '01h05s'
secondToTime(3905, {s: '秒', m: '分', h: '时', d: '天', M: '月', y: '年', minUtil: 's', maxUnit: 'y', hideZero: false, isAddZero: true})
Parameters:
Name Type Description
argData number

秒数

argOption Object

配置项

Properties
Name Type Description
s string

秒的单位,默认为'秒'

m string

分的单位,默认为'分'

h string

时的单位,默认为'时'

d string

天的单位,默认为'天'

M string

月的单位,默认为'月'

y string

年的单位,默认为'年'

minUtil string

最小显示的时间单位,小于该单位的舍去,默认为's'

maxUnit string

最大的时间单位,默认为'y',大于该单位的合入该单位 's,m,h,d,M,y 对应 秒 分 时 天 月 年',例如: 'm' '13月'

hideZero boolean

是否隐藏为0的时间单位,默认为false,例如 01h05s

isAddZero boolean

是否小于10时,是否添加0,默认为true

Returns:

转换后的倒计时格式的字符串

Type
string

(inner) setCookie(argName, argValue, argTime, argPath, domain)

Description:
  • 设置cookie

Source:
Parameters:
Name Type Default Description
argName string

要设置的key

argValue string

要设置的value

argTime number 24

过期时间/时 默认24

argPath number /

path

domain number

domain

(inner) setEnv(env)

Description:
  • 设置env参数,一般在main.js中调用

Source:
Example
setEnv(import.meta.env)
Parameters:
Name Type Description
env AnyObject

要设置的值

(inner) setLog(logConfig)

Description:
  • 设置日志输出logLevel 1 error 2 warn 3 info 4 log 5 debug

Source:
Example
setLog(localStorage.getItem('logLevel'),{
   error: (...arg) => {
     // todo
   }
 })
Parameters:
Name Type Description
logConfig AnyObject

重写配置

Properties
Name Type Description
error function

错误日志回调(做额外处理用)

(inner) setObj(key, data) → {AnyObject}

Description:
  • 设置object参数,可做运行时缓存

Source:
Parameters:
Name Type Description
key string

要设置的key

data AnyObject

要设置的值

Returns:
Type
AnyObject

(inner) setStorage(argKey, argData) → {string}

Description:
  • 设置storage的值,默认将obj转为json

Source:
Parameters:
Name Type Description
argKey string

要获取的key

argData unknown

要保存的数据

Returns:

保存的数据String

Type
string

(inner) setTitle(argTitle)

Description:
  • 设置标题

Source:
Parameters:
Name Type Description
argTitle string

标题

(inner) setUrlParams(argParams, noMarknullable) → {string}

Description:
  • obj转url参数

Source:
Parameters:
Name Type Attributes Description
argParams any

参数对象

noMark boolean <nullable>

默认带?,true时,不带

Returns:
Type
string

(inner) sleep(ms)

Description:
  • setTimeout promise版,异步阻塞函数

Source:
Parameters:
Name Type Description
ms number

时间,毫秒

(inner) string10to62(argData) → {string}

Description:
  • 将10进制数据转换为62进制,用于短网址转换。

Source:
Example
// 示例
const data = 123456;
const convertedData = string10to62(data);
console.log(convertedData); // 输出: 'w7E'
Parameters:
Name Type Description
argData number | string

要处理的数据。

Returns:
  • 返回处理好的数据。
Type
string

(inner) string62to10(argData) → {number}

Description:
  • 将62进制数据转换为10进制,用于短网址转换。

Source:
Example
// 示例
const data = 'w7E';
const convertedData = string62to10(data);
console.log(convertedData); // 输出: 123456
Parameters:
Name Type Description
argData string

要处理的数据。

Returns:
  • 返回处理好的数据。
Type
number

(inner) throttle(fn, delayopt, …extra) → {function}

Description:
  • 节流函数:该函数用于限制函数的执行频率,使其在指定的时间间隔内最多执行一次

Source:
Example
```
const sayHelloFn = (a: string,b:any) => {
  console.log(a,b);
}
const throttleHello = throttle(sayHelloFn, 300,'extra info);
throttleHello('Hello from 1');
throttleHello('Hello from 2');
// Hello from 1 extra info
```
Parameters:
Name Type Attributes Default Description
fn function

要节流的函数。

delay number <optional>
300

函数执行之间的延迟时间(毫秒)。默认为 300 毫秒。

extra any <repeatable>

可选的额外参数,传递给节流函数的原始调用。

Returns:

返回一个新的函数,该函数具有节流行为。

Type
function

(inner) toFixed(argData, argNum, argType) → {string}

Description:
  • 对数据进行toFixed处理。

Source:
Example
// 示例
const data = 123.456;
const fixedData = toFixed(data, 2, 'round');
console.log(fixedData); // 输出: '123.46'
Parameters:
Name Type Default Description
argData string | number

要处理的数据。

argNum number 2

要保留的位数,默认返回2位小数。

argType string round

返回类型,round:默认四舍五入,floor:向下取整,ceil:向上取整,abs:绝对值。

Returns:
  • 返回处理好的数据。
Type
string

(inner) toHump(argData, argUnit) → {string}

Description:
  • 将下划线字符串转换为驼峰字符串

Source:
Example
// 示例
const data = 'underscore_case';
const convertedData = toHump(data);
console.log(convertedData); // 输出: 'underscoreCase'
Parameters:
Name Type Default Description
argData string

要转换的字符串。

argUnit string _

要转换的字符,默认为“_”。

Returns:
  • 转换后的驼峰字符串。
Type
string

(inner) toLine(argData, argUnit) → {string}

Description:
  • 将驼峰字符串转换为下划线字符串

Source:
Example
// 示例
const data = 'camelCase';
const convertedData = toLine(data);
console.log(convertedData); // 输出: 'camel_case'
Parameters:
Name Type Default Description
argData string

要转换的字符串。

argUnit string _

要转换的字符,默认为“_”。

Returns:
  • 转换后的下划线字符串。
Type
string

类型转换相关处理

Description:
  • 公共函数,使用'lj-utils'引入

Source:
Author:
  • linjielinlin 993353454@qq.com
Description:
  • 文件相关处理

Source:
Author:
  • linjielinlin 993353454@qq.com
Description:
  • 判断函数

Source:
Author:
  • linjielinlin 993353454@qq.com
Description:
  • 类型转换相关处理

Source:
Author:
  • linjielinlin 993353454@qq.com

Methods

(inner) arrayToObj(list, key, extraData) → {Object}

Description:
  • 指定数组key,转换为对象

Source:
Example
// 示例
const list = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
const obj = arrayToObj(list, 'id');
console.log(obj); // 输出: { '1': { id: 1, name: 'Alice' }, '2': { id: 2, name: 'Bob' } }
Parameters:
Name Type Description
list Array.<any>

数组。

key string

对象对应的键值。

extraData string | object

为string时,返回对象的键值对,为object时,返回对象。

Returns:
  • 返回的对象。
Type
Object

(inner) autoPlayAudio(audioUrl, isWeixin) → {HTMLAudioElement}

Description:
  • 自动播放音频并返回音频元素。

Source:
Parameters:
Name Type Description
audioUrl string

音频地址

isWeixin boolean

是否在微信中

Returns:
  • 音频元素
Type
HTMLAudioElement

(inner) blobToBase64(argBlob) → {Promise}

Description:
  • 将Blob对象转换为base64字符串

Source:
Example
blobToBase64(blob).then(base64 => console.log(base64));
Parameters:
Name Type Description
argBlob Blob

需要处理的Blob对象

Returns:

返回base64字符串

Type
Promise

(inner) blobToFile(argBlob, argName) → {File}

Description:
  • 将Blob对象转换为File对象

Source:
Example
const file = blobToFile(blob, 'example.txt');
Parameters:
Name Type Description
argBlob Blob

Blob对象

argName string

文件名,默认为当前时间戳

Returns:

返回File对象

Type
File

(inner) blobUrlToFile(argData) → {Promise}

Description:
  • 将blobUrl转换为File对象

Source:
Example
blobUrlToFile(url).then(file => console.log(file));
Parameters:
Name Type Description
argData string

blobUrl

Returns:

返回File对象

Type
Promise

(inner) dataURLtoBlob(argData) → {Blob}

Description:
  • 将图片的dataUrl base64转换为Blob对象

Source:
Example
const blob = dataURLtoBlob(dataUrl);
Parameters:
Name Type Description
argData string

dataUrl

Returns:

返回Blob对象

Type
Blob

(inner) debounce(func, delay) → {function}

Description:
  • 函数防抖,用于限制函数调用的频率。

Source:
Example
```
const debouncedHello = debounce(sayHello, 1000);
debouncedHello('Hello from 1');
debouncedHello('Hello from 2');
```
Parameters:
Name Type Description
func function

要进行防抖的函数

delay number

延迟时间,单位毫秒

Returns:

返回防抖后的函数

Type
function

(inner) decodeHtml(argHtml) → {string}

Description:
  • 反转义HTML标签。

Source:
Example
// 返回 "&lt;p&gt;Hello, World!&lt;/p&gt;"
decodeHtml("<p>Hello, World!</p>");
Parameters:
Name Type Description
argHtml string

需要反转义的文本。

Returns:

反转义后的文本。

Type
string

(inner) deepCopy(obj)

Source:
Parameters:
Name Type Description
obj

需要拷贝的对象

Returns:

拷贝后的对象

(inner) delCookie(argName)

Description:
  • 清除cookie

Source:
Parameters:
Name Type Description
argName string

要清除的值

(inner) delay(time)

Description:
  • 同步阻塞函数。

Source:
Parameters:
Name Type Default Description
time number 0

延迟的时间量,单位为毫秒

(inner) dlFile(argData, argName, argDelTime)

Description:
  • 下载文件

Source:
Example
dlFile(data, 'example.txt', 10000);
Parameters:
Name Type Description
argData string | Blob | File

Blob对象/File对象/dataUrl/base64

argName string

文件名

argDelTime number

移除dateUrl时间

(inner) encodeHtml(argHtml) → {string}

Description:
  • 转义html标签

Source:
Example
// returns '&lt;p&gt;Hello, World!&lt;/p&gt;'
encodeHtml('<p>Hello, World!</p>')
Parameters:
Name Type Description
argHtml string

需要转义的文本

Returns:
Type
string

(inner) formatNumber(argData, argNum) → {string}

Description:
  • 将数据转换为数量单位k/w

Source:
Example
// returns '2k'
formatNumber(2000, 2)
Parameters:
Name Type Description
argData number

数据

argNum number

保留的小数位数,默认为2

Returns:

计算结果

Type
string

(inner) formatSize(argData, argNum, argIndex, argRate, unit) → {string}

Description:
  • 将byte数据转换为容量单位

Source:
Example
// returns '1.95K'
formatSize(2000, 2, 0, 1024, ['B', 'K', 'M', 'G', 'T', 'P'])
Parameters:
Name Type Description
argData number

byte数据

argNum number

保留的小数位数,默认为2

argIndex number

起始单位偏移,例如: 0:b 1:k 2:m,默认为0

argRate number

进制,默认为1024

unit Array.<string>

进制,默认为['B', 'K', 'M', 'G', 'T', 'P']

Returns:

计算结果

Type
string

(inner) formatTime(date, fmt, emptyTip) → {string}

Description:
  • 日期格式化显示。

Source:
Example
// 返回 '2022-01-01 00:00:00'
formatTime(new Date(2022, 0, 1));
Parameters:
Name Type Description
date string | number | Date

时间对象或时间戳,默认为当前时间。

fmt string

格式化字符串,默认为'YYYY-MM-DD HH:mm:ss'。E为星期数,EEE:星期一,q为季度,S为毫秒数。

emptyTip string

当date为false时的默认值,默认为''。

Returns:

格式化后的日期字符串。

Type
string

(inner) friendlyTime(date, fmt, emptyTip) → {string}

Description:
  • 日期格式化友好显示。例如:刚刚,x分钟前,...。超过一年的按 fmt来格式化。

Source:
Example
// 返回 '刚刚'
friendlyTime(new Date());
Parameters:
Name Type Description
date string | number | Date

时间对象或时间戳,默认为当前时间。

fmt string

格式化字符串,默认为'YYYY-MM-DD HH:mm:ss'。

emptyTip string

当date为false时的默认值,默认为''。

Returns:

格式化后的友好日期字符串。

Type
string

(inner) getCookie(argName) → {string}

Description:
  • 获取cookie

Source:
Parameters:
Name Type Description
argName string

要获取的值

Returns:
Type
string

(inner) getCookieObj() → {object}

Description:
  • 获取cookie对象

Source:
Returns:
Type
object

(inner) getDuration(argFile) → {Promise}

Description:
  • 获取音视频文件的时长

Source:
Example
getDuration(file).then(duration => console.log(duration));
Parameters:
Name Type Description
argFile Blob | File | string

音视频数据,如果是string类型,则为链接

Returns:

返回时长(单位:秒)

Type
Promise

(inner) getEnv(key) → {string}

Description:
  • 获取env参数

Source:
Parameters:
Name Type Description
key string

要获取的值

Returns:

获取的值

Type
string

(inner) getInfo() → {Info}

Description:
  • 检测浏览器状态,系统状态 *

Source:
Returns:

{ ua: ua, platform: 平台, isMobile: 移动端, isWin: winPC端, isIphone: iphone, isIpad: ipad, isMac: mac, isAppleMobile: 苹果移动端webview isSafari: Safari浏览器, isIos: Ios平台, isAndroid: android平台, isIE: 显示8 9 10, true为11以上 ... }

Type
Info

(inner) getNetworkStatus() → {boolean}

Description:
  • 获取当前网络状态(H5)

Source:
Example
```
const status = getNetworkStatus();
```
Returns:
  • boolean

  • Type
    boolean

(inner) getObj(key, argData, isDeepCopy) → {AnyObject}

Description:
  • 获取object参数

Source:
Parameters:
Name Type Description
key string

要获取的值

argData string

要合并的值

isDeepCopy boolean

是否深拷贝

Returns:

获取的值

Type
AnyObject

(inner) getRandomColor()

Description:
  • 获取随机颜色

Source:
Returns:

string

(inner) getRegexp() → {object|object}

Description:
  • 正则收集

Source:
Example
```
const regex = getRegexp();
```
Returns:
  • Type
    object
  • Type
    object

(inner) getStorage(argKey, argNoJson) → {any}

Description:
  • 获取storage的值,默认将json转为obj

Source:
Parameters:
Name Type Description
argKey string

要获取的key

argNoJson string

true时不自动转换JSON字符串

Returns:

key对应的数据

Type
any

(inner) getUrlParam(argName, argUrl) → {string}

Description:
  • 获取url参数

Source:
Parameters:
Name Type Description
argName string

要获取的key

argUrl string

url数据

Returns:
Type
string

(inner) getUrlParamObj(argData) → {any}

Description:
  • 获取所有url参数,eg: a=1&b=2 to {a:1,b:2}

Source:
Parameters:
Name Type Description
argData string

要处理的数据

Returns:
Type
any

(inner) getUuid() → {string}

Description:
  • 获取简单uuid

Source:
Returns:

uuid

Type
string

(inner) hideInfo(argData, argStart, argEnd) → {string}

Description:
  • 数据中间加星号

Source:
Example
// 示例
const data = '1234567890';
const hiddenData = hideInfo(data, 3, 4);
console.log(hiddenData); // 输出: '123***7890'
Parameters:
Name Type Default Description
argData string | number

要处理的数据。

argStart number 3

前端显示多少位。

argEnd number 4

后面显示多少位。

Returns:
  • 返回处理好的数据。
Type
string

(inner) isBlob(argData) → {boolean}

Description:
  • 判断一个值是否为Blob

Source:
Example
isBlob(new Blob()); // true
Parameters:
Name Type Description
argData any

需要判断的数据

Returns:

如果是Blob返回true,否则返回false

Type
boolean

(inner) isFile(argData) → {boolean}

Description:
  • 判断一个值是否为File

Source:
Example
isFile(new File([""], "filename")); // true
Parameters:
Name Type Description
argData any

需要判断的数据

Returns:

如果是File返回true,否则返回false

Type
boolean

(inner) isIdCard(code) → {boolean}

Description:
  • 判断一个字符串是否为正确的身份证号码

Source:
Example
isIdCard('320311770706001'); // false
Parameters:
Name Type Description
code string

身份证号码

Returns:

如果是正确的身份证号码返回true,否则返回false

Type
boolean

(inner) isJson(argData) → {boolean}

Description:
  • 判断一个值是否为JSON

Source:
Example
isJson('{"name":"John"}'); // true
Parameters:
Name Type Description
argData any

需要判断的数据

Returns:

如果是JSON返回true,否则返回false

Type
boolean

(inner) isPrime(argValue) → {boolean}

Description:
  • 判断一个数是否为质数

Source:
Example
isPrime(5); // true
Parameters:
Name Type Description
argValue number

需要判断的数值

Returns:

如果是质数返回true,否则返回false

Type
boolean

(inner) loadFile(argUrl, argType, argOptions) → {Promise}

Description:
  • 动态加载html文件标签

Source:
Example
loadFile(url, 'js', {force: true}).then(() => console.log('Loaded'));
Parameters:
Name Type Description
argUrl string

要加载的url

argType string

加载类型 js/css

argOptions object
argOption.disCheck string

不检查是否有相同标签

argOption.force string

是否强制添加,true时先删除再添加

Returns:

返回Promise对象

Type
Promise

(inner) objToArray(obj, keyopt, valueopt, isReverseopt) → {array}

Description:
  • 将对象转换为键值对数组。

Source:
Example
// Example usage
const obj = { a: 1, b: 2 };
const result = objToArray(obj, 'id', 'v', true);
console.log(result); // Output: [{ v: 'a', id: 1 }, { v: 'b', id: 2 }]
Parameters:
Name Type Attributes Default Description
obj object

要转换的对象。

key string <optional>
'key'

每个键值对的键名称默认key。

value string <optional>
'value'

每个键值对的值名称默认value。

isReverse boolean <optional>
false

如果为true,则键值对将被颠倒,默认为false。

Returns:
  • 键值对数组。
Type
array

(inner) objToObj(obj, tmplObj, isAssign) → {Object}

Description:
  • 从原始对象中复制属性,并将其赋值给新对象,生成一个新对象。

Source:
Example
// 示例
const obj = { a: 1, b: 2 };
const tmplObj = { a: 0, c: 0 };
const newObj = objToObj(obj, tmplObj);
console.log(newObj); // 输出: { a: 1, c: '' }
Parameters:
Name Type Default Description
obj Object

要复制属性的原始对象。

tmplObj Object

要赋值属性的新对象模板。

isAssign boolean false

可选。确定是否将属性赋值给原始对象。

Returns:

复制了属性的新对象。

Type
Object

(inner) off(el, event, handler)

Description:
  • 移除事件绑定

Source:
Parameters:
Name Type Description
el Element

绑定元素

event string

事件名称

handler function

事件处理函数

(inner) on(el, event, handler)

Description:
  • 添加事件绑定

Source:
Parameters:
Name Type Description
el Element

绑定元素

event string

事件名称

handler function

事件处理函数

(inner) px2vw(argPx, argWith, argUnit, argNum) → {string}

Description:
  • 将px单位转换为vw单位

Source:
Example
// returns '187.5vw'
px2vw(200, 375, 'vw', 6)
Parameters:
Name Type Description
argPx number

px单位的数值

argWith number

px对应的最大宽度,默认为375

argUnit string

单位,'vw'或'%',默认为'vw'

argNum number

保留的小数位数,默认为6

Returns:

转换后的数值

Type
string

(inner) randomInt(min, max) → {number}

Description:
  • 获取随机数,含最大值,含最小值

Source:
Parameters:
Name Type Default Description
min number 0

最小值

max number 100

最大值

Returns:
Type
number

(inner) remInit(argBaseSize, argWidth)

Description:
  • 使用postcss-px2rem时使用

Source:
Parameters:
Name Type Default Description
argBaseSize number 16

基础大小 16px(要跟配置一致)

argWidth number 375

基准宽度

(inner) replaceUrlParam(name, value, url) → {string}

Description:
  • 通过正则匹配修改当前页面的url中的参数

Source:
Parameters:
Name Type Description
name string

key

value string | number | undefined | null

要替换的value

url string

要替换的网址,默认location.href

Returns:
Type
string

(inner) requestDeviceMotionPermission()

Description:
  • 摇一摇,请求使用 DeviceMotionEvent API 的权限。for ios

Source:
Example
```
const hasRequest = await requestDeviceMotionPermission()
if (hasRequest) {
   useEventListener(window, 'devicemotion', handleShake)
 } else {
   showToast('未授权访问运动传感器,请手动点击!')
 }
```
Returns:

Promise,指示是否已授予权限。

(inner) rmbPrice(argData, argRate, argUnit, argDef) → {string}

Description:
  • 显示人民币价格。

Source:
Example
// 返回 '¥100.00'
rmbPrice(100, 2);
Parameters:
Name Type Description
argData unknown

价格。

argRate number

保留多少位小数,默认为-1。

argUnit string

单位,默认为'¥'。

argDef string

空数据默认值,默认为'--'。

Returns:

格式化后的价格字符串,例如:'¥100'。

Type
string

(inner) safe(argData, argCheck, argValue, argSetValueForce) → {any}

Description:
  • 数据安全访问

Source:
Parameters:
Name Type Description
argData any

[原始数据]

argCheck string

[要返回的数据,用'.'连接,数组用'.+数字表示']

argValue any

[如果数据有误,返回的值,选填]

argSetValueForce boolean | 0 | 1

[是否强制赋值argValue]

Returns:
Type
any

(inner) safeData(argData, argCheck, argValue, argSetValueForce) → {any}

Description:
  • 数据安全访问

Source:
Parameters:
Name Type Description
argData any

[原始数据]

argCheck string

[要返回的数据,用'.'连接,数组用'.+数字表示']

argValue any

[如果数据为undefined/null,返回argValue,选填]

argSetValueForce boolean | 0 | 1

[是否强制赋值argValue,强制赋值时只返回true/false]

Returns:
Type
any

(inner) secondToTime(argData, argOption) → {string}

Description:
  • 将秒数转换为倒计时格式

Source:
Example
// returns '01h05s'
secondToTime(3905, {s: '秒', m: '分', h: '时', d: '天', M: '月', y: '年', minUtil: 's', maxUnit: 'y', hideZero: false, isAddZero: true})
Parameters:
Name Type Description
argData number

秒数

argOption Object

配置项

Properties
Name Type Description
s string

秒的单位,默认为'秒'

m string

分的单位,默认为'分'

h string

时的单位,默认为'时'

d string

天的单位,默认为'天'

M string

月的单位,默认为'月'

y string

年的单位,默认为'年'

minUtil string

最小显示的时间单位,小于该单位的舍去,默认为's'

maxUnit string

最大的时间单位,默认为'y',大于该单位的合入该单位 's,m,h,d,M,y 对应 秒 分 时 天 月 年',例如: 'm' '13月'

hideZero boolean

是否隐藏为0的时间单位,默认为false,例如 01h05s

isAddZero boolean

是否小于10时,是否添加0,默认为true

Returns:

转换后的倒计时格式的字符串

Type
string

(inner) setCookie(argName, argValue, argTime, argPath, domain)

Description:
  • 设置cookie

Source:
Parameters:
Name Type Default Description
argName string

要设置的key

argValue string

要设置的value

argTime number 24

过期时间/时 默认24

argPath number /

path

domain number

domain

(inner) setEnv(env)

Description:
  • 设置env参数,一般在main.js中调用

Source:
Example
setEnv(import.meta.env)
Parameters:
Name Type Description
env AnyObject

要设置的值

(inner) setLog(logConfig)

Description:
  • 设置日志输出logLevel 1 error 2 warn 3 info 4 log 5 debug

Source:
Example
setLog(localStorage.getItem('logLevel'),{
   error: (...arg) => {
     // todo
   }
 })
Parameters:
Name Type Description
logConfig AnyObject

重写配置

Properties
Name Type Description
error function

错误日志回调(做额外处理用)

(inner) setObj(key, data) → {AnyObject}

Description:
  • 设置object参数,可做运行时缓存

Source:
Parameters:
Name Type Description
key string

要设置的key

data AnyObject

要设置的值

Returns:
Type
AnyObject

(inner) setStorage(argKey, argData) → {string}

Description:
  • 设置storage的值,默认将obj转为json

Source:
Parameters:
Name Type Description
argKey string

要获取的key

argData unknown

要保存的数据

Returns:

保存的数据String

Type
string

(inner) setTitle(argTitle)

Description:
  • 设置标题

Source:
Parameters:
Name Type Description
argTitle string

标题

(inner) setUrlParams(argParams, noMarknullable) → {string}

Description:
  • obj转url参数

Source:
Parameters:
Name Type Attributes Description
argParams any

参数对象

noMark boolean <nullable>

默认带?,true时,不带

Returns:
Type
string

(inner) sleep(ms)

Description:
  • setTimeout promise版,异步阻塞函数

Source:
Parameters:
Name Type Description
ms number

时间,毫秒

(inner) string10to62(argData) → {string}

Description:
  • 将10进制数据转换为62进制,用于短网址转换。

Source:
Example
// 示例
const data = 123456;
const convertedData = string10to62(data);
console.log(convertedData); // 输出: 'w7E'
Parameters:
Name Type Description
argData number | string

要处理的数据。

Returns:
  • 返回处理好的数据。
Type
string

(inner) string62to10(argData) → {number}

Description:
  • 将62进制数据转换为10进制,用于短网址转换。

Source:
Example
// 示例
const data = 'w7E';
const convertedData = string62to10(data);
console.log(convertedData); // 输出: 123456
Parameters:
Name Type Description
argData string

要处理的数据。

Returns:
  • 返回处理好的数据。
Type
number

(inner) throttle(fn, delayopt, …extra) → {function}

Description:
  • 节流函数:该函数用于限制函数的执行频率,使其在指定的时间间隔内最多执行一次

Source:
Example
```
const sayHelloFn = (a: string,b:any) => {
  console.log(a,b);
}
const throttleHello = throttle(sayHelloFn, 300,'extra info);
throttleHello('Hello from 1');
throttleHello('Hello from 2');
// Hello from 1 extra info
```
Parameters:
Name Type Attributes Default Description
fn function

要节流的函数。

delay number <optional>
300

函数执行之间的延迟时间(毫秒)。默认为 300 毫秒。

extra any <repeatable>

可选的额外参数,传递给节流函数的原始调用。

Returns:

返回一个新的函数,该函数具有节流行为。

Type
function

(inner) toFixed(argData, argNum, argType) → {string}

Description:
  • 对数据进行toFixed处理。

Source:
Example
// 示例
const data = 123.456;
const fixedData = toFixed(data, 2, 'round');
console.log(fixedData); // 输出: '123.46'
Parameters:
Name Type Default Description
argData string | number

要处理的数据。

argNum number 2

要保留的位数,默认返回2位小数。

argType string round

返回类型,round:默认四舍五入,floor:向下取整,ceil:向上取整,abs:绝对值。

Returns:
  • 返回处理好的数据。
Type
string

(inner) toHump(argData, argUnit) → {string}

Description:
  • 将下划线字符串转换为驼峰字符串

Source:
Example
// 示例
const data = 'underscore_case';
const convertedData = toHump(data);
console.log(convertedData); // 输出: 'underscoreCase'
Parameters:
Name Type Default Description
argData string

要转换的字符串。

argUnit string _

要转换的字符,默认为“_”。

Returns:
  • 转换后的驼峰字符串。
Type
string

(inner) toLine(argData, argUnit) → {string}

Description:
  • 将驼峰字符串转换为下划线字符串

Source:
Example
// 示例
const data = 'camelCase';
const convertedData = toLine(data);
console.log(convertedData); // 输出: 'camel_case'
Parameters:
Name Type Default Description
argData string

要转换的字符串。

argUnit string _

要转换的字符,默认为“_”。

Returns:
  • 转换后的下划线字符串。
Type
string