Global

Members

CacheObject | DiskCache

# constant DiskCache

磁盘缓存,底层是localStorage

View Source cache.js, line 194

CacheObject

# constant MemoryCache

内存缓存

View Source cache.js, line 183

# constant MimeDef

完整的Mime定义,需要配合MimeShortDef,给文件系统使用

View Source browser/file.js, line 152

Object

# constant MimeShortDef

精简类型的Mime定义

View Source browser/file.js, line 121

Object

# constant TimeDef

time definition with millisecond unit

View Source date.js, line 305

# constant awaitPromiseRes

wait for res if res is instance of Promise

View Source async.js, line 9

# constant cloneByJSON

View Source obj.js, line 10

# constant completeMime

对特殊的mime进行补全

View Source browser/file.js, line 90

# constant getShortMimeByMime

由完整的mime获取简短的mime

View Source browser/file.js, line 188

# constant openFileSelectionWindow

View Source browser/file.js, line 20

# constant openOneFileSelectionWindow

View Source browser/file.js, line 30

Methods

# CacheFactory(cacheopt, lifeCycleopt) → {CacheObject}

create object to manage cache

Parameters:
Name Type Attributes Default Description
cache object <optional>
{}

cache data object

lifeCycle number <optional>
0

cache time ms

View Source cache.js, line 29

CacheObject

# LockerWrapper(locker, func) → {function}

create function with locker

Parameters:
Name Type Description
locker TriggerLock

a instance of TriggerLocker

func function

you would like to control the function through locker, the default value is empty function, just like noop

View Source lock.js, line 88

function

# array2Map(list, fieldOrHandler) → {object}

group map by field or handler to map object

Parameters:
Name Type Description
list array.<*>
fieldOrHandler string | function

View Source arr.js, line 11

object

# bindNativeEvent(element, eventName, eventHandler) → {undefined}

bind native event

Parameters:
Name Type Description
element HTMLElement
eventName string
eventHandler function

View Source browser/dom.js, line 73

undefined

# checkBit(flag, bitFlag) → {boolean}

check bitflag if it is 1 in flag

Parameters:
Name Type Description
flag number
bitFlag number

View Source bit.js, line 7

boolean

# cloneDeep(value) → {Object|*}

深拷贝

Parameters:
Name Type Description
value

View Source clone.js, line 6

Object | *

# colorToHex(rgb) → {string}

color string to hex like #000000, rgb(255,255,255) and rgba(255,255,255,0)

Parameters:
Name Type Description
rgb string

View Source color.js, line 13

string

# compareToNow(timestamp) → {number}

compare timestamp with now timestamp

Parameters:
Name Type Description
timestamp number

View Source date.js, line 202

timestamp offset with now date

number

# convertMimes(mimeList) → {Array.<string>}

convert mime shorthand to completed mime. mime will be filtered if it is invalid

Parameters:
Name Type Description
mimeList Array.<string>

['jpg', 'png', ...]

View Source browser/file.js, line 79

['image/jpg', 'image/png', ...]

Array.<string>

# createDiskCacher(DISK_CACHE_KEY, lifeCycleopt) → {CacheObject|DiskCache}

create object to manage cache by localStorage

Parameters:
Name Type Attributes Default Description
DISK_CACHE_KEY string

cache group key

lifeCycle number | function <optional>
0

cache time

View Source cache.js, line 107

# createNodeInDocumentBody(tagNameopt) → {HTMLDivElement}

create Node and insert it into body

Parameters:
Name Type Attributes Default Description
tagName string <optional>
'div

View Source browser/dom.js, line 14

HTMLDivElement

# dateFormat(fmt, date) → {*}

translate date instance to string

Parameters:
Name Type Description
fmt string
date Date

View Source date.js, line 33

*

# debounce(func, timeopt) → {function}

delay function call until last time after specified time

Parameters:
Name Type Attributes Default Description
func function

function

time number <optional>
300

delay time(ms)

View Source aop.js, line 53

function

