Members
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 |
# 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 |
function
# array2Map(list, fieldOrHandler) → {object}
group map by field or handler to map object
Parameters:
Name | Type | Description |
---|---|---|
list |
array.<*>
|
|
fieldOrHandler |
string
|
function
|
object
# asyncRetry(func, timesopt) → {Promise}
retry function call until success
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
func |
function
|
|||
times |
number
|
<optional> |
3 |
Promise
# bindNativeEvent(element, eventName, eventHandler) → {undefined}
bind native event
Parameters:
Name | Type | Description |
---|---|---|
element |
HTMLElement
|
|
eventName |
string
|
|
eventHandler |
function
|
undefined
# checkBit(flag, bitFlag) → {boolean}
check bitflag if it is 1 in flag
Parameters:
Name | Type | Description |
---|---|---|
flag |
number
|
|
bitFlag |
number
|
boolean
# 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
|
string
# compareToNow(timestamp) → {number}
compare timestamp with now timestamp
Parameters:
Name | Type | Description |
---|---|---|
timestamp |
number
|
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', ...] |
['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 |
。
# createNodeInDocumentBody(tagNameopt) → {HTMLDivElement}
create Node and insert it into body
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
tagName |
string
|
<optional> |
'div |
HTMLDivElement
# dateFormat(fmt, date) → {*}
translate date instance to string
Parameters:
Name | Type | Description |
---|---|---|
fmt |
string
|
|
date |
Date
|
*
# 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) |
function
# 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 |
function
# diffArrays(one, two) → {Array.<any>}
get difference between two arrays
Parameters:
Name | Type | Description |
---|---|---|
one |
Array.<any>
|
|
two |
Array.<any>
|
Array.<any>
# ellipsis(text, maxNum) → {string}
a function like css's ellipsis
Parameters:
Name | Type | Description |
---|---|---|
text |
string
|
|
maxNum |
number
|
string
# equals(a, b) → {boolean}
用于对比两个数据是否相等,相等/相同,注意Date/RegExp可能会出问题
Parameters:
Name | Type | Description |
---|---|---|
a |
any
|
|
b |
any
|
boolean
# fixArrayIndex(array, index) → {*}
fix index of array
Parameters:
Name | Type | Description |
---|---|---|
array |
array
|
|
index |
number
|
*
# forEach(obj, fn) → {void}
forEach
Parameters:
Name | Type | Description |
---|---|---|
obj |
Object
|
Array
|
obj |
fn |
function
|
callback |
无返回值
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' |
string
# genRangeValue(type) → {*}
generate random value by type
Parameters:
Name | Type | Description |
---|---|---|
type |
function
|
like Function, String and so on |
*
# getArgTestCasesOfFunction(func) → {Array.<Array.<*>>}
generate random test cases of function arguments
Parameters:
Name | Type | Description |
---|---|---|
func |
function
|
test function with name. like function name(){} |
Array.<Array.<*>>
# getCombination(arrays) → {Array.<Array.<*>>}
生成多个数组的组合列表。
Parameters:
Name | Type | Description |
---|---|---|
arrays |
Array.<Array.<*>>
|
一个数组的数组,每个数组代表一组可选元素。 |
- 返回一个包含所有可能组合的数组。
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 |
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] );
# getCurrUrlParam(key) → {string}
get query value from window.location.href
Parameters:
Name | Type | Description |
---|---|---|
key |
string
|
string
# getDayOfMonth(year, month) → {number}
get the day of the month
Parameters:
Name | Type | Description |
---|---|---|
year |
number
|
|
month |
number
|
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
|
1-7
number
# getDaysBetween(start, end) → {Number}
get days between start end end
Parameters:
Name | Type | Description |
---|---|---|
start |
string
|
Date
|
|
end |
string
|
Date
|
相隔天数
Number
# getElementsOfCircleArray(circleArray, index, length) → {Array.<any>}
get elements of circleArray
Parameters:
Name | Type | Description |
---|---|---|
circleArray |
array
|
|
index |
number
|
|
length |
number
|
Array.<any>
# getFieldList(itemList, field) → {Array}
collecting some field of item to generate list;
Parameters:
Name | Type | Description |
---|---|---|
itemList |
array
|
target list |
field |
string
|
Array
# getFileExtension(filename) → {string}
解析文件后缀名,而且会强制转换小写,例如有的客户会jpg改为JPG等非法文件,导致后端接口失败
Parameters:
Name | Type | Description |
---|---|---|
filename |
string
|
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
|
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 |
*
|
object
|
undefined
# getGbLen(str) → {number}
compute string length including Chinese and English chars
Parameters:
Name | Type | Description |
---|---|---|
str |
string
|
number
# getLeftTimeInfo(timestamp) → {Object}
get rest information of the time
Parameters:
Name | Type | Description |
---|---|---|
timestamp |
number
|
ms unit |
Object
# getQueryObject(url) → {object}
get query object from url
Parameters:
Name | Type | Description |
---|---|---|
url |
string
|
object
# getTriggerLock() → {TriggerLock}
get lockFactory instance of click action
# getUrlFileExtension(url) → {string}
解析url资源后缀,而且会强制转换小写,例如有的客户会jpg改为JPG等非法文件,导致后端接口失败
Parameters:
Name | Type | Description |
---|---|---|
url |
string
|
string
# getUrlParam(url, key) → {string}
get query value from url by specified key
Parameters:
Name | Type | Description |
---|---|---|
url |
string
|
|
key |
string
|
query key |
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
|
URLSearchParams
# 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> |
any
# hex2rgb(hex) → {Array.<number>}
hex to rgb
Parameters:
Name | Type | Description |
---|---|---|
hex |
string
|
Array.<number>
# 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
|
Array.<any>
# isAbsoluteUrl(value) → {Boolean}
check if value is a absolute url
Parameters:
Name | Type | Description |
---|---|---|
value |
String
|
url |
是否为绝对路径
Boolean
# isArray(value) → {boolean}
check if it is an empty object
Parameters:
Name | Type | Description |
---|---|---|
value |
*
|
boolean
# isBoolean(value) → {boolean}
check if it is a boolean
Parameters:
Name | Type | Description |
---|---|---|
value |
*
|
boolean
# isClass(value) → {string|boolean}
check if value is class
Parameters:
Name | Type | Description |
---|---|---|
value |
*
|
string
|
boolean
# isDate(value) → {boolean}
check if it is a instance of Date
Parameters:
Name | Type | Description |
---|---|---|
value |
*
|
boolean
# isEmpty(value) → {boolean}
check if it is a instance of Error
Parameters:
Name | Type | Description |
---|---|---|
value |
*
|
boolean
# isEmptyArr(value) → {boolean}
check if it is an empty array
Parameters:
Name | Type | Description |
---|---|---|
value |
*
|
it must be an array value |
boolean
# isFalsy(value) → {boolean}
check if it is a falsy value
Parameters:
Name | Type | Description |
---|---|---|
value |
*
|
boolean
# isFunction(value) → {boolean}
check if it is a function
Parameters:
Name | Type | Description |
---|---|---|
value |
*
|
boolean
# isJSON(str) → {boolean}
check if the value is json string
Parameters:
Name | Type | Description |
---|---|---|
str |
string
|
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
|
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
|
boolean
# isNormalStr(value) → {boolean}
value can't includes some values
Parameters:
Name | Type | Description |
---|---|---|
value |
string
|
boolean
# isNumber(value) → {boolean}
check if it is a number
Parameters:
Name | Type | Description |
---|---|---|
value |
*
|
boolean
# isObject(value) → {boolean}
check if it is an object
Parameters:
Name | Type | Description |
---|---|---|
value |
*
|
boolean
# isObjectString(value) → {boolean}
check if value is json with object
Parameters:
Name | Type | Description |
---|---|---|
value |
string
|
boolean
# isParsedDate(obj) → {string|boolean}
is ParsedDate
Parameters:
Name | Type | Description |
---|---|---|
obj |
string
boolean
# isPromise(value) → {boolean}
whether value is Promise type
Parameters:
Name | Type | Description |
---|---|---|
value |
*
|
boolean
# isRegExp(value) → {boolean}
check if it is a instance of RegExp
Parameters:
Name | Type | Description |
---|---|---|
value |
*
|
boolean
# isString(value) → {boolean}
check if it is a string value
Parameters:
Name | Type | Description |
---|---|---|
value |
*
|
boolean
# isStringArray(value) → {boolean}
check if value is array with string type
Parameters:
Name | Type | Description |
---|---|---|
value |
*
|
boolean
# isTypeArray(value, typeExpect) → {*}
is array with elements that match typeExpect
Parameters:
Name | Type | Description |
---|---|---|
value |
array
|
|
typeExpect |
function
|
*
# isUndefined(value) → {boolean}
check if it is undefined
Parameters:
Name | Type | Description |
---|---|---|
value |
*
|
boolean
# isUrl(value) → {boolean}
check if the value is url
Parameters:
Name | Type | Description |
---|---|---|
value |
string
|
boolean
# jsonParse(string, defaultValue) → {any}
JSON.parse with try catch
Parameters:
Name | Type | Description |
---|---|---|
string |
string
|
|
defaultValue |
object
|
array
|
undefined
|
any
# jsonStringify(object, defaultValue, extArgs) → {string|*}
JSON.stringify with try catch
Parameters:
Name | Type | Description |
---|---|---|
object |
object
|
array
|
|
defaultValue |
string
|
undefined
|
|
extArgs |
string
|
*
# memorize(func) → {function}
cache returned value for function calls
Parameters:
Name | Type | Description |
---|---|---|
func |
function
|
。 |
return new function caching returned values of calls
function
# noEquals(a, b) → {boolean}
用于对比两个数据是否不相等,相等/相同,注意Date/RegExp可能会出问题
Parameters:
Name | Type | Description |
---|---|---|
a |
any
|
|
b |
any
|
boolean
# padZero(value) → {string}
add leading zero if value <10
Parameters:
Name | Type | Description |
---|---|---|
value |
number
|
string
# parseDate(date) → {Object}
parse date instance to object
Parameters:
Name | Type | Description |
---|---|---|
date |
Date
|
Object
# parseDateStr(str) → {Object}
parse date string to object with 'YYYY-MM-DD' pattern
Parameters:
Name | Type | Description |
---|---|---|
str |
string
|
Object
# promisify(api) → {function}
promisfy wx api, 保留 success, fail模式, 并返回等价promise
Parameters:
Name | Type | Description |
---|---|---|
api |
function
|
function
# pxToRpx(value, pageWidthPx) → {number}
px转换为rpx
Parameters:
Name | Type | Description |
---|---|---|
value |
number
|
|
pageWidthPx |
number
|
number
# queryObject2String(queryObject) → {string}
translate object to query string
Parameters:
Name | Type | Description |
---|---|---|
queryObject |
object
|
string
# queryString2Object(queryString) → {object}
translate query string to object
Parameters:
Name | Type | Description |
---|---|---|
queryString |
string
|
object
# removeElementsOfArray(array, field, value) → {array.<object>}
remove specified element from array
Parameters:
Name | Type | Description |
---|---|---|
array |
array.<object>
|
|
field |
string
|
|
value |
*
|
array.<object>
# removeNode(container, node)
remove node from container
Parameters:
Name | Type | Description |
---|---|---|
container |
HTMLElement
|
|
node |
HTMLElement
|
# renderVueComponentInDocumentBody(component, options) → {VNode|undefined}
创建一个vue实例并且插入到body里面
Parameters:
Name | Type | Description |
---|---|---|
component |
object
|
|
options |
object
|
VNode
|
undefined
# rgbArgs2hex(red, green, blue) → {string}
rgb to hex string
Parameters:
Name | Type | Description |
---|---|---|
red |
number
|
string
|
|
green |
number
|
string
|
|
blue |
number
|
string
|
string
# safeJsonParse(string, defaultValue) → {any}
JSON.parse with try catch
Parameters:
Name | Type | Description |
---|---|---|
string |
any
|
|
defaultValue |
object
|
array
|
undefined
|
any
# async selectOSFile(fileTypeListopt, multipleopt) → {Promise.<Array.<BrowserFileDef>>}
从windows资源管理器选择文件
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
fileTypeList |
Array.<string>
|
<optional> |
[] | 文件类型,如果不传递则不限制文件选择的类型范围 |
multiple |
boolean
|
<optional> |
false | 是否支持多选 |
Promise.<Array.<BrowserFileDef>>
# setCurrUrlParam(key, value) → {string}
get query value of window.location.href
Parameters:
Name | Type | Description |
---|---|---|
key |
string
|
|
value |
string
|
string
# setObjCookie(key, value, options)
读取cookie并且序列化
Parameters:
Name | Type | Description |
---|---|---|
key |
string
|
|
value |
*
|
|
options |
object
|
undefined
|
# setSelectorOfDOM(dom, selector) → {undefined}
用css选择符设置到node上
Parameters:
Name | Type | Description |
---|---|---|
dom |
HTMLElement
|
|
selector |
string
|
undefined
# setUrlParam(url, key, value) → {string}
set query value of url
Parameters:
Name | Type | Description |
---|---|---|
url |
string
|
|
key |
string
|
|
value |
*
|
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 |
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
|
string
# setter(obj, key, value) → {*}
set value to obj with specified key path
Parameters:
Name | Type | Description |
---|---|---|
obj |
object
|
|
key |
string
|
|
value |
*
|
*
# sleep(timeopt) → {Promise.<any>}
sleep for time(ms)
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
time |
number
|
<optional> |
0 |
Promise.<any>
# sleepSecond(secondopt) → {Promise.<any>}
sleep for seconds
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
second |
number
|
<optional> |
0 |
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 |
*
# splitArrayByPredicate(list, predicateopt) → {SplitListByConditionResult}
separating list to true list and false list
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
list |
array
|
|||
predicate |
function
|
<optional> |
noop |
# 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 |
string
# throttle(func, delayopt) → {function}
control call time interval of function
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
func |
function
|
|||
delay |
number
|
<optional> |
300 | ms |
function
# toDate(value) → {Date|undefined}
string to date instance
Parameters:
Name | Type | Description |
---|---|---|
value |
ParsedDate
|
Date
|
undefined
# toObject(value) → {*}
translate value to object if value is type of object
Parameters:
Name | Type | Description |
---|---|---|
value |
object
|
string
|
*
# toUrl(options) → {string}
parse options to url
Parameters:
Name | Type | Description |
---|---|---|
options |
ParsedUrl
|
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
|
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内核下的系统路径 |
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. |
Object
# DiskCache
Properties:
Name | Type | Description |
---|---|---|
Cacher |
CacheObject
|
|
getCache |
function
|
|
setCache |
function
|
|
getTotalData |
function
|
|
reportError |
function
|
|
clearCache |
function
|
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 |
object
# SplitListByConditionResult
Properties:
Name | Type | Description |
---|---|---|
trueList |
array
|
|
falseList |
array
|