This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 判断设备是否为 Android,包含**桌面模式** | |
* | |
* @see https://useragentstring.com/ ua 检测 | |
* | |
* @returns | |
*/ | |
function isAndroid() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function throttle(func, threshold) { | |
let start = Date.now(), timer; | |
return function (...args) { | |
const ctx = this, curr = Date.now(); | |
clearTimeout(timer); | |
if (curr - start >= threshold) { | |
func.apply(ctx, args); | |
start = curr; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
1. T extends (...args: any) => any 为约束条件,约束 T 的类型为 `(...args: any) => any` | |
2. T extends (...args: any) => infer R ? R : any 取值,如果 `T extends (...args: any) => R` 那么返回值为 `R` 否则为 `any` | |
``` | |
type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any; | |
``` | |
如果 T 是Promise 返回值为 `U` 否则 为 `never` | |
``` | |
type PromiseType<T> = T extends Promise<infer U> ? U : never; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function encode(id) { | |
return ('' + parseInt(id) * 71) | |
.split('') | |
.map(v => parseInt(v) + 65) | |
.map(code => String.fromCharCode(code)) | |
.join(''); | |
} | |
function decode(code) { | |
return parseInt(code.split('').map(char => char.charCodeAt(0) - 65).join('')) / 71; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function escape(col) { | |
return '"' + col.replace(/"/g, '""') + '"'; | |
} | |
const utf8BOM = '\ufeff'; | |
const csvData = `姓名,年龄 | |
小 明,10 | |
小红, 10 | |
小李 ,8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var importScript = (function (oBody) { | |
return function (sSrc, fOnload) { | |
var oScript = document.createElement('script'); | |
oScript.type = 'text\/javascript'; | |
if (typeof fOnload === 'function') { | |
oScript.onerror = function (evt) { | |
fOnload(new URIError('The script ' + evt.target.src + ' is not accessible.')); | |
}; | |
oScript.onload = function () { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function promisify(fn) { | |
return (...args) => { | |
return new Promise((resolve, reject) => { | |
fn(...args, (err, ...vals) => { | |
if (err) return reject(err); | |
resolve(...vals); | |
}); | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"lastUpload":"2021-07-21T07:48:58.873Z","extensionVersion":"v3.4.3"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function get(obj, fields) { | |
if (!obj) return; | |
return fields.split('.') | |
.reduce((obj, key) => obj[key], obj); | |
} | |
function set(obj, fields, val) { | |
if (!obj) return; |
NewerOlder