# decodeHtml(html) → {*}

解码

Parameters:
Name Type Description
html *

View Source decodeHtml.js, line 7

*

# deepAssign() → {any}

递归深复制,比较靠谱,不用担心JSON.parse报错

View Source clone.js, line 34

any

# delay(func, timeopt) → {function}

delay function call and collect calling parameters util to call at last. like debounce

Parameters:
Name Type Attributes Default Description
func function
time number <optional>
300

View Source aop.js, line 34

function

# ellipsis(text, maxNum) → {string}

a function like css's ellipsis

Parameters:
Name Type Description
text string
maxNum number

View Source str.js, line 64

string

# encodeHtml(html) → {*}

编码

Parameters:
Name Type Description
html *

View Source decodeHtml.js, line 27

*

# equals(a, b) → {boolean}

用于对比两个数据是否相等,相等/相同,注意Date/RegExp可能会出问题

Parameters:
Name Type Description
a any
b any

View Source typer.js, line 121

boolean

# fixArrayIndex(array, index) → {*}

fix index of array

Parameters:
Name Type Description
array array
index number

View Source arr.js, line 179

*

# forEach(obj, fn) → {void}

forEach

Parameters:
Name Type Description
obj Object | Array

obj

fn function

callback

View Source Iterate.js, line 10

无返回值

void

# formatDate(date, pattern) → {string}

format date to string for compat it with IOS mobile

Parameters:
Name Type Description
date Date | String

Date or time like '1995-01-01

pattern string

like 'YYYY-MM-DD HH:mm:ss'

View Source date.js, line 294

string

# genRangeValue(type) → {*}

generate random value by type

Parameters:
Name Type Description
type function

like Function, String and so on

View Source test.js, line 21

*

# getArgTestCasesOfFunction(func) → {Array.<Array.<*>>}

generate random test cases of function arguments

Parameters:
Name Type Description
func function

test function with name. like function name(){}

View Source test.js, line 71

Array.<Array.<*>>

# getCombination(arrays) → {Array.<Array.<*>>}

生成多个数组的组合列表。

Parameters:
Name Type Description
arrays Array.<Array.<*>>

一个数组的数组,每个数组代表一组可选元素。

View Source obj.js, line 120

  • 返回一个包含所有可能组合的数组。
Array.<Array.<*>>
Example
// 示例用法
    let combos = getCombination([
        [1, 2],
        [3, 4],
        [5, 6]
    ]);

    console.log(combos); // [[1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6], [2, 3, 5], [2, 3, 6], [2, 4, 5], [2, 4, 6]]

# getCombinationOfObject(obj, objDef) → {Array.<object>}

get combination of object by objDef. But it doesn't support definition about array

Parameters:
Name Type Description
obj object

original obj data

objDef object

the definition object of getting fields of obj

View Source obj.js, line 76

Array.<object>
Example
import { getCombinationOfObject } from * "@ustinian-wang/kit";
let testData  ={ a: 1, b: 2 };
let dataList = getCombinationOfObject(testData, {
     a: [1, 2,3],
     b: [4, 5, 6]
 });
let newData = deepAssign( {}, testData, dataList[0] );

# getCookie() → {*}

读取cookie

View Source cookie.js, line 18

*

# getCurrUrlParam(key) → {string}

get query value from window.location.href

Parameters:
Name Type Description
key string

View Source url.js, line 104

string

# getDayOfMonth(year, month) → {number}

get the day of the month

Parameters:
Name Type Description
year number
month number

View Source date.js, line 10

1-31 or 1-30 or 1-28 or 1-29

number

# getDayOfWeek(year, month, date) → {number}

get the day of the week

Parameters:
Name Type Description
year number
month number
date number

View Source date.js, line 22

1-7

number

# getDaysBetween(start, end) → {Number}

get days between start end end

Parameters:
Name Type Description
start string | Date
end string | Date

View Source date.js, line 156

相隔天数

Number

# getElementsOfCircleArray(circleArray, index, length) → {Array.<any>}

