", js-common-functions Global

Global

Methods

# ajax(url, data, method) → {Promise}

Parameters:
Name Type Description
url String

Request address

data Object

Request parameters

method String

Request way get/post

View Source index.ts, line 124

Promise

# checkBankCard(bankCard) → {Boolean}

Parameters:
Name Type Description
bankCard String

Bank card number

View Source index.ts, line 259

Boolean

# checkEmail(email) → {Boolean}

Parameters:
Name Type Description
email String

Mail

View Source index.ts, line 231

Boolean

# checkIdCard(idCard) → {Boolean}

Parameters:
Name Type Description
idCard String

ID number

View Source index.ts, line 250

Boolean

# checkPassword(password) → {Boolean}

Parameters:
Name Type Description
password String

password

View Source index.ts, line 222

Boolean

# checkPhone(phone, isChina) → {Boolean}

Parameters:
Name Type Description
phone String

phone number

isChina Boolean

Is it a Chinese mobile phone number?

View Source index.ts, line 241

Boolean

# checkPhoneSystem()

View Source index.ts, line 266

# deepClone(obj) → {Object}

Parameters:
Name Type Description
obj Object

Objects to copy

View Source index.ts, line 8

Deep copy of the object

Object

# fetch(url, setting) → {Promise}

Parameters:
Name Type Description
url string

Request address

setting string

Request configuration

View Source index.ts, line 303

Request promise

Promise

# filterHTML(str) → {string}

Parameters:
Name Type Description
str string

String

View Source index.ts, line 379

String

string

# getObjectLength(obj)

Parameters:
Name Type Description
obj Object

To get an object of the number of properties

View Source index.ts, line 68

# getPhoneAttribution(phone)

Parameters:
Name Type Description
phone String

phone number

View Source index.ts, line 276

# getScrollTop() → {Number}

Get the distance from the top of the scroll bar

View Source index.ts, line 423

The distance from the top of the scroll bar

Number

# isContain(arr, value)

Parameters:
Name Type Description
arr Array

Array to be judged

value any

To determine the value

View Source index.ts, line 152

# isFloat(val) → {boolean}

Parameters:
Name Type Description
val any

View Source index.ts, line 387

boolean

# isInteger(val) → {boolean}

Parameters:
Name Type Description
val any

View Source index.ts, line 395

boolean

# isPC() → {Boolean}

View Source index.ts, line 341

true or false

Boolean

# mergeArrays(array1, array2) → {Array}

Parameters:
Name Type Description
array1 Array

The first array to merge.

array2 Array

The second array to merge.

View Source index.ts, line 454

The merged array.

Array

# randomCode(len)

Parameters:
Name Type Description
len Number

Verification code length

View Source index.ts, line 210

# randomColor() → {String}

View Source index.ts, line 177

Random color

String
Example
console.log(randomColor()) // #e6e6e6

# shallowClone(obj) → {Object}

Parameters:
Name Type Description
obj Object

Objects to copy

View Source index.ts, line 43

Shallow copy of the object

Object

# sortBy(arr, key, order)

Parameters:
Name Type Description
arr Array

Array to be sorted

key String

Sort KEY

order String

Sort mode, ASC ascending, DESC descending

View Source index.ts, line 193

Example
sortBy([{name: 'a'}, {name: 'b'}], 'name', 'asc')
// => [{name: 'a'}, {name: 'b'}]
sortBy([{name: 'a'}, {name: 'b'}], 'name', 'desc')
// => [{name: 'b'}, {name: 'a'}]
sortBy([{name: 'a'}, {name: 'b'}], 'name')
// => [{name: 'a'}, {name: 'b'}]

# stringifyQueryString(obj) → {String}

Parameters:
Name Type Description
obj Object

View Source index.ts, line 403

String

# timeFormat(time) → {*}

Parameters:
Name Type Description
time *

Timestamp

View Source index.ts, line 82

Time format X days ago

*
Example
console.log(timeFormat(1588888888)); // 2 days ago

# trim(str, type) → {string}

Parameters:
Name Type Description
str string

String

type string

Type 1: All space type 2: front and rear space type 3: Front space type 4: rear

View Source index.ts, line 359

String

string

# unique(arr) → {Array}

Parameters:
Name Type Description
arr Array

Array to be heavy

View Source index.ts, line 162

Array
Example
console.log(unique([1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10])) // [1,2,3,4,5,6,7,8,9,10]

# windowResize(downCb, upCb) → {function}

H5 soft keyboard is retracted, bounce back When the software keyboard pops up will change the current Window.innerHeight, monitor this value change

Parameters:
Name Type Description
downCb function

When the soft keyboard bounces, the retracted callback

upCb function

When the soft keyboard bounces

View Source index.ts, line 434

function