csv data
+separator, default ','
+the first row is the table header data, default false
+array
+CSVToArray('a,b\\nc,d')
// `[['a','b'],['c','d']]`.
CSVToArray('a;b\\\nc;d', ';')
// `[['a','b'],['c','d']]`.
CSVToArray('col1,col2\\\na,b\\\nc,d', ',', true)
// `[['a','b'],['c','d']]`.
+
+1.0.9
+Converts a comma-separated string of values (CSV) to an array of 2D objects. The first line of the string is used as the header line.
+csv data
+delimiter, default ','
+CSVToJSON('col1,col2\\na,b\\\nc,d')
// `[{'col1': 'a', 'col2': 'b'}, {'col1': 'c', 'col2': 'd'}]`.
CSVToJSON('col1;col2\\\na;b\\\nc;d', ';')
// `[{'col1': 'a', 'col2': 'b'}, {'col1': 'c', 'col2': 'd'}]`.
+
+1.0.9
+Converts an array of objects to a comma-separated value (CSV) string containing only the specified columns.
+the specified columns
+delimiter, default ','
+JSONToCSV([{ a: 1, b: 2 }, { a: 3, b: 4, c: 5 }, { a: 6 }, { b: 7 }], ['a', 'b'])
// 'a,b\n "1", "2"\n "3", "4"\n "6",""\n"", "7"'
JSONToCSV([{ a: 1, b: 2 }, { a: 3, b: 4, c: 5 }, { a: 6 }, { b: 7 }], ['a', 'b'], ';')
// 'a;b\n "1"; "2"\n "3"; "4"\n "6";""\n""; "7"'
+
+1.0.9
+addEvent() event delegate, supports multiple delegates
+js dom object
+The event type. No need to add on
+callback method
+1.0.2
+Returns true if the provided predicate function returns true for all elements in a set, otherwise it returns false.
+the target array
+the judgment method
+all([4, 2, 3], x => x > 1)
// true
+
+1.0.9
+Returns true if the provided predicate function returns true for at least one element of a set, otherwise it returns false.
+the target array
+the judgment method
+any([0, 1, 2, 0], x => x >= 2)
// true
+
+1.0.9
+Get the APP version from navigator.userAgent, support 'x.x.x' & 'x.x.x-tagname.x'
+app name
+string|null
+// navigator.userAgent => '5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 AppName/1.0.0-beta.8'
appVersion('Chrome') // 114.0.0.0
appVersion('Safari') // 537.36
appVersion('appname', false) // null
appVersion('appname') // 1.0.0-beta.8
+
+5.1.0
+arrayBuffer to base64
+arrayBuffer
+Optional
mime: stringimage mime, eq: image/png
+arrayBufferToBase64(arrayBuffer, 'image/png')
// data:image/png;base64,xxxxxxxxxxxx
arrayBufferToBase64(arrayBuffer)
// xxxxxxxxxxxx
+
+5.13.0
+Converts a two-dimensional array to a comma-separated string of values (CSV).
+delimiter, default ','
+CSV data
+arrayToCSV([['a', 'b'], ['c', 'd']])
// '"a", "b" \n "c", "d"'
arrayToCSV([['a', 'b'], ['c', 'd']], ';')
// '"a"; "b"\n "c"; "d"'
arrayToCSV([['a', '"b" great'], ['c', 3.1415]])
// '"a", """b"" great"\n "c",3.1415'
+
+1.0.9
+Async await wrapper for easy error handling
+Promise
+const bar = () => new Promise<boolean>((resolve, reject) => {})
const foo = () => new Promise<string>((resolve, reject) => {})
;(async () => {
const [err, data] = await awaitToDone(bar())
const [err1, data1] = await awaitToDone(bar(), foo())
const [err2, data2] = await awaitToDone([bar(), foo()])
})()
+
+1.0.0
+saqqdy
+Get the browser name and version
+Optional
ua: stringua or any ua like string, may not be passed, default is navigator.userAgent
+BrowserVersion|null
+// Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) Ap…KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36
browserVersion() // \{ name: 'Chrome', version: '114.0.0.0' \}
+
+5.2.0
+Data cleaning methods
+the object to be cleaned, must be passed
+the data queue to be cleaned, can be passed as array or object
+Optional
nullFix: any1.0.2
+The client method returns a browser judgment result: { ANDROID: true, GECKO: true, GLSH_APP: false, IE: false, IOS: false, IPAD: false, IPHONE: false, MOBILE: true, MOBILEDEVICE. true, OPERA: false, QQ: false, QQBROWSER: false, TRIDENT: false, WEBKIT: true, WEIXIN: false }
optional, e.g. pass in MicroMessenger to return whether it is the built-in browser of Weixin
+optional, pass in a custom ua, default takes the browser's navigator.userAgent
+Will be refactored for the next major release
+1.0.1
+Version number size comparison, tag version: rc > beta > alpha > other
+input version
+compare version
+1/0/-1
+compareVersion('1.11.0', '1.9.9')
// => 1: 1=Version 1.11.0 is newer than 1.9.9
compareVersion('1.11.0', '1.11.0')
// => 0: 0=Versions 1.11.0 and 1.11.0 are the same
compareVersion('1.11.0', '1.99.0')
// => -1: -1=Version 1.11.0 is older than 1.99.0
compareVersion('1.0.0.0.0.10', '1.0')
// => -1
// compare tag version: rc > beta > alpha > other
compareVersion('1.11.0', '1.11.0-beta.1')
// => -1
compareVersion('1.11.0-beta.1', '1.11.0')
// => -1
compareVersion('1.11.0-beta.10', '1.11.0-beta.10')
// => 0
compareVersion('1.11.0-alpha.10', '1.11.0-beta.1')
// => -1
compareVersion('1.11.0-alpha.10', '1.11.0-rc.1')
// => -1
compareVersion('1.11.0-tag.10', '1.11.0-alpha.1')
// => -1
compareVersion('1.11.0-tag.10', '1.11.0-tag.1')
// => 1
compareVersion('1.11.0-release.10', '1.11.0-tag.1')
// => 1
+
+4.7.0
+debounce & throttle
+class
+1.0.2
+Several ways of file downloading:
+link
+filename
+Optional
type: stringdownload type 'href','open','download','request'
+deep copy & merge objects
+boolean | ExtendData
+Rest
...args: ArrayOneMore<ExtendObjectData>ArrayOneMore
1.0.2
+Rest
...args: ArrayOneMore<ExtendObjectData>Rest
...args: ArrayOneMore<ExtendArrayData>Rest
...args: ArrayOneMore<ExtendArrayData>Intercept the decimal places, do not fill in the missing 0
+the number of digits to be processed, required
+the number of decimal places to keep, default is 2
+fixNumber('100.888')
// 100.88
fixNumber('100.8', 2)
// 100.8
fixNumber('100.8888', 3)
// 100.888
+
+1.0.2
+Get the APP version number
+app name
+Optional
withApp: booleanwhether to bring the name
+Optional
userAgent: stringua, may not be passed, default is navigator.appVersion
+null/true/false
+please use 'appVersion' instead
+1.0.1
+Get the cache, if the deposited is Object, the retrieved is also Object, no need to convert again
+cache name
+const data1 = 100
const data2 = { a: 10 }
const data3 = null
setCache('data1', data1)
setCache('data2', data2)
setCache('data3', data3)
getCache('data1') // 100
getCache('data2') // {a:10}
getCache('data3') // null
getCache('data4') // null
+
+1.0.2
+Get directory form URL parameters
+pass in the url address
+It will be refactored and renamed getDirParams in the next major release.
+1.0.1
+Determine file type based on link suffix
+file url
+result
+getFileType('/name.png')
// { "suffix": "png", "type": "image" }
getFileType('/name.PDF')
// { "suffix": "pdf", "type": "pdf" }
getFileType('/name.xyz')
// { "suffix": "xyz", "type": "other" }
+
+5.11.0
+Get the phone system version
+system type string Android, iPod, iWatch or iPhone
+Optional
withOS: booleanwhether to bring the name
+Optional
userAgent: stringua, may not be passed, default takes navigator.appVersion
+getOsVersion('iPhone')
// '13.2.3'
getOsVersion('iPhone', true)
// 'iPhone/13.2.3'
+
+please use 'osVersion' instead
+1.0.1
+Get array, object property values based on path string
+target array, object
+query target, can pass function
+Optional
defaultValue: anydefault value
+result
+const target = {
a: 1,
b: [{
c: 2
d: NaN
}]
}
getProperty(target, 'a') // 1
getProperty(target, 'd', 100) // 100
getProperty(target, 'b[0].c') // 2
getProperty(target, 'b[0].d', 100) // 100
getProperty(target, () => 'a') // 1
+
+2.2.4
+Optional
defaultValue: anyGet a single query parameter (behind "#")
+key name
+getQueryParam('key1')
// key1 => xxx
getQueryParam('key1', 'https://test.com?key1=100#/home?key1=200')
// key1 => 200
+
+5.0.0
+Get all URL parameters (behind "#")
+pass in the url string
+getQueryParams('https://test.com?key1=100#/home?key1=200')
// \{"key1":"200"\}
getQueryParams('https://test.com?key1=100#/home?key1=200', true)
// \{"key1":200\}
getQueryParams(true)
// \{"key1":200\}
+
+5.0.0
+Read sessionStorage
+name
+const data1 = 100
const data2 = { a: 10 }
const data3 = null
setSession('data1', data1)
setSession('data2', data2)
setSession('data3', data3)
getSession('data1') // 100
getSession('data2') // {a:10}
getSession('data3') // null
getSession('data4') // null
+
+1.0.2
+Get the target type
+target
+type
+1.0.2
+Get a single URL parameter (from the "location.search", before "#")
+key name
+getUrlParam('key1')
// key1 => xxx
getUrlParam('key1', 'https://test.com?key1=100#/home?key1=200')
// key1 => 100
+
+5.0.0
+Get all URL parameters (from the "location.search", before "#")
+pass in the url string
+getUrlParams('https://test.com?key1=100#/home?key1=200')
// \{"key1":"100"\}
getUrlParams('https://test.com?key1=100#/home?key1=200', true)
// \{"key1":100\}
getUrlParams(true)
// \{"key1":100\}
+
+5.0.0
+Determine if target is an plain object
+any target
+isPlainObject({}) // true
isPlainObject(window) // false
+
+5.0.0
+Dynamic loading of resources, support js, images, css links, css style strings
+link to the resource, type must be passed when passing in styleString
+parameters: attrs, props, force
+Replacing specific data in a template string, support ${xxxx}
{{xxxx}}
and {xxxx}
Template string
+Template data of map function
+const tmp = "My name is ${name}, I'm ${age} years old."
mapTemplate(tmp, {
name: 'saqqdy',
age: 18
})
// My name is saqqdy, I'm 18 years old.
mapTemplate(tmp, key => ({ name: 'saqqdy', age: 28 }[key]))
// My name is saqqdy, I'm 28 years old.
const tmp = "My name is {{name}}, I'm {{age}} years old."
mapTemplate(tmp, {
name: 'saqqdy',
age: 18
})
// My name is saqqdy, I'm 18 years old.
+
+5.9.0
+return the next version, Only version types with no more than 3 digits are supported. (Follow the npm version rules)
+version(like: 1.0.0)
+Optional
type: "major" | "minor" | "patch" | "premajor" | "preminor" | "prepatch" | "prerelease"optional, version type
+optional, prerelease id
+nextVersion('1.2.33') // 1.2.34
nextVersion('1.2.33', 'major') // 2.0.0
nextVersion('1.2.33', 'premajor', 'alpha') // 2.0.0-alpha.1
+
+5.10.0
+Get the system name and version
+Optional
ua: stringua or any ua like string, may not be passed, default is navigator.userAgent
+OsVersion|null
+// ipad => 'Mozilla/5.0 (iPad; CPU OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/87.0.4280.77 Mobile/15E148 Safari/604.1'
osVersion() // \{ name: 'iOS', version: '13.3' \}
// iphone => 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1'
osVersion() // \{ name: 'iOS', version: '13.2.3' \}
// mac os => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'
osVersion() // \{ name: 'MacOS', version: '10.15.7' \}
// windows => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'
osVersion() // \{ name: 'Windows', version: '10.0' \}
// windows xp => 'Mozilla/5.0 (Windows NT 5.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'
osVersion() // \{ name: 'Windows', version: 'XP' \}
// windows phone => 'Mozilla/5.0 (Windows Phone OS 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36'
osVersion() // \{ name: 'WindowsPhone', version: '10.0' \}
+
+5.1.0
+parse url params
+url string (like: ?key1=value1&key2=value2)
+Converts a specific string to a corresponding value (Scientific notation, binary, octal and hexadecimal types of data are not converted, like: 0b111, 0o13, 0xFF, 1e3, -1e-2)
+object
+parseUrlParam('?key1=100&key2=true&key3=null&key4=undefined&key5=NaN&key6=10.888&key7=Infinity&key8=test')
// \{"key1":"100","key2":"true","key3":"null","key4":"undefined","key5":"NaN","key6":"10.888","key7":"Infinity","key8":"test"\}
parseUrlParam('?key1=100&key2=true&key3=null&key4=undefined&key5=NaN&key6=10.888&key7=Infinity&key8=test', true)
// \{"key1":100,"key2":true,"key3":null,"key5":NaN,"key6":10.888,"key7":Infinity,"key8":"test"\}
+
+5.0.0
+Convert an object to a promise like api
+original object
+resolver function
+import { promiseFactory, waiting } from 'js-cool'
function promise() {
const stats = {
value: 100
}
const resolver = () =>
new Promise(resolve =>
waiting(2000).then(() => {
stats.value = 200
resolve(stats)
})
)
return promiseFactory(stats, resolver)
}
const res = promise() // res => 100
const res = await promise() // res => 200
+
+5.10.0
+punctual setInterval
+A function to be executed after the timer expires.
+The time, in milliseconds that the timer should wait before the specified function or code is executed. If this parameter is omitted, a value of 0 is used, meaning execute "immediately", or more accurately, the next event cycle.
+Optional
args: TArgsAdditional arguments which are passed through to the function specified by handler.
+const printDate = () => console.log(new Date())
punctualTimer(printDate, 1000)
+
+5.18.0
+Generate random hexadecimal colors
+Optional
min: number | [number, number, number]the minimum value of the random numbers, eg: [10, 10, 10]
+Optional
max: number | [number, number, number]the maximum value of the random number, eg: [255, 255, 255]
+randomColor()
// #bf444b
randomColor(200)
// #d6e9d7
randomColor(200, 255)
// #d3f9e4
randomColor([0, 0, 0], [255, 255, 255])
// #d6e9d7
+
+5.5.0
+Generate n random integers that sum to a fixed sum
+Optional
n: numberNumber of generated integers, default: 1
+Optional
sum: numberSum of generated integers, default: 100
+Optional
noZero: booleanrandomNumbers()
// [8]
randomNumbers(4, 5)
// [1, 1, 2, 1]
randomNumbers(4, 5, false)
// [0, 1, 2, 2]
+
+5.4.0
+Get a random string
+Optional
len: numberthe length of the random string that needs to be obtained
+Optional
options: boolean | RandomStringOptionsoptional, randomString options
+// 1. No parameters are passed, a 32-bit (possibly) string containing upper and lower case letters and numbers is generated by default
randomString()
// PVSjz902EqYbmxaLtvDnggtnlvt5uFTZ
// 2. Generate a 16-bit random string
randomString(16)
// coTgZy0mqqMJ1sMM
// 3. Same effect as #2 above
randomString({
length: 16
})
// ngCI5aPqJm84t90d
// 4. Generate containing special characters (old way of passing values, not recommended)
randomString(true)
// 0Uby@op3B-sK5]dHl4S|15As.OlHiNXd
// 5. Same effect as #4 above (recommended)
randomString({
charTypes: ['uppercase', 'lowercase', 'number', 'special']
})
// m,2^vpkrE,F,DbcSFk0=vr&@DJ27j9XK
// 6. Same effect as #4 above, Limit string length to 16 bits
randomString(16, true)
// dXz[J_sYM^3d8fnA
// 7. Generate a 16-bit random number
randomString({
length: 16,
charTypes: 'number'
})
// 7450026301030286
// 8. Elimination of confusing characters: oOLl,9gq,Vv,Uu,I1
randomString({
length: 16,
noConfuse: true
})
// 8DEGna8ppC4mqyew
// 9. The generated random string must contain at least 1 character of each type of character specified, e.g. to generate a 16-bit password that must contain upper and lower case letters, numbers, and special characters.
randomString({
length: 16,
strict: true
})
// PFYAPD5KFqOHIADL
+
+5.0.0
+Optional
len: boolean | RandomStringOptionsOptional
options: boolean | RandomStringOptionsremoveEvent removes the event delegate created by addEvent
+js dom object
+The type of the event. No need to add on
+Callback method.
+1.0.2
+Secure parsing of JSON strings
+JSON string
+Whether to convert data, default: true
+safeParse('100')
// 100
safeParse('{"a":"undefined","b":"NaN","c":"Infinity","d":"9007199254740993"}')
// { b: NaN, c: Infinity, d: 9007199254740993n }
+
+Secure stringify of JSON Object
+JSON Object
+Whether to convert data, default: true
+safeStringify(100)
// "100"
safeStringify(undefined)
// "undefined"
safeStringify(NaN)
// "NaN"
safeStringify(Infinity)
// "Infinity"
safeStringify({ a: undefined, b: NaN, c: Infinity, d: BigInt(Number.MAX_SAFE_INTEGER) + 2n })
// {"a":"undefined","b":"NaN","c":"Infinity","d":"9007199254740993"}
+
+tree object depth lookup
+tree object
+required Query method
+optional Default subclass name, query name
+optional Number of lookups, if not passed, query all
+5.0.0
+Get the cache, if the deposited is Object, the retrieved is also Object, no need to convert again
+cache name
+cache data, can be passed directly into Object
+Optional
seconds: string | numbercache time (seconds)
+// set boolean
setCache('boolean', true)
// set object
setCache('object', { name: 'saqqdy' })
// set number, expires in 20 seconds
setCache('number', 666, 20)
+
+1.0.2
+setCookie method for writing cookies
+cookie name
+Set the value to be stored, either as an object or as a string
+cookie validity default 1 day
+path, default '/'
+SameSite, default true
+// expires in 86400 seconds
setCookie('token', 'xxxxxx')
// set to path
setCookie('token', 'xxxxxx', 20, '/app')
// enable samesite
setCookie('number', 666, 20, '/', false)
+
+1.0.2
+Set array, object property values based on path strings
+target array, object
+set target, support function, 'a' | 'a[1].c'
+const target = {
a: 1,
b: [{
c: 2
}]
}
setProperty(target, 'a', 2)
setProperty(target, 'b[0].c', 3)
setProperty(target, () => 'a', 100)
+
+2.7.0
+Write sessionStorage
+name
+Set the value to be stored, either as an object or as a string
+Optional
seconds: string | numberthe valid time
+// set boolean
setSession('boolean', true)
// set object
setSession('object', { name: 'saqqdy' })
// set number, expires in 20 seconds
setSession('number', 666, 20)
+
+1.0.2
+shuffling algorithm, Reordering arrays or strings
+arrays or strings
+Optional
size: numbernew array or string length
+const str = 'abcde'
const arr = [1,2,3]
shuffle(str)
// cdbse
shuffle(arr)
// [3, 1, 2]
shuffle(arr, 2)
// [3, 2]
+
+5.4.0
+Optional
size: numberSort Chinese by Chinese phonetic alphabet
+const items = ['啊我', '波拉', 'abc', 0, 3, '10', ',11', 13, null, '阿吧', 'ABB', 'BDD', 'ACD', 'ä']
items.sort(sortPinyin)
// [ ",11", 0, "10", 13, 3, "ä", "ABB", "abc", "ACD", "BDD", null, "阿吧", "啊我", "波拉" ]
items.sort((a, b) => sortPinyin(a, b, { ignorePunctuation: true, numeric:true }))
// [ 0, 3, "10", ",11", 13, "ä", "ABB", "abc", "ACD", "BDD", null, "阿吧", "啊我", "波拉" ]
+
+5.14.0
+Sorter factory function
+Optional
locales: string | string[]A string with a BCP 47 language tag, or an array of such strings.
+Optional
options: CollatorOptionsAn object adjusting the output format.
+const items = ['啊我', '波拉', 'abc', 0, 3, '10', ',11', 13, null, '阿吧', 'ABB', 'BDD', 'ACD', 'ä']
items.sort(
sorter('zh-Hans-CN', {
ignorePunctuation: true,
sensitivity: 'variant',
numeric: true
})
)
// [ 0, 3, "10", ",11", 13, "ä", "ABB", "abc", "ACD", "BDD", null, "阿吧", "啊我", "波拉" ]
+
+5.14.0
+splice url params
+json object
+Convert a null value type (null/undefined/) to an empty string, default: false
+spliceUrlParam('\{"key1":"100","key2":true,"key3":null,"key4":undefined,"key5":"测试"\}')
// ?key1=100&key2=true&key3=null&key4=undefined&key5=测试
spliceUrlParam('\{"key1":"100","key2":true,"key3":null,"key4":undefined\}', true)
// ?key1=100&key2=true&key3=&key4=
spliceUrlParam('\{"key1":"100","key2":true,"key3":null,"key4":undefined\}', true, false)
// key1=100&key2=true&key3=&key4=
+
+5.3.0
+windowSize to get the window size
+windowSize() // { width: 1280, height: 800 }
+
+1.0.1
+rc
> beta
> alpha
> other
${xxxx}
{{xxxx}}
and {xxxx}
# use pnpm
pnpm install js-cool
## use npm
npm install --save js-cool
+
+import { osVersion } from 'js-cool'
osVersion()
+
+const { osVersion } = require('js-cool')
osVersion()
+
+<script src="https://unpkg.com/js-cool@latest/dist/index.global.prod.js"></script>
<script>
jsCool.browserVersion()
</script>
+
+The client method returns a browser result object
+Since: 1.0.1
Arguments: none
Returns: object
Example:
+import { client } from 'js-cool'
client.get(['device', 'browser', 'engine', 'os']) // { device: 'xxx', browser: 'xxx', os: 'xxx', engine: 'xxx' }
client.get('device') // { device: 'xxx' }
+
+declare class Client {
matchMap: Record<InfoKeys, boolean>
root: Window & typeof globalThis
navigator: Navigator
constructor(options: ClientOptions)
get(names?: InfoTypes | InfoTypes[]): Partial<{
device: InfoKeys | undefined
os: InfoKeys | undefined
browser: InfoKeys | undefined
engine: InfoKeys | undefined
language: any
network: any
orientation: string | undefined
}>
getInfoByType(infoKey: InfoKey): InfoKeys | undefined
getOrientationStatus(): 'vertical' | 'horizontal' | undefined
getNetwork(): any
getLanguage(): any
}
+
+Collection of common regular expressions
+Since: 1.0.1
Arguments: none
Returns: none
Example:
+pattern.number.test('333') // true
+
+declare const pattern: {
any: RegExp
number: RegExp
string: RegExp
postcode: RegExp
url: RegExp
username: RegExp
float: RegExp
email: RegExp
mobile: RegExp
chinese: RegExp
tel: RegExp
qq: RegExp
pass: RegExp
json: RegExp
arrjson: RegExp
array: RegExp
isjson: RegExp
textarea: RegExp
}
+
+Remove all attributes of HTML tags
+Since: 1.0.1
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
string | +string with html tags | +string |
+- | +true |
+- | +
Returns: string
Example:
+clearAttr('<div id="testID">test</div>')
// '<div>test</div>'
+
+declare function clearAttr(string: string): string
+
+Remove HTML tags
+Since: 1.0.1
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
string | +string with html tags | +string |
+- | +true |
+- | +
Returns: string
Example:
+clearHtml('<div>test<br />string</div>')
// 'teststring'
+
+declare function clearHtml(string: string): string
+
+Escaping HTML Special Characters
+Since: 5.5.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
string | +string with html tags | +string |
+- | +true |
+- | +
Returns: string
Example:
+escape('<div>test<br />string</div>')
// '<div>test<br />string</div>'
+
+declare function escape(string: string): string
+
+Restore HTML Special Characters
+Since: 5.5.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
string | +string | +string |
+- | +true |
+- | +
Returns: string
Example:
+unescape('<div>test<br />string</div>')
// '<div>test<br />string</div>'
+
+declare function unescape(string: string): string
+
+Get the number in the string
+Since: 1.0.1
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
string | +pass in a string with a number | +string |
+- | +true |
+- | +
Returns: string
Example:
+getNumber('Chrome123.33')
// '123.33'
getNumber('234test.88')
// '234.88'
+
+declare function getNumber(string: string): string
+
+Converts humped strings to -spaced and all lowercase Dash pattern
+Since: 1.0.1
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
string | +the string to be converted | +string |
+- | +true |
+- | +
Returns: string
Example:
+camel2Dash('jsCool') // js-cool
+
+declare function camel2Dash(string: string): string
+
+Converts -spaced and all lowercase Dash patterns to humped strings
+Since: 1.0.1
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
string | +the string to be converted | +string |
+- | +true |
+- | +
Returns: string
Example:
+dash2Camel('js-cool') // jsCool
+
+declare function dash2Camel(string: string): string
+
+Generate random hexadecimal colors
+++Support for custom color value ranges starting with version 5.17.0, which can be used to customize the generation of darker, lighter, warmer colors, etc.
+
Since: 5.5.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
min | +the minimum value of the random numbers | +number / [number, number, number] |
+- | +false |
+- | +
max | +the maximum value of the random numbers | +number / [number, number, number] |
+- | +false |
+- | +
Returns: string
Example:
+randomColor()
// #bf444b
randomColor(200)
// #d6e9d7
randomColor(200, 255)
// #d3f9e4
randomColor([0, 0, 0], [255, 255, 255])
// #e2f2f3
+
+declare function randomColor(
min?: number | [number, number, number],
max?: number | [number, number, number]
): string
+
+Get a random number
+Since: 5.0.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
min | +the minimum value of the random number | +number |
+- | +false |
+1 | +
max | +the maximum value of the random number | +number |
+- | +false |
+10 | +
Returns: number
Example:
+randomNumber() // 8
randomNumber(0.1, 0.9) // 0.8
+
+declare function randomNumber(min?: number, max?: number): number
+
+Generate n random integers that sum to a fixed sum
+Since: 5.4.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
n | +Number of generated integers | +number |
+- | +false |
+1 | +
sum | +Sum of generated integers | +number |
+- | +false |
+100 | +
noZero | +Generate integers that are not zero | +boolean |
+- | +false |
+true |
+
Returns: Array<number>
Example:
+randomNumbers()
// [8]
randomNumbers(4, 5)
// [1, 1, 2, 1]
randomNumbers(4, 5, false)
// [0, 1, 2, 2]
+
+declare function randomNumbers(n?: number, sum?: number): number[]
+
+Get a random string
+++v5.4.0
+widthSpecialChar
changed tooptions
, still compatible with old usage, widthSpecialChar=true equivalent to { charTypes: ['uppercase', 'lowercase', 'number', 'special'] }
Since: 5.0.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
len | +the length of the random string that needs to be obtained | +number |
+- | +false |
+32 | +
options | +randomString options | +RandomStringOptions boolean |
+- | +false |
+{ charTypes: ['uppercase', 'lowercase', 'number'] } |
+
Returns: string
Example:
+// 1. No parameters are passed, a 32-bit (possibly) string containing upper and lower case letters and numbers is generated by default
randomString()
// PVSjz902EqYbmxaLtvDnggtnlvt5uFTZ
// 2. Generate a 16-bit random string
randomString(16)
// coTgZy0mqqMJ1sMM
// 3. Same effect as #2 above
randomString({
length: 16
})
// ngCI5aPqJm84t90d
// 4. Generate containing special characters (old way of passing values, not recommended)
randomString(true)
// 0Uby@op3B-sK5]dHl4S|15As.OlHiNXd
// 5. Same effect as #4 above (recommended)
randomString({
charTypes: ['uppercase', 'lowercase', 'number', 'special']
})
// m,2^vpkrE,F,DbcSFk0=vr&@DJ27j9XK
// 6. Same effect as #4 above, Limit string length to 16 bits
randomString(16, true)
// dXz[J_sYM^3d8fnA
// 7. Generate a 16-bit random number
randomString({
length: 16,
charTypes: 'number'
})
// 7450026301030286
// 8. Elimination of confusing characters: oOLl,9gq,Vv,Uu,I1
randomString({
length: 16,
noConfuse: true
})
// 8DEGna8ppC4mqyew
// 9. The generated random string must contain at least 1 character of each type of character specified, e.g. to generate a 16-bit password that must contain upper and lower case letters, numbers, and special characters.
randomString({
length: 16,
strict: true
})
// PFYAPD5KFqOHIADL
+
+declare function randomString(len?: number, options?: RandomStringOptions | boolean): string
declare function randomString(
len?: RandomStringOptions | boolean,
options?: RandomStringOptions | boolean
): string
declare type RandomStringCharType = 'uppercase' | 'lowercase' | 'number' | 'special'
declare interface RandomStringOptions {
length?: number
charTypes?: RandomStringCharType | ArrayOneMore<RandomStringCharType>
/**
* Elimination of confusing characters: oOLl,9gq,Vv,Uu,I1
*/
noConfuse?: boolean
/**
* The generated random string must contain each of the listed character types
*/
strict?: boolean
}
+
+shuffling algorithm, Reordering arrays or strings
+Since: 5.4.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
value | +arrays or strings | +array string |
+- | +true |
+- | +
size | +new array or string length | +number |
+- | +false |
+- | +
Returns: array | string
Example:
+const str = 'abcde'
const arr = [1, 2, 3]
shuffle(str)
// cdbse
shuffle(arr)
// [3, 1, 2]
shuffle(arr, 2)
// [3, 2]
+
+declare function shuffle(value: string, size?: number): string
declare function shuffle<T extends unknown[] = unknown[]>(value: T, size?: number): T
+
+Generating Browser Fingerprints
+Since: 5.2.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
domain | +key string | +string |
+- | +false |
+location.host | +
Returns: string
Example:
+fingerprint('www.saqqdy.com') // wc7sWJJA8
+
+declare function fingerprint(domain?: string): string | null
+
+Get the length of the string, Chinese counts as 2 characters
+Since: 1.0.1
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
str | +input string | +string |
+- | +true |
+- | +
Returns: number
Example:
+getCHSLength('测试') // 2
+
+declare function getCHSLength(str: string): number
+
+Intercept string, Chinese counts as 2 bytes
+Since: 1.0.1
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
str | +the string to be intercepted | +string |
+- | +true |
+- | +
len | +length | +number |
+- | +false |
+- | +
hasDot | +output with dot | +boolean |
+- | +false |
+false |
+
Returns: string
Example:
+cutCHSString('测试', 1) // 测
cutCHSString('测试', 1, true) // 测...
+
+declare function cutCHSString(str: string, len?: number, hasDot?: boolean): string
+
+First letter capitalized
+Since: 1.0.1
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
string | +the string to be converted | +string |
+- | +true |
+- | +
Returns: string
Example:
+upperFirst('saqqdy') // Saqqdy
+
+declare function upperFirst(string: string): string
+
+Determine if a string is a number
+Since: 1.0.1
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
str | +the string to be tested | +string |
+- | +true |
+- | +
Returns: boolean
Example:
+isDigitals('2.11') // true
isDigitals('2.3x') // false
+
+declare function isDigitals(str: string): boolean
+
+Determine if a function is defined
+Since: 1.0.1
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
name | +function name | +string |
+- | +true |
+- | +
Returns: boolean
Example:
+isExitsFunction('test') // false
isExitsFunction('console.log') // true
+
+declare function isExitsFunction(name: string): boolean
+
+Determine if a variable is defined
+Since: 1.0.1
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
name | +variable name | +string |
+- | +true |
+- | +
Returns: boolean
Example:
+isExitsVariable('test') // false
isExitsVariable('window') // true
+
+declare function isExitsVariable(name: string): boolean
+
+Determine if 2 objects are equal
+Since: 5.12.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
a | +source | +any |
+- | +true |
+- | +
b | +compare | +any |
+- | +true |
+- | +
Returns: boolean
Example:
+isEqual({ a: 22, b: {} }, { b: {}, a: 22 })
// true
isEqual([1, 2], [2, 1])
// false
isEqual(NaN, NaN)
// true
+
+declare function isEqual<T, P>(a: T, b: P): boolean
+
+Determine if window object
+Since: 5.0.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
target | +any target | +any |
+- | +true |
+- | +
Returns: boolean
Example:
+isWindow({}) // false
isWindow(window) // true
+
+declare function isWindow<T = any>(target: T): target is Window
+
+Determine if target is an plain object
+Since: 5.0.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
target | +any target | +any |
+- | +true |
+- | +
Returns: boolean
Example:
+isPlainObject({}) // true
isPlainObject(window) // false
+
+type Primitive = bigint | boolean | null | number | string | symbol | undefined
type JSONValue = Primitive | PlainObject | JSONArray
// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
interface PlainObject {
[key: string]: JSONValue
}
interface JSONArray extends Array<JSONValue> {}
declare function isPlainObject(target: unknown): target is PlainObject
+
+Determine if dark color mode
+Since: 5.5.0
Arguments: none
+Returns: boolean
Example:
+isDarkMode() // false
+
+declare function isDarkMode(): boolean
+
+Determine if target is an object
+Since: 5.0.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
target | +any target | +any |
+- | +true |
+- | +
Returns: boolean
Example:
+isObject({}) // true
+
+declare function isObject<T = any>(target: T): target is Object
+
+Determine if target is Date
+Since: 5.15.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
target | +any target | +any |
+- | +true |
+- | +
Returns: boolean
Example:
+const now = new Date()
isDate(now)
// true
+
+declare function isDate<T = any>(target: T): target is Date
+
+Determine if target is RegExp
+Since: 5.15.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
target | +any target | +any |
+- | +true |
+- | +
Returns: boolean
Example:
+isRegExp(/\d/) // true
+
+declare function isRegExp<T = any>(target: T): target is RegExp
+
+Determine if it is an array
+Since: 1.0.2
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
target | +any target | +any |
+- | +true |
+- | +
Returns: boolean
Example:
+isArray([]) // true
+
+declare function isIterable(target: any): target is any[]
+
+Determine if it is iterable
+Since: 5.7.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
target | +any target | +any |
+- | +true |
+- | +
Returns: boolean
Example:
+isIterable([]) // true
+
+declare function isIterable<T = any>(target: T | Iterable<T>): target is Iterable<T>
+
+Determine if it is running on the browser side
+Since: 4.5.0
Arguments: none
Returns: boolean
Example:
+function test() {
if (!inBrowser) return null
// ...
}
+
+declare const inBrowser: boolean
+
+Determine if it is running on node.js
+Since: 5.13.0
Arguments: none
Returns: boolean
Example:
+if (inNodeJs) {
//
}
+
+declare const inNodeJs: boolean
+
+Get the window size
+Since: 1.0.1
Arguments: none
Returns: { width, height }
Example:
+windowSize()
// { width: 1280, height: 800 }
+
+declare interface WindowSizeObj {
width: number
height: number
}
declare function windowSize(): WindowSizeObj
+
+Get the APP version number
+++deprecated please use 'appVersion' instead
+
Since: 1.0.1
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
appName | +app name | +string |
+- | +true |
+- | +
withApp | +whether to bring the name | +boolean |
+- | +false |
+- | +
userAgent | +ua or any ua like string, may not be passed | +string |
+- | +false |
+navigator.userAgent |
+
Returns: string | boolean | null
Example:
+// navigator.userAgent => '5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 AppName/1.0.0-beta.8'
getAppVersion('Chrome') // 114.0.0.0
getAppVersion('Safari', true) // Safari/537.36
+
+declare function getAppVersion(
appName: string,
withApp?: boolean,
userAgent?: string
): string | boolean | null
+
+Get the app version number
+Since: 5.1.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
appName | +app name | +string |
+- | +true |
+- | +
ua | +ua or any ua like string, may not be passed | +string |
+- | +false |
+navigator.userAgent | +
ignoreCase | +whether to ignore case | +boolean |
+true /false |
+false |
+true |
+
Returns: string | null
Example:
+// navigator.userAgent => '5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 AppName/1.0.0-beta.8'
appVersion('Chrome') // 114.0.0.0
appVersion('Safari') // 537.36
appVersion('appname', false) // null
appVersion('appname') // 1.0.0-beta.8
+
+declare function appVersion(appName: string): string | null
declare function appVersion(appName: string, ua: string): string | null
declare function appVersion(appName: string, ua: boolean): string | null
declare function appVersion(appName: string, ua: string, ignoreCase: boolean): string | null
+
+Get the phone system version
+++deprecated: please use 'osVersion' instead
+
Since: 1.0.1
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
osName | +system type string Android, iPod, iWatch or iPhone | +string |
+- | +true |
+- | +
withOS | +whether to bring the name | +string |
+- | +false |
+- | +
userAgent | +ua or any ua like string, may not be passed | +string |
+- | +false |
+navigator.userAgent |
+
Returns: string | boolean | null
Example:
+getOsVersion('iPhone')
// '13.2.3'
getOsVersion('iPhone', true)
// 'iPhone/13.2.3'
+
+declare function getOsVersion(
osName: string,
withOS?: boolean,
userAgent?: string
): string | boolean | null
+
+get the system version
+Since: 5.1.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
ua | +ua or any ua like string, may not be passed | +string |
+- | +false |
+navigator.userAgent | +
Returns: OsVersion | null
Example:
+// ipad => 'Mozilla/5.0 (iPad; CPU OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/87.0.4280.77 Mobile/15E148 Safari/604.1'
osVersion() // \{ name: 'iOS', version: '13.3' \}
// iphone => 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1'
osVersion() // \{ name: 'iOS', version: '13.2.3' \}
// mac os => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'
osVersion() // \{ name: 'MacOS', version: '10.15.7' \}
// windows => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'
osVersion() // \{ name: 'Windows', version: '10.0' \}
// windows xp => 'Mozilla/5.0 (Windows NT 5.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'
osVersion() // \{ name: 'Windows', version: 'XP' \}
// windows phone => 'Mozilla/5.0 (Windows Phone OS 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36'
osVersion() // \{ name: 'WindowsPhone', version: '10.0' \}
+
+declare interface OsVersion {
name: 'Windows' | 'MacOS' | 'Android' | 'iOS' | 'WindowsPhone' | 'Debian' | 'WebOS'
version: string
}
declare function osVersion(ua?: string): OsVersion | null
+
+Get the browser name and version
+Since: 5.2.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
ua | +ua or any ua like string, may not be passed | +string |
+- | +false |
+navigator.userAgent | +
Returns: BrowserVersion | null
Example:
+// Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) Ap…KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36
browserVersion() // \{ name: 'Chrome', version: '114.0.0.0' \}
+
+declare interface BrowserVersion {
name: 'Windows' | 'MacOS' | 'Android' | 'iOS' | 'WindowsPhone' | 'Debian' | 'WebOS'
version: string
}
declare function browserVersion(ua?: string): BrowserVersion | null
+
+++v5.8.0 support compare tag version
+
Version number size comparison, tag version: rc
> beta
> alpha
> other
Since: 4.7.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
input | +input version | +string |
+- | +true |
+- | +
compare | +compare version | +string |
+- | +true |
+- | +
Returns: 0 | 1 | -1
Example:
+compareVersion('1.11.0', '1.9.9')
// => 1: 1=Version 1.11.0 is newer than 1.9.9
compareVersion('1.11.0', '1.11.0')
// => 0: 0=Versions 1.11.0 and 1.11.0 are the same
compareVersion('1.11.0', '1.99.0')
// => -1: -1=Version 1.11.0 is older than 1.99.0
compareVersion('1.0.0.0.0.10', '1.0')
// => -1
// compare tag version: rc > beta > alpha > other
compareVersion('1.11.0', '1.11.0-beta.1')
// => -1
compareVersion('1.11.0-beta.1', '1.11.0')
// => -1
compareVersion('1.11.0-beta.10', '1.11.0-beta.10')
// => 0
compareVersion('1.11.0-alpha.10', '1.11.0-beta.1')
// => -1
compareVersion('1.11.0-alpha.10', '1.11.0-rc.1')
// => -1
compareVersion('1.11.0-tag.10', '1.11.0-alpha.1')
// => -1
compareVersion('1.11.0-tag.10', '1.11.0-tag.1')
// => 1
compareVersion('1.11.0-release.10', '1.11.0-tag.1')
// => 1
+
+declare function compareVersion(input: string, compare: string): 0 | 1 | -1
+
+parse url params. (If covert is passed true: Scientific notation, binary, octal and hexadecimal types of data are not converted, like: 0b111, 0o13, 0xFF, 1e3, -1e-2)
+Since: 5.0.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
url | +url string (like: ?key1=value1&key2=value2) | +string |
+- | +true |
+- | +
covert | +Converts a specific string to a corresponding value | +boolean |
+true /false |
+false |
+false |
+
Returns: object
Example:
+parseUrlParam(
'?key1=100&key2=true&key3=null&key4=undefined&key5=NaN&key6=10.888&key7=Infinity&key8=test'
)
// \{"key1":"100","key2":"true","key3":"null","key4":"undefined","key5":"NaN","key6":"10.888","key7":"Infinity","key8":"test"\}
parseUrlParam(
'?key1=100&key2=true&key3=null&key4=undefined&key5=NaN&key6=10.888&key7=Infinity&key8=test',
true
)
// \{"key1":100,"key2":true,"key3":null,"key5":NaN,"key6":10.888,"key7":Infinity,"key8":"test"\}
+
+declare function parseUrlParam(url: string, covert?: boolean): Record<string, unknown>
+
+Splice URL parameters (single layer only)
+++v5.20.0 Breaking change: remove encodeURIComponent +v5.21.0 Breaking change: covert support boolean & SpliceUrlParamOptions
+
Since: 5.3.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
params | +json object | +object |
+- | +true |
+- | +
covert | +Convert a null value type (null/undefined/) to an empty string or spliceUrlParamOptions | +boolean | SpliceUrlParamOptions |
+- | +false |
+false |
+
Returns: string
Example:
+spliceUrlParam({ key1: '100', key2: true, key3: null, key4: undefined, key5: '测试' })
// ?key1=100&key2=true&key3=null&key4=undefined&key5=测试
spliceUrlParam({ key1: '100', key2: true, key3: null, key4: undefined }, true)
// ?key1=100&key2=true&key3=&key4=
spliceUrlParam(
{ key1: '100', key2: true, key3: null, key4: undefined },
{ covert: true, withQuestionsMark: false }
)
// key1=100&key2=true&key3=&key4=
+
+declare function spliceUrlParam<T extends Record<string, unknown>>(
params: T,
covert?: SpliceUrlParamOptions | boolean
): string
declare interface SpliceUrlParamOptions {
covert?: boolean
encode?: boolean
withQuestionsMark?: boolean
}
+
+Secure parsing of JSON strings
+++support BigInt since
+v5.17.1
Since: 5.16.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
data | +JSON string | +string |
+- | +true |
+- | +
covert | +Whether to convert data | +boolean |
+true /false |
+false |
+true |
+
Returns: Object
Example:
+safeParse('100')
// 100
safeParse('{"a":"undefined","b":"NaN","c":"Infinity","d":"9007199254740993"}')
// { b: NaN, c: Infinity, d: 9007199254740993n }
+
+declare function safeParse(data: string, covert?: boolean): any
+
+Secure stringify of JSON Object
+++support BigInt since
+v5.17.1
Since: 5.16.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
data | +JSON Object | +any |
+- | +true |
+- | +
covert | +Whether to convert data | +boolean |
+true /false |
+false |
+true |
+
Returns: string
Example:
+safeStringify(100)
// "100"
safeStringify(undefined)
// "undefined"
safeStringify(NaN)
// "NaN"
safeStringify(Infinity)
// "Infinity"
safeStringify({ a: undefined, b: NaN, c: Infinity, d: BigInt(Number.MAX_SAFE_INTEGER) + 2n })
// {"a":"undefined","b":"NaN","c":"Infinity","d":"9007199254740993"}
+
+declare function safeStringify(data: any, covert?: boolean): string
+
+Get the URL parameter in the form of a directory
+++It will be refactored and renamed getDirParams in the next major release.
+
Since: 1.0.1
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
url | +http url | +object |
+- | +true |
+- | +
Returns: object
Example:
+//
+
+declare interface DirParamType {
path?: string[]
host?: string
}
declare function getDirParam(url: string): DirParamType
+
+Get a single query parameter (behind "#")
+Since: 5.0.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
key | +key name | +string |
+- | +true |
+- | +
url | +pass in the url string | +string |
+- | +false |
+location.href |
+
Returns: string
Example:
+getQueryParam('key1')
// key1 => xxx
getQueryParam('key1', 'https://test.com?key1=100#/home?key1=200')
// key1 => 200
+
+declare function getQueryParam(key: string): string | undefined
declare function getQueryParam(key: string, url: string): string | undefined
+
+Get all query parameters (behind "#"). (If covert is passed true: Scientific notation, binary, octal and hexadecimal types of data are not converted, like: 0b111, 0o13, 0xFF, 1e3, -1e-2)
+Since: 5.0.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
url | +pass in the url string | +string |
+- | +false |
+location.href |
+
covert | +Converts a specific string to a corresponding value | +boolean |
+true /false |
+false |
+false |
+
Returns: object
Example:
+getQueryParams('https://test.com?key1=100#/home?key1=200')
// \{"key1":"200"\}
getQueryParams('https://test.com?key1=100#/home?key1=200', true)
// \{"key1":200\}
getQueryParams(true)
// \{"key1":200\}
+
+declare function getQueryParams(url?: string, covert?: boolean): Record<string, unknown> | null
+
+Get a single URL parameter (from the "location.search", before "#")
+Since: 5.0.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
key | +key name | +string |
+- | +true |
+- | +
url | +pass in the url string | +string |
+- | +false |
+location.href |
+
Returns: string
Example:
+getUrlParam('key1')
// key1 => xxx
getUrlParam('key1', 'https://test.com?key1=100#/home?key1=200')
// key1 => 100
+
+declare function getUrlParam(key: string): string | undefined
declare function getUrlParam(key: string, url: string): string | undefined
+
+Get all URL parameters (from the "location.search", before "#"). (If covert is passed true: Scientific notation, binary, octal and hexadecimal types of data are not converted, like: 0b111, 0o13, 0xFF, 1e3, -1e-2)
+Since: 5.0.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
url | +pass in the url string | +string |
+- | +false |
+location.href |
+
covert | +Converts a specific string to a corresponding value | +boolean |
+true /false |
+false |
+false |
+
Returns: object
Example:
+getUrlParams('https://test.com?key1=100#/home?key1=200')
// \{"key1":"100"\}
getUrlParams('https://test.com?key1=100#/home?key1=200', true)
// \{"key1":100\}
getUrlParams(true)
// \{"key1":100\}
+
+declare function getUrlParams(url?: string, covert?: boolean): Record<string, unknown> | null
+
+Get the cache, if the deposited is Object, the retrieved is also Object, no need to convert again
+Since: 1.0.2
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
name | +cache key name | +string |
+- | +true |
+- | +
Returns: any
Example:
+import { getCache, setCache } from 'js-cool'
const data1 = 100
const data2 = { a: 10 }
const data3 = null
setCache('data1', data1)
setCache('data2', data2)
setCache('data3', data3)
getCache('data1') // 100
getCache('data2') // {a:10}
getCache('data3') // null
getCache('data4') // null
+
+declare function getCache(name: string): any
+
+Set the cache, if the deposited is Object, the retrieved is also Object, no need to convert again
+Since: 1.0.2
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
name | +cache key name | +string |
+- | +true |
+- | +
value | +cache data, can be passed directly into Object | +any |
+- | +true |
+- | +
seconds | +cache time (seconds) | +number |
+- | +false |
+- | +
Returns: void
Example:
+import { getCache, setCache } from 'js-cool'
const data1 = 100
const data2 = { a: 10 }
const data3 = null
setCache('data1', data1)
setCache('data2', data2, 10)
getCache('data1') // 100
getCache('data2') // {a:10}
setTimeout(() => {
getCache('data2') // null
}, 15000)
+
+declare function setCache<T = unknown>(name: string, value: T, seconds?: number | string): void
+
+Delete localStorage
+Since: 1.0.2
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
name | +cache key name | +string |
+- | +true |
+- | +
Returns: void
Example:
+delCache('data')
+
+declare function delCache(name: string): void
+
+Get the session, if the deposited is Object, the retrieved is also Object, no need to convert again
+Since: 1.0.2
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
name | +session key name | +string |
+- | +true |
+- | +
Returns: any
Example:
+const data1 = 100
const data2 = { a: 10 }
const data3 = null
setSession('data1', data1)
setSession('data2', data2)
setSession('data3', data3)
getSession('data1') // 100
getSession('data2') // {a:10}
getSession('data3') // null
getSession('data4') // null
+
+declare function getSession(name: string): any
+
+Set the session, if the deposited is Object, the retrieved is also Object, no need to convert again
+Since: 1.0.2
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
name | +session key name | +string |
+- | +true |
+- | +
value | +session data, can be passed directly into Object | +any |
+- | +true |
+- | +
seconds | +session time (seconds) | +number |
+- | +false |
+- | +
Returns: void
Example:
+import { getSession, setSession } from 'js-cool'
const data1 = 100
const data2 = { a: 10 }
const data3 = null
setSession('data1', data1)
setSession('data2', data2, 10)
getSession('data1') // 100
getSession('data2') // {a:10}
setTimeout(() => {
getSession('data2') // null
}, 15000)
+
+declare function setSession<T = unknown>(name: string, value: T, seconds?: number | string): void
+
+Delete sessionStorage
+Since: 1.0.2
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
name | +session key name | +string |
+- | +true |
+- | +
Returns: void
Example:
+delSession('data')
+
+declare function delSession(name: string): void
+
+Get cookie by name
+Since: 1.0.2
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
name | +cookie key name | +string |
+- | +true |
+- | +
Returns: any
Example:
+getCookie('data1') // 100
+
+declare function getCookie(name: string): string
+
+Get all cookies
+Since: 5.6.0
Arguments: 'none'
+Returns: object
Example:
+getCookies()
// { token: 'xxx', name: 'saqqdy' }
+
+declare function getCookies(): Record<string, string>
+
+Set cookie
+Since: 1.0.2
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
name | +cookie key name | +string |
+- | +true |
+- | +
value | +cookie data, can be passed directly into Object | +any |
+- | +true |
+- | +
seconds | +cookie time (seconds) | +number |
+- | +false |
+- | +
path | +cookie path | +string |
+- | +false |
+/ |
+
samesite | +SameSite type | +string |
+Strict /Lax /None |
+false |
+None |
+
Returns: void
Example:
+import { getCookie, setCookie } from 'js-cool'
const data1 = 100
const data2 = 200
setCookie('data1', data1)
setCookie('data2', data2, 10)
getCookie('data1') // 100
getCookie('data2') // 200
setTimeout(() => {
getCookie('data2') // null
}, 15000)
+
+declare function setCookie<T extends string | number | boolean>(
name: string,
value: T,
seconds: string | number,
path?: string,
samesite?: boolean
): void
+
+Delete cookie
+Since: 1.0.2
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
name | +cookie key name | +string |
+- | +true |
+- | +
Returns: void
Example:
+delCookie('data')
+
+declare function delCookie(name: string): void
+
+convert strings, numbers to base64
+Since: 1.0.1
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
input | +the string to be encoded | +string /number |
+- | +true |
+- | +
Returns: void
Example:
+encodeBase64('data')
+
+declare function encodeBase64(name: string): string
+
+base64 decoding
+Since: 1.0.1
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
input | +the string to be decoded | +string /number |
+- | +true |
+- | +
Returns: void
Example:
+decodeBase64('data')
+
+declare function decodeBase64(name: string): string
+
+convert strings, numbers to utf8
+Since: 1.0.1
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
input | +the string to be encoded | +string /number |
+- | +true |
+- | +
Returns: void
Example:
+encodeUtf8('data')
+
+declare function encodeUtf8(name: string): string
+
+utf8 decoding
+Since: 1.0.1
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
input | +the string to be decoded | +string /number |
+- | +true |
+- | +
Returns: void
Example:
+decodeUtf8('data')
+
+declare function decodeUtf8(name: string): string
+
+stop bubbling
+Since: 1.0.2
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
e | +dom's event object | +Event |
+- | +true |
+- | +
Returns: boolean
Example:
+stopBubble(event)
+
+declare function stopBubble(e: Event): boolean
+
+stop default events
+Since: 1.0.2
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
e | +dom's event object | +Event |
+- | +true |
+- | +
Returns: boolean
Example:
+stopDefault(event)
+
+declare function stopDefault(e: Event): boolean
+
+event delegate, support multiple delegates
+Since: 1.0.2
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
element | +js dom object | +HTMLElement |
+- | +true |
+- | +
type | +The type of the event. No need to add on | +string |
+- | +true |
+- | +
handler | +Callback method | +function |
+- | +true |
+- | +
Returns: void
Example:
+addEvent(document, 'click', functionName)
+
+declare function addEvent(element: AnyObject, type: string, handler: AnyFunction): void
+
+removeEvent removes the event delegate created by addEvent
+Since: 1.0.2
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
element | +js dom object | +HTMLElement |
+- | +true |
+- | +
type | +The type of the event. No need to add on | +string |
+- | +true |
+- | +
handler | +Callback method | +function |
+- | +true |
+- | +
Returns: void
Example:
+removeEvent(document, 'click', functionName)
+
+declare function removeEvent(element: AnyObject, type: string, handler: AnyFunction): void
+
+Get slide to top and bottom return 'top' 'bottom', recommend using limit flow
+Since: 1.0.2
Arguments: none
Returns: 'top' | 'bottom' | undefined
+Example:
+getScrollPosition() // ‘bottom’
+
+declare function getScrollPosition(): string | void
+
+return the next zIndex value
+++change mix defaults to 0
+
Since: 1.0.2
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
min | +minimum value | +number |
+- | +false |
+0 |
+
max | +maximum value | +number |
+- | +false |
+- | +
Returns: number
Example:
+nextIndex() // 1
nextIndex(1000) // 1001
nextIndex(10, 100) // 100
+
+declare function nextIndex(min?: number, max?: number): number
+
+return the next version, Only version types with no more than 3 digits are supported. (Follow the npm version rules)
+Since: 5.10.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
version | +version(like: 1.0.0) | +string |
+- | +true |
+- | +
type | +version type | +major | minor | patch | premajor | preminor | prepatch | prerelease |
+- | +false |
+patch |
+
preid | +prerelease id | +string |
+- | +false |
+'' | +
Returns: string
Example:
+nextVersion('1.2.33') // 1.2.34
nextVersion('1.2.33', 'major') // 2.0.0
nextVersion('1.2.33', 'premajor', 'alpha') // 2.0.0-alpha.1
+
+declare function nextVersion(
version: string,
type?: 'major' | 'minor' | 'patch' | 'premajor' | 'preminor' | 'prepatch' | 'prerelease',
preid?: string
): string
+
+punctual setInterval
+Since: 5.18.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
handler | +A function to be executed after the timer expires. | +function |
+- | +true |
+- | +
delay | +The time, in milliseconds that the timer should wait before the specified function or code is executed. If this parameter is omitted, a value of 0 is used, meaning execute "immediately", or more accurately, the next event cycle. | +number |
+- | +true |
+- | +
...args | +Additional arguments which are passed through to the function specified by handler. | +any[] |
+- | +false |
+- | +
Returns: void
Example:
+const printDate = () => console.log(new Date())
punctualTimer(printDate, 1000)
+
+declare function punctualTimer<TArgs extends any[]>(
handler: (args: void) => void,
delay: number,
[...args]?: TArgs
): void
declare function punctualTimer<TArgs extends any[]>(
handler: (...args: TArgs) => void,
delay: number,
[...args]?: TArgs
): void
+
+Convert an object to a promise like api
+Since: 5.10.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
original | +original object | +object |
+- | +true |
+- | +
resolver | +resolver function | +Function |
+- | +true |
+- | +
Returns: T & PromiseLike<T>
Example:
+import { promiseFactory, waiting } from 'js-cool'
function promise() {
const stats = {
value: 100
}
const resolver = () =>
new Promise(resolve =>
waiting(2000).then(() => {
stats.value = 200
resolve(stats)
})
)
return promiseFactory(stats, resolver)
}
const res = promise()
// res => 100
const res = await promise()
// res => 200
+
+declare function promiseFactory<T extends object>(
original: T,
resolver: () => Promise<any>
): T & PromiseLike<T>
+
+truncate a few decimal places, not 0 for shortage
+Since: 1.0.2
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
number | +the number of digits to be processed | +number /string |
+- | +true |
+- | +
n | +the number of decimal places to keep | +number |
+- | +false |
+2 |
+
Returns: string | number
Example:
+fixNumber('100.888')
// 100.88
fixNumber('100.8', 2)
// 100.8
fixNumber('100.8888', 3)
// 100.888
+
+declare function fixNumber(number: string | number, n?: number): number
+
+Replacing specific data in a template string, support ${xxxx}
{{xxxx}}
and {xxxx}
Since: 5.9.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
tmp | +Template string | +string |
+- | +true |
+- | +
data | +Template data of map function | +Function | Object |
+- | +true |
+- | +
Returns: string
Example:
+const tmp = "My name is ${name}, I'm ${age} years old."
mapTemplate(tmp, {
name: 'saqqdy',
age: 18
})
// My name is saqqdy, I'm 18 years old.
mapTemplate(tmp, key => ({ name: 'saqqdy', age: 28 })[key])
// My name is saqqdy, I'm 28 years old.
const tmp1 = "My name is {{name}}, I'm {{age}} years old."
mapTemplate(tmp1, {
name: 'saqqdy',
age: 18
})
// My name is saqqdy, I'm 18 years old.
+
+declare function mapTemplate(
tmp: string,
data: ((value: string) => unknown) | Record<string, unknown>
): string
+
+deep copy & merge objects
+Since: 1.0.2
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
target | +boolean or array or object | +boolean /ArrayOneMore<ExtendData> |
+- | +true |
+- | +
...args | +array or object | +ArrayOneMore<ExtendData> |
+- | +true |
+- | +
Returns: array | object
Example:
+extend(true, {}, {})
+
+declare function extend(
target: ExtendObjectData,
...args: ArrayOneMore<ExtendObjectData>
): ExtendObjectData
declare function extend(target: boolean, ...args: ArrayOneMore<ExtendObjectData>): ExtendObjectData
declare function extend(
target: ExtendArrayData,
...args: ArrayOneMore<ExtendArrayData>
): ExtendArrayData
declare function extend(target: boolean, ...args: ArrayOneMore<ExtendArrayData>): ExtendArrayData
declare type ExtendArrayData = any[]
declare type ExtendData = ExtendArrayData | ExtendObjectData
declare type ExtendObjectData = Record<string, any>
+
+deep copy (Buffer, Promise, Set, Map are not supported)
+Since: 5.15.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
source | +source object | +any |
+- | +true |
+- | +
Returns: object
Example:
+const source = { a: 100, reg: /\d+/g, arr: [1, 2] }
const res = clone(source)
// { a: 100, reg: /\d+/g, arr: [1, 2] }
+
+declare function clone<T = any>(parent: T): T
+
+anti-dither throttling
+Since: 1.0.2
Arguments: none
Returns: void
Example:
+const delay = new Delay()
delay.register('key', () => {
//
})
+
+declare function delay(): {
map: any
register(id: string, fn: AnyFunction, time: number, boo: boolean): void
destroy(id: string): void
}
+
+Get the target type
+Since: 1.0.2
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
target | +any target | +any |
+- | +true |
+- | +
Returns: string
Example:
+getType({}) // object
getType([]) // array
getType(new Promise()) // promise
getType(new Date()) // date
getType(async () => {}) // function
getType(navigator) // navigator
getType(global) // global
getType(window) // window
getType(Symbol('')) // symbol
+
+declare function getType<T = any>(
target: T
):
| 'string'
| 'number'
| 'bigint'
| 'boolean'
| 'symbol'
| 'undefined'
| 'object'
| 'function'
| 'window'
| 'error'
| 'promise'
| 'math'
| 'document'
| 'navigator'
| 'global'
| 'array'
| 'date'
| 'regexp'
| 'null'
+
+Determine file type based on link suffix
+Since: 5.11.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
url | +file url | +string |
+- | +true |
+- | +
Returns: object
Example:
+getFileType('/name.png')
// { "suffix": "png", "type": "image" }
getFileType('/name.PDF')
// { "suffix": "pdf", "type": "pdf" }
getFileType('/name.xyz')
// { "suffix": "xyz", "type": "other" }
+
+declare function getFileType(url: string): {
suffix: string
type: 'audio' | 'video' | 'image' | 'other' | 'word' | 'txt' | 'excel' | 'pdf' | 'ppt' | 'zip'
}
+
+Sorter factory function
+Since: 5.14.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
locales | +A string with a BCP 47 language tag, or an array of such strings | +string Array |
+- | +false |
+- | +
options | +An object adjusting the output format. | +Intl.CollatorOptions |
+- | +false |
+- | +
Returns: Function
Example:
+const items = ['啊我', '波拉', 'abc', 0, 3, '10', ',11', 13, null, '阿吧', 'ABB', 'BDD', 'ACD', 'ä']
items.sort(
sorter('zh-Hans-CN', {
ignorePunctuation: true,
sensitivity: 'variant',
numeric: true
})
)
// [ 0, 3, "10", ",11", 13, "ä", "ABB", "abc", "ACD", "BDD", null, "阿吧", "啊我", "波拉" ]
+
+declare function sorter(
locales?: string | string[],
options?: Intl.CollatorOptions
): <T = string, P = string>(a: T, b: P) => number
+
+Sort Chinese by Chinese phonetic alphabet
+Since: 5.14.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
a | +The first element for comparison. | +any |
+- | +true |
+- | +
b | +The second element for comparison. | +any |
+- | +true |
+- | +
options | +An object adjusting the output format. | +Intl.CollatorOptions |
+- | +false |
+- | +
Returns: number
Example:
+const items = ['啊我', '波拉', 'abc', 0, 3, '10', ',11', 13, null, '阿吧', 'ABB', 'BDD', 'ACD', 'ä']
items.sort(sortPinyin)
// [ ",11", 0, "10", 13, 3, "ä", "ABB", "abc", "ACD", "BDD", null, "阿吧", "啊我", "波拉" ]
items.sort((a, b) => sortPinyin(a, b, { ignorePunctuation: true, numeric: true }))
// [ 0, 3, "10", ",11", 13, "ä", "ABB", "abc", "ACD", "BDD", null, "阿吧", "啊我", "波拉" ]
+
+declare function sortPinyin<T = string, P = string>(
a: T,
b: P,
options?: Intl.CollatorOptions
): number
+
+Data cleaning methods
+Since: 1.0.2
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
data | +the object to be cleaned | +object |
+- | +true |
+- | +
map | +the data queue to be cleaned, can be passed as array or object | +array /object |
+- | +true |
+- | +
nullFix | +the value returned if there is no corresponding property, the default does not return the property | +any |
+- | +false |
+- | +
Returns: any
Example:
+//
+
+declare function cleanData(data: any, map: any[] | AnyObject, nullFix?: any): any
+
+Several ways of file downloading:
+Since: 1.0.5
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
url | +url link | +string |
+- | +true |
+- | +
filename | +file name | +string |
+- | +true |
+- | +
type | +download type | +string |
+href /open /download /request |
+false |
+download |
+
Returns: void
Example:
+download('https://unpkg.com/browse/js-cool@5.2.0/dist/index.global.prod.js')
+
+declare function download(url: string, filename: string, type?: string): void
+
+tree object depth lookup
+Since: 5.0.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
tree | +tree object | +array /object |
+- | +true |
+- | +
expression | +required Query method | +any |
+- | +true |
+- | +
keySet | +optional Default subclass name, query name | +SearchKeySet |
+- | +true |
+- | +
number | +optional Number of lookups, if not passed, query all | +number |
+- | +false |
+- | +
Returns: any
Example:
+//
+
+declare function searchObject(
tree: object | any[],
expression: any,
keySet: SearchKeySet,
number?: number
): any[]
+
+Open link in new tab (file jump download if browser can't parse)
+Since: 1.0.6
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
url | +http url | +string |
+- | +true |
+- | +
Returns: boolean | undefined
Example:
+openUrl('https://www.saqqdy.com/js-cool')
+
+declare function openUrl(url: string): void
+
+copy to clipboard
+Since: 5.0.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
value | +any value | +any |
+- | +true |
+- | +
Returns: boolean | undefined
Example:
+copy('10000')
+
+declare function copy(value: string): boolean | undefined
+
+Digital thousandths division
+Since: 3.0.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
num | +the number | +string /number |
+- | +true |
+- | +
Returns: string
Example:
+toThousands(10000) // '10,000'
+
+declare function toThousands(num: string | number): string
+
+return true if the provided predicate function returns true for all elements in a set, otherwise return false
+Since: 1.0.9
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
arr | +the target array | +array |
+- | +true |
+- | +
fn | +the judgment method | +function |
+- | +true |
+- | +
Returns: boolean
Example:
+all([4, 2, 3], x => x > 1)
// true
+
+declare const all: <T = unknown>(arr: T[], fn: AnyFunction) => boolean
+
+Returns true if the provided predicate function returns true for at least one element of a set, false otherwise
+Since: 1.0.9
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
arr | +the target array | +array |
+- | +true |
+- | +
fn | +the judgment method | +function |
+- | +true |
+- | +
Returns: boolean
Example:
+any([0, 1, 2, 0], x => x >= 2)
// true
+
+declare const any: <T = unknown>(arr: T[], fn: AnyFunction) => boolean
+
+generate uuid on browser side, use v4 method
+Since: 1.0.9
Arguments: none
Returns: string
Example:
+uuid() // '4222fcfe-5721-4632-bede-6043885be57d'
+
+declare const uuid: () => string
+
+Converts a comma-separated string of values (CSV) to a 2D array.
+Since: 1.0.9
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
data | +csv data | +string |
+- | +true |
+- | +
delimiter | +delimiter | +string |
+- | +false |
+',' | +
omitFirstRow | +the first row is the table header data | +boolean |
+- | +false |
+false |
+
Returns: string
Example:
+CSVToArray('a,b\\nc,d') // `[['a','b'],['c','d']]`
CSVToArray('a;b\\\nc;d', ';') // `[['a','b'],['c','d']]`
CSVToArray('col1,col2\\\na,b\\\nc,d', ',', true) // `[['a','b'],['c','d']]`
+
+declare const CSVToArray: (data: string, delimiter?: string, omitFirstRow?: boolean) => string[][]
+
+Converts a two-dimensional array to a comma-separated string of values (CSV).
+Since: 1.0.9
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
arr | +json data | +array |
+- | +true |
+- | +
delimiter | +delimiter | +string |
+- | +false |
+',' | +
Returns: string
Example:
+arrayToCSV([
['a', 'b'],
['c', 'd']
])
// '"a", "b" \n "c", "d"'
arrayToCSV(
[
['a', 'b'],
['c', 'd']
],
';'
)
// '"a"; "b"\n "c"; "d"'
arrayToCSV([
['a', '"b" great'],
['c', 3.1415]
])
// '"a", """b"" great"\n "c",3.1415'
+
+declare function arrayToCSV<T extends unknown[][]>(data: T, delimiter?: string): string
+
+Converts a comma-separated string of values (CSV) to an array of 2D objects. The first line of the string is used as the header line.
+Since: 1.0.9
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
data | +csv data | +string |
+- | +true |
+- | +
delimiter | +delimiter | +string |
+- | +false |
+',' | +
Returns: string
Example:
+CSVToJSON('col1,col2\\na,b\\\nc,d')
// `[{'col1': 'a', 'col2': 'b'}, {'col1': 'c', 'col2': 'd'}]`
CSVToJSON('col1;col2\\\na;b\\\nc;d', ';')
// `[{'col1': 'a', 'col2': 'b'}, {'col1': 'c', 'col2': 'd'}]`
+
+declare function CSVToJSON(data: string, delimiter?: string): any[]
+
+Converts an array of objects to a comma-separated value (CSV) string containing only the specified columns.
+Since: 1.0.9
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
arr | +json data | +array |
+- | +true |
+- | +
columns | +the specified columns | +array |
+- | +true |
+- | +
delimiter | +delimiter | +string |
+- | +false |
+',' | +
Returns: string
Example:
+JSONToCSV([{ a: 1, b: 2 }, { a: 3, b: 4, c: 5 }, { a: 6 }, { b: 7 }], ['a', 'b']) // 'a,b\n "1", "2"\n "3", "4"\n "6",""\n"", "7"'
JSONToCSV([{ a: 1, b: 2 }, { a: 3, b: 4, c: 5 }, { a: 6 }, { b: 7 }], ['a', 'b'], ';') // 'a;b\n "1"; "2"\n "3"; "4"\n "6";""\n""; "7"'
+
+declare const JSONToCSV: (arr: any[], columns: any[], delimiter?: string) => string
+
+Converts RGB component values to color codes.
+Since: 1.0.9
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
r | +the 1st value of RGB | +number |
+- | +true |
+- | +
g | +RGB's 2nd value | +number |
+- | +true |
+- | +
b | +RGB's 3nd value | +number |
+- | +true |
+- | +
Returns: string
Example:
+RGBToHex(255, 165, 1) // 'ffa501'
+
+declare const RGBToHex: (r: number, g: number, b: number) => string
+
+Find the intersection of multiple arrays
+Since: 2.2.1
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
...arr | +array targets | +array |
+- | +true |
+- | +
Returns: array
Example:
+intersect([1, 2], [2, 3, 4], [2, 8], [2, '33']) // [2]
+
+declare function intersect<T = unknown>(...args: T[][]): T[]
+
+Find the concatenation of multiple arrays
+Since: 2.2.1
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
...arr | +array targets | +array |
+- | +true |
+- | +
Returns: array
Example:
+union([1, 2], [2, '33']) // [1, 2, '33']
+
+declare function union<T = unknown>(...args: T[][]): T[]
+
+Find the set of differences of multiple arrays that belong to A but not to B/C/D... of the elements of
+Since: 2.2.1
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
...arr | +array targets | +array |
+- | +true |
+- | +
Returns: array
Example:
+minus([1, 2], [2, '33'], [2, 4]) // [1]
+
+declare function minus<T = unknown>(...args: T[][]): T[]
+
+Find the complement of multiple arrays
+Since: 2.2.1
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
...arr | +array targets | +array |
+- | +true |
+- | +
Returns: array
Example:
+complement([1, 2], [2, '33'], [2]) // [1, '33']
+
+declare function complement<T = unknown>(...args: T[][]): T[]
+
+Whether the array contains the specified element
+Since: 2.2.1
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
arr | +array target | +array |
+- | +true |
+- | +
item | +any array member | +any |
+- | +true |
+- | +
Returns: boolean
Example:
+contains([1, 2], 2) // true
contains([1, 2], 3) // false
+
+declare function contains(arr: any[], item: any): boolean
+
+Array de-duplication
+Since: 2.2.1
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
arr | +array target | +array |
+- | +true |
+- | +
Returns: array
Example:
+unique([1, 2, 2, '33']) // [1, 2, '33']
+
+declare function unique<T = unknown>(arr: T[]): T[]
+
+ipv6 address completion
+Since: 2.2.2
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
ip | +ip address | +string |
+- | +true |
+- | +
Returns: string
Example:
+fillIPv6('2409:8005:800::2') // '2409:8005:0800:0000:0000:0000:0000:0002'
fillIPv6('2409:8005:800::1c') // '2409:8005:0800:0000:0000:0000:0000:001c'
+
+declare function fillIPv6(ip: string): string
+
+Get array, object property values based on path string
+++v5.19.0 support defaultValue
+
Since: 2.2.4
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
target | +target array, object | +array /object |
+- | +true |
+- | +
prop | +query target, can pass function | +string /function |
+- | +true |
+- | +
defaultValue | +default value | +any |
+- | +false |
+- | +
Returns: any
Example:
+const target = {
a: 1,
b: [
{
c: 2,
d: NaN
}
]
}
getProperty(target, 'a') // 1
getProperty(target, 'd', 100) // 100
getProperty(target, 'b[0].c') // 2
getProperty(target, 'b[0].d', 100) // 100
getProperty(target, () => 'a') // 1
+
+export declare function getProperty<T extends Record<string, any>>(
target: T,
prop:
| string
| {
(): string
},
defaultValue?: any
): any
export declare function getProperty<T extends Array<any>>(
target: T,
prop:
| string
| {
(): string
},
defaultValue?: any
): any
+
+Set array, object property values based on path string
+Since: 2.7.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
target | +target array, object | +array /object |
+- | +true |
+- | +
prop | +set target, support function, 'a' | 'a[1].c' | +string /function |
+- | +true |
+- | +
value | +value | +any |
+- | +true |
+- | +
Returns: any
Example:
+const target = {
a: 1,
b: [
{
c: 2
}
]
}
setProperty(target, 'a', 2)
setProperty(target, 'b[0].c', 3)
setProperty(target, () => 'a', 100)
+
+declare function setProperty(
target: any,
prop:
| string
| {
(): string
},
value: any
): any
+
+load resources dynamically, support js, images, css links, css style strings
+Since: 2.8.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
url | +link to the resource, type must be passed when passing in styleString | +string |
+- | +true |
+- | +
options | +parameters: attrs, props, force | +SourceOptions |
+- | +false |
+- | +
Returns: boolean | imageUrl
Example:
+loadSource('/source/url', options)
+
+import { ImageAttributes } from 'mount-image'
import { LinkAttributes } from 'mount-css'
import { ScriptAttributes } from 'mount-script'
import { StyleAttributes } from 'mount-style'
declare function loadSource(
url: string,
option: SourceFileType | SourceOptions
): Promise<boolean | string>
declare type SourceFileType = 'js' | 'img' | 'css' | 'style' | string
declare interface SourceOptions {
type: SourceFileType
attrs?: LinkAttributes | StyleAttributes | ScriptAttributes | ImageAttributes
props?: LinkAttributes | StyleAttributes | ScriptAttributes | ImageAttributes
force?: boolean
}
+
+dynamically load css link resources
+Since: 2.8.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
url | +resource url | +string |
+- | +true |
+- | +
options | +parameters: attrs, props, force | +CssOptions |
+- | +false |
+- | +
Returns: boolean
Example:
+mountCss('/source/url', options)
+
+declare interface CssOptions {
attrs?: LinkAttributes
props?: LinkAttributes
force?: boolean
}
declare interface HTMLLinkElementEX extends HTMLLinkElement {
onreadystatechange?: any
readyState?: 'loaded' | 'complete'
}
declare type LinkAttributes = Pick<
HTMLLinkElement,
| 'as'
| 'charset'
| 'crossOrigin'
| 'disabled'
| 'href'
| 'hreflang'
| 'imageSizes'
| 'imageSrcset'
| 'integrity'
| 'media'
| 'referrerPolicy'
| 'rel'
| 'rev'
| 'target'
| 'type'
>
declare function mountCss(src: string, option?: CssOptions): Promise<boolean>
+
+load image resource dynamically
+Since: 2.8.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
url | +resource url | +string |
+- | +true |
+- | +
options | +parameters: attrs, props, force | +ImgOptions |
+- | +false |
+- | +
Returns: boolean | imageUrl
Example:
+mountImg('/source/url', options)
+
+declare interface HTMLImageElementEX extends HTMLImageElement {
onreadystatechange?: any
readyState?: 'loaded' | 'complete'
}
declare type ImageAttributes = Pick<
HTMLImageElement,
| 'align'
| 'alt'
| 'border'
| 'crossOrigin'
| 'decoding'
| 'height'
| 'hspace'
| 'isMap'
| 'loading'
| 'longDesc'
| 'lowsrc'
| 'name'
| 'referrerPolicy'
| 'sizes'
| 'src'
| 'srcset'
| 'useMap'
| 'vspace'
| 'width'
>
declare interface ImgOptions {
attrs?: ImageAttributes
props?: ImageAttributes
force?: boolean
}
declare function mountImage(src: string, option?: ImgOptions): Promise<boolean | string>
+
+load js link resources dynamically
+Since: 2.8.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
url | +resource url | +string |
+- | +true |
+- | +
options | +parameters: attrs, props, force | +JsOptions |
+- | +false |
+- | +
Returns: boolean
Example:
+mountJs('/source/url', options)
+
+declare interface HTMLScriptElementEX extends HTMLScriptElement {
onreadystatechange?: any
readyState?: 'loaded' | 'complete'
}
declare interface JsOptions {
attrs?: ScriptAttributes
props?: ScriptAttributes
force?: boolean
}
declare function mountJs(src: string, option?: JsOptions): Promise<boolean>
declare type ScriptAttributes = Pick<
HTMLScriptElement,
| 'async'
| 'charset'
| 'crossOrigin'
| 'defer'
| 'event'
| 'htmlFor'
| 'integrity'
| 'noModule'
| 'referrerPolicy'
| 'src'
| 'text'
| 'type'
>
+
+load css styles dynamically
+Since: 2.8.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
url | +resource url | +string |
+- | +true |
+- | +
options | +parameters: attrs, props, force | +StyleOptions |
+- | +false |
+- | +
Returns: boolean
Example:
+mountStyle('/source/url', options)
+
+declare function mountStyle(css: string, option?: StyleOptions): Promise<boolean>
declare type StyleAttributes = Pick<HTMLStyleElement, 'disabled' | 'media' | 'type'>
declare interface StyleOptions {
attrs?: StyleAttributes
props?: StyleAttributes
}
+
+Image preloading
+Since: 5.5.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
images | +images url | +string array |
+- | +true |
+- | +
Returns: void
+Example:
+preloader('path/of/image')
preloader(['path/of/image'])
+
+declare function preloader(images: string): HTMLImageElement
declare function preloader(images: string[]): Record<string, HTMLImageElement>
+
+++v5.8.1 Support throw on timeout
+
waiting for a while
+Since: 5.5.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
milliseconds | +waiting time (milliseconds) | +number |
+- | +true |
+- | +
throwOnTimeout | +throw on timeout | +boolean |
+- | +false |
+false |
+
Returns: Promise<void>
Example:
+waiting(2000)
await waiting(2000, true)
// reject
+
+declare function waiting(milliseconds: number, throwOnTimeout?: boolean): Promise<void>
+
+Async await wrapper for easy error handling
+++v5.7.0 Extend awaitTo to support passing in multiple promises
+
Since: 5.2.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
promise | +promise function | +Promise Promise[] |
+- | +true |
+- | +
...promises | +Promise rest params | +Promise[] |
+- | +false |
+- | +
Returns: [Error, undefined]
or [null, data | data[]]
Example:
+import { awaitTo as to } from 'js-cool'
// 1. simple use
const [err, data] = await to(new Promise())
if (err) {
// handle request error
}
// 2. Pass in multiple promises
const [err, data] = await to(promise1, promise2)
// or
const [err, data] = await to([promise1, promise2])
+
+declare function awaitTo<T, E = Error>(promise: Promise<T>): Promise<[E, undefined] | [null, T]>
declare function awaitTo<P extends readonly unknown[] | [], E = Error>(
promise: PromiseAll<P>
): Promise<[E, undefined] | [null, P]>
declare function awaitTo<T, P extends readonly unknown[] | [], E = Error>(
promise: Promise<T>,
...promises: PromiseAll<P>
): Promise<[E, undefined] | [null, [T, ...P]]>
export declare type PromiseAll<P extends readonly unknown[] | []> = {
-readonly [K in keyof P]: Promise<P[K]>
}
+
+arrayBuffer to base64
+++v5.19.1 remove default params of mime
+
Since: 5.13.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
input | +arrayBuffer data | +ArrayBuffer |
+- | +true |
+- | +
mime | +image mime | +String |
+- | +false |
+- | +
Returns: String
Example:
+arrayBufferToBase64(arrayBuffer, 'image/png')
// data:image/png;base64,xxxxxxxxxxxx
arrayBufferToBase64(arrayBuffer)
// xxxxxxxxxxxx
+
+declare function arrayBufferToBase64(input: ArrayBuffer, mime?: string): string
+
+arrayBuffer to blob
+Since: 5.13.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
input | +arrayBuffer data | +ArrayBuffer |
+- | +true |
+- | +
mime | +image mime | +String |
+- | +false |
+image/png |
+
Returns: Blob
Example:
+arrayBufferToBlob(arrayBuffer, 'image/png')
// Blob
+
+declare function arrayBufferToBlob(input: ArrayBuffer, mime?: string): Blob
+
+base64 to arrayBuffer
+Since: 5.13.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
input | +base64 string | +String |
+- | +true |
+- | +
Returns: ArrayBuffer
Example:
+base64ToArrayBuffer(base64)
// ArrayBuffer
+
+declare function base64ToArrayBuffer(input: string): ArrayBuffer
+
+base64 to blob
+Since: 5.13.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
input | +base64 string | +String |
+- | +true |
+- | +
Returns: Blob
Example:
+base64ToBlob(base64)
// Blob
+
+declare function base64ToBlob(input: string): Blob
+
+base64 to file
+Since: 5.13.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
input | +base64 string | +String |
+- | +true |
+- | +
fileName | +file name | +String |
+- | +true |
+- | +
Returns: File
Example:
+base64ToFile(base64, 'image.png')
// File
+
+declare function base64ToFile(input: string, fileName: string): File
+
+blob to arrayBuffer
+Since: 5.13.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
input | +blob data | +Blob |
+- | +true |
+- | +
Returns: ArrayBuffer
Example:
+blobToArrayBuffer(blob).then(data => {
// ArrayBuffer
})
+
+declare function blobToArrayBuffer(input: Blob): Promise<ArrayBuffer | null>
+
+blob to base64
+Since: 5.13.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
input | +blob data | +Blob |
+- | +true |
+- | +
Returns: String
Example:
+blobToBase64(blob).then(data => {
// data:image/png;base64,xxxxxxxxxxxx
})
+
+declare function blobToBase64(input: Blob): Promise<string | null>
+
+blob to url
+Since: 5.13.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
input | +blob data | +Blob |
+- | +true |
+- | +
Returns: Object
Example:
+blobToUrl(blob)
// blob:xxxxxxx
+
+declare function blobToUrl(input: Blob): string
+
+file to base64
+Since: 5.13.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
input | +file data | +File |
+- | +true |
+- | +
Returns: String
Example:
+fileToBase64(file).then(data => {
// data:image/png;base64,xxxxxxxxxxxx
})
+
+declare function fileToBase64(input: File): Promise<string | null>
+
+svg to blob
+Since: 5.13.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
input | +svg string | +String |
+- | +true |
+- | +
Returns: Blob
Example:
+svgToBlob(svg)
// Blob
+
+declare function svgToBlob(input: string): Blob
+
+url to blob
+Since: 5.13.0
Arguments:
+Parameters | +Description | +Type | +Optional | +Required | +Default | +
---|---|---|---|---|---|
input | +url | +String |
+- | +true |
+- | +
Returns: Blob
Example:
+urlToBlob(url).then(blob => {
// Blob
})
+
+declare function urlToBlob(input: string): Promise<Blob | null>
+
+Please open an issue here.
+Readonly
[unscopables]Is an object whose properties have the value 'true' +when they will be absent when used in a 'with' statement.
+Optional
Readonly
[unscopables]?: booleanIs an object whose properties have the value 'true' +when they will be absent when used in a 'with' statement.
+Optional
length?: booleanGets or sets the length of the array. This is a number one higher than the highest index in the array.
+Gets or sets the length of the array. This is a number one higher than the highest index in the array.
+Combines two or more arrays. +This method returns a new array without modifying any existing arrays.
+Rest
...items: ConcatArray<JSONValue>[]Additional arrays and/or items to add to the end of the array.
+Combines two or more arrays. +This method returns a new array without modifying any existing arrays.
+Returns the this object after copying a section of the array identified by start and end +to the same array starting at position target
+If target is negative, it is treated as length+target where length is the +length of the array.
+If start is negative, it is treated as length+start. If end is negative, it +is treated as length+end.
+Optional
end: numberIf not specified, length of the this object is used as its default value.
+Determines whether all the members of an array satisfy the specified test.
+A function that accepts up to three arguments. The every method calls +the predicate function for each element in the array until the predicate returns a value +which is coercible to the Boolean value false, or until the end of the array.
+Optional
thisArg: anyAn object to which the this keyword can refer in the predicate function. +If thisArg is omitted, undefined is used as the this value.
+Determines whether all the members of an array satisfy the specified test.
+A function that accepts up to three arguments. The every method calls +the predicate function for each element in the array until the predicate returns a value +which is coercible to the Boolean value false, or until the end of the array.
+Optional
thisArg: anyAn object to which the this keyword can refer in the predicate function. +If thisArg is omitted, undefined is used as the this value.
+Changes all array elements from start
to end
index to a static value
and returns the modified array
value to fill array section with
+Optional
start: numberindex to start filling the array at. If start is negative, it is treated as +length+start where length is the length of the array.
+Optional
end: numberindex to stop filling the array at. If end is negative, it is treated as +length+end.
+Returns the elements of an array that meet the condition specified in a callback function.
+A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
+Optional
thisArg: anyAn object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
+Returns the elements of an array that meet the condition specified in a callback function.
+A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
+Optional
thisArg: anyAn object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
+Returns the value of the first element in the array where predicate is true, and undefined +otherwise.
+find calls predicate once for each element of the array, in ascending +order, until it finds one where predicate returns true. If such an element is found, find +immediately returns that element value. Otherwise, find returns undefined.
+Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of +predicate. If it is not provided, undefined is used instead.
+Optional
thisArg: anyReturns the index of the first element in the array where predicate is true, and -1 +otherwise.
+find calls predicate once for each element of the array, in ascending +order, until it finds one where predicate returns true. If such an element is found, +findIndex immediately returns that element index. Otherwise, findIndex returns -1.
+Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of +predicate. If it is not provided, undefined is used instead.
+Returns the value of the last element in the array where predicate is true, and undefined +otherwise.
+findLast calls predicate once for each element of the array, in descending +order, until it finds one where predicate returns true. If such an element is found, findLast +immediately returns that element value. Otherwise, findLast returns undefined.
+Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of +predicate. If it is not provided, undefined is used instead.
+Optional
thisArg: anyReturns the index of the last element in the array where predicate is true, and -1 +otherwise.
+findLastIndex calls predicate once for each element of the array, in descending +order, until it finds one where predicate returns true. If such an element is found, +findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
+Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of +predicate. If it is not provided, undefined is used instead.
+Calls a defined callback function on each element of an array. Then, flattens the result into +a new array. +This is identical to a map followed by flat with depth 1.
+A function that accepts up to three arguments. The flatMap method calls the +callback function one time for each element in the array.
+Optional
thisArg: ThisAn object to which the this keyword can refer in the callback function. If +thisArg is omitted, undefined is used as the this value.
+Performs the specified action for each element in an array.
+A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
+Optional
thisArg: anyAn object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
+Determines whether an array includes a certain element, returning true or false as appropriate.
+The element to search for.
+Optional
fromIndex: numberThe position in this array at which to begin searching for searchElement.
+Returns the index of the first occurrence of a value in an array, or -1 if it is not present.
+The value to locate in the array.
+Optional
fromIndex: numberThe array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
+Adds all the elements of an array into a string, separated by the specified separator string.
+Optional
separator: stringA string used to separate one element of the array from the next in the resulting string. If omitted, the array elements are separated with a comma.
+Returns the index of the last occurrence of a specified value in an array, or -1 if it is not present.
+The value to locate in the array.
+Optional
fromIndex: numberThe array index at which to begin searching backward. If fromIndex is omitted, the search starts at the last index in the array.
+Calls a defined callback function on each element of an array, and returns an array that contains the results.
+A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
+Optional
thisArg: anyAn object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
+Appends new elements to the end of an array, and returns the new length of the array.
+Rest
...items: JSONValue[]New elements to add to the array.
+Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
+Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
+A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
+If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
+Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
+Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
+A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
+If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
+Returns a copy of a section of an array. +For both start and end, a negative index can be used to indicate an offset from the end of the array. +For example, -2 refers to the second to last element of the array.
+Optional
start: numberThe beginning index of the specified portion of the array. +If start is undefined, then the slice begins at index 0.
+Optional
end: numberThe end index of the specified portion of the array. This is exclusive of the element at the index 'end'. +If end is undefined, then the slice extends to the end of the array.
+Determines whether the specified callback function returns true for any element of an array.
+A function that accepts up to three arguments. The some method calls +the predicate function for each element in the array until the predicate returns a value +which is coercible to the Boolean value true, or until the end of the array.
+Optional
thisArg: anyAn object to which the this keyword can refer in the predicate function. +If thisArg is omitted, undefined is used as the this value.
+Sorts an array in place. +This method mutates the array and returns a reference to the same array.
+Optional
compareFn: ((a, b) => number)Function used to determine the order of the elements. It is expected to return +a negative value if the first argument is less than the second argument, zero if they're equal, and a positive +value otherwise. If omitted, the elements are sorted in ascending, ASCII character order.
+[11,2,22,1].sort((a, b) => a - b)
+
+Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
+The zero-based location in the array from which to start removing elements.
+Optional
deleteCount: numberThe number of elements to remove.
+An array containing the elements that were deleted.
+Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
+The zero-based location in the array from which to start removing elements.
+The number of elements to remove.
+Rest
...items: JSONValue[]Elements to insert into the array in place of the deleted elements.
+An array containing the elements that were deleted.
+Returns a copy of an array with its elements sorted.
+Optional
compareFn: ((a, b) => number)Function used to determine the order of the elements. It is expected to return +a negative value if the first argument is less than the second argument, zero if they're equal, and a positive +value otherwise. If omitted, the elements are sorted in ascending, ASCII character order.
+[11, 2, 22, 1].toSorted((a, b) => a - b) // [1, 2, 11, 22]
+
+Copies an array and removes elements and, if necessary, inserts new elements in their place. Returns the copied array.
+The zero-based location in the array from which to start removing elements.
+The number of elements to remove.
+Rest
...items: JSONValue[]Elements to insert into the copied array in place of the deleted elements.
+The copied array.
+Copies an array and removes elements while returning the remaining elements.
+The zero-based location in the array from which to start removing elements.
+Optional
deleteCount: numberThe number of elements to remove.
+A copy of the original array with the remaining elements.
+Inserts new elements at the start of an array, and returns the new length of the array.
+Rest
...items: JSONValue[]Elements to insert at the start of the array.
+Copies an array, then overwrites the value at the provided index with the +given value. If the index is negative, then it replaces from the end +of the array.
+The index of the value to overwrite. If the index is +negative, then it replaces from the end of the array.
+The value to write into the copied array.
+The copied array with the updated value.
+Optional
charOptional
lengthOptional
noElimination of confusing characters: oOLl,9gq,Vv,Uu,I1
+Optional
strictThe generated random string must contain each of the listed character types
+Optional
covertOptional
encodeOptional
with(\n promise: PromiseAll
\n): Promise<[E, undefined] | [null, P]>\n\ndeclare function awaitTo \n): Promise<[E, undefined] | [null, [T, ...P]]>\n\nexport declare type PromiseAll = {\n -readonly [K in keyof P]: Promise \n}\n```"
+ },
+ {
+ "kind": "text",
+ "text": "\n\n### Blob arrayBuffer base64 file blobUrl\n\n#### arrayBufferToBase64\n\narrayBuffer to base64\n\n> v5.19.1 remove default params of mime\n\n- Since: "
+ },
+ {
+ "kind": "code",
+ "text": "`5.13.0`"
+ },
+ {
+ "kind": "text",
+ "text": "\n\n- Arguments:\n\n| Parameters | Description | Type | Optional | Required | Default |\n| ---------- | ---------------- | ------------- | -------- | -------- | ------- |\n| input | arrayBuffer data | "
+ },
+ {
+ "kind": "code",
+ "text": "`ArrayBuffer`"
+ },
+ {
+ "kind": "text",
+ "text": " | - | "
+ },
+ {
+ "kind": "code",
+ "text": "`true`"
+ },
+ {
+ "kind": "text",
+ "text": " | - |\n| mime | image mime | "
+ },
+ {
+ "kind": "code",
+ "text": "`String`"
+ },
+ {
+ "kind": "text",
+ "text": " | - | "
+ },
+ {
+ "kind": "code",
+ "text": "`false`"
+ },
+ {
+ "kind": "text",
+ "text": " | - |\n\n- Returns: "
+ },
+ {
+ "kind": "code",
+ "text": "`String`"
+ },
+ {
+ "kind": "text",
+ "text": "\n\n- Example:\n\n"
+ },
+ {
+ "kind": "code",
+ "text": "```ts\narrayBufferToBase64(arrayBuffer, 'image/png')\n// data:image/png;base64,xxxxxxxxxxxx\n\narrayBufferToBase64(arrayBuffer)\n// xxxxxxxxxxxx\n```"
+ },
+ {
+ "kind": "text",
+ "text": "\n\n- Types:\n\n"
+ },
+ {
+ "kind": "code",
+ "text": "```ts\ndeclare function arrayBufferToBase64(input: ArrayBuffer, mime?: string): string\n```"
+ },
+ {
+ "kind": "text",
+ "text": "\n\n#### arrayBufferToBlob\n\narrayBuffer to blob\n\n- Since: "
+ },
+ {
+ "kind": "code",
+ "text": "`5.13.0`"
+ },
+ {
+ "kind": "text",
+ "text": "\n\n- Arguments:\n\n| Parameters | Description | Type | Optional | Required | Default |\n| ---------- | ---------------- | ------------- | -------- | -------- | ----------- |\n| input | arrayBuffer data | "
+ },
+ {
+ "kind": "code",
+ "text": "`ArrayBuffer`"
+ },
+ {
+ "kind": "text",
+ "text": " | - | "
+ },
+ {
+ "kind": "code",
+ "text": "`true`"
+ },
+ {
+ "kind": "text",
+ "text": " | - |\n| mime | image mime | "
+ },
+ {
+ "kind": "code",
+ "text": "`String`"
+ },
+ {
+ "kind": "text",
+ "text": " | - | "
+ },
+ {
+ "kind": "code",
+ "text": "`false`"
+ },
+ {
+ "kind": "text",
+ "text": " | "
+ },
+ {
+ "kind": "code",
+ "text": "`image/png`"
+ },
+ {
+ "kind": "text",
+ "text": " |\n\n- Returns: "
+ },
+ {
+ "kind": "code",
+ "text": "`Blob`"
+ },
+ {
+ "kind": "text",
+ "text": "\n\n- Example:\n\n"
+ },
+ {
+ "kind": "code",
+ "text": "```ts\narrayBufferToBlob(arrayBuffer, 'image/png')\n// Blob\n```"
+ },
+ {
+ "kind": "text",
+ "text": "\n\n- Types:\n\n"
+ },
+ {
+ "kind": "code",
+ "text": "```ts\ndeclare function arrayBufferToBlob(input: ArrayBuffer, mime?: string): Blob\n```"
+ },
+ {
+ "kind": "text",
+ "text": "\n\n#### base64ToArrayBuffer\n\nbase64 to arrayBuffer\n\n- Since: "
+ },
+ {
+ "kind": "code",
+ "text": "`5.13.0`"
+ },
+ {
+ "kind": "text",
+ "text": "\n\n- Arguments:\n\n| Parameters | Description | Type | Optional | Required | Default |\n| ---------- | ------------- | -------- | -------- | -------- | ------- |\n| input | base64 string | "
+ },
+ {
+ "kind": "code",
+ "text": "`String`"
+ },
+ {
+ "kind": "text",
+ "text": " | - | "
+ },
+ {
+ "kind": "code",
+ "text": "`true`"
+ },
+ {
+ "kind": "text",
+ "text": " | - |\n\n- Returns: "
+ },
+ {
+ "kind": "code",
+ "text": "`ArrayBuffer`"
+ },
+ {
+ "kind": "text",
+ "text": "\n\n- Example:\n\n"
+ },
+ {
+ "kind": "code",
+ "text": "```ts\nbase64ToArrayBuffer(base64)\n// ArrayBuffer\n```"
+ },
+ {
+ "kind": "text",
+ "text": "\n\n- Types:\n\n"
+ },
+ {
+ "kind": "code",
+ "text": "```ts\ndeclare function base64ToArrayBuffer(input: string): ArrayBuffer\n```"
+ },
+ {
+ "kind": "text",
+ "text": "\n\n#### base64ToBlob\n\nbase64 to blob\n\n- Since: "
+ },
+ {
+ "kind": "code",
+ "text": "`5.13.0`"
+ },
+ {
+ "kind": "text",
+ "text": "\n\n- Arguments:\n\n| Parameters | Description | Type | Optional | Required | Default |\n| ---------- | ------------- | -------- | -------- | -------- | ------- |\n| input | base64 string | "
+ },
+ {
+ "kind": "code",
+ "text": "`String`"
+ },
+ {
+ "kind": "text",
+ "text": " | - | "
+ },
+ {
+ "kind": "code",
+ "text": "`true`"
+ },
+ {
+ "kind": "text",
+ "text": " | - |\n\n- Returns: "
+ },
+ {
+ "kind": "code",
+ "text": "`Blob`"
+ },
+ {
+ "kind": "text",
+ "text": "\n\n- Example:\n\n"
+ },
+ {
+ "kind": "code",
+ "text": "```ts\nbase64ToBlob(base64)\n// Blob\n```"
+ },
+ {
+ "kind": "text",
+ "text": "\n\n- Types:\n\n"
+ },
+ {
+ "kind": "code",
+ "text": "```ts\ndeclare function base64ToBlob(input: string): Blob\n```"
+ },
+ {
+ "kind": "text",
+ "text": "\n\n#### base64ToFile\n\nbase64 to file\n\n- Since: "
+ },
+ {
+ "kind": "code",
+ "text": "`5.13.0`"
+ },
+ {
+ "kind": "text",
+ "text": "\n\n- Arguments:\n\n| Parameters | Description | Type | Optional | Required | Default |\n| ---------- | ------------- | -------- | -------- | -------- | ------- |\n| input | base64 string | "
+ },
+ {
+ "kind": "code",
+ "text": "`String`"
+ },
+ {
+ "kind": "text",
+ "text": " | - | "
+ },
+ {
+ "kind": "code",
+ "text": "`true`"
+ },
+ {
+ "kind": "text",
+ "text": " | - |\n| fileName | file name | "
+ },
+ {
+ "kind": "code",
+ "text": "`String`"
+ },
+ {
+ "kind": "text",
+ "text": " | - | "
+ },
+ {
+ "kind": "code",
+ "text": "`true`"
+ },
+ {
+ "kind": "text",
+ "text": " | - |\n\n- Returns: "
+ },
+ {
+ "kind": "code",
+ "text": "`File`"
+ },
+ {
+ "kind": "text",
+ "text": "\n\n- Example:\n\n"
+ },
+ {
+ "kind": "code",
+ "text": "```ts\nbase64ToFile(base64, 'image.png')\n// File\n```"
+ },
+ {
+ "kind": "text",
+ "text": "\n\n- Types:\n\n"
+ },
+ {
+ "kind": "code",
+ "text": "```ts\ndeclare function base64ToFile(input: string, fileName: string): File\n```"
+ },
+ {
+ "kind": "text",
+ "text": "\n\n#### blobToArrayBuffer\n\nblob to arrayBuffer\n\n- Since: "
+ },
+ {
+ "kind": "code",
+ "text": "`5.13.0`"
+ },
+ {
+ "kind": "text",
+ "text": "\n\n- Arguments:\n\n| Parameters | Description | Type | Optional | Required | Default |\n| ---------- | ----------- | ------ | -------- | -------- | ------- |\n| input | blob data | "
+ },
+ {
+ "kind": "code",
+ "text": "`Blob`"
+ },
+ {
+ "kind": "text",
+ "text": " | - | "
+ },
+ {
+ "kind": "code",
+ "text": "`true`"
+ },
+ {
+ "kind": "text",
+ "text": " | - |\n\n- Returns: "
+ },
+ {
+ "kind": "code",
+ "text": "`ArrayBuffer`"
+ },
+ {
+ "kind": "text",
+ "text": "\n\n- Example:\n\n"
+ },
+ {
+ "kind": "code",
+ "text": "```ts\nblobToArrayBuffer(blob).then(data => {\n // ArrayBuffer\n})\n```"
+ },
+ {
+ "kind": "text",
+ "text": "\n\n- Types:\n\n"
+ },
+ {
+ "kind": "code",
+ "text": "```ts\ndeclare function blobToArrayBuffer(input: Blob): Promise Converts a comma-separated string of values (CSV) to a 2D array. csv data separator, default ',' the first row is the table header data, default false array 1.0.9 Converts a comma-separated string of values (CSV) to an array of 2D objects. The first line of the string is used as the header line. csv data delimiter, default ',' 1.0.9 Converts an array of objects to a comma-separated value (CSV) string containing only the specified columns. the specified columns delimiter, default ',' 1.0.9 Converts RGB component values to color codes. the 1st value of RGB RGB's 2nd value RGB's 3rd value 1.0.9 Returns true if the provided predicate function returns true for all elements in a set, otherwise it returns false. the target array the judgment method 1.0.9 Returns true if the provided predicate function returns true for at least one element of a set, otherwise it returns false. the target array the judgment method 1.0.9 Get the APP version from navigator.userAgent, support 'x.x.x' & 'x.x.x-tagname.x' app name string|null 5.1.0 arrayBuffer to base64 arrayBuffer image mime, eq: image/png 5.13.0 arrayBuffer to blob arrayBuffer image mime, default: image/png 5.13.0 Converts a two-dimensional array to a comma-separated string of values (CSV). delimiter, default ',' CSV data 1.0.9 Async await wrapper for easy error handling Promise 1.0.0 saqqdy base64 to arrayBuffer base64 string 5.13.0 base64 to blob base64 string 5.13.0 base64 to file base64 string file name 5.13.0 blob to arrayBuffer blob data 5.13.0 blob to base64 blob data 5.13.0 blob to blobUrl blob data 5.13.0 Get the browser name and version ua or any ua like string, may not be passed, default is navigator.userAgent BrowserVersion|null 5.2.0 Converts humped strings to -spaced and all lowercase Dash pattern the string to be converted 1.0.1 Data cleaning methods the object to be cleaned, must be passed the data queue to be cleaned, can be passed as array or object 1.0.2 Remove all attributes of HTML tags pass in the string newString 1.0.1 Removing HTML tags string with html tags newString 1.0.1 The client method returns a browser judgment result: optional, e.g. pass in MicroMessenger to return whether it is the built-in browser of Weixin optional, pass in a custom ua, default takes the browser's navigator.userAgent Will be refactored for the next major release 1.0.1 Version number size comparison, tag version: rc > beta > alpha > other input version compare version 1/0/-1 4.7.0 Whether the array contains the specified element the target array the target to find boolean 2.2.1 copy to clipboard any target 5.0.0 Intercept string, Chinese counts as 2 bytes the string to be intercepted 1.0.1 Converts -spaced and all lowercase Dash patterns to humped strings the string to be converted 1.0.1 base64 decoding the string to be decoded decoded string 1.0.1 Decoding Utf8 decoded string 1.0.1 Delete localStorage name 1.0.2 Delete cookie cookie name 1.0.2 Delete sessionStorage name 1.0.2 debounce & throttle class 1.0.2 Several ways of file downloading: link filename download type 'href','open','download','request' String, number to base64 the string to be encoded 1.0.1 Encoding Utf8 1.0.1 Escaping HTML Special Characters string with html tags 5.5.0 deep copy & merge objects boolean | ExtendData ArrayOneMore 1.0.2 file to base64 file data 5.13.0 Read full IPv6 2.2.2 Generating Browser Fingerprints key string, default: location.host 5.2.0 Intercept the decimal places, do not fill in the missing 0 the number of digits to be processed, required the number of decimal places to keep, default is 2 1.0.2 Get the APP version number app name whether to bring the name ua, may not be passed, default is navigator.appVersion null/true/false please use 'appVersion' instead 1.0.1 Get the length of the text, Chinese counts as 2 bytes string 1.0.1 Get the cache, if the deposited is Object, the retrieved is also Object, no need to convert again cache name 1.0.2 Read cookie by name cookie name 1.0.2 Read all cookies 5.6.0 Get directory form URL parameters pass in the url address It will be refactored and renamed getDirParams in the next major release. 1.0.1 Determine file type based on link suffix file url result 5.11.0 Get the number in the string pass in a string with a number 1.0.1 Get the phone system version system type string Android, iPod, iWatch or iPhone whether to bring the name ua, may not be passed, default takes navigator.appVersion please use 'osVersion' instead 1.0.1 Get array, object property values based on path string target array, object query target, can pass function default value result 2.2.4 Get a single query parameter (behind "#") key name 5.0.0 Get all URL parameters (behind "#") pass in the url string 5.0.0 Get slide to top and bottom return 'top' 'bottom', recommend using limit flow will be removed in the next major release. 1.0.2 Read sessionStorage name 1.0.2 Get the target type target type 1.0.2 Get a single URL parameter (from the "location.search", before "#") key name 5.0.0 Get all URL parameters (from the "location.search", before "#") pass in the url string 5.0.0 Determine if it is an array any target 1.0.2 Determine if dark color mode 5.5.0 Determine if target is Date any target 5.15.0 Whether or not it is a string consisting of numbers the string to be tested will be removed in the next major release. 1.0.1 The presence or absence of the specified function incoming function name 1.0.1 The presence or absence of the specified variable variable name 1.0.1 Determine if target is an object any target 5.0.0 Determine if target is an plain object any target 5.0.0 Determine if target is RegExp any target 5.15.0 Determine if target is an window object any 5.0.0 Dynamic loading of resources, support js, images, css links, css style strings link to the resource, type must be passed when passing in styleString parameters: attrs, props, force Replacing specific data in a template string, support Template string Template data of map function 5.9.0 Dynamic loading of css link resources resource address parameters: attrs, props, force Dynamic loading of image resources resource address parameters: attrs, props, force Dynamic loading of js linked resources resource address parameters: attrs, props, force Dynamic loading of css styles parameters: attrs, props Return the next zIndex value optional, minimum value optional, maximum value 1.0.2 return the next version, Only version types with no more than 3 digits are supported. (Follow the npm version rules) version(like: 1.0.0) optional, version type optional, prerelease id 5.10.0 Open link in new tab (file jump download if browser can't parse) link 1.0.6 Get the system name and version ua or any ua like string, may not be passed, default is navigator.userAgent OsVersion|null 5.1.0 parse url params url string (like: ?key1=value1&key2=value2) Converts a specific string to a corresponding value (Scientific notation, binary, octal and hexadecimal types of data are not converted, like: 0b111, 0o13, 0xFF, 1e3, -1e-2) object 5.0.0 Image preloading images url 5.5.0 Convert an object to a promise like api original object resolver function 5.10.0 punctual setInterval A function to be executed after the timer expires. The time, in milliseconds that the timer should wait before the specified function or code is executed. If this parameter is omitted, a value of 0 is used, meaning execute "immediately", or more accurately, the next event cycle. Additional arguments which are passed through to the function specified by handler. 5.18.0 Generate random hexadecimal colors the minimum value of the random numbers, eg: [10, 10, 10] the maximum value of the random number, eg: [255, 255, 255] 5.5.0 Get a random integer the minimum value of the random number the maximum value of the random number 5.0.0 Generate n random integers that sum to a fixed sum Number of generated integers, default: 1 Sum of generated integers, default: 100 5.4.0 Get a random string the length of the random string that needs to be obtained optional, randomString options 5.0.0 removeEvent removes the event delegate created by addEvent js dom object The type of the event. No need to add on Callback method. 1.0.2 Secure parsing of JSON strings JSON string Whether to convert data, default: true Secure stringify of JSON Object JSON Object Whether to convert data, default: true tree object depth lookup tree object required Query method optional Default subclass name, query name optional Number of lookups, if not passed, query all 5.0.0 Get the cache, if the deposited is Object, the retrieved is also Object, no need to convert again cache name cache data, can be passed directly into Object cache time (seconds) 1.0.2 setCookie method for writing cookies cookie name Set the value to be stored, either as an object or as a string cookie validity default 1 day path, default '/' SameSite, default true 1.0.2 Set array, object property values based on path strings target array, object set target, support function, 'a' | 'a[1].c' 2.7.0 Write sessionStorage name Set the value to be stored, either as an object or as a string the valid time 1.0.2 shuffling algorithm, Reordering arrays or strings arrays or strings new array or string length 5.4.0 Sort Chinese by Chinese phonetic alphabet 5.14.0 Sorter factory function A string with a BCP 47 language tag, or an array of such strings. An object adjusting the output format. 5.14.0 splice url params json object Convert a null value type (null/undefined/) to an empty string, default: false 5.3.0 Block bubbling dom's event object 1.0.2 Block default events dom's event object 1.0.2 svg to blob svg string 5.13.0 Digital thousandths division input number 3.0.0 Remove leading and trailing spaces from strings pass in the string will be removed in the next major release. 1.0.1 Restore HTML Special Characters string 5.5.0 First letter capitalized the string to be converted 1.0.1 url to blob url 5.13.0 Browser-side generation of uuid, using v4 method 1.0.9 waiting for a while waiting time (milliseconds) throw on timeout 5.5.0 windowSize to get the window size 1.0.1 Determine if it is running on the browser side 4.5.0 boolean Determine if it is running on node.js 5.13.0 boolean Collection of common regular expressions It will be refactored and renamed patterns in the next major release. 1.0.1Type alias AnyObject
Type alias ExtendArrayData
Type alias ExtendData
Type alias ExtendObjectData
Type alias JSONValue
Type alias Primitive
Type alias RandomStringCharType
Variable default
CSVToArray: ((data, delimiter?, omitFirstRow?) => string[][]);
CSVToJSON: ((data, delimiter?) => any[]);
JSONToCSV: ((arr, columns, delimiter?) => string);
RGBToHex: ((r, g, b) => string);
addEvent: typeof addEvent;
all: (<T>(arr, fn) => boolean);
any: (<T>(arr, fn) => boolean);
appVersion: {
(appName): string | null;
(appName, ua): string | null;
(appName, ua): string | null;
(appName, ua, ignoreCase): string | null;
};
arrayBufferToBase64: ((input, mime?) => string);
arrayBufferToBlob: ((input, mime?) => Blob);
arrayToCSV: (<T>(arr, delimiter?) => string);
awaitTo: {
<T, E>(promise): Promise<[E, undefined] | [null, T]>;
<P, E>(promise): Promise<[E, undefined] | [null, P]>;
<T, P, E>(promise, ...promises): Promise<[E, undefined] | [null, [T, ...P]]>;
};
base64ToArrayBuffer: ((input) => ArrayBuffer);
base64ToBlob: ((input) => Blob);
base64ToFile: ((input, fileName) => File);
blobToArrayBuffer: ((input) => Promise<ArrayBuffer | null>);
blobToBase64: ((input) => Promise<string | null>);
blobToUrl: ((input) => string);
browserVersion: ((ua?) => BrowserVersion | null);
camel2Dash: ((string) => string);
cleanData: ((data, map, nullFix?) => any);
clearAttr: ((string) => string);
clearHtml: ((string) => string);
client: ((name?, userAgent?) => boolean | {
ANDROID: boolean;
GECKO: boolean;
IE: boolean;
IOS: boolean;
IPAD: boolean;
IPHONE: boolean;
MOBILE: boolean;
OPERA: boolean;
QQ: null | RegExpMatchArray;
QQBROWSER: boolean;
TRIDENT: boolean;
WEBKIT: boolean;
WEIXIN: boolean;
});
clone: (<T>(parent) => T);
compareVersion: ((input, compare) => -1 | 0 | 1);
complement: (<T>(...args) => T[]);
contains: ((arr, item) => boolean);
copy: ((value) => undefined | boolean);
cutCHSString: ((str, len?, hasDot?) => string);
dash2Camel: ((string) => string);
decodeBase64: ((input) => string);
decodeUtf8: ((utftext) => string);
delCache: ((name) => void);
delCookie: ((name) => void);
delSession: ((name) => void);
delay: (() => {
map: any;
destroy(id): void;
register(id, fn, time, boo): void;
});
download: ((url, filename, type?) => void);
encodeBase64: ((input) => string);
encodeUtf8: ((string) => string);
escape: ((string) => string);
extend: {
(target, ...args): ExtendObjectData;
(target, ...args): ExtendObjectData;
(target, ...args): ExtendArrayData;
(target, ...args): ExtendArrayData;
};
fileToBase64: ((input) => Promise<string | null>);
fillIPv6: ((ip) => string);
fingerprint: ((domain?) => null | string);
fixNumber: ((number, n?) => number);
getAppVersion: ((appName, withApp?, userAgent?) => string | boolean | null);
getCHSLength: ((str) => number);
getCache: ((name) => any);
getCookie: ((name) => any);
getCookies: (() => Record<string, string>);
getDirParam: ((url) => DirParamType);
getFileType: ((url) => {
suffix: string;
type: "audio" | "video" | "image" | "other" | "word" | "txt" | "excel" | "pdf" | "ppt" | "zip";
});
getNumber: ((string) => string);
getOsVersion: ((osName, withOS?, userAgent?) => string | boolean | null);
getProperty: {
<T>(target, prop, defaultValue?): any;
<T>(target, prop, defaultValue?): any;
};
getQueryParam: {
(key): string | undefined;
(key, url): string | undefined;
};
getQueryParams: {
(url): Record<string, string>;
(url): Record<string, unknown>;
(url, covert): Record<string, unknown>;
};
getScrollPosition: (() => undefined | "bottom" | "top");
getSession: ((name) => any);
getType: (<T>(target) => "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "window" | "error" | "promise" | "math" | "document" | "navigator" | "global" | "null" | "array" | "date" | "regexp");
getUrlParam: {
(key): string | undefined;
(key, url): string | undefined;
};
getUrlParams: {
(url): Record<string, string>;
(url): Record<string, unknown>;
(url, covert): Record<string, unknown>;
};
inBrowser: boolean;
inNodeJs: boolean;
intersect: (<T>(...args) => T[]);
isArray: ((target) => target is any[]);
isDarkMode: (() => boolean);
isDate: ((target) => target is Date);
isDigitals: ((str) => boolean);
isEqual: (<T, P>(a, b) => boolean);
isExitsFunction: ((name) => boolean);
isExitsVariable: ((name) => boolean);
isIterable: (<T>(target) => target is Iterable<T>);
isObject: ((target) => target is Object);
isPlainObject: ((target) => target is PlainObject);
isRegExp: ((target) => target is RegExp);
isWindow: ((target) => target is Window);
loadSource: ((url, option) => Promise<boolean | string>);
mapTemplate: ((tmp, data) => string);
minus: (<T>(...args) => T[]);
mountCss: ((src, option?) => Promise<boolean>);
mountImg: ((src, option?) => Promise<boolean | string>);
mountJs: ((src, option?) => Promise<boolean>);
mountStyle: ((css, option?) => Promise<boolean>);
nextIndex: ((min?, max?) => number);
nextVersion: ((version, type?, preid?) => string);
openUrl: ((url) => void);
osVersion: ((ua?) => OsVersion | null);
parseUrlParam: ((url, covert?) => Record<string, unknown>);
pattern: {
any: RegExp;
array: RegExp;
arrjson: RegExp;
chinese: RegExp;
email: RegExp;
float: RegExp;
isjson: RegExp;
json: RegExp;
mobile: RegExp;
number: RegExp;
pass: RegExp;
postcode: RegExp;
qq: RegExp;
string: RegExp;
tel: RegExp;
textarea: RegExp;
url: RegExp;
username: RegExp;
};
preloader: {
(images): HTMLImageElement;
(images): Record<string, HTMLImageElement>;
};
promiseFactory: (<T>(original, resolver) => T & PromiseLike<T>);
punctualTimer: {
<TArgs>(handler, delay, args?): void;
<TArgs>(handler, delay, __namedParameters?): void;
};
randomColor: ((min?, max?) => string);
randomNumber: ((min?, max?) => number);
randomNumbers: ((n?, sum?, noZero?) => number[]);
randomString: {
(len?, options?): string;
(len?, options?): string;
};
removeEvent: ((element, type, handler) => void);
safeParse: ((data, covert?) => any);
safeStringify: ((data, covert?) => string);
searchObject: ((tree, expression, keySet, number?) => any[]);
setCache: (<T>(name, value, seconds?) => void);
setCookie: (<T>(name, value, seconds, path?, samesite?) => void);
setProperty: ((target, prop, value) => any);
setSession: (<T>(name, value, seconds?) => void);
shuffle: {
(value, size?): string;
<T>(value, size?): T;
};
sortPinyin: (<T, P>(a, b, options?) => number);
sorter: ((locales?, options?) => (<T, P>(a, b) => number));
spliceUrlParam: (<T>(params, covert?) => string);
stopBubble: ((e) => boolean);
stopDefault: ((e) => boolean);
svgToBlob: ((input) => Blob);
toThousands: ((num) => string);
trim: ((string) => string);
unescape: ((string) => string);
union: (<T>(...args) => T[]);
unique: (<T>(arr) => T[]);
upperFirst: ((string) => string);
urlToBlob: ((input) => Promise<Blob | null>);
uuid: (() => string);
version: string;
waiting: ((milliseconds, throwOnTimeout?) => Promise<void>);
windowSize: (() => WindowSizeObj);
}Type declaration
CSVTo
Parameters
Returns string[][]
Example
+CSVToArray('a,b\\nc,d')
// `[['a','b'],['c','d']]`.
CSVToArray('a;b\\\nc;d', ';')
// `[['a','b'],['c','d']]`.
CSVToArray('col1,col2\\\na,b\\\nc,d', ',', true)
// `[['a','b'],['c','d']]`.
+Since
CSVToJSON: ((data, delimiter?) => any[])
Parameters
Returns any[]
+
+Example
+CSVToJSON('col1,col2\\na,b\\\nc,d')
// `[{'col1': 'a', 'col2': 'b'}, {'col1': 'c', 'col2': 'd'}]`.
CSVToJSON('col1;col2\\\na;b\\\nc;d', ';')
// `[{'col1': 'a', 'col2': 'b'}, {'col1': 'c', 'col2': 'd'}]`.
+Since
JSONToCSV: ((arr, columns, delimiter?) => string)
Parameters
Returns string
+
+Example
+JSONToCSV([{ a: 1, b: 2 }, { a: 3, b: 4, c: 5 }, { a: 6 }, { b: 7 }], ['a', 'b'])
// 'a,b\n "1", "2"\n "3", "4"\n "6",""\n"", "7"'
JSONToCSV([{ a: 1, b: 2 }, { a: 3, b: 4, c: 5 }, { a: 6 }, { b: 7 }], ['a', 'b'], ';')
// 'a;b\n "1"; "2"\n "3"; "4"\n "6";""\n""; "7"'
+Since
RGBTo
Parameters
Returns string
+
+Example
+RGBToHex(255, 165, 1)
// 'ffa501'
+Since
add
all: (<T>(arr, fn) => boolean)
Type Parameters
Parameters
Returns boolean
+
+Example
+all([4, 2, 3], x => x > 1)
// true
+Since
any: (<T>(arr, fn) => boolean)
Type Parameters
Parameters
Returns boolean
+
+Example
+any([0, 1, 2, 0], x => x >= 2)
// true
+Since
app
(appName): string | null;
(appName, ua): string | null;
(appName, ua): string | null;
(appName, ua, ignoreCase): string | null;
}Parameters
Returns string | null
Example
+// navigator.userAgent => '5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 AppName/1.0.0-beta.8'
appVersion('Chrome') // 114.0.0.0
appVersion('Safari') // 537.36
appVersion('appname', false) // null
appVersion('appname') // 1.0.0-beta.8
+Since
Parameters
Returns string | null
Parameters
Returns string | null
Parameters
Returns string | null
array
Parameters
Optional
mime: stringReturns string
+
+Example
+arrayBufferToBase64(arrayBuffer, 'image/png')
// data:image/png;base64,xxxxxxxxxxxx
arrayBufferToBase64(arrayBuffer)
// xxxxxxxxxxxx
+Since
array
Parameters
Returns Blob
+
+Since
array
Type Parameters
Parameters
Returns string
Example
+arrayToCSV([['a', 'b'], ['c', 'd']])
// '"a", "b" \n "c", "d"'
arrayToCSV([['a', 'b'], ['c', 'd']], ';')
// '"a"; "b"\n "c"; "d"'
arrayToCSV([['a', '"b" great'], ['c', 3.1415]])
// '"a", """b"" great"\n "c",3.1415'
+Since
await
<T, E>(promise): Promise<[E, undefined] | [null, T]>;
<P, E>(promise): Promise<[E, undefined] | [null, P]>;
<T, P, E>(promise, ...promises): Promise<[E, undefined] | [null, [T, ...P]]>;
}Type Parameters
Parameters
Returns Promise<[E, undefined] | [null, T]>
+
+Example
+const bar = () => new Promise<boolean>((resolve, reject) => {})
const foo = () => new Promise<string>((resolve, reject) => {})
;(async () => {
const [err, data] = await awaitToDone(bar())
const [err1, data1] = await awaitToDone(bar(), foo())
const [err2, data2] = await awaitToDone([bar(), foo()])
})()
+Since
Author
Type Parameters
Parameters
Returns Promise<[E, undefined] | [null, P]>
Type Parameters
Returns Promise<[E, undefined] | [null, [T, ...P]]>
base64
Parameters
Returns ArrayBuffer
+
+Since
base64
Parameters
Returns Blob
+
+Since
base64
Parameters
Returns File
+
+Since
blob
Parameters
Returns Promise<ArrayBuffer | null>
+
+Since
blob
Parameters
Returns Promise<string | null>
+
+Since
blob
Parameters
Returns string
+
+Since
browser
Parameters
Optional
ua: stringReturns BrowserVersion | null
Example
+// Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) Ap…KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36
browserVersion() // \{ name: 'Chrome', version: '114.0.0.0' \}
+Since
camel2
Parameters
Returns string
+
+Since
clean
Parameters
Optional
nullFix: anyReturns any
+
+Since
clear
Parameters
Returns string
Since
clear
Parameters
Returns string
Since
client: ((name?, userAgent?) => boolean | {
ANDROID: boolean;
GECKO: boolean;
IE: boolean;
IOS: boolean;
IPAD: boolean;
IPHONE: boolean;
MOBILE: boolean;
OPERA: boolean;
QQ: null | RegExpMatchArray;
QQBROWSER: boolean;
TRIDENT: boolean;
WEBKIT: boolean;
WEIXIN: boolean;
})
ANDROID: boolean;
GECKO: boolean;
IE: boolean;
IOS: boolean;
IPAD: boolean;
IPHONE: boolean;
MOBILE: boolean;
OPERA: boolean;
QQ: null | RegExpMatchArray;
QQBROWSER: boolean;
TRIDENT: boolean;
WEBKIT: boolean;
WEIXIN: boolean;
}{ ANDROID: true, GECKO: true, GLSH_APP: false, IE: false, IOS: false, IPAD: false, IPHONE: false, MOBILE: true, MOBILEDEVICE. true, OPERA: false, QQ: false, QQBROWSER: false, TRIDENT: false, WEBKIT: true, WEIXIN: false }
Parameters
Returns boolean | {
ANDROID: boolean;
GECKO: boolean;
IE: boolean;
IOS: boolean;
IPAD: boolean;
IPHONE: boolean;
MOBILE: boolean;
OPERA: boolean;
QQ: null | RegExpMatchArray;
QQBROWSER: boolean;
TRIDENT: boolean;
WEBKIT: boolean;
WEIXIN: boolean;
}
+
+Deprecated
Since
clone: (<T>(parent) => T)
compare
Parameters
Returns -1 | 0 | 1
Example
+compareVersion('1.11.0', '1.9.9')
// => 1: 1=Version 1.11.0 is newer than 1.9.9
compareVersion('1.11.0', '1.11.0')
// => 0: 0=Versions 1.11.0 and 1.11.0 are the same
compareVersion('1.11.0', '1.99.0')
// => -1: -1=Version 1.11.0 is older than 1.99.0
compareVersion('1.0.0.0.0.10', '1.0')
// => -1
// compare tag version: rc > beta > alpha > other
compareVersion('1.11.0', '1.11.0-beta.1')
// => -1
compareVersion('1.11.0-beta.1', '1.11.0')
// => -1
compareVersion('1.11.0-beta.10', '1.11.0-beta.10')
// => 0
compareVersion('1.11.0-alpha.10', '1.11.0-beta.1')
// => -1
compareVersion('1.11.0-alpha.10', '1.11.0-rc.1')
// => -1
compareVersion('1.11.0-tag.10', '1.11.0-alpha.1')
// => -1
compareVersion('1.11.0-tag.10', '1.11.0-tag.1')
// => 1
compareVersion('1.11.0-release.10', '1.11.0-tag.1')
// => 1
+Since
complement: (<T>(...args) => T[])
contains: ((arr, item) => boolean)
Parameters
Returns boolean
Example
+contains([1, 2], 2) // true
contains([1, 2], 3) // false
+Since
copy: ((value) => undefined | boolean)
Parameters
Returns undefined | boolean
+
+Since
cutCHSString: ((str, len?, hasDot?) => string)
Parameters
Returns string
+
+Since
dash2
Parameters
Returns string
+
+Since
decode
Parameters
Returns string
Since
decode
Parameters
Returns string
Since
del
Parameters
Returns void
Since
del
Parameters
Returns void
Since
del
Parameters
Returns void
Since
delay: (() => {
map: any;
destroy(id): void;
register(id, fn, time, boo): void;
})
map: any;
destroy(id): void;
register(id, fn, time, boo): void;
}Returns {
map: any;
destroy(id): void;
register(id, fn, time, boo): void;
}map: any
destroy:function
register:function
Parameters
Returns void
Since
download: ((url, filename, type?) => void)
+
+Parameters
Optional
type: stringReturns void
encode
Parameters
Returns string
+
+Since
encode
Parameters
Returns string
+
+Since
escape: ((string) => string)
Parameters
Returns string
+
+Example
+escape('<div>test<br />string</div>')
// '<div>test<br />string</div>'
+Since
extend: {
(target, ...args): ExtendObjectData;
(target, ...args): ExtendObjectData;
(target, ...args): ExtendArrayData;
(target, ...args): ExtendArrayData;
}Parameters
Rest
...args: ArrayOneMore<ExtendObjectData>Returns ExtendObjectData
Since
Parameters
Rest
...args: ArrayOneMore<ExtendObjectData>Returns ExtendObjectData
Parameters
Rest
...args: ArrayOneMore<ExtendArrayData>Returns ExtendArrayData
Parameters
Rest
...args: ArrayOneMore<ExtendArrayData>Returns ExtendArrayData
file
Parameters
Returns Promise<string | null>
+
+Since
fillIPv6: ((ip) => string)
Parameters
Returns string
+
+Example
+fillIPv6('2409:8005:800::2')
// '2409:8005:0800:0000:0000:0000:0000:0002'
fillIPv6('2409:8005:800::1c')
// '2409:8005:0800:0000:0000:0000:0000:001c'
+Since
fingerprint: ((domain?) => null | string)
Parameters
Optional
domain: stringReturns null | string
+
+Since
fix
Parameters
Returns number
+
+Example
+fixNumber('100.888')
// 100.88
fixNumber('100.8', 2)
// 100.8
fixNumber('100.8888', 3)
// 100.888
+Since
get
Parameters
Optional
withApp: booleanOptional
userAgent: stringReturns string | boolean | null
Deprecated
Since
getCHSLength: ((str) => number)
Parameters
Returns number
+
+Example
+getCHSLength('测试')
// 2
+Since
get
Parameters
Returns any
+
+Example
+const data1 = 100
const data2 = { a: 10 }
const data3 = null
setCache('data1', data1)
setCache('data2', data2)
setCache('data3', data3)
getCache('data1') // 100
getCache('data2') // {a:10}
getCache('data3') // null
getCache('data4') // null
+Since
get
Parameters
Returns any
+
+Example
+getCookie('data1')
// 100
+Since
get
Returns Record<string, string>
+
+Example
+getCookies()
// \{ token: 'xxx', name: 'saqqdy' \}
+Since
get
Parameters
Returns DirParamType
+
+Deprecated
Since
get
suffix: string;
type: "audio" | "video" | "image" | "other" | "word" | "txt" | "excel" | "pdf" | "ppt" | "zip";
})
suffix: string;
type: "audio" | "video" | "image" | "other" | "word" | "txt" | "excel" | "pdf" | "ppt" | "zip";
}Parameters
Returns {
suffix: string;
type: "audio" | "video" | "image" | "other" | "word" | "txt" | "excel" | "pdf" | "ppt" | "zip";
}suffix: string
type: "audio" | "video" | "image" | "other" | "word" | "txt" | "excel" | "pdf" | "ppt" | "zip"
Example
+getFileType('/name.png')
// { "suffix": "png", "type": "image" }
getFileType('/name.PDF')
// { "suffix": "pdf", "type": "pdf" }
getFileType('/name.xyz')
// { "suffix": "xyz", "type": "other" }
+Since
get
Parameters
Returns string
+
+Example
+getNumber('Chrome123.33')
// '123.33'.
getNumber('234test.88')
// '234.88'.
+Since
get
Parameters
Optional
withOS: booleanOptional
userAgent: stringReturns string | boolean | null
+
+Example
+getOsVersion('iPhone')
// '13.2.3'
getOsVersion('iPhone', true)
// 'iPhone/13.2.3'
+Deprecated
Since
get
<T>(target, prop, defaultValue?): any;
<T>(target, prop, defaultValue?): any;
}Type Parameters
Parameters
Optional
defaultValue: anyReturns any
Example
+const target = {
a: 1,
b: [{
c: 2
d: NaN
}]
}
getProperty(target, 'a') // 1
getProperty(target, 'd', 100) // 100
getProperty(target, 'b[0].c') // 2
getProperty(target, 'b[0].d', 100) // 100
getProperty(target, () => 'a') // 1
+Since
Type Parameters
Parameters
Optional
defaultValue: anyReturns any
get
(key): string | undefined;
(key, url): string | undefined;
}Parameters
Returns string | undefined
+
+Example
+getQueryParam('key1')
// key1 => xxx
getQueryParam('key1', 'https://test.com?key1=100#/home?key1=200')
// key1 => 200
+Since
Parameters
Returns string | undefined
get
(url): Record<string, string>;
(url): Record<string, unknown>;
(url, covert): Record<string, unknown>;
}Parameters
Returns Record<string, string>
+
+Example
+getQueryParams('https://test.com?key1=100#/home?key1=200')
// \{"key1":"200"\}
getQueryParams('https://test.com?key1=100#/home?key1=200', true)
// \{"key1":200\}
getQueryParams(true)
// \{"key1":200\}
+Since
Parameters
Returns Record<string, unknown>
Parameters
Returns Record<string, unknown>
get
Returns undefined | "bottom" | "top"
+
+Deprecated
Since
get
Parameters
Returns any
+
+Example
+const data1 = 100
const data2 = { a: 10 }
const data3 = null
setSession('data1', data1)
setSession('data2', data2)
setSession('data3', data3)
getSession('data1') // 100
getSession('data2') // {a:10}
getSession('data3') // null
getSession('data4') // null
+Since
get
Type Parameters
Parameters
Returns "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "window" | "error" | "promise" | "math" | "document" | "navigator" | "global" | "null" | "array" | "date" | "regexp"
Since
get
(key): string | undefined;
(key, url): string | undefined;
}Parameters
Returns string | undefined
+
+Example
+getUrlParam('key1')
// key1 => xxx
getUrlParam('key1', 'https://test.com?key1=100#/home?key1=200')
// key1 => 100
+Since
Parameters
Returns string | undefined
get
(url): Record<string, string>;
(url): Record<string, unknown>;
(url, covert): Record<string, unknown>;
}Parameters
Returns Record<string, string>
+
+Example
+getUrlParams('https://test.com?key1=100#/home?key1=200')
// \{"key1":"100"\}
getUrlParams('https://test.com?key1=100#/home?key1=200', true)
// \{"key1":100\}
getUrlParams(true)
// \{"key1":100\}
+Since
Parameters
Returns Record<string, unknown>
Parameters
Returns Record<string, unknown>
in
in
intersect: (<T>(...args) => T[])
is
Parameters
Returns target is any[]
+
+Example
+isArray([]) // true
+
Since
is
Returns boolean
+
+Example
+isDarkMode() // true
+
Since
is
Parameters
Returns target is Date
+
+Example
+const now = new Date()
isDate(now)
// true
+Since
is
Parameters
Returns boolean
+
+Deprecated
Since
is
is
Parameters
Returns boolean
+
+Example
+isExitsFunction('test') // false
isExitsFunction('console.log') // true
+Since
is
Parameters
Returns boolean
+
+Example
+isExitsVariable('test') // false
isExitsVariable('window') // true
+Since
is
is
Parameters
Returns target is Object
+
+Example
+isObject({}) // true
+
Since
is
Parameters
Returns target is PlainObject
+
+Example
+isPlainObject({}) // true
isPlainObject(window) // false
+Since
is
Parameters
Returns target is RegExp
+
+Example
+isRegExp(/\d/) // true
+
Since
is
Parameters
Returns target is Window
+
+Example
+isWindow({}) // false
isWindow(window) // true
+Since
load
Parameters
Returns Promise<boolean | string>
+
+map
${xxxx}
{{xxxx}}
and {xxxx}
Parameters
Returns string
+
+Example
+const tmp = "My name is ${name}, I'm ${age} years old."
mapTemplate(tmp, {
name: 'saqqdy',
age: 18
})
// My name is saqqdy, I'm 18 years old.
mapTemplate(tmp, key => ({ name: 'saqqdy', age: 28 }[key]))
// My name is saqqdy, I'm 28 years old.
const tmp = "My name is {{name}}, I'm {{age}} years old."
mapTemplate(tmp, {
name: 'saqqdy',
age: 18
})
// My name is saqqdy, I'm 18 years old.
+Since
minus: (<T>(...args) => T[])
mount
Parameters
Optional
option: CssOptionsReturns Promise<boolean>
+
+mount
Parameters
Optional
option: ImgOptionsReturns Promise<boolean | string>
+
+mount
Parameters
Optional
option: JsOptionsReturns Promise<boolean>
+
+mount
Parameters
Optional
option: StyleOptionsReturns Promise<boolean>
+
+next
Parameters
Returns number
+
+Example
+nextIndex()
// 1
nextIndex(1000)
// 1001
nextIndex(10, 100)
// 100
+Since
next
Parameters
Optional
type: "major" | "minor" | "patch" | "premajor" | "preminor" | "prepatch" | "prerelease"Returns string
+
+Example
+nextVersion('1.2.33') // 1.2.34
nextVersion('1.2.33', 'major') // 2.0.0
nextVersion('1.2.33', 'premajor', 'alpha') // 2.0.0-alpha.1
+Since
open
Parameters
Returns void
Since
os
Parameters
Optional
ua: stringReturns OsVersion | null
Example
+// ipad => 'Mozilla/5.0 (iPad; CPU OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/87.0.4280.77 Mobile/15E148 Safari/604.1'
osVersion() // \{ name: 'iOS', version: '13.3' \}
// iphone => 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1'
osVersion() // \{ name: 'iOS', version: '13.2.3' \}
// mac os => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'
osVersion() // \{ name: 'MacOS', version: '10.15.7' \}
// windows => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'
osVersion() // \{ name: 'Windows', version: '10.0' \}
// windows xp => 'Mozilla/5.0 (Windows NT 5.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'
osVersion() // \{ name: 'Windows', version: 'XP' \}
// windows phone => 'Mozilla/5.0 (Windows Phone OS 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36'
osVersion() // \{ name: 'WindowsPhone', version: '10.0' \}
+Since
parse
Parameters
Returns Record<string, unknown>
Example
+parseUrlParam('?key1=100&key2=true&key3=null&key4=undefined&key5=NaN&key6=10.888&key7=Infinity&key8=test')
// \{"key1":"100","key2":"true","key3":"null","key4":"undefined","key5":"NaN","key6":"10.888","key7":"Infinity","key8":"test"\}
parseUrlParam('?key1=100&key2=true&key3=null&key4=undefined&key5=NaN&key6=10.888&key7=Infinity&key8=test', true)
// \{"key1":100,"key2":true,"key3":null,"key5":NaN,"key6":10.888,"key7":Infinity,"key8":"test"\}
+Since
pattern: {
any: RegExp;
array: RegExp;
arrjson: RegExp;
chinese: RegExp;
email: RegExp;
float: RegExp;
isjson: RegExp;
json: RegExp;
mobile: RegExp;
number: RegExp;
pass: RegExp;
postcode: RegExp;
qq: RegExp;
string: RegExp;
tel: RegExp;
textarea: RegExp;
url: RegExp;
username: RegExp;
}any: RegExp
array: RegExp
arrjson: RegExp
chinese: RegExp
email: RegExp
float: RegExp
isjson: RegExp
json: RegExp
mobile: RegExp
number: RegExp
pass: RegExp
postcode: RegExp
qq: RegExp
string: RegExp
tel: RegExp
textarea: RegExp
url: RegExp
username: RegExp
preloader: {
(images): HTMLImageElement;
(images): Record<string, HTMLImageElement>;
}Parameters
Returns HTMLImageElement
Since
Parameters
Returns Record<string, HTMLImageElement>
promise
Type Parameters
Parameters
Returns Promise<any>
Returns T & PromiseLike<T>
+
+Example
+import { promiseFactory, waiting } from 'js-cool'
function promise() {
const stats = {
value: 100
}
const resolver = () =>
new Promise(resolve =>
waiting(2000).then(() => {
stats.value = 200
resolve(stats)
})
)
return promiseFactory(stats, resolver)
}
const res = promise() // res => 100
const res = await promise() // res => 200
+Since
punctual
<TArgs>(handler, delay, args?): void;
<TArgs>(handler, delay, __namedParameters?): void;
}Type Parameters
Parameters
Parameters
Returns void
Optional
args: TArgsReturns void
Example
+const printDate = () => console.log(new Date())
punctualTimer(printDate, 1000)
+Since
Type Parameters
Parameters
Returns void
random
Parameters
Optional
min: number | [number, number, number]Optional
max: number | [number, number, number]Returns string
+
+Example
+randomColor()
// #bf444b
randomColor(200)
// #d6e9d7
randomColor(200, 255)
// #d3f9e4
randomColor([0, 0, 0], [255, 255, 255])
// #d6e9d7
+Since
random
Parameters
Returns number
+
+Example
+randomNumber()
// 8
randomNumber(0.1, 0.9)
// 0.8
+Since
random
Parameters
Optional
n: numberOptional
sum: numberOptional
noZero: booleanReturns number[]
+
+Example
+randomNumbers()
// [8]
randomNumbers(4, 5)
// [1, 1, 2, 1]
randomNumbers(4, 5, false)
// [0, 1, 2, 2]
+Since
random
(len?, options?): string;
(len?, options?): string;
}Parameters
Optional
len: numberOptional
options: boolean | RandomStringOptionsReturns string
+
+Example
+// 1. No parameters are passed, a 32-bit (possibly) string containing upper and lower case letters and numbers is generated by default
randomString()
// PVSjz902EqYbmxaLtvDnggtnlvt5uFTZ
// 2. Generate a 16-bit random string
randomString(16)
// coTgZy0mqqMJ1sMM
// 3. Same effect as #2 above
randomString({
length: 16
})
// ngCI5aPqJm84t90d
// 4. Generate containing special characters (old way of passing values, not recommended)
randomString(true)
// 0Uby@op3B-sK5]dHl4S|15As.OlHiNXd
// 5. Same effect as #4 above (recommended)
randomString({
charTypes: ['uppercase', 'lowercase', 'number', 'special']
})
// m,2^vpkrE,F,DbcSFk0=vr&@DJ27j9XK
// 6. Same effect as #4 above, Limit string length to 16 bits
randomString(16, true)
// dXz[J_sYM^3d8fnA
// 7. Generate a 16-bit random number
randomString({
length: 16,
charTypes: 'number'
})
// 7450026301030286
// 8. Elimination of confusing characters: oOLl,9gq,Vv,Uu,I1
randomString({
length: 16,
noConfuse: true
})
// 8DEGna8ppC4mqyew
// 9. The generated random string must contain at least 1 character of each type of character specified, e.g. to generate a 16-bit password that must contain upper and lower case letters, numbers, and special characters.
randomString({
length: 16,
strict: true
})
// PFYAPD5KFqOHIADL
+Since
Parameters
Optional
len: boolean | RandomStringOptionsOptional
options: boolean | RandomStringOptionsReturns string
remove
Parameters
Returns void
Since
safe
Parameters
Returns any
+
+Example
+safeParse('100')
// 100
safeParse('{"a":"undefined","b":"NaN","c":"Infinity","d":"9007199254740993"}')
// { b: NaN, c: Infinity, d: 9007199254740993n }
+safe
Parameters
Returns string
+
+Example
+safeStringify(100)
// "100"
safeStringify(undefined)
// "undefined"
safeStringify(NaN)
// "NaN"
safeStringify(Infinity)
// "Infinity"
safeStringify({ a: undefined, b: NaN, c: Infinity, d: BigInt(Number.MAX_SAFE_INTEGER) + 2n })
// {"a":"undefined","b":"NaN","c":"Infinity","d":"9007199254740993"}
+search
Parameters
Returns any[]
+
+Since
set
Type Parameters
Parameters
Optional
seconds: string | numberReturns void
Example
+// set boolean
setCache('boolean', true)
// set object
setCache('object', { name: 'saqqdy' })
// set number, expires in 20 seconds
setCache('number', 666, 20)
+Since
set
Type Parameters
Parameters
Returns void
Example
+// expires in 86400 seconds
setCookie('token', 'xxxxxx')
// set to path
setCookie('token', 'xxxxxx', 20, '/app')
// enable samesite
setCookie('number', 666, 20, '/', false)
+Since
set
Parameters
Returns any
+
+Example
+const target = {
a: 1,
b: [{
c: 2
}]
}
setProperty(target, 'a', 2)
setProperty(target, 'b[0].c', 3)
setProperty(target, () => 'a', 100)
+Since
set
Type Parameters
Parameters
Optional
seconds: string | numberReturns void
Example
+// set boolean
setSession('boolean', true)
// set object
setSession('object', { name: 'saqqdy' })
// set number, expires in 20 seconds
setSession('number', 666, 20)
+Since
shuffle: {
(value, size?): string;
<T>(value, size?): T;
}Parameters
Optional
size: numberReturns string
+
+Example
+const str = 'abcde'
const arr = [1,2,3]
shuffle(str)
// cdbse
shuffle(arr)
// [3, 1, 2]
shuffle(arr, 2)
// [3, 2]
+Since
Type Parameters
Parameters
Optional
size: numberReturns T
sort
Type Parameters
Parameters
Returns number
+
+Example
+const items = ['啊我', '波拉', 'abc', 0, 3, '10', ',11', 13, null, '阿吧', 'ABB', 'BDD', 'ACD', 'ä']
items.sort(sortPinyin)
// [ ",11", 0, "10", 13, 3, "ä", "ABB", "abc", "ACD", "BDD", null, "阿吧", "啊我", "波拉" ]
items.sort((a, b) => sortPinyin(a, b, { ignorePunctuation: true, numeric:true }))
// [ 0, 3, "10", ",11", 13, "ä", "ABB", "abc", "ACD", "BDD", null, "阿吧", "啊我", "波拉" ]
+Since
sorter: ((locales?, options?) => (<T, P>(a, b) => number))
Parameters
Optional
locales: string | string[]Optional
options: CollatorOptionsReturns (<T, P>(a, b) => number)
+
+Example
+const items = ['啊我', '波拉', 'abc', 0, 3, '10', ',11', 13, null, '阿吧', 'ABB', 'BDD', 'ACD', 'ä']
items.sort(
sorter('zh-Hans-CN', {
ignorePunctuation: true,
sensitivity: 'variant',
numeric: true
})
)
// [ 0, 3, "10", ",11", 13, "ä", "ABB", "abc", "ACD", "BDD", null, "阿吧", "啊我", "波拉" ]
+Since
splice
Type Parameters
Parameters
Returns string
+
+Example
+spliceUrlParam('\{"key1":"100","key2":true,"key3":null,"key4":undefined,"key5":"测试"\}')
// ?key1=100&key2=true&key3=null&key4=undefined&key5=测试
spliceUrlParam('\{"key1":"100","key2":true,"key3":null,"key4":undefined\}', true)
// ?key1=100&key2=true&key3=&key4=
spliceUrlParam('\{"key1":"100","key2":true,"key3":null,"key4":undefined\}', true, false)
// key1=100&key2=true&key3=&key4=
+Since
stop
Parameters
Returns boolean
+
+Since
stop
Parameters
Returns boolean
+
+Since
svg
Parameters
Returns Blob
+
+Since
to
Parameters
Returns string
+
+Example
+toThousands(10000000222)
// 10,000,000,222
toThousands(100.2232323)
// 100.2232323
toThousands(null)
// ''
+Since
trim: ((string) => string)
Parameters
Returns string
+
+Deprecated
Since
unescape: ((string) => string)
Parameters
Returns string
+
+Example
+unescape('<div>test<br />string</div>')
// '<div>test<br />string</div>'
+Since
union: (<T>(...args) => T[])
unique: (<T>(arr) => T[])
upper
Parameters
Returns string
+
+Example
+upperFirst('saqqdy') // Saqqdy
+
Since
url
Parameters
Returns Promise<Blob | null>
+
+Since
uuid: (() => string)
Returns string
+
+Example
+uuid() // '4222fcfe-5721-4632-bede-6043885be57d'
+
Since
version: string
waiting: ((milliseconds, throwOnTimeout?) => Promise<void>)
Parameters
Returns Promise<void>
Since
window
Returns WindowSizeObj
+
+Example
+windowSize() // { width: 1280, height: 800 }
+
Since
Variable inBrowser
Const
Since
Returns
Variable inNodeJs
Const
Since
Returns
Variable pattern
Const
any: RegExp;
array: RegExp;
arrjson: RegExp;
chinese: RegExp;
email: RegExp;
float: RegExp;
isjson: RegExp;
json: RegExp;
mobile: RegExp;
number: RegExp;
pass: RegExp;
postcode: RegExp;
qq: RegExp;
string: RegExp;
tel: RegExp;
textarea: RegExp;
url: RegExp;
username: RegExp;
} = ...Type declaration
any: RegExp
array: RegExp
arrjson: RegExp
chinese: RegExp
email: RegExp
float: RegExp
isjson: RegExp
json: RegExp
mobile: RegExp
number: RegExp
pass: RegExp
postcode: RegExp
qq: RegExp
string: RegExp
tel: RegExp
textarea: RegExp
url: RegExp
username: RegExp
Deprecated
Since
Returns
+
+Variable version
Const
Converts a comma-separated string of values (CSV) to a 2D array.
+