get elements of circleArray

Parameters:
Name Type Description
circleArray array
index number
length number

View Source arr.js, line 153

Array.<any>

# getFieldList(itemList, field) → {Array}

collecting some field of item to generate list;

Parameters:
Name Type Description
itemList array

target list

field string

View Source arr.js, line 37

Array

# getFileExtension(filename) → {string}

解析文件后缀名,而且会强制转换小写,例如有的客户会jpg改为JPG等非法文件,导致后端接口失败

Parameters:
Name Type Description
filename string

View Source file.js, line 9

string

# getFirstByField(list, field, value) → {object|null}

get first item when field is equals with others in memory reference

Parameters:
Name Type Description
list Array.<object>
field string
value any

View Source arr.js, line 88

object | null

# getFirstByFieldEquals(list, fieldopt, value) → {object|undefined}

get first item when field is equals with others

Parameters:
Name Type Attributes Default Description
list Array.<object>
field string <optional>
''
value *

View Source arr.js, line 266

object | undefined

# getGbLen(str) → {number}

compute string length including Chinese and English chars

Parameters:
Name Type Description
str string

View Source str.js, line 150

number

# getLeftTimeInfo(timestamp) → {Object}

get rest information of the time

Parameters:
Name Type Description
timestamp number

ms unit

View Source date.js, line 181

Object

# getObjCookie(key) → {*}

读取cookie并且反序列化

Parameters:
Name Type Description
key string

View Source cookie.js, line 27

*

# getQueryObject(url) → {object}

get query object from url

Parameters:
Name Type Description
url string

View Source query.js, line 16

object

# getToday() → {String}

get today sting with 'YYYYMMDD' pattern

View Source date.js, line 166

String

# getTriggerLock() → {TriggerLock}

get lockFactory instance of click action

View Source lock.js, line 78

TriggerLock

# getUrlFileExtension(url) → {string}

解析url资源后缀,而且会强制转换小写,例如有的客户会jpg改为JPG等非法文件,导致后端接口失败

Parameters:
Name Type Description
url string

View Source file.js, line 30

string

# getUrlParam(url, key) → {string}

get query value from url by specified key

Parameters:
Name Type Description
url string
key string

query key

View Source url.js, line 94

query value

string
Example
let url = 'http://www.google.com?a=6';
let value = getUrlParam('a');
console.log(value);//'6'

# getUrlSearchParam(url) → {URLSearchParams}

get instance of URLSearchParams by parsing url

Parameters:
Name Type Description
url string

View Source url.js, line 79

URLSearchParams

# getWindow() → {Window}

get window

View Source env.js, line 5

Window

# getter(obj, path, defaultValueopt) → {any}

read data's key

Parameters:
Name Type Attributes Description
obj object
path string

//eg: a.b.c

defaultValue any <optional>

View Source obj.js, line 156

any

# insertArrayToCircleArray(options) → {Array.<any>}

insert elements to circle array

Parameters:
Name Type Attributes Default Description
options Object
circleArray Array.<any>

the last is previous of the first in logic

array Array.<any>
circleArrayIndex number <optional>
0
match function

View Source arr.js, line 109

Array.<any>

# isAbsoluteUrl(value) → {Boolean}

check if value is a absolute url

Parameters:
Name Type Description
value String

url

View Source url.js, line 197

是否为绝对路径

Boolean

# isArray(value) → {boolean}

check if it is an empty object

Parameters:
Name Type Description
value *

View Source typer.js, line 57

boolean

# isBoolean(value) → {boolean}

check if it is a boolean

Parameters:
Name Type Description
value *

View Source typer.js, line 93

boolean

# isClass(value) → {string|boolean}

check if value is class

Parameters:
Name Type Description
value *

View Source typer.js, line 225

string | boolean

# isDate(value) → {boolean}

check if it is a instance of Date

Parameters:
Name Type Description
value *

View Source typer.js, line 162

boolean

# isEmpty(value) → {boolean}

check if it is a instance of Error

Parameters:
Name Type Description
value *

View Source typer.js, line 180

boolean

# isEmptyArr(value) → {boolean}

check if it is an empty array

Parameters:
Name Type Description
value *

it must be an array value

View Source typer.js, line 48

boolean

# isEmptyObj(obj) → {boolean}

是否是空对象

Parameters:
Name Type Description
obj object

View Source typer.js, line 111

boolean

# isEmptyStr(value) → {boolean}

是否是空字符串

Parameters:
Name Type Description
value string

View Source typer.js, line 144

boolean

# isFalsy(value) → {boolean}

check if it is a falsy value

Parameters:
Name Type Description
value *

View Source typer.js, line 194

boolean

# isFunction(value) → {boolean}

check if it is a function

Parameters:
Name Type Description
value *

View Source typer.js, line 75

boolean

# isJSON(str) → {boolean}

check if the value is json string

Parameters:
Name Type Description
str string

View Source str.js, line 84

boolean

# isMatch(object, source) → {boolean}

dead simple _.isMatch implementation. https://lodash.com/docs/4.17.15#isMatch Performs a partial deep comparison between object and source to determine if object contains equivalent property values.

Parameters:
Name Type Description
object Object
source Object

View Source typer.js, line 18

boolean

# isNormalEventName(value) → {boolean}

check if value is normal event name like 'click.myEvent' with jQuery event name style

Parameters:
Name Type Description
value string

View Source str.js, line 50

boolean

# isNormalStr(value) → {boolean}

value can't includes some values

Parameters:
Name Type Description
value string

View Source str.js, line 20

boolean

# isNull(value) → {boolean}

check if it is null

Parameters:
Name Type Description
value *

View Source typer.js, line 102

boolean

# isNumber(value) → {boolean}

check if it is a number

Parameters:
Name Type Description
value *

View Source typer.js, line 84

boolean

# isNumberArray(array) → {*}

is number array

Parameters:
Name Type Description
array Array.<any>

View Source arr.js, line 204

*

# isObject(value) → {boolean}

check if it is an object

Parameters:
Name Type Description
value *

View Source typer.js, line 66

boolean

# isObjectString(value) → {boolean}

check if value is json with object

Parameters:
Name Type Description
value string

View Source typer.js, line 212

boolean

# isParsedDate(obj) → {string|boolean}

is ParsedDate

Parameters:
Name Type Description
obj

View Source date.js, line 142

string
boolean

# isPromise(value) → {boolean}

whether value is Promise type

Parameters:
Name Type Description
value *

View Source typer.js, line 8

boolean

# isRegExp(value) → {boolean}

check if it is a instance of RegExp

Parameters:
Name Type Description
value *

View Source typer.js, line 171

boolean

# isString(value) → {boolean}

check if it is a string value

Parameters:
Name Type Description
value *

View Source typer.js, line 203

boolean

# isStringArray(value) → {boolean}

check if value is array with string type

Parameters:
Name Type Description
value *

View Source arr.js, line 313

boolean

# isTypeArray(value, typeExpect) → {*}

is array with elements that match typeExpect

Parameters:
Name Type Description
value array
typeExpect function

View Source arr.js, line 218

*

# isUndefined(value) → {boolean}

check if it is undefined

Parameters:
Name Type Description
value *

View Source typer.js, line 153

boolean

# isUrl(value) → {boolean}

check if the value is url

Parameters:
Name Type Description
value string

View Source url.js, line 183

boolean

# jsonParse(string, defaultValue) → {any}

JSON.parse with try catch

Parameters:
Name Type Description
string string
defaultValue object | array | undefined

View Source str.js, line 116

any

# jsonStringify(object, defaultValue, extArgs) → {string|*}

JSON.stringify with try catch

Parameters:
Name Type Description
object object | array
defaultValue string | undefined
extArgs

View Source str.js, line 135

string | *

# memorize(func) → {function}

cache returned value for function calls

Parameters:
Name Type Description
func function

View Source aop.js, line 9

return new function caching returned values of calls

function

# noEquals(a, b) → {boolean}

用于对比两个数据是否不相等,相等/相同,注意Date/RegExp可能会出问题

Parameters:
Name Type Description
a any
b any

View Source typer.js, line 135

boolean

# padZero(value) → {string}

add leading zero if value <10

Parameters:
Name Type Description
value number

View Source str.js, line 8

string

# parseDate(date) → {Object}

parse date instance to object

Parameters:
Name Type Description
date Date

View Source date.js, line 104

Object

# parseDateStr(str) → {Object}

parse date string to object with 'YYYY-MM-DD' pattern

Parameters:
Name Type Description
str string

View Source date.js, line 79

Object

# parseUrl(url) → {ParsedUrl}

parse url as object

Parameters:
Name Type Description
url string

View Source url.js, line 16

ParsedUrl

# promisify(api) → {function}

promisfy wx api, 保留 success, fail模式, 并返回等价promise

Parameters:
Name Type Description
api function

View Source async.js, line 21

function

# pxToRpx(value, pageWidthPx) → {number}

px转换为rpx

Parameters:
Name Type Description
value number
pageWidthPx number

View Source other.js, line 9

number

# queryObject2String(queryObject) → {string}

translate object to query string

Parameters:
Name Type Description
queryObject object

View Source query.js, line 53

string

# queryString2Object(queryString) → {object}

translate query string to object

Parameters:
Name Type Description
queryString string

View Source query.js, line 31

object

# removeElementsOfArray(array, field, value) → {array.<object>}

remove specified element from array

Parameters:
Name Type Description
array array.<object>
field string
value *

View Source arr.js, line 229

array.<object>

# removeNode(container, node)

remove node from container

Parameters:
Name Type Description
container HTMLElement
node HTMLElement

View Source browser/dom.js, line 90

# renderVueComponentInDocumentBody(component, options) → {VNode|undefined}

创建一个vue实例并且插入到body里面

Parameters:
Name Type Description
component object
options object

View Source browser/dom.js, line 31

VNode | undefined

# rgbStr2hex(red, green, blue) → {string}

rgb to hex string

Parameters:
Name Type Description
red number | string
green number | string
blue number | string

View Source color.js, line 31

string

# safeJsonParse(string, defaultValue) → {any}

JSON.parse with try catch

Parameters:
Name Type Description
string any
defaultValue object | array | undefined

View Source str.js, line 102

any

# async selectOSFile(fileTypeListopt, multipleopt) → {Promise.<Array.<BrowserFileDef>>}

从windows资源管理器选择文件

Parameters:
Name Type Attributes Default Description
fileTypeList Array.<string> <optional>
[]

文件类型,如果不传递则不限制文件选择的类型范围

multiple boolean <optional>
false

是否支持多选

View Source browser/file.js, line 40

Promise.<Array.<BrowserFileDef>>

# setCookie()

设置cookie

View Source cookie.js, line 7

# setCurrUrlParam(key, value) → {string}

get query value of window.location.href

Parameters:
Name Type Description
key string
value string

View Source url.js, line 135

string

# setObjCookie(key, value, options)

读取cookie并且序列化

Parameters:
Name Type Description
key string
value *
options object | undefined

View Source cookie.js, line 40

# setSelectorOfDOM(dom, selector) → {undefined}

用css选择符设置到node上

Parameters:
Name Type Description
dom HTMLElement
selector string

View Source browser/dom.js, line 50

undefined

# setUrlParam(url, key, value) → {string}

set query value of url

Parameters:
Name Type Description
url string
key string
value *

View Source url.js, line 120

url with new query value

string
Example
let url = 'http://google.com?a=2';
url = setUrlParam(url, 'a', '6');
console.log(url);//'http://google.com?a=6'

# setUrlParams(url, params) → {string}

set some query values to url

Parameters:
Name Type Description
url
params object

query string object

View Source url.js, line 169

string
Example
var params = {
    a: 11,
    b: 22
}
var url = 'http://google.com?a=1&b=2';
url = setQueryParam(url, params);
console.log(url); //'http://google.com?a=11&b=22'

# setUrlRandomParam(url, key) → {string}

set random query value to url by specified key

Parameters:
Name Type Description
url string
key string

View Source url.js, line 151

string

# setter(obj, key, value) → {*}

set value to obj with specified key path

Parameters:
Name Type Description
obj object
key string
value *

View Source obj.js, line 21

*

# sleep(timeopt) → {Promise.<any>}

sleep for time(ms)

Parameters:
Name Type Attributes Default Description
time number <optional>
0

View Source async.js, line 47

Promise.<any>

# sleepSecond(secondopt) → {Promise.<any>}

sleep for seconds

Parameters:
Name Type Attributes Default Description
second number <optional>
0

View Source async.js, line 58

Promise.<any>

# sortObjectArray(data, field, order) → {*}

sort array by field

Parameters:
Name Type Description
data Array.<object>
field string
order string

desc, asc. default is desc

View Source arr.js, line 280

*

# splitArrayByPredicate(list, predicateopt) → {SplitListByConditionResult}

separating list to true list and false list

Parameters:
Name Type Attributes Default Description
list array
predicate function <optional>
noop

View Source arr.js, line 62

# subGbStr(str, index, pointopt) → {string}

slice specified length of string with EN, CN chars

Parameters:
Name Type Attributes Default Description
str string
index number
point boolean <optional>
true

View Source str.js, line 172

string

# throttle(func, delayopt) → {function}

control call time interval of function

Parameters:
Name Type Attributes Default Description
func function
delay number <optional>
300

ms

View Source aop.js, line 71

function

# toDate(value) → {Date|undefined}

string to date instance

Parameters:
Name Type Description
value ParsedDate

View Source date.js, line 124

Date | undefined

# toObject(value) → {*}

translate value to object if value is type of object

Parameters:
Name Type Description
value object | string

View Source obj.js, line 142

*

# toUrl(options) → {string}

parse options to url

Parameters:
Name Type Description
options ParsedUrl

View Source url.js, line 56

full url

string

# uniqueArray2Map(list, uniqueFieldOrHandler) → {Object}

translate object to map struct eg: [{a:1},{a:2}] => {1:{a:1}, 2:{a:2}}

Parameters:
Name Type Description
list Array
uniqueFieldOrHandler string | function

View Source arr.js, line 250

Object

Type Definitions

object

# BrowserFileDef

windows文件对象

Properties:
Name Type Description
lastModified number

最后修改的时间,格式是数值时间戳

lastModifiedDate Date

最后修改的时间,格式是Date

name string

文件名称

size number

文件尺寸,多少字节

type string

文件类型,如 "image/png"

webkitRelativePath string

文件在webkit内核下的系统路径

View Source browser/file.js, line 1

Object

# CacheObject

A cache object with methods to manage cache data.

Properties:
Name Type Description
cache object

The cache object that holds the cache data.

getData function

Returns the cache data.

containsKey function

Checks if the cache contains a specific key.

getCache function

Retrieves the value associated with a specific key from the cache.

setCache function

Sets a value in the cache for a specific key.

clearCache function

Clears the entire cache.

init function

Initializes the cache with a new cache object.

clearExpire function

Clears expired cache entries based on the defined life cycle.

View Source cache.js, line 11

Object

# DiskCache

Properties:
Name Type Description
Cacher CacheObject
getCache function
setCache function
getTotalData function
reportError function
clearCache function

View Source cache.js, line 91

object

# ParsedDate

View Source date.js, line 92

Object

# ParsedUrl

Properties:
Name Type Description
search string

query string of url

headOfUrl string

The head part of the url like location.origin

hash string

The hash part of the url. eg: #hash

View Source url.js, line 1

object

# SplitListByConditionResult

Properties:
Name Type Description
trueList array
falseList array

View Source arr.js, line